Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AbstractFixBunduArtifact.java @ 9072:02739b8c010d
bundu progress (Klon FixationAnalysis +Vollmer funktioniert; Verzweigung neue Berechnungsart Bezugswst)
author | gernotbelger |
---|---|
date | Wed, 16 May 2018 17:43:47 +0200 |
parents | |
children | 6c24c857ccf9 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AbstractFixBunduArtifact.java Wed May 16 17:43:47 2018 +0200 @@ -0,0 +1,143 @@ +/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.client.shared.model; + +import java.util.List; + +import com.google.gwt.core.client.GWT; + +/** + * @author Domenico Nardi Tironi + * + */ +public abstract class AbstractFixBunduArtifact extends DefaultArtifact { + + /** The name of this artifact: 'fixanalysis'. */ + + protected FixFilter filter; + + public AbstractFixBunduArtifact() { + this.filter = null; + } + + public AbstractFixBunduArtifact(final String uuid, final String hash) { + super(uuid, hash); + this.filter = null; + } + + public AbstractFixBunduArtifact(final String uuid, final String hash, final boolean inBackground, final List<CalculationMessage> messages) { + super(uuid, hash, inBackground, messages); + } + + public FixFilter getFilter() { + return createFilter(); + } + + protected abstract String getEventstateId(); + + protected FixFilter createFilter() { + if (this.filter == null) { + this.filter = new FixFilter(); + } + final DataList[] old = this.artifactDescription.getOldData(); + + final String river = this.artifactDescription.getDataValueAsString("river"); + if (river != null) { + this.filter.setRiver(river); + } + + final String from = this.artifactDescription.getDataValueAsString("ld_from"); + if (from != null) { + try { + final double fkm = Double.parseDouble(from); + this.filter.setFromKm(fkm); + } + catch (final NumberFormatException nfe) { + GWT.log("Could not parse from km."); + } + } + + final String to = this.artifactDescription.getDataValueAsString("ld_to"); + if (to != null) { + try { + final double tkm = Double.parseDouble(to); + this.filter.setToKm(tkm); + } + catch (final NumberFormatException nfe) { + GWT.log("Could not parse to km"); + } + } + + final String start = this.artifactDescription.getDataValueAsString("start"); + if (start != null) { + try { + final long s = Long.parseLong(start); + this.filter.setFromDate(s); + } + catch (final NumberFormatException nfe) { + GWT.log("Could not parse start date"); + } + } + + final String end = this.artifactDescription.getDataValueAsString("end"); + if (end != null) { + try { + final long e = Long.parseLong(end); + this.filter.setToDate(e); + } + catch (final NumberFormatException nfe) { + GWT.log("Could not parse end date"); + } + } + + final String q1 = this.artifactDescription.getDataValueAsString("q1"); + if (q1 != null) { + try { + final int q1i = Integer.parseInt(q1); + this.filter.setFromClass(q1i); + } + catch (final NumberFormatException nfe) { + GWT.log("Could not parse start class"); + } + } + + final String q2 = this.artifactDescription.getDataValueAsString("q2"); + if (q2 != null) { + try { + final int q2i = Integer.parseInt(q2); + this.filter.setToClass(q2i); + } + catch (final NumberFormatException nfe) { + GWT.log("could not parse end class"); + } + } + + for (final DataList list : old) { + final List<Data> items = list.getAll(); + final String state = list.getState(); + if (state.equals(getEventstateId())) { + final Data de = getData(items, "events"); + final IntegerArrayData iad = (IntegerArrayData) de; + this.filter.setEvents(iad.getValues()); + } + } + + return this.filter; + } + + protected Data getData(final List<Data> data, final String name) { + for (final Data d : data) { + if (name.equals(d.getLabel())) { + return d; + } + } + return null; + } +}