# HG changeset patch # User Ingo Weinzierl # Date 1300695435 0 # Node ID 43f03f6047b970eff97ffb59d039453a6e391cfb # Parent 05207cc4a084b5a76ae24e1cf47a16173da2bd56 Implemented the step-back part of the advance() operation. flys-artifacts/trunk@1522 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 05207cc4a084 -r 43f03f6047b9 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Mar 21 06:11:01 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon Mar 21 08:17:15 2011 +0000 @@ -1,3 +1,8 @@ +2011-03-21 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: + Implemented the step-back part of the advance() operation. + 2011-03-21 Ingo Weinzierl * src/main/resources/messages_de.properties: Fixed a german umlaut. diff -r 05207cc4a084 -r 43f03f6047b9 flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon Mar 21 06:11:01 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon Mar 21 08:17:15 2011 +0000 @@ -182,8 +182,6 @@ * @return a document that contains a SUCCESS or FAILURE message. */ public Document advance(Document target, CallContext context) { - logger.info("FLYSArtifact.advance()"); - Document doc = XMLUtils.newDocument(); XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( @@ -196,8 +194,10 @@ String targetState = XMLUtils.xpathString( target, XPATH_ADVANCE_TARGET, ArtifactNamespaceContext.INSTANCE); + logger.info("FLYSArtifact.advance() to '" + targetState + "'"); + if (isStateReachable(targetState, context)) { - logger.debug("Advance: Step forward."); + logger.info("Advance: Step forward"); Vector prev = getPreviousStateIds(); prev.add(getCurrentStateId()); @@ -206,8 +206,23 @@ return describe(target, context); } + else if (isPreviousState(targetState, context)) { + logger.info("Advance: Step back to"); - // TODO IMPLEMENT STEP BACK! + Vector prevs = getPreviousStateIds(); + int targetIdx = prevs.indexOf(targetState); + int start = prevs.size() - 1; + + for (int i = start; i >= targetIdx; i--) { + String prev = prevs.get(i); + logger.debug("Remove state id '" + prev + "'"); + prevs.remove(prev); + } + + setCurrentStateId(targetState); + + return describe(target, context); + } logger.warn("Advance: Cannot advance to '" + targetState + "'"); ec.addAttr(result, "type", OPERATION_FAILED, true); @@ -354,6 +369,11 @@ */ protected State fillState(State state) { Map stateData = state.getData(); + + if (stateData == null) { + return state; + } + Set keys = stateData.keySet(); for (String key: keys) { @@ -394,5 +414,24 @@ return tEngine.isStateReachable(stateId, currentState, sEngine); } + + + /** + * Determines if the state with the identifier stateId is a previous + * state of the current state. + * + * @param stateId The target state identifier. + * @param context The context object. + */ + protected boolean isPreviousState(String stateId, Object context) { + logger.debug("Determine if the state '" + stateId + "' is old."); + + Vector prevs = getPreviousStateIds(); + if (prevs.contains(stateId)) { + return true; + } + + return false; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :