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: raimund@647: import de.intevation.lada.model.land.LMessung; raimund@647: import de.intevation.lada.model.land.LProbe; 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) { raimund@647: LMessung messung = (LMessung)object; raimund@647: Integer probeId = messung.getProbeId(); raimund@647: Response response = repository.getById(LProbe.class, probeId, "land"); raimund@677: LProbe probe = (LProbe) response.getData(); raimund@677: if (probe == null) { raimund@647: Map errors = new HashMap(); raimund@647: errors.put("lprobe", 604); raimund@647: } raimund@647: if (probe.getProbeentnahmeEnde() == null || raimund@647: probe.getProbeentnahmeEnde().after(messung.getMesszeitpunkt())) { raimund@647: Violation violation = new Violation(); raimund@677: violation.addWarning("messzeitpunkt", 632); raimund@647: return violation; raimund@647: } raimund@647: return null; raimund@647: } raimund@647: }