public static Observation addObservationToPeriod(Observation observation, Period[] periodRef, NFPControler controler) throws RecordStoreException, IOException {
Log.log("SaveObservationModel.addObservationToPeriod("+observation+","+periodRef[0]);
final PeriodDAO periodDAO = controler.getPeriodDAO();
final ObservationDAO observationDAO = controler.getObservationDAO();
Period period = periodRef[0];
if(period.getStart() == null) {
period.setStart(observation.getDate());
period.setEnd(observation.getDate());
}else{
if (observation.getDate().getTime() < period.getStart().getTime())
period.setStart(observation.getDate());
if (observation.getDate().getTime() > period.getEnd().getTime())
period.setEnd(observation.getDate());
if (Utils.getDaysBetween(period.getStart(), period.getEnd()) > SaveObservationModel.MAX_PERIOD_DAYS)
throw new IllegalArgumentException("${period.days.exceded} " + SaveObservationModel.MAX_PERIOD_DAYS);
}
period = periodDAO.persist(period);
observation = observationDAO.persist(observation);
Vector observationIds = periodDAO.getObservationIds(period);