mschaefer@9014: /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde mschaefer@9014: * Software engineering by mschaefer@9014: * Björnsen Beratende Ingenieure GmbH mschaefer@9014: * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt mschaefer@9014: * mschaefer@9014: * This file is Free Software under the GNU AGPL (>=v3) mschaefer@9014: * and comes with ABSOLUTELY NO WARRANTY! Check out the mschaefer@9014: * documentation coming with Dive4Elements River for details. mschaefer@9014: */ mschaefer@9014: mschaefer@9014: package org.dive4elements.river.importer.uinfo.importitem; mschaefer@9014: mschaefer@9014: import java.util.List; mschaefer@9014: mschaefer@9014: import org.apache.log4j.Logger; mschaefer@9014: import org.dive4elements.river.importer.common.AbstractKmLineImport; mschaefer@9014: import org.dive4elements.river.model.uinfo.Vegetation; mschaefer@9014: import org.dive4elements.river.model.uinfo.VegetationType; mschaefer@9014: import org.dive4elements.river.model.uinfo.VegetationZone; mschaefer@9014: import org.hibernate.Query; mschaefer@9014: import org.hibernate.Session; mschaefer@9014: mschaefer@9014: /** mschaefer@9014: * Imported vegetation values of a river station. mschaefer@9014: * mschaefer@9014: * @author Matthias Schäfer mschaefer@9014: * mschaefer@9014: */ mschaefer@9014: public class VegetationZoneImport extends AbstractKmLineImport { mschaefer@9014: mschaefer@9014: /***** FIELDS *****/ mschaefer@9014: mschaefer@9014: private static Logger log = Logger.getLogger(VegetationZoneImport.class); mschaefer@9014: mschaefer@9014: private final VegetationTypeImport vegetationType; mschaefer@9014: mschaefer@9014: private final Integer minOverflowDays; mschaefer@9014: mschaefer@9014: private final Integer maxOverflowDays; mschaefer@9014: mschaefer@9401: private final Integer color_r; mschaefer@9401: mschaefer@9401: private final Integer color_g; mschaefer@9401: mschaefer@9401: private final Integer color_b; mschaefer@9014: mschaefer@9014: /***** CONSTRUCTOR *****/ mschaefer@9014: mschaefer@9401: public VegetationZoneImport(final int vegetationTypeId, final int minOverflowDays, final int maxOverflowDays, final int color_r, mschaefer@9401: final int color_g, final int color_b) { mschaefer@9014: super(Double.NaN); mschaefer@9014: this.vegetationType = new VegetationTypeImport(vegetationTypeId); mschaefer@9401: this.minOverflowDays = Integer.valueOf(minOverflowDays); mschaefer@9401: this.maxOverflowDays = Integer.valueOf(maxOverflowDays); mschaefer@9401: this.color_r = Integer.valueOf(color_r); mschaefer@9401: this.color_g = Integer.valueOf(color_g); mschaefer@9401: this.color_b = Integer.valueOf(color_b); mschaefer@9014: } mschaefer@9014: mschaefer@9014: mschaefer@9014: /***** METHODS *****/ mschaefer@9014: mschaefer@9014: @Override mschaefer@9014: public VegetationZone queryValueItem(final Session session, final Vegetation parent) { mschaefer@9014: final Query query = session.createQuery("FROM VegetationZone WHERE (vegetation=:parent)" mschaefer@9014: + " AND (vegetationType=:type)"); mschaefer@9014: query.setParameter("parent", parent); mschaefer@9014: query.setParameter("type", this.vegetationType); mschaefer@9014: final List rows = query.list(); mschaefer@9014: if (!rows.isEmpty()) mschaefer@9014: return (VegetationZone) rows.get(0); mschaefer@9014: else mschaefer@9014: return null; mschaefer@9014: } mschaefer@9014: mschaefer@9014: mschaefer@9014: @Override mschaefer@9014: public VegetationZone createValueItem(final Vegetation parent) { mschaefer@9014: final VegetationType type = this.vegetationType.getPeer(); mschaefer@9014: if (type == null) { mschaefer@9014: log.error("Unknown vegetation zone class " + this.vegetationType.getId()); mschaefer@9014: return null; mschaefer@9014: } mschaefer@9401: return new VegetationZone(parent, type, this.minOverflowDays, this.maxOverflowDays, this.color_r, this.color_g, this.color_b); mschaefer@9014: } mschaefer@9014: }