# HG changeset patch # User Tim Englich # Date 1253087066 0 # Node ID 4ebe57b170d3cb542fe2695299f4ba6f7eddfeff # Parent 3cb753564552c927ef15ea47b8528263271d28b7 Integration of moving through the Artifact-States and rendering the UI. gnv/trunk@91 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 3cb753564552 -r 4ebe57b170d3 gnv/Changelog --- a/gnv/Changelog Tue Sep 15 14:19:55 2009 +0000 +++ b/gnv/Changelog Wed Sep 16 07:44:26 2009 +0000 @@ -1,3 +1,32 @@ +2009-09-16 Tim Englich + + * src/test/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientTestCase.java Edited: + Added Transformerlogic to the Testcase + + * src/main/webapp/WEB-INF/jsp/index.jsp Edited: + Integrated the UI of the Artifact + + * src/main/webapp/WEB-INF/config/struts-config.xml Edited: + Added ActionHandling for managing the next Businesslogic to go to the next Step of an Artifact + + * src/main/webapp/WEB-INF/config/templates/describe-ui.xsl Edited: + Added Transformation-Rules for Input-Elements + + * src/main/java/de/intevation/gnv/artifactdatabase/objects/DefaultInputParameter.java Added, + src/main/java/de/intevation/gnv/artifactdatabase/objects/InputParameter.java Added: + Infrastructur for providing InputParametes as an Object + + * src/main/java/de/intevation/gnv/artifactdatabase/objects/Artifact.java Edited, + src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactDescription.java (getInputParameter) (setInputParameter) Edited: + Add Methods for providing the reuired Input-Parametes of the current ArtifactDescription + + * src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Edited, + src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java (doNextStep) Edited: + Added doNextStep Method for doing all ControllerWork to move the Artifact into the next Step + + * src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java Added: + Action for switching to the next Step of an Artifact + 2009-09-15 Tim Englich * src/test/java/de/intevation/gnv/util/XSLTransformerTestCase.java: diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java Wed Sep 16 07:44:26 2009 +0000 @@ -0,0 +1,79 @@ +/** + * + */ +package de.intevation.gnv.action; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +import de.intevation.gnv.action.sessionmodel.SessionModel; +import de.intevation.gnv.action.sessionmodel.SessionModelFactory; +import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient; +import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; +import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; +import de.intevation.gnv.artifactdatabase.objects.DefaultInputParameter; +import de.intevation.gnv.artifactdatabase.objects.InputParameter; +import de.intevation.gnv.util.XSLTransformer; + +/** + * @author Tim Englich + * + */ +public class NextArtifactStepAction extends ArtifactDatabaseActionBase { + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(SelectArtifactFactoryAction.class); + + /** + * Constructor + */ + public NextArtifactStepAction() { + super(); + } + + /** + * @see de.intevation.gnv.action.ArtifactDatabaseActionBase#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request); + ArtifactDescription ad = (ArtifactDescription)sm.getCurrentArtifact(); + Collection inputParameter = ad.getInputParameter(); + Collection ips = null; + if (inputParameter != null){ + ips = new ArrayList(inputParameter.size()); + Iterator it = inputParameter.iterator(); + while (it.hasNext()){ + String name = it.next(); + String[] values = request.getParameterValues(name); + InputParameter ip = new DefaultInputParameter(name, values); + ips.add(ip); + } + } + // TODO: Woher kommt der zu erreichende Status; + String target = ad.getReachableStates().iterator().next(); + ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory.getInstance().getArtifactDatabaseClient(); + ArtifactDescription artifactDescription = adc.doNextStep(sm.getSelectedArtifactFactory(), sm.getCurrentArtifact(), target, ips); + + XSLTransformer transformer = new XSLTransformer(); + String ui = transformer.transform(artifactDescription.getCurrentUI(), "UTF-8", request.getRealPath("WEB-INF/config/templates/describe-ui.xsl")); + + request.setAttribute("ui", ui); + + return super.execute(mapping, form, request, response); + } + + +} diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java --- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java Tue Sep 15 14:19:55 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java Wed Sep 16 07:44:26 2009 +0000 @@ -9,6 +9,7 @@ import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; import de.intevation.gnv.artifactdatabase.objects.ArtifactFactory; import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; +import de.intevation.gnv.artifactdatabase.objects.InputParameter; /** * @author Tim Englich @@ -39,4 +40,12 @@ * @throws ArtifactDatabaseClientException */ public ArtifactDescription getCurrentStepDescription(ArtifactObject artifactFactory, ArtifactObject currentArtifact) throws ArtifactDatabaseClientException; + + /** + * + * @param currentArtifact + * @return the Current Artifact + * @throws ArtifactDatabaseClientException + */ + public ArtifactDescription doNextStep(ArtifactObject artifactFactory, ArtifactObject currentArtifact, String state2reach, Collection inputParameter) throws ArtifactDatabaseClientException; } diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java --- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Tue Sep 15 14:19:55 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Wed Sep 16 07:44:26 2009 +0000 @@ -29,6 +29,7 @@ import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; import de.intevation.gnv.artifactdatabase.objects.ArtifactFactory; import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; +import de.intevation.gnv.artifactdatabase.objects.InputParameter; import de.intevation.gnv.util.XMLUtils; /** @@ -245,7 +246,7 @@ try { Document request = this.createDescribeRequestBody(currentArtifact); - String url = ((ArtifactFactory)artifactFactory).getDataBaseUrl()+"/artifact/"+ currentArtifact.getId(); + String url = this.getArtifactUrl(artifactFactory, currentArtifact); Document result = this.doGetRequest(url); return this.readDescription(result,currentArtifact); } catch (IOException e) { @@ -253,13 +254,24 @@ throw new ArtifactDatabaseClientException(e); } } + + /** + * @param artifactFactory + * @param currentArtifact + * @return + */ + private String getArtifactUrl(ArtifactObject artifactFactory, + ArtifactObject currentArtifact) { + String url = ((ArtifactFactory)artifactFactory).getDataBaseUrl()+"/artifact/"+ currentArtifact.getId(); + return url; + } private ArtifactDescription readDescription(Document document, ArtifactObject artifact) throws ArtifactDatabaseClientException{ XMLUtils xmlUtils = new XMLUtils(); if (artifact instanceof ArtifactDescription){ ArtifactDescription ad = (ArtifactDescription)artifact; Node uiNode = xmlUtils.getNodeXPath(document, "/result/ui"); - uiNode = uiNode.getFirstChild(); +// uiNode = uiNode.getFirstChild(); Node outputNode = xmlUtils.getNodeXPath(document, "/result/outputs"); String currentState = xmlUtils.getStringXPath(document, "/result/state/@name"); NodeList statesList = xmlUtils.getNodeSetXPath(document, "/result/reachable-states/state/@name"); @@ -268,6 +280,17 @@ reachableStates.add(statesList.item(i).getNodeValue()); } + NodeList inputNodes = xmlUtils.getNodeSetXPath(document, "/result/model/input"); + if (inputNodes != null){ + Collection inputParameter = new ArrayList(inputNodes.getLength()); + for (int i = 0; i < inputNodes.getLength(); i++){ + Node inputNode = inputNodes.item(i); + String name = xmlUtils.getStringXPath(inputNode, "@name"); + inputParameter.add(name); + } + ad.setInputParameter(inputParameter); + } + ad.setCurrentOut(outputNode); ad.setCurrentUI(uiNode); ad.setCurrentState(currentState); @@ -280,7 +303,93 @@ } - + + /** + * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#doNextStep(de.intevation.gnv.artifactdatabase.objects.ArtifactObject, de.intevation.gnv.artifactdatabase.objects.ArtifactObject, java.lang.String, java.util.Collection) + */ + public ArtifactDescription doNextStep(ArtifactObject artifactFactory, + ArtifactObject currentArtifact, String target, + Collection inputParameter) + throws ArtifactDatabaseClientException { + + try { + // 1 Feed + Document feedDocument = this.createFeedRequestBody(currentArtifact, inputParameter); + String url = this.getArtifactUrl(artifactFactory, currentArtifact); + InputStream feedResult = this.doPostRequest(url, feedDocument); + // TODO feedResult auswerten und ggf. Fehler werfen. + // 2 Advance + Document advanceDocument = this.createAdvanceRequestBody(currentArtifact, target); + log.debug(new XMLUtils().writeDocument2String(advanceDocument)); + InputStream advanceResult = this.doPostRequest(url, advanceDocument); + // TODO feedResult auswerten und ggf. Fehler werfen. + // 3 Descibe + return this.getCurrentStepDescription(artifactFactory, currentArtifact); + } catch (IOException e) { + log.error(e,e); + throw new ArtifactDatabaseClientException(e); + } + } - + private Document createFeedRequestBody(ArtifactObject currentArtifact, + Collection inputParameter){ + Document document = new XMLUtils().newDocument(); + Node rootNode = this.createRootNode(document); + + Element typeNode = this.createArtifactElement(document, "type"); + typeNode.setAttribute("name", "feed"); + rootNode.appendChild(typeNode); + + Element uuidNode = this.createArtifactElement(document, "uuid"); + uuidNode.setAttribute("value", currentArtifact.getId()); + rootNode.appendChild(uuidNode); + + Element hashNode = this.createArtifactElement(document, "hash"); + hashNode.setAttribute("value", currentArtifact.getHash()); + rootNode.appendChild(hashNode); + + Element dataNode = this.createArtifactElement(document, "data"); + rootNode.appendChild(dataNode); + if (inputParameter != null){ + Iterator it = inputParameter.iterator(); + while(it.hasNext()){ + InputParameter ip = it.next(); + String name = ip.getName(); + String[] values = ip.getValues(); + if (values != null){ + for (int i = 0; i < values.length; i++){ + String value = values[i]; + Element inputNode = this.createArtifactElement(document, "input"); + inputNode.setAttribute("name", name); + inputNode.setAttribute("value", value); + dataNode.appendChild(inputNode); + } + } + } + } + + + return document; + } + + private Document createAdvanceRequestBody(ArtifactObject currentArtifact, String target){ + Document document = new XMLUtils().newDocument(); + Node rootNode = this.createRootNode(document); + + Element typeNode = this.createArtifactElement(document, "type"); + typeNode.setAttribute("name", "advance"); + rootNode.appendChild(typeNode); + + Element uuidNode = this.createArtifactElement(document, "uuid"); + uuidNode.setAttribute("value", currentArtifact.getId()); + rootNode.appendChild(uuidNode); + + Element hashNode = this.createArtifactElement(document, "hash"); + hashNode.setAttribute("value", currentArtifact.getHash()); + rootNode.appendChild(hashNode); + Element targetNode = this.createArtifactElement(document, "target"); + targetNode.setAttribute("name", target); + rootNode.appendChild(targetNode); + return document; + } } diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/Artifact.java --- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/Artifact.java Tue Sep 15 14:19:55 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/Artifact.java Wed Sep 16 07:44:26 2009 +0000 @@ -22,6 +22,7 @@ private Node currentOut = null; private Collection reachableStates; + private Collection inputParameter; private String currentState = null; /** @@ -131,4 +132,18 @@ this.selected = selected; } + /** + * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#getInputParameter() + */ + public Collection getInputParameter() { + return this.inputParameter; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#setInputParameter(java.util.Collection) + */ + public void setInputParameter(Collection inputParameter) { + this.inputParameter = inputParameter; + } + } diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactDescription.java --- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactDescription.java Tue Sep 15 14:19:55 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactDescription.java Wed Sep 16 07:44:26 2009 +0000 @@ -16,36 +16,42 @@ /** * @return the currentUI */ - public abstract Node getCurrentUI(); + public Node getCurrentUI(); /** @param currentUI the currentUI to set */ - public abstract void setCurrentUI(Node currentUI); + public void setCurrentUI(Node currentUI); /** @param currentOut the currentOut to set */ - public abstract void setCurrentOut(Node currentOut); + public void setCurrentOut(Node currentOut); /** * @return the reachableStates */ - public abstract Collection getReachableStates(); - + public Collection getReachableStates(); /** @param reachableStates the reachableStates to set */ - public abstract void setReachableStates(Collection reachableStates); + public void setReachableStates(Collection reachableStates); /** * @return the currentState */ - public abstract String getCurrentState(); + public String getCurrentState(); /** @param currentState the currentState to set */ - public abstract void setCurrentState(String currentState); + public void setCurrentState(String currentState); + + /** + * @return the reachableStates + */ + public Collection getInputParameter(); + + public void setInputParameter(Collection inputParameter); } \ No newline at end of file diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/DefaultInputParameter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/DefaultInputParameter.java Wed Sep 16 07:44:26 2009 +0000 @@ -0,0 +1,41 @@ +/** + * + */ +package de.intevation.gnv.artifactdatabase.objects; +/** + * @author Tim Englich + * + */ +public class DefaultInputParameter implements InputParameter { + + + private String name = null; + + private String[] values = null; + + /** + * Constructor + * @param name + * @param values + */ + public DefaultInputParameter(String name, String[] values) { + super(); + this.name = name; + this.values = values; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.InputParameter#getName() + */ + public String getName() { + return this.name; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.InputParameter#getValues() + */ + public String[] getValues() { + return this.values; + } + +} diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/InputParameter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/InputParameter.java Wed Sep 16 07:44:26 2009 +0000 @@ -0,0 +1,15 @@ +/** + * + */ +package de.intevation.gnv.artifactdatabase.objects; +/** + * @author Tim Englich + * + */ +public interface InputParameter { + + public String getName(); + + public String[] getValues(); + +} diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/main/webapp/WEB-INF/config/struts-config.xml --- a/gnv/src/main/webapp/WEB-INF/config/struts-config.xml Tue Sep 15 14:19:55 2009 +0000 +++ b/gnv/src/main/webapp/WEB-INF/config/struts-config.xml Wed Sep 16 07:44:26 2009 +0000 @@ -21,6 +21,14 @@ name="success" path="/WEB-INF/jsp/index.jsp"/> + + + diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/main/webapp/WEB-INF/config/templates/describe-ui.xsl --- a/gnv/src/main/webapp/WEB-INF/config/templates/describe-ui.xsl Tue Sep 15 14:19:55 2009 +0000 +++ b/gnv/src/main/webapp/WEB-INF/config/templates/describe-ui.xsl Wed Sep 16 07:44:26 2009 +0000 @@ -5,14 +5,27 @@ xmlns:xform="http://www.w3.org/2002/xforms" xmlns:art="http://www.intevation.de/2009/artifacts"> + + + + - +     - + + + + + + + :
+
+ + \ No newline at end of file diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/main/webapp/WEB-INF/jsp/index.jsp --- a/gnv/src/main/webapp/WEB-INF/jsp/index.jsp Tue Sep 15 14:19:55 2009 +0000 +++ b/gnv/src/main/webapp/WEB-INF/jsp/index.jsp Wed Sep 16 07:44:26 2009 +0000 @@ -4,11 +4,14 @@ <%@page import="de.intevation.gnv.action.sessionmodel.SessionModel"%> <%@page import="de.intevation.gnv.action.sessionmodel.SessionModelFactory"%> <%@page import="java.util.Iterator"%> +<%Object ui = request.getAttribute("ui"); + String action = (ui == null ? "selectArtifactFactory.do" : "next.do"); +%> -
+ <% - Object ui = request.getAttribute("ui"); + SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request); Collection artifactFactories = sm.getArtifactFactories(); if (artifactFactories != null && ui == null){ diff -r 3cb753564552 -r 4ebe57b170d3 gnv/src/test/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientTestCase.java --- a/gnv/src/test/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientTestCase.java Tue Sep 15 14:19:55 2009 +0000 +++ b/gnv/src/test/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientTestCase.java Wed Sep 16 07:44:26 2009 +0000 @@ -3,6 +3,7 @@ */ package de.intevation.gnv.artifactdatabase.client; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -12,6 +13,8 @@ import de.intevation.gnv.artifactdatabase.client.exception.ArtifactDatabaseClientException; import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; +import de.intevation.gnv.artifactdatabase.objects.DefaultInputParameter; +import de.intevation.gnv.artifactdatabase.objects.InputParameter; import de.intevation.gnv.util.XSLTransformer; import junit.framework.TestCase; @@ -61,6 +64,13 @@ XSLTransformer transformer = new XSLTransformer(); String transformedUI = transformer.transform(ad.getCurrentUI(), "UTF-8",("src/main/webapp/WEB-INF/config/templates/describe-ui.xsl")); log.debug(transformedUI); + + Collection inputParameter = new ArrayList(1); + inputParameter.add(new DefaultInputParameter("product", new String[]{"timeSeries"})); + ad = artifactDatabaseClient.doNextStep(aof, artifact, "timeSeries",inputParameter); + + transformedUI = transformer.transform(ad.getCurrentUI(), "UTF-8",("src/main/webapp/WEB-INF/config/templates/describe-ui.xsl")); + log.debug(transformedUI); } }