Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 1178:1b432c260e97
Enabled the FloodMapState to fetch waterlevel data from external Artifact.
flys-artifacts/trunk@2764 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 15 Sep 2011 15:36:05 +0000 |
parents | ace192d3283d |
children | be8b5c06a1f8 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java Thu Sep 15 15:10:04 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java Thu Sep 15 15:36:05 2011 +0000 @@ -65,7 +65,7 @@ System.getProperty("flys.uesk.keep.artifactsdir", "false"); - public static final String WSP_ARTIFACT_UUID = "uesk.wsp.artifact"; + public static final String WSP_ARTIFACT = "wsp"; public static final String WINFO_WSP_STATE_ID = "state.winfo.waterlevel"; @@ -690,6 +690,39 @@ } + protected WQKms getWQKms(FLYSArtifact flys, CallContext cc) { + String wspString = flys.getDataAsString(WSP_ARTIFACT); + String[] parts = wspString.split(";"); + + String otherArtifact = parts[0]; + + int idx = -1; + try { + idx = Integer.parseInt(parts[2]); + } + catch (NumberFormatException nfe) { /* do nothing */ } + + FLYSArtifact src = otherArtifact != null + ? FLYSUtils.getArtifact(otherArtifact, cc) + : flys; + + logger.debug("Use waterlevel provided by Artifact: " + src.identifier()); + + CalculationResult rawData = (CalculationResult) src.compute( + cc, + null, + WINFO_WSP_STATE_ID, + ComputeType.ADVANCE, + false); + + WQKms[] wqkms = (WQKms[]) rawData.getData(); + + return wqkms == null || idx == -1 || idx >= wqkms.length + ? null + : wqkms[idx]; + } + + protected void setWsp( FLYSArtifact artifact, CallContext context, @@ -698,44 +731,31 @@ { logger.debug("FloodMapState.setWsp"); - String otherArtifact = artifact.getDataAsString(WSP_ARTIFACT_UUID); - FLYSArtifact src = otherArtifact != null - ? FLYSUtils.getArtifact(otherArtifact, context) - : artifact; + WQKms data = getWQKms(artifact, context); - CalculationResult rawData = (CalculationResult) src.compute( - context, - null, - WINFO_WSP_STATE_ID, - ComputeType.ADVANCE, - false); - - if (rawData == null) { + if (data == null) { logger.warn("No WST data found!"); return; } - WQKms[] data = (WQKms[]) rawData.getData(); - WstWriter writer = new WstWriter(data.length); + WstWriter writer = new WstWriter(1); // TODO REMOVE job.setWspTag(...) This is only used until the user is // able to select the WSP column himself! boolean writeWspTag = true; double[] buf = new double[4]; - for (WQKms wqkms: data) { - logger.debug("Add WST column: " + wqkms.getName()); - writer.addColumn(wqkms.getName()); + logger.debug("Add WST column: " + data.getName()); + writer.addColumn(data.getName()); - if (writeWspTag) { - job.setWspTag(wqkms.getName()); - writeWspTag = false; - } + if (writeWspTag) { + job.setWspTag(data.getName()); + writeWspTag = false; + } - for (int i = 0, num = wqkms.size(); i < num; i++) { - wqkms.get(i, buf); - writer.add(buf); - } + for (int i = 0, num = data.size(); i < num; i++) { + data.get(i, buf); + writer.add(buf); } FileOutputStream fout = null;