teichmann@5831: package org.dive4elements.river.artifacts.states; ingo@2702: ingo@2702: import java.util.ArrayList; ingo@2702: import java.util.List; ingo@2702: ingo@2702: import org.apache.log4j.Logger; ingo@2702: teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; teichmann@5831: import org.dive4elements.artifactdatabase.state.FacetActivity; ingo@2702: teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.FLYSArtifact; teichmann@5831: import org.dive4elements.river.artifacts.access.FlowVelocityAccess; teichmann@5831: import org.dive4elements.river.artifacts.model.CalculationResult; teichmann@5831: import org.dive4elements.river.artifacts.model.DataFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.FlowVelocityCalculation; teichmann@5831: import org.dive4elements.river.artifacts.model.FlowVelocityData; teichmann@5831: import org.dive4elements.river.artifacts.model.FlowVelocityFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.FlowVelocityFilterFacet; teichmann@5831: import org.dive4elements.river.artifacts.resources.Resources; ingo@2702: ingo@2702: felix@4466: /* State in which flow velocities can/will be calculated. */ ingo@2702: public class FlowVelocityState extends DefaultState implements FacetTypes { ingo@2702: ingo@2702: private static Logger logger = Logger.getLogger(FlowVelocityState.class); ingo@2702: ingo@2706: public static final String I18N_MAINCHANNEL_FACET = ingo@2706: "facet.flow_velocity.mainchannel"; ingo@2706: ingo@2706: public static final String I18N_TOTALCHANNEL_FACET = ingo@2706: "facet.flow_velocity.totalchannel"; ingo@2706: ingo@2706: public static final String I18N_TAU_FACET = ingo@2706: "facet.flow_velocity.tauchannel"; ingo@2706: rrenkert@4669: public static final String I18N_MAINCHANNEL_FACET_RAW = rrenkert@4669: "facet.flow_velocity.mainchannel.raw"; rrenkert@4669: rrenkert@4669: public static final String I18N_TOTALCHANNEL_FACET_RAW = rrenkert@4669: "facet.flow_velocity.totalchannel.raw"; rrenkert@4669: rrenkert@4669: public static final String I18N_TAU_FACET_RAW = rrenkert@4669: "facet.flow_velocity.tauchannel.raw"; rrenkert@4669: felix@4466: public static final String I18N_DISCHARGE_FACET = felix@4466: "facet.flow_velocity.discharge"; felix@4466: ingo@2706: ingo@2702: @Override ingo@2702: public Object computeAdvance( ingo@2702: FLYSArtifact artifact, ingo@2702: String hash, ingo@2702: CallContext context, ingo@2702: List facets, ingo@2702: Object old ingo@2702: ) { ingo@2702: logger.debug("FlowVelocityState.computeAdvance"); ingo@2702: ingo@2702: List newFacets = new ArrayList(); sascha@3232: felix@4826: FlowVelocityAccess access = new FlowVelocityAccess(artifact, context); ingo@2702: ingo@2702: CalculationResult res = old instanceof CalculationResult ingo@2702: ? (CalculationResult) old ingo@3230: : new FlowVelocityCalculation().calculate(access); ingo@2702: ingo@2702: if (facets == null || res == null) { ingo@2702: return res; ingo@2702: } ingo@2702: ingo@2702: FlowVelocityData[] data = (FlowVelocityData[]) res.getData(); ingo@2702: ingo@2702: logger.debug("Calculated " + data.length + " FlowVelocityData objects"); ingo@2702: ingo@2706: String id = getID(); ingo@2706: int idx = 0; ingo@2702: ingo@2702: for (FlowVelocityData d: data) { rrenkert@4624: if (d.getType().equals("main")) { rrenkert@4624: newFacets.add(new FlowVelocityFacet( rrenkert@4624: idx, rrenkert@4624: FLOW_VELOCITY_MAINCHANNEL, rrenkert@4669: buildFacetName(artifact, context, d, I18N_MAINCHANNEL_FACET_RAW), rrenkert@4624: ComputeType.ADVANCE, rrenkert@4624: id, rrenkert@4624: hash rrenkert@4624: )); ingo@2706: rrenkert@4624: newFacets.add(new FlowVelocityFacet( rrenkert@4624: idx, rrenkert@4624: FLOW_VELOCITY_TAU, rrenkert@4669: buildFacetName(artifact, context, d, I18N_TAU_FACET_RAW), rrenkert@4669: ComputeType.ADVANCE, rrenkert@4669: id, rrenkert@4669: hash rrenkert@4669: )); rrenkert@4669: newFacets.add(new FlowVelocityFilterFacet( rrenkert@4669: idx, rrenkert@4669: FLOW_VELOCITY_MAINCHANNEL_FILTERED, rrenkert@4669: buildMainChannelName(artifact, context, d), rrenkert@4669: ComputeType.ADVANCE, rrenkert@4669: id, rrenkert@4669: hash rrenkert@4669: )); rrenkert@4669: newFacets.add(new FlowVelocityFilterFacet( rrenkert@4669: idx, rrenkert@4669: FLOW_VELOCITY_TAU_FILTERED, rrenkert@4624: buildTauName(artifact, context, d), rrenkert@4624: ComputeType.ADVANCE, rrenkert@4624: id, rrenkert@4624: hash rrenkert@4624: )); rrenkert@4624: } rrenkert@4624: else if (d.getType().equals("total")) { rrenkert@4624: newFacets.add(new FlowVelocityFacet( rrenkert@4624: idx, rrenkert@4624: FLOW_VELOCITY_TOTALCHANNEL, rrenkert@4669: buildFacetName(artifact, context, d, I18N_TOTALCHANNEL_FACET_RAW), rrenkert@4669: ComputeType.ADVANCE, rrenkert@4669: id, rrenkert@4669: hash rrenkert@4669: )); rrenkert@4669: newFacets.add(new FlowVelocityFilterFacet( rrenkert@4669: idx, rrenkert@4669: FLOW_VELOCITY_TOTALCHANNEL_FILTERED, rrenkert@4624: buildTotalChannelName(artifact, context, d), rrenkert@4624: ComputeType.ADVANCE, rrenkert@4624: id, rrenkert@4624: hash rrenkert@4624: )); teichmann@4736: rrenkert@4624: } rrenkert@4624: else if(d.getType().equals("main_total")) { rrenkert@4624: newFacets.add(new FlowVelocityFacet( rrenkert@4624: idx, rrenkert@4624: FLOW_VELOCITY_MAINCHANNEL, rrenkert@4669: buildFacetName(artifact, context, d, I18N_MAINCHANNEL_FACET_RAW), rrenkert@4624: ComputeType.ADVANCE, rrenkert@4624: id, rrenkert@4624: hash rrenkert@4624: )); rrenkert@4624: newFacets.add(new FlowVelocityFacet( rrenkert@4624: idx, rrenkert@4624: FLOW_VELOCITY_TAU, rrenkert@4669: buildFacetName(artifact, context, d, I18N_TAU_FACET_RAW), rrenkert@4624: ComputeType.ADVANCE, rrenkert@4624: id, rrenkert@4624: hash rrenkert@4624: )); rrenkert@4624: newFacets.add(new FlowVelocityFacet( rrenkert@4624: idx, rrenkert@4624: FLOW_VELOCITY_TOTALCHANNEL, rrenkert@4669: buildFacetName(artifact, context, d, I18N_TOTALCHANNEL_FACET_RAW), rrenkert@4669: ComputeType.ADVANCE, rrenkert@4669: id, rrenkert@4669: hash rrenkert@4669: )); rrenkert@4669: newFacets.add(new FlowVelocityFilterFacet( rrenkert@4669: idx, rrenkert@4669: FLOW_VELOCITY_MAINCHANNEL_FILTERED, rrenkert@4669: buildMainChannelName(artifact, context, d), rrenkert@4669: ComputeType.ADVANCE, rrenkert@4669: id, rrenkert@4669: hash rrenkert@4669: )); rrenkert@4669: newFacets.add(new FlowVelocityFilterFacet( rrenkert@4669: idx, rrenkert@4669: FLOW_VELOCITY_TAU_FILTERED, rrenkert@4669: buildTauName(artifact, context, d), rrenkert@4669: ComputeType.ADVANCE, rrenkert@4669: id, rrenkert@4669: hash rrenkert@4669: )); rrenkert@4669: newFacets.add(new FlowVelocityFilterFacet( rrenkert@4669: idx, rrenkert@4669: FLOW_VELOCITY_TOTALCHANNEL_FILTERED, rrenkert@4624: buildTotalChannelName(artifact, context, d), rrenkert@4624: ComputeType.ADVANCE, rrenkert@4624: id, rrenkert@4624: hash rrenkert@4624: )); rrenkert@4624: } ingo@2706: felix@4466: newFacets.add(new FlowVelocityFacet( felix@4466: idx, felix@4466: FLOW_VELOCITY_DISCHARGE, felix@4466: buildDischargeName(artifact, context, d), felix@4466: ComputeType.ADVANCE, felix@4466: id, felix@4466: hash felix@4466: )); felix@4466: ingo@2706: idx++; ingo@2702: } ingo@2702: ingo@2702: Facet csv = new DataFacet( ingo@2702: CSV, "CSV data", ComputeType.ADVANCE, hash, id); ingo@2702: ingo@2702: // TODO ADD PDF FACET ingo@2702: ingo@2702: newFacets.add(csv); ingo@2702: ingo@2702: logger.debug("Created " + newFacets.size() + " new Facets."); ingo@2702: ingo@2702: facets.addAll(newFacets); ingo@2702: ingo@2702: return res; ingo@2702: } ingo@2706: ingo@2706: ingo@2706: protected String buildFacetName( ingo@2706: FLYSArtifact flys, ingo@2706: CallContext cc, ingo@2706: FlowVelocityData data, ingo@2706: String resourceId ingo@2706: ) { ingo@2706: Object[] args = new Object[] { ingo@2706: data.getZone() ingo@2706: }; ingo@2706: ingo@2706: return Resources.getMsg( ingo@2706: cc.getMeta(), ingo@2706: resourceId, ingo@2706: resourceId, ingo@2706: args); ingo@2706: } ingo@2706: ingo@2706: ingo@2706: protected String buildMainChannelName( ingo@2706: FLYSArtifact flys, ingo@2706: CallContext cc, ingo@2706: FlowVelocityData data ingo@2706: ) { ingo@2706: return buildFacetName(flys, cc, data, I18N_MAINCHANNEL_FACET); ingo@2706: } ingo@2706: ingo@2706: ingo@2706: protected String buildTotalChannelName( ingo@2706: FLYSArtifact flys, ingo@2706: CallContext cc, ingo@2706: FlowVelocityData data ingo@2706: ) { ingo@2706: return buildFacetName(flys, cc, data, I18N_TOTALCHANNEL_FACET); ingo@2706: } ingo@2706: ingo@2706: felix@4466: protected String buildDischargeName( felix@4466: FLYSArtifact flys, felix@4466: CallContext cc, felix@4466: FlowVelocityData data felix@4466: ) { felix@4466: return buildFacetName(flys, cc, data, I18N_DISCHARGE_FACET); felix@4466: } felix@4466: ingo@2706: protected String buildTauName( ingo@2706: FLYSArtifact flys, ingo@2706: CallContext cc, ingo@2706: FlowVelocityData data ingo@2706: ) { ingo@2706: return buildFacetName(flys, cc, data, I18N_TAU_FACET); ingo@2706: } rrenkert@4669: rrenkert@4669: static { rrenkert@4669: // Active/deactivate facets. rrenkert@4669: FacetActivity.Registry.getInstance().register( rrenkert@4669: "minfo", rrenkert@4669: new FacetActivity() { rrenkert@4669: @Override rrenkert@4669: public Boolean isInitialActive( rrenkert@4669: Artifact artifact, rrenkert@4669: Facet facet, rrenkert@4669: String output rrenkert@4669: ) { rrenkert@4669: String name = facet.getName(); rrenkert@4793: if (name.equals(FLOW_VELOCITY_MAINCHANNEL_FILTERED) || rrenkert@4793: name.equals(FLOW_VELOCITY_TAU_FILTERED) || rrenkert@4793: name.equals(FLOW_VELOCITY_DISCHARGE) || rrenkert@4793: name.equals(FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) { rrenkert@4793: return Boolean.TRUE; rrenkert@4793: } rrenkert@4793: else if (name.equals(FLOW_VELOCITY_MAINCHANNEL) || rrenkert@4669: name.equals(FLOW_VELOCITY_TAU) || rrenkert@4669: name.equals(FLOW_VELOCITY_TOTALCHANNEL)) { rrenkert@4669: return Boolean.FALSE; rrenkert@4669: } rrenkert@4669: else { rrenkert@4793: return null; rrenkert@4669: } rrenkert@4669: } rrenkert@4669: }); rrenkert@4669: } ingo@2702: } ingo@2702: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :