Mercurial > lada > lada-server
view src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java @ 711:3ec358698b4d
Code style and documentation.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 22 Jul 2015 16:03:03 +0200 |
parents | 7a97e4b1cc18 |
children | 1c41c7b8f7c2 |
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.probe; import java.util.List; import javax.inject.Inject; import de.intevation.lada.model.land.LProbe; 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 probe. * Validates if the probe has a unique "hauptprobennr". * * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> */ @ValidationRule("Probe") public class UniqueHauptprobenNr implements Rule { @Inject @RepositoryConfig(type=RepositoryType.RO) private Repository repo; @SuppressWarnings("unchecked") @Override public Violation execute(Object object) { LProbe probe = (LProbe)object; QueryBuilder<LProbe> builder = new QueryBuilder<LProbe>( repo.entityManager("land"), LProbe.class); builder.and("hauptprobenNr", probe.getHauptprobenNr()); Response response = repo.filter(builder.getQuery(), "land"); if (!((List<LProbe>)response.getData()).isEmpty()) { LProbe found = ((List<LProbe>)response.getData()).get(0); // The probe found in the db equals the new probe. (Update) if (probe.getId() != null && probe.getId().equals(found.getId())) { return null; } Violation violation = new Violation(); violation.addError("hauptprobenNr", 611); return violation; } return null; } }