teichmann@5831: package org.dive4elements.river.artifacts.states.minfo; raimund@3629: ingo@3749: import java.util.ArrayList; ingo@3767: import java.util.Date; ingo@3749: import java.util.List; ingo@3749: ingo@3749: import org.apache.log4j.Logger; ingo@3749: teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5831: import org.dive4elements.artifacts.CallMeta; teichmann@5831: import org.dive4elements.river.artifacts.FLYSArtifact; teichmann@5831: import org.dive4elements.river.artifacts.access.BedQualityAccess; 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.DateRange; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedDensityFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedDiameterFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedDiameterResult; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedParametersResult; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedPorosityFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedQualityCalculation; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedQualityDiameterResult; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedQualityResult; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedloadDiameterFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedloadDiameterResult; teichmann@5831: import org.dive4elements.river.artifacts.resources.Resources; teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState; raimund@3629: sascha@3750: ingo@3757: public class BedQualityState extends DefaultState implements FacetTypes { ingo@3757: ingo@3757: private static final long serialVersionUID = 1L; ingo@3757: ingo@3757: private static final Logger logger = Logger ingo@3757: .getLogger(BedQualityState.class); sascha@3750: ingo@3767: public static final String I18N_TOPLAYER = "bedquality.toplayer"; ingo@3767: public static final String I18N_SUBLAYER = "bedquality.sublayer"; ingo@3767: ingo@3767: public static final String I18N_FACET_BED_POROSITY_TOPLAYER = "facet.bedquality.bed.porosity.toplayer"; ingo@3767: public static final String I18N_FACET_BED_POROSITY_SUBLAYER = "facet.bedquality.bed.porosity.sublayer"; ingo@3767: public static final String I18N_FACET_BED_DENSITY_TOPLAYER = "facet.bedquality.bed.density.toplayer"; ingo@3767: public static final String I18N_FACET_BED_DENSITY_SUBLAYER = "facet.bedquality.bed.density.sublayer"; ingo@3767: public static final String I18N_FACET_BED_DIAMETER_TOPLAYER = "facet.bedquality.bed.diameter.toplayer"; ingo@3767: public static final String I18N_FACET_BED_DIAMETER_SUBLAYER = "facet.bedquality.bed.diameter.sublayer"; ingo@3767: public static final String I18N_FACET_BEDLOAD_DIAMETER = "facet.bedquality.bedload.diameter"; ingo@3767: ingo@3749: @Override ingo@3757: public Object computeAdvance(FLYSArtifact artifact, String hash, ingo@3757: CallContext context, List facets, Object old) { ingo@3749: logger.debug("BedQualityState.computeAdvance"); raimund@3629: ingo@3749: List newFacets = new ArrayList(); ingo@3749: felix@4825: BedQualityAccess access = new BedQualityAccess(artifact, context); ingo@3749: ingo@3757: CalculationResult res = old instanceof CalculationResult ? (CalculationResult) old ingo@3749: : new BedQualityCalculation().calculate(access); ingo@3749: ingo@3749: if (facets == null || res == null) { ingo@3749: return res; ingo@3749: } ingo@3749: ingo@3762: BedQualityResult[] results = (BedQualityResult[]) res.getData(); ingo@3757: ingo@3762: if (results == null || results.length == 0) { ingo@3762: logger.warn("Calculation computed no results!"); ingo@3762: return res; ingo@3762: } ingo@3757: ingo@3767: generateFacets(context, newFacets, results, getID(), hash); ingo@3762: logger.debug("Created " + newFacets.size() + " new Facets."); ingo@3757: ingo@3749: facets.addAll(newFacets); ingo@3749: ingo@3749: return res; ingo@3749: } ingo@3762: ingo@3767: protected void generateFacets(CallContext context, List newFacets, ingo@3762: BedQualityResult[] results, String stateId, String hash) { ingo@3762: logger.debug("BedQualityState.generateFacets"); ingo@3762: ingo@3767: CallMeta meta = context.getMeta(); ingo@3767: ingo@3785: newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); ingo@3762: for (int idx = 0; idx < results.length; idx++) { ingo@3762: BedQualityResult result = results[idx]; ingo@3784: DateRange range = result.getDateRange(); ingo@3784: BedDiameterResult[] bedDiameter = result.getBedResults(); ingo@3784: for (int j = 0; j < bedDiameter.length; j++) { ingo@3784: newFacets.add(new BedDiameterFacet((idx << 8) + j, ingo@3784: BED_QUALITY_BED_DIAMETER_TOPLAYER, ingo@3784: createDiameterTopLayerDescription( ingo@3784: meta, ingo@3784: bedDiameter[j], ingo@3784: range), ingo@3762: ComputeType.ADVANCE, stateId, hash)); ingo@3762: ingo@3784: newFacets.add(new BedDiameterFacet((idx << 8) +j, ingo@3784: BED_QUALITY_BED_DIAMETER_SUBLAYER, ingo@3784: createDiameterSubLayerDescription( ingo@3784: meta, ingo@3784: bedDiameter[j], ingo@3784: range), ingo@3766: ComputeType.ADVANCE, stateId, hash)); ingo@3784: } ingo@3784: BedloadDiameterResult[] bedloadDiameter = result.getBedloadResults(); ingo@3784: for (int j = 0; j < bedloadDiameter.length; j++) { ingo@3784: newFacets.add(new BedloadDiameterFacet( ingo@3784: (idx << 8) + j, ingo@3784: BED_QUALITY_BEDLOAD_DIAMETER, ingo@3784: createDiameterDescription( ingo@3784: meta, bedloadDiameter[j]), ingo@3784: ComputeType.ADVANCE, ingo@3784: stateId, ingo@3784: hash)); ingo@3767: ingo@3784: } ingo@3784: BedParametersResult[] bedParameters = result.getParameters(); ingo@3784: for (int j = 0; j < bedParameters.length; j++) { ingo@3784: newFacets.add(new BedPorosityFacet((idx << 8) + j, ingo@3784: BED_QUALITY_POROSITY_TOPLAYER, ingo@3784: createPorosityTopLayerDescription( ingo@3784: meta, ingo@3784: bedParameters[j], ingo@3784: range), ingo@3767: ComputeType.ADVANCE, stateId, hash)); ingo@3767: ingo@3784: newFacets.add(new BedPorosityFacet((idx << 8) + j, ingo@3784: BED_QUALITY_POROSITY_SUBLAYER, ingo@3784: createPorositySubLayerDescription( ingo@3784: meta, ingo@3784: bedParameters[j], ingo@3784: range), ingo@3762: ComputeType.ADVANCE, stateId, hash)); ingo@3784: ingo@3784: newFacets.add(new BedDensityFacet((idx << 8) + j, ingo@3784: BED_QUALITY_SEDIMENT_DENSITY_TOPLAYER, ingo@3784: createDensityTopLayerDescription( ingo@3784: meta, ingo@3784: bedParameters[j], ingo@3784: range), ingo@3784: ComputeType.ADVANCE, stateId, hash)); ingo@3784: ingo@3784: newFacets.add(new BedDensityFacet((idx << 8) + j, ingo@3784: BED_QUALITY_SEDIMENT_DENSITY_SUBLAYER, ingo@3784: createDensitySubLayerDescription( ingo@3784: meta, ingo@3784: bedParameters[j], ingo@3784: range), ingo@3784: ComputeType.ADVANCE, stateId, hash)); ingo@3762: } ingo@3762: } ingo@3762: } ingo@3767: ingo@3767: protected String createPorosityTopLayerDescription(CallMeta meta, ingo@3784: BedParametersResult result, DateRange range) { ingo@3767: Date from = range != null ? range.getFrom() : new Date(); ingo@3767: Date to = range != null ? range.getTo() : new Date(); sascha@3772: ingo@3767: String toplayer = Resources.getMsg(meta, I18N_TOPLAYER, I18N_TOPLAYER); ingo@3767: return Resources.getMsg(meta, I18N_FACET_BED_POROSITY_TOPLAYER, ingo@3767: I18N_FACET_BED_POROSITY_TOPLAYER, new Object[] { from, to, toplayer }); ingo@3767: } ingo@3767: ingo@3767: protected String createPorositySubLayerDescription(CallMeta meta, ingo@3784: BedParametersResult result, DateRange range) { ingo@3767: Date from = range != null ? range.getFrom() : new Date(); ingo@3767: Date to = range != null ? range.getTo() : new Date(); sascha@3772: ingo@3767: String sublayer = Resources.getMsg(meta, I18N_SUBLAYER, I18N_SUBLAYER); ingo@3767: return Resources.getMsg(meta, I18N_FACET_BED_POROSITY_SUBLAYER, ingo@3767: I18N_FACET_BED_POROSITY_SUBLAYER, new Object[] { from, to, sublayer }); ingo@3767: } ingo@3767: ingo@3767: protected String createDensityTopLayerDescription(CallMeta meta, ingo@3784: BedParametersResult result, DateRange range) { ingo@3767: Date from = range != null ? range.getFrom() : new Date(); ingo@3767: Date to = range != null ? range.getTo() : new Date(); sascha@3772: ingo@3767: String toplayer = Resources.getMsg(meta, I18N_TOPLAYER, I18N_TOPLAYER); ingo@3767: return Resources.getMsg(meta, I18N_FACET_BED_DENSITY_TOPLAYER, ingo@3767: I18N_FACET_BED_DENSITY_TOPLAYER, new Object[] { from, to, toplayer }); ingo@3767: } ingo@3767: ingo@3767: protected String createDensitySubLayerDescription(CallMeta meta, ingo@3784: BedParametersResult result, DateRange range) { ingo@3767: Date from = range != null ? range.getFrom() : new Date(); ingo@3767: Date to = range != null ? range.getTo() : new Date(); sascha@3772: ingo@3767: String sublayer = Resources.getMsg(meta, I18N_SUBLAYER, I18N_SUBLAYER); ingo@3767: return Resources.getMsg(meta, I18N_FACET_BED_DENSITY_SUBLAYER, ingo@3767: I18N_FACET_BED_DENSITY_SUBLAYER, new Object[] { from, to, sublayer }); ingo@3767: } ingo@3767: ingo@3767: protected String createDiameterTopLayerDescription(CallMeta meta, ingo@3784: BedDiameterResult result, DateRange range) { ingo@3767: Date from = range != null ? range.getFrom() : new Date(); ingo@3767: Date to = range != null ? range.getTo() : new Date(); ingo@3767: ingo@3767: String toplayer = Resources.getMsg(meta, I18N_TOPLAYER, I18N_TOPLAYER); ingo@3767: ingo@3767: return Resources.getMsg(meta, I18N_FACET_BED_DIAMETER_TOPLAYER, ingo@3767: I18N_FACET_BED_DIAMETER_TOPLAYER, new Object[] { result.getType(), ingo@3767: from, to, toplayer }); ingo@3767: } ingo@3767: ingo@3767: protected String createDiameterSubLayerDescription(CallMeta meta, ingo@3784: BedDiameterResult result, DateRange range) { ingo@3767: Date from = range != null ? range.getFrom() : new Date(); ingo@3767: Date to = range != null ? range.getTo() : new Date(); sascha@3772: ingo@3767: String sublayer = Resources.getMsg(meta, I18N_SUBLAYER, I18N_SUBLAYER); ingo@3767: return Resources.getMsg(meta, I18N_FACET_BED_DIAMETER_SUBLAYER, ingo@3767: I18N_FACET_BED_DIAMETER_SUBLAYER, new Object[] { result.getType(), ingo@3767: from, to, sublayer }); ingo@3767: } ingo@3767: ingo@3767: protected String createDiameterDescription(CallMeta meta, ingo@3784: BedQualityDiameterResult result) { ingo@3767: return Resources.getMsg(meta, I18N_FACET_BEDLOAD_DIAMETER, ingo@3767: I18N_FACET_BEDLOAD_DIAMETER, new Object[] { result.getType() }); ingo@3767: } raimund@3629: } christian@3761: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :