Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java @ 8946:5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
author | gernotbelger |
---|---|
date | Tue, 13 Mar 2018 18:49:33 +0100 |
parents | 11bf13cf0463 |
children | 798d9dcbccdd |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java Tue Mar 13 09:55:53 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java Tue Mar 13 18:49:33 2018 +0100 @@ -17,10 +17,14 @@ import java.util.TreeMap; import org.apache.commons.lang.math.DoubleRange; +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.river.artifacts.BedHeightsArtifact; import org.dive4elements.river.artifacts.math.Linear; +import org.dive4elements.river.artifacts.model.Calculation; import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; import org.dive4elements.river.model.BedHeight; import org.dive4elements.river.model.BedHeightValue; +import org.dive4elements.river.utils.RiverUtils; /** * Provides bed heigts for vcarious calculations. @@ -47,12 +51,47 @@ return result; } + public static BedHeightsFinder forId(final CallContext context, final String soundingId, final DoubleRange calcRange, final Calculation problems) { + + // REMARK: absolutely unbelievable.... + // The way how bed-heights (and other data too) is accessed is different for nearly every calculation-type + // throughout flys. + // The knowledge on how to parse the datacage-ids is spread through the complete code-base... + + // We use here the way on how bed-heights are accessed by the BedDifferenceAccess/BedDifferenceCalculation, but + // this is plain random + final String[] parts = soundingId.split(";"); + + final BedHeightsArtifact artifact = (BedHeightsArtifact) RiverUtils.getArtifact(parts[0], context); + + final Integer bedheightId = artifact.getDataAsInteger("height_id"); + + // REMARK: this only works with type 'single'; unclear on how to distinguish from epoch data (or whatever the + // other type means) + // Luckily, the requirement is to only access 'single' data here. + // final String bedheightType = artifact.getDataAsString("type"); + + // REMARK: BedDifferences uses this, but we also need the metadata of the BedHeight + // REMARK: second absolutely awful thing: BedHeight is a hibernate binding class, accessing the database via + // hibernate stuff + // BedHeightFactory uses its own (direct) way of accessing the data, with its own implemented data classes. + // return BedHeightFactory.getHeight(bedheightType, bedheightId, from, to); + + final BedHeightsFinder bedHeight = bedheightId == null ? null : BedHeightsFinder.forId(bedheightId, calcRange); + if (bedHeight != null) + return bedHeight; + + // FIXME: 10n + problems.addProblem("Failed to access sounding with id '{0}'", soundingId); + return null; + } + /** * Creates a {@link BedHeightsFinder} for a dataset from the database, specified by its id. * * @return <code>null</code> if no bed height with the given id exists. */ - public static BedHeightsFinder forId(final int id, final DoubleRange range) { + private static BedHeightsFinder forId(final int id, final DoubleRange range) { final BedHeight bedHeight = BedHeight.getBedHeightById(id); if (bedHeight == null)