teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.access; sascha@3209: ingo@3426: import java.util.Date; aheinecke@6859: import java.util.List; ingo@3426: ingo@3426: import org.apache.log4j.Logger; ingo@3426: teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@5831: import org.dive4elements.river.artifacts.model.DateRange; aheinecke@6859: import org.dive4elements.river.model.MeasurementStation; sascha@3210: sascha@3209: public class SQRelationAccess sascha@3777: extends RiverAccess sascha@3209: { sascha@3209: private static Logger log = Logger.getLogger(SQRelationAccess.class); sascha@3209: ingo@3426: protected Double location; sascha@3210: ingo@3426: protected DateRange period; sascha@3210: ingo@3426: protected Double outliers; sascha@3209: rrenkert@5396: private String method; rrenkert@5396: aheinecke@6859: protected MeasurementStation measurementStation; aheinecke@6859: sascha@3209: public SQRelationAccess() { sascha@3209: } sascha@3209: teichmann@5867: public SQRelationAccess(D4EArtifact artifact) { sascha@3209: super(artifact); sascha@3209: } sascha@3209: sascha@3210: public Double getLocation() { sascha@3210: if (location == null) { sascha@3210: // XXX: The parameter name suggests plural!? sascha@3210: location = getDouble("ld_locations"); sascha@3210: } sascha@3210: sascha@3210: if (log.isDebugEnabled()) { sascha@3210: log.debug("location: " + location); sascha@3210: } sascha@3210: sascha@3210: return location; sascha@3210: } sascha@3210: ingo@3426: public DateRange getPeriod() { ingo@3426: if (period == null) { ingo@3426: Long start = getLong("start"); ingo@3426: Long end = getLong("end"); ingo@3426: ingo@3426: if (start != null && end != null) { ingo@3426: period = new DateRange(new Date(start), new Date(end)); ingo@3426: } sascha@3210: } ingo@3426: ingo@3426: return period; sascha@3210: } sascha@3210: sascha@3210: public Double getOutliers() { sascha@3210: if (outliers == null) { sascha@3210: outliers = getDouble("outliers"); sascha@3210: } sascha@3210: if (log.isDebugEnabled()) { sascha@3210: log.debug("outliers: " + outliers); sascha@3210: } sascha@3210: return outliers; sascha@3210: } rrenkert@5396: rrenkert@5396: public String getOutlierMethod() { rrenkert@5396: if (method == null) { rrenkert@5396: method = getString("outlier-method"); rrenkert@5396: } rrenkert@5396: if (log.isDebugEnabled()) { rrenkert@5396: log.debug("outlier-method: " + method); rrenkert@5396: } rrenkert@5396: return method; rrenkert@5396: } aheinecke@6859: aheinecke@6859: public String getMeasurementStationName() { aheinecke@6859: MeasurementStation station = getMeasurementStation(); aheinecke@6859: return station == null ? null : station.getName(); aheinecke@6859: } aheinecke@6859: aheinecke@6859: public String getMeasurementStationGaugeName() { aheinecke@6859: MeasurementStation station = getMeasurementStation(); aheinecke@6859: return station == null ? null : station.getGaugeName(); aheinecke@6859: } aheinecke@6859: aheinecke@6859: public MeasurementStation getMeasurementStation() { aheinecke@6859: if (measurementStation != null) { aheinecke@6859: return measurementStation; aheinecke@6859: } aheinecke@6859: List candidates = MeasurementStation.getStationsAtKM( felix@7261: getRiverName(), getLocation()); aheinecke@7380: if (candidates != null && !candidates.isEmpty()) { aheinecke@6859: // Just take the first one as we only use the name aheinecke@6859: // and that "should" be unique at the location aheinecke@6859: measurementStation = candidates.get(0); aheinecke@6859: } aheinecke@6859: aheinecke@6859: return measurementStation; aheinecke@6859: } sascha@3209: } sascha@3209: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :