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@565: package de.intevation.lada.validation.rules.messung; raimund@565: raimund@565: import java.util.List; raimund@565: raimund@565: import javax.inject.Inject; raimund@565: raimund@565: import de.intevation.lada.model.land.LMessung; raimund@565: import de.intevation.lada.model.land.LMesswert; raimund@565: import de.intevation.lada.util.annotation.RepositoryConfig; raimund@565: import de.intevation.lada.util.data.QueryBuilder; raimund@565: import de.intevation.lada.util.data.Repository; raimund@565: import de.intevation.lada.util.data.RepositoryType; raimund@565: import de.intevation.lada.util.rest.Response; raimund@565: import de.intevation.lada.validation.Violation; raimund@565: import de.intevation.lada.validation.annotation.ValidationRule; raimund@565: import de.intevation.lada.validation.rules.Rule; raimund@565: raimund@711: /** raimund@711: * Validation rule for messungen. raimund@711: * Validates if the messung has messwerte. raimund@711: * raimund@711: * @author Raimund Renkert raimund@711: */ raimund@565: @ValidationRule("Messung") raimund@565: public class HasMesswert implements Rule { raimund@565: raimund@565: @Inject raimund@565: @RepositoryConfig(type=RepositoryType.RO) raimund@565: private Repository repo; raimund@565: raimund@565: @Override raimund@565: public Violation execute(Object object) { raimund@565: LMessung messung = (LMessung)object; raimund@565: QueryBuilder builder = raimund@565: new QueryBuilder( raimund@565: repo.entityManager("land"), LMesswert.class); raimund@565: builder.and("messungsId", messung.getId()); raimund@565: Response response = repo.filter(builder.getQuery(), "land"); raimund@565: @SuppressWarnings("unchecked") raimund@565: List messwerte = (List)response.getData(); raimund@565: if (messwerte == null || messwerte.isEmpty()) { raimund@565: Violation violation = new Violation(); raimund@565: violation.addWarning("messwert", 631); raimund@565: return violation; raimund@565: } raimund@565: return null; raimund@565: } raimund@565: }