view gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AbstractFixBunduArtifact.java @ 9416:05405292a7ca

Navigationtheme panel now shows themes of dWt and WQ charts grayed out, if the current station is outside the valid range of the theme.
author gernotbelger
date Thu, 16 Aug 2018 16:28:03 +0200
parents 6c24c857ccf9
children
line wrap: on
line source
/** 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);
    }

    protected abstract String getEventstateId();

    public final FixFilter getFilter() {
        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;
    }
}

http://dive4elements.wald.intevation.org