Skip to content
Snippets Groups Projects
Commit 39bd2398 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Making sure the model handles no observations without throwing an error

parent a4741a27
No related branches found
No related tags found
No related merge requests found
......@@ -247,10 +247,6 @@ public class PsilaRosaeObservationModel extends I18nImpl implements Model{
public void setConfiguration(ModelConfiguration config) throws ConfigValidationException {
this.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.pestObservations = this.getObjectMapper().convertValue(config.getConfigParameter("pestObservations"), new TypeReference<List<ObservationImpl>>(){});
if(this.pestObservations == null || this.pestObservations.isEmpty())
{
throw new ConfigValidationException("ERROR: No observations");
}
Collections.sort(this.pestObservations);
// Setting timezone
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
......@@ -292,6 +288,10 @@ public class PsilaRosaeObservationModel extends I18nImpl implements Model{
}
public Observation getObservationAtDate(Date currentDate) {
if(this.pestObservations == null || this.pestObservations.isEmpty())
{
return null;
}
for(Observation obs:this.pestObservations)
{
if(this.weatherUtil.normalizeToExactDate(obs.getTimeOfObservation(), timeZone).compareTo(currentDate) == 0)
......@@ -321,6 +321,10 @@ public class PsilaRosaeObservationModel extends I18nImpl implements Model{
}
public Observation getObservationValidForDate(Date currentDate) {
if(this.pestObservations == null || this.pestObservations.isEmpty())
{
return null;
}
Long currentTime = currentDate.getTime();
Observation currentObservation = null;
for(Observation obs:this.pestObservations)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment