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

Making sure the model handles no observations without throwing an error

parent 840f69ea
No related branches found
No related tags found
No related merge requests found
...@@ -261,10 +261,6 @@ public class DeliaRadicumFloralisObservationModel extends I18nImpl implements Mo ...@@ -261,10 +261,6 @@ public class DeliaRadicumFloralisObservationModel extends I18nImpl implements Mo
public void setConfiguration(ModelConfiguration config) throws ConfigValidationException { public void setConfiguration(ModelConfiguration config) throws ConfigValidationException {
this.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); this.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.pestObservations = this.getObjectMapper().convertValue(config.getConfigParameter("pestObservations"), new TypeReference<List<ObservationImpl>>(){}); 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); Collections.sort(this.pestObservations);
// Setting timezone // Setting timezone
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone")); this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
...@@ -314,6 +310,10 @@ public class DeliaRadicumFloralisObservationModel extends I18nImpl implements Mo ...@@ -314,6 +310,10 @@ public class DeliaRadicumFloralisObservationModel extends I18nImpl implements Mo
} }
public Observation getObservationValidForDate(Date currentDate) { public Observation getObservationValidForDate(Date currentDate) {
if(this.pestObservations == null || this.pestObservations.isEmpty())
{
return null;
}
Long currentTime = currentDate.getTime(); Long currentTime = currentDate.getTime();
Observation currentObservation = null; Observation currentObservation = null;
for(Observation obs:this.pestObservations) 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