raimund@711: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
raimund@711: * Software engineering by Intevation GmbH
raimund@711: *
raimund@711: * This file is Free Software under the GNU GPL (v>=3)
raimund@711: * and comes with ABSOLUTELY NO WARRANTY! Check out
raimund@711: * the documentation coming with IMIS-Labordaten-Application for details.
raimund@711: */
raimund@647: package de.intevation.lada.validation.rules.messung;
raimund@647:
raimund@647: import java.util.HashMap;
raimund@647: import java.util.Map;
raimund@647:
raimund@647: import javax.inject.Inject;
raimund@647:
tom@1097: import de.intevation.lada.model.land.Messung;
tom@1097: import de.intevation.lada.model.land.Probe;
raimund@647: import de.intevation.lada.util.annotation.RepositoryConfig;
raimund@647: import de.intevation.lada.util.data.Repository;
raimund@647: import de.intevation.lada.util.data.RepositoryType;
raimund@647: import de.intevation.lada.util.rest.Response;
raimund@647: import de.intevation.lada.validation.Violation;
raimund@647: import de.intevation.lada.validation.annotation.ValidationRule;
raimund@647: import de.intevation.lada.validation.rules.Rule;
raimund@647:
raimund@711: /**
raimund@711: * Validation rule for messungen.
raimund@711: * Validates if the "messzeitpunkt" is before or after the
raimund@711: * "probeentnahmebeginn"
raimund@711: *
raimund@711: * @author Raimund Renkert
raimund@711: */
raimund@647: @ValidationRule("Messung")
raimund@647: public class Date implements Rule {
raimund@647:
raimund@647: @Inject
raimund@647: @RepositoryConfig(type=RepositoryType.RO)
raimund@647: private Repository repository;
raimund@647:
raimund@647: @Override
raimund@647: public Violation execute(Object object) {
tom@1097: Messung messung = (Messung)object;
raimund@647: Integer probeId = messung.getProbeId();
tom@1097: Response response = repository.getById(Probe.class, probeId, "land");
tom@1097: Probe probe = (Probe) response.getData();
raimund@677: if (probe == null) {
raimund@647: Map errors = new HashMap();
raimund@647: errors.put("lprobe", 604);
raimund@647: }
tom@1316: if (messung.getMesszeitpunkt() != null) {
tom@1316: if (probe.getProbeentnahmeEnde() == null ||
tom@1316: probe.getProbeentnahmeEnde().after(messung.getMesszeitpunkt())) {
tom@1316: Violation violation = new Violation();
tom@1316: violation.addWarning("messzeitpunkt", 632);
tom@1316: return violation;
tom@1316: }
raimund@647: }
raimund@647: return null;
raimund@647: }
raimund@647: }