Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java @ 222:3e82b4f1c455
Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Added the possibility to switch to an alternative Transition.
gnv-artifacts/trunk@284 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Thu, 05 Nov 2009 14:45:54 +0000 |
parents | ee2d4134d0b3 |
children | 3d6d89bcbf42 |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Tue Nov 03 11:46:30 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Thu Nov 05 14:45:54 2009 +0000 @@ -56,8 +56,10 @@ */ private static Logger log = Logger.getLogger(GNVArtifactBase.class); - private static String MINVALUEFIELDNAME = "minvalue"; - private static String MAXVALUEFIELDNAME = "maxvalue"; + private final static String MINVALUEFIELDNAME = "minvalue"; + private final static String MAXVALUEFIELDNAME = "maxvalue"; + + private final static String NODATASELECTIONKEY = "n/n"; private final static String DESCRIBEDATAKEY = "_DESCRIBEDATA"; @@ -68,10 +70,14 @@ protected String dataName = null; protected boolean dataMultiSelect = false; + + protected boolean dataNoSelect = false; protected String queryID = null; private Collection<String> reachableTransitions = null; + + private Transition alternativeTransition = null; protected Collection<String> inputValueNames = null; @@ -107,7 +113,28 @@ * @see de.intevation.gnv.transition.Transition#reachableTransitions() */ public Collection<String> reachableTransitions() { - return this.reachableTransitions; + + if (this.couldAlternativeTransitionUsed()){ + return this.alternativeTransition.reachableTransitions(); + }else{ + return this.reachableTransitions; + } + + } + + /** + * @return + */ + private boolean couldAlternativeTransitionUsed() { + // TODO das muss hier noch etwas freier gestaltet werden. + Object[] inputValues = this.inputValueNames.toArray(); + String key = (String)inputValues[inputValues.length-1]; + boolean returnValue= this.alternativeTransition != null && + this.inputData != null && + this.inputData.containsKey(key) && + this.inputData.get(key).getValue(). + equals(NODATASELECTIONKEY); + return returnValue; } /** @@ -135,7 +162,13 @@ this.reachableTransitions.add(reachableTransition); } - + + Node alternativeTransitionNode = Config.getNodeXPath(configuration, + "alternativeTransition/transition"); + if (alternativeTransitionNode != null){ + this.alternativeTransition = TransitionFactory.getInstance() + .createTransition(alternativeTransitionNode); + } NodeList inputValuesNodes = Config.getNodeSetXPath(configuration, "inputvalues/inputvalue"); this.inputValues = new HashMap<String, InputValue>(inputValuesNodes @@ -169,11 +202,17 @@ this.dataName = Config.getStringXPath(configuration, "dataname"); String dataMultiSelectValue = Config.getStringXPath(configuration, - "data-multiselect"); + "data-multiselect"); if (dataMultiSelectValue != null) { this.dataMultiSelect = Boolean.parseBoolean(dataMultiSelectValue); } - + + String dataNoSelectValue =Config.getStringXPath(configuration, + "data-noselect"); + if (dataNoSelectValue != null) { + this. dataNoSelect = Boolean.parseBoolean(dataNoSelectValue); + } + } /** @@ -298,12 +337,16 @@ public boolean isTransitionReachable(String transitionID) { log.debug("TransitionBase.isTransitionReachable"); boolean returnValue = false; - Iterator<String> transitions = reachableTransitions.iterator(); - while (transitions.hasNext()) { - if (transitions.next().equals(transitionID)) { - log.debug("Transition " + transitionID + " wird unterstützt."); - returnValue = true; - break; + if (this.couldAlternativeTransitionUsed()){ + return alternativeTransition.isTransitionReachable(transitionID); + }else{ + Iterator<String> transitions = reachableTransitions.iterator(); + while (transitions.hasNext()) { + if (transitions.next().equals(transitionID)) { + log.debug("Transition " + transitionID + " wird unterstützt."); + returnValue = true; + break; + } } } return returnValue; @@ -316,52 +359,60 @@ public void advance(String uuid, CallMeta callMeta) throws TransitionException { log.debug("TransitionBase.advance"); - try { - List<String> list = new ArrayList<String>(); - - Iterator<String> it = this.inputValueNames.iterator(); - int i = 0; - while (it.hasNext()) { - String value = it.next(); - InputData data = this.inputData.get(value); - if (data != null - && this.inputValues.containsKey(data.getName())) { - int size = this.inputValues.get(data.getName()) - .usedInQueries(); - String type = this.inputValues.get(data.getName()) - .getType(); - String requestValue = data.getValue(); - if (type.equalsIgnoreCase("string")) { - requestValue = this - .prepareInputData4DBQuery(requestValue); - } else if (type.equalsIgnoreCase("date")) { - requestValue = this - .prepareInputData4DateDBQuery(requestValue); - } else if (type.equalsIgnoreCase("coordinate")){ - requestValue = this - .prepareInputData4RegionDBQuery(requestValue); - } - for (int j = 0; j < size; j++) { - list.add(requestValue); + + if (this.couldAlternativeTransitionUsed()){ + this.alternativeTransition.setParent(this.getParent()); + this.alternativeTransition.putInputData(this.inputData != null ? + this.inputData.values() : + null,uuid); + this.alternativeTransition.advance(uuid, callMeta); + }else{ + try { + List<String> list = new ArrayList<String>(); + Iterator<String> it = this.inputValueNames.iterator(); + int i = 0; + while (it.hasNext()) { + String value = it.next(); + InputData data = this.inputData.get(value); + if (data != null + && this.inputValues.containsKey(data.getName())) { + int size = this.inputValues.get(data.getName()) + .usedInQueries(); + String type = this.inputValues.get(data.getName()) + .getType(); + String requestValue = data.getValue(); + if (type.equalsIgnoreCase("string")) { + requestValue = this + .prepareInputData4DBQuery(requestValue); + } else if (type.equalsIgnoreCase("date")) { + requestValue = this + .prepareInputData4DateDBQuery(requestValue); + } else if (type.equalsIgnoreCase("coordinate")){ + requestValue = this + .prepareInputData4RegionDBQuery(requestValue); + } + for (int j = 0; j < size; j++) { + list.add(requestValue); + } } } + String[] filterValues = list.toArray(new String[0]); + Collection<Result> result = null; + try { + if (this.queryID != null) { + QueryExecutor queryExecutor = QueryExecutorFactory + .getInstance().getQueryExecutor(); + result = queryExecutor.executeQuery(this.queryID, + filterValues); + } + this.purifyResult(result, uuid); + } catch (RuntimeException e) { + log.error(e, e); + } + } catch (QueryException e) { + log.error(e, e); + throw new TransitionException(e); } - String[] filterValues = list.toArray(new String[0]); - Collection<Result> result = null; - try { - if (this.queryID != null) { - QueryExecutor queryExecutor = QueryExecutorFactory - .getInstance().getQueryExecutor(); - result = queryExecutor.executeQuery(this.queryID, - filterValues); - } - this.purifyResult(result, uuid); - } catch (RuntimeException e) { - log.error(e, e); - } - } catch (QueryException e) { - log.error(e, e); - throw new TransitionException(e); } } @@ -424,18 +475,29 @@ * @param result * @return */ - protected NamedCollection<KeyValueDescibeData> extractKVP( - Collection<Result> result, + protected NamedCollection<KeyValueDescibeData> extractKVP(Collection<Result> result, String keyid, String valueid) { Iterator<Result> rit = result.iterator(); + int dataSize = (this.dataNoSelect ? result.size()+1 : result.size()); + NamedCollection<KeyValueDescibeData> keyValueDescibeData = new NamedArrayList<KeyValueDescibeData>( - this.dataName, result.size()); + this.dataName, dataSize); keyValueDescibeData.setMultiSelect(this.dataMultiSelect); + + if (this.dataNoSelect){ + keyValueDescibeData.add(new DefaultKeyValueDescribeData(NODATASELECTIONKEY, + "Keine Auswahl")); + } + String previousKey = null; while (rit.hasNext()) { Result resultValue = rit.next(); - keyValueDescibeData.add(new DefaultKeyValueDescribeData(resultValue - .getString(keyid), resultValue.getString(valueid))); + String tmpKey = resultValue.getString(keyid); + // TODO: HACK da die ARCSDE kein DISTINCT auf räumlichen Anfragen unterstützt. + if (previousKey == null || !tmpKey.equals(previousKey)){ + previousKey = tmpKey; + keyValueDescibeData.add(new DefaultKeyValueDescribeData(tmpKey, resultValue.getString(valueid))); + } } return keyValueDescibeData; } @@ -653,6 +715,10 @@ * @see de.intevation.gnv.transition.Transition#getInputData() */ public Collection<InputData> getInputData() throws TransitionException { - return this.inputData != null ? this.inputData.values() : null; + if (this.couldAlternativeTransitionUsed()){ + return this.alternativeTransition.getInputData(); + }else{ + return this.inputData != null ? this.inputData.values() : null; + } } }