Mercurial > lada > lada-server
view src/main/java/de/intevation/lada/validation/rules/messung/HasMesswert.java @ 1345:883ab3a6f525 tip
changed version to 2.7-SNAPSHOT after release2.6.2 for default branch
author | Marco Lechner, Bundesamt fuer Strahlenschutz, SW 2.1 <mlechner@bfs.de> |
---|---|
date | Fri, 07 Apr 2017 11:14:37 +0200 |
parents | 186d602e031a |
children |
line wrap: on
line source
/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz * Software engineering by Intevation GmbH * * This file is Free Software under the GNU GPL (v>=3) * and comes with ABSOLUTELY NO WARRANTY! Check out * the documentation coming with IMIS-Labordaten-Application for details. */ package de.intevation.lada.validation.rules.messung; import java.util.List; import javax.inject.Inject; import de.intevation.lada.model.land.Messung; import de.intevation.lada.model.land.Messwert; import de.intevation.lada.util.annotation.RepositoryConfig; import de.intevation.lada.util.data.QueryBuilder; import de.intevation.lada.util.data.Repository; import de.intevation.lada.util.data.RepositoryType; import de.intevation.lada.util.rest.Response; import de.intevation.lada.validation.Violation; import de.intevation.lada.validation.annotation.ValidationRule; import de.intevation.lada.validation.rules.Rule; /** * Validation rule for messungen. * Validates if the messung has messwerte. * * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> */ @ValidationRule("Messung") public class HasMesswert implements Rule { @Inject @RepositoryConfig(type=RepositoryType.RO) private Repository repo; @Override public Violation execute(Object object) { Messung messung = (Messung)object; QueryBuilder<Messwert> builder = new QueryBuilder<Messwert>( repo.entityManager("land"), Messwert.class); builder.and("messungsId", messung.getId()); Response response = repo.filter(builder.getQuery(), "land"); @SuppressWarnings("unchecked") List<Messwert> messwerte = (List<Messwert>)response.getData(); if (messwerte == null || messwerte.isEmpty()) { Violation violation = new Violation(); violation.addWarning("messwert", 631); return violation; } return null; } }