sascha@3203: package de.intevation.flys.artifacts.access; sascha@3203: sascha@3203: import de.intevation.artifactdatabase.data.StateData; sascha@3203: import de.intevation.flys.artifacts.FLYSArtifact; sascha@3210: import de.intevation.flys.artifacts.model.DateRange; sascha@3203: sascha@3203: import java.util.Arrays; sascha@3203: import java.util.Date; sascha@3203: sascha@3203: import org.apache.log4j.Logger; sascha@3203: ingo@3230: sascha@3203: public class FixationArtifactAccess sascha@3207: extends Access sascha@3203: { sascha@3203: private static Logger log = Logger.getLogger(FixationArtifactAccess.class); sascha@3203: sascha@3203: protected String river; sascha@3203: sascha@3203: protected String calculationMode; sascha@3203: sascha@3203: protected Double from; sascha@3203: protected Double to; sascha@3203: protected Double step; sascha@3203: sascha@3203: protected Long start; sascha@3203: protected Long end; sascha@3203: sascha@3203: protected Integer qSectorStart; sascha@3203: protected Integer qSectorEnd; sascha@3203: sascha@3203: protected DateRange referencePeriod; sascha@3203: protected DateRange [] analysisPeriods; sascha@3203: sascha@3203: protected int [] events; sascha@3203: sascha@3203: protected Boolean preprocessing; sascha@3203: sascha@3203: protected String function; sascha@3203: sascha@3203: protected double [] qs; sascha@3203: sascha@3203: public FixationArtifactAccess() { sascha@3203: } sascha@3203: sascha@3203: public FixationArtifactAccess(FLYSArtifact artifact) { sascha@3207: super(artifact); sascha@3203: } sascha@3203: sascha@3203: public String getRiver() { sascha@3203: if (river == null) { sascha@3207: river = getString("river"); sascha@3203: } sascha@3203: if (log.isDebugEnabled()) { sascha@3203: log.debug("river: '" + river + "'"); sascha@3203: } sascha@3203: return river; sascha@3203: } sascha@3203: sascha@3203: public String getCalculationMode() { sascha@3203: if (calculationMode == null) { sascha@3207: calculationMode = getString("calculation.mode"); sascha@3203: } sascha@3203: sascha@3203: if (log.isDebugEnabled()) { sascha@3203: log.debug("calculationMode: '" + calculationMode + "'"); sascha@3203: } sascha@3203: return calculationMode; sascha@3203: } sascha@3203: sascha@3203: public Double getFrom() { sascha@3203: sascha@3203: if (from == null) { sascha@3207: from = getDouble("from"); sascha@3203: } sascha@3203: sascha@3203: if (log.isDebugEnabled()) { sascha@3203: log.debug("from: '" + from + "'"); sascha@3203: } sascha@3203: sascha@3203: return from; sascha@3203: } sascha@3203: sascha@3203: public Double getTo() { sascha@3203: sascha@3203: if (to == null) { sascha@3207: to = getDouble("to"); sascha@3203: } sascha@3203: sascha@3203: if (log.isDebugEnabled()) { sascha@3203: log.debug("to: '" + to + "'"); sascha@3203: } sascha@3203: sascha@3203: return to; sascha@3203: } sascha@3203: sascha@3203: public Double getStep() { sascha@3203: sascha@3203: if (step == null) { sascha@3207: step = getDouble("step"); sascha@3203: } sascha@3203: sascha@3203: if (log.isDebugEnabled()) { sascha@3203: log.debug("step: '" + step + "'"); sascha@3203: } sascha@3203: sascha@3203: return step; sascha@3203: } sascha@3203: sascha@3203: public Long getStart() { sascha@3203: sascha@3203: if (start == null) { sascha@3207: start = getLong("start"); sascha@3203: } sascha@3203: sascha@3203: if (log.isDebugEnabled()) { sascha@3203: log.debug("start: '" + start + "'"); sascha@3203: } sascha@3203: sascha@3203: return start; sascha@3203: } sascha@3203: sascha@3203: public Long getEnd() { sascha@3203: sascha@3203: if (end == null) { sascha@3207: end = getLong("end"); sascha@3203: } sascha@3203: sascha@3203: if (log.isDebugEnabled()) { sascha@3203: log.debug("end: '" + end + "'"); sascha@3203: } sascha@3203: sascha@3203: return end; sascha@3203: } sascha@3203: sascha@3203: public Integer getQSectorStart() { sascha@3203: sascha@3203: if (qSectorStart == null) { sascha@3207: qSectorStart = getInteger("q1"); sascha@3203: } sascha@3203: sascha@3209: if (log.isDebugEnabled()) { sascha@3209: log.debug("q1: '" + qSectorStart + "'"); sascha@3209: } sascha@3209: sascha@3203: return qSectorStart; sascha@3203: } sascha@3203: sascha@3203: public Integer getQSectorEnd() { sascha@3203: sascha@3203: if (qSectorEnd == null) { sascha@3207: qSectorEnd = getInteger("q2"); sascha@3203: } sascha@3203: sascha@3209: if (log.isDebugEnabled()) { sascha@3209: log.debug("q2: '" + qSectorEnd + "'"); sascha@3209: } sascha@3209: sascha@3203: return qSectorEnd; sascha@3203: } sascha@3203: sascha@3203: public int [] getEvents() { sascha@3203: if (events == null) { sascha@3207: events = getIntArray("events"); sascha@3203: } sascha@3209: if (log.isDebugEnabled() && events != null) { sascha@3209: log.debug("events: " + Arrays.toString(events)); sascha@3209: } sascha@3203: return events; sascha@3203: } sascha@3203: sascha@3203: public DateRange getReferencePeriod() { sascha@3203: if (referencePeriod == null) { sascha@3203: StateData refStart = artifact.getData("ref_start"); sascha@3203: StateData refEnd = artifact.getData("ref_end"); sascha@3203: sascha@3203: if (refStart == null || refEnd == null) { sascha@3203: log.warn("missing 'ref_start' or 'ref_start' value"); sascha@3203: return null; sascha@3203: } sascha@3203: sascha@3203: try { sascha@3203: long rs = Long.parseLong((String)refStart.getValue()); sascha@3203: long re = Long.parseLong((String)refEnd .getValue()); sascha@3203: sascha@3203: if (rs > re) { long t = rs; rs = re; re = t; } sascha@3203: sascha@3203: Date from = new Date(rs); sascha@3203: Date to = new Date(re); sascha@3203: referencePeriod = new DateRange(from, to); sascha@3203: } sascha@3203: catch (NumberFormatException nfe) { sascha@3203: log.warn("ref_start or ref_end is not an integer."); sascha@3203: } sascha@3203: } sascha@3203: sascha@3203: return referencePeriod; sascha@3203: } sascha@3203: sascha@3203: public DateRange [] getAnalysisPeriods() { sascha@3203: if (analysisPeriods == null) { sascha@3211: analysisPeriods = getDateRange("ana_data"); sascha@3203: } sascha@3203: sascha@3203: return analysisPeriods; sascha@3203: } sascha@3280: christian@3279: /** christian@3279: * @return DateRange object ranging from eldest to youngest date christian@3279: * of analysis and reference periods. christian@3279: */ christian@3279: public DateRange getDateRange() { christian@3279: DateRange refP = getReferencePeriod(); sascha@3280: christian@3279: Date from = refP.getFrom(); christian@3279: Date to = refP.getTo(); sascha@3280: christian@3279: DateRange[] rs = getAnalysisPeriods(); christian@3279: for(DateRange r : rs) { christian@3279: if(r.getFrom().before(from)) { christian@3279: from = r.getFrom(); christian@3279: } christian@3279: if(r.getTo().after(to)) { christian@3279: to = r.getTo(); christian@3279: } christian@3279: } sascha@3280: christian@3279: return new DateRange(from, to); christian@3279: } sascha@3203: sascha@3203: public Boolean getPreprocessing() { sascha@3203: if (preprocessing == null) { sascha@3207: preprocessing = getBoolean("preprocessing"); sascha@3203: } sascha@3209: if (log.isDebugEnabled()) { sascha@3209: log.debug("preprocessing: " + preprocessing); sascha@3209: } sascha@3203: return preprocessing; sascha@3203: } sascha@3203: sascha@3203: public String getFunction() { sascha@3203: if (function == null) { sascha@3207: function = getString("function"); sascha@3203: } sascha@3203: if (log.isDebugEnabled()) { sascha@3203: log.debug("function: " + function); sascha@3203: } sascha@3203: return function; sascha@3203: } sascha@3203: sascha@3203: public double [] getQs() { sascha@3203: if (qs == null) { sascha@3207: qs = getDoubleArray("qs"); sascha@3203: } sascha@3207: sascha@3207: if (log.isDebugEnabled() && qs != null) { sascha@3203: log.debug("qs: " + Arrays.toString(qs)); sascha@3203: } sascha@3203: return qs; sascha@3203: } sascha@3203: } sascha@3203: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :