raimund@3058: package de.intevation.flys.artifacts.states;
raimund@3058:
ingo@3072: import java.util.ArrayList;
ingo@3072: import java.util.List;
ingo@3072:
raimund@3058: import org.apache.log4j.Logger;
raimund@3058:
ingo@3072: import de.intevation.artifacts.CallContext;
ingo@3072:
ingo@3072: import de.intevation.artifactdatabase.state.Facet;
ingo@3072:
ingo@3072: import de.intevation.flys.artifacts.FLYSArtifact;
ingo@3072: import de.intevation.flys.artifacts.MINFOArtifact;
ingo@3072: import de.intevation.flys.artifacts.model.DataFacet;
ingo@3072: import de.intevation.flys.artifacts.model.FacetTypes;
ingo@3072: import de.intevation.flys.artifacts.model.CalculationResult;
ingo@3072: import de.intevation.flys.artifacts.model.sq.SQCurveFacet;
ingo@3072: import de.intevation.flys.artifacts.model.sq.SQMeasurementFacet;
ingo@3072: import de.intevation.flys.artifacts.model.sq.SQOutlierFacet;
ingo@3072: import de.intevation.flys.artifacts.model.sq.SQRelationCalculation;
ingo@3079: import de.intevation.flys.artifacts.model.sq.SQResult;
raimund@3058: import de.intevation.flys.artifacts.states.DefaultState;
raimund@3058:
raimund@3058: /**
raimund@3058: * @author Raimund Renkert
raimund@3058: */
ingo@3072: public class SQRelation extends DefaultState implements FacetTypes {
raimund@3058:
raimund@3058: private static Logger logger = Logger.getLogger(SQRelation.class);
raimund@3058:
raimund@3058:
raimund@3058: public SQRelation() {
raimund@3058: }
raimund@3058:
ingo@3072:
raimund@3058: @Override
ingo@3072: public Object computeAdvance(
ingo@3072: FLYSArtifact artifact,
ingo@3072: String hash,
ingo@3072: CallContext context,
ingo@3072: List facets,
ingo@3072: Object old
ingo@3072: ) {
ingo@3072: logger.debug("SQRelation.computeAdvance");
ingo@3072:
ingo@3072: List newFacets = new ArrayList();
ingo@3072:
ingo@3072: CalculationResult res = old instanceof CalculationResult
ingo@3072: ? (CalculationResult) old
ingo@3072: : new SQRelationCalculation().calculate((MINFOArtifact) artifact);
ingo@3072:
ingo@3072: if (facets == null || res == null) {
ingo@3072: return res;
ingo@3072: }
ingo@3072:
ingo@3079: SQResult[] sqr = (SQResult[]) res.getData();
ingo@3079: createFacets(newFacets, sqr, hash);
ingo@3072:
ingo@3072: Facet csv = new DataFacet(
ingo@3072: CSV, "CSV data", ComputeType.ADVANCE, hash, id);
ingo@3072:
ingo@3072: Facet pdf = new DataFacet(
ingo@3072: PDF, "PDF data", ComputeType.ADVANCE, hash, id);
ingo@3072:
ingo@3072: newFacets.add(csv);
ingo@3072: newFacets.add(pdf);
ingo@3072:
ingo@3072: logger.debug("Created " + newFacets.size() + " new Facets.");
ingo@3072:
ingo@3072: facets.addAll(newFacets);
ingo@3072:
ingo@3072: return res;
raimund@3058: }
raimund@3058:
ingo@3072:
ingo@3079: protected void createFacets(
ingo@3079: List container,
ingo@3079: SQResult[] sqr,
ingo@3079: String hash
ingo@3079: ) {
ingo@3099: String stateId = getID();
ingo@3099:
ingo@3072: // TODO Create facets for each parameter type (A-F)
ingo@3099: container.add(new SQMeasurementFacet(
ingo@3099: 0,
ingo@3099: SQ_A_MEASUREMENT,
ingo@3099: "Measurement TODO",
ingo@3099: hash,
ingo@3099: stateId
ingo@3099: ));
ingo@3099:
ingo@3079: container.add(new SQCurveFacet(0, SQ_A_CURVE, "TODO"));
ingo@3072:
sascha@3087: for (int i = 0, C = sqr[0].getOutliersCount(); i < C; i++) {
ingo@3079: container.add(new SQOutlierFacet(
ingo@3079: 0,
ingo@3079: i,
ingo@3079: SQ_A_OUTLIER,
ingo@3079: "OUTLIER AT" + i,
ingo@3099: hash,
ingo@3099: stateId
ingo@3079: ));
ingo@3079: }
ingo@3072: }
raimund@3058: }
raimund@3058: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :