Mercurial > dive4elements > gnv-client
changeset 12:4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
gnv/trunk@91 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- 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 <tim.englich@intevation.de> + + * 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 <tim.englich@intevation.de> * src/test/java/de/intevation/gnv/util/XSLTransformerTestCase.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 <tim.englich@intevation.de> + * + */ +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<String> inputParameter = ad.getInputParameter(); + Collection<InputParameter> ips = null; + if (inputParameter != null){ + ips = new ArrayList<InputParameter>(inputParameter.size()); + Iterator<String> 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); + } + + +}
--- 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 <tim.englich@intevation.de> @@ -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> inputParameter) throws ArtifactDatabaseClientException; }
--- 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<String> inputParameter = new ArrayList<String>(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> 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> 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<InputParameter> 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; + } }
--- 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<String> reachableStates; + private Collection<String> inputParameter; private String currentState = null; /** @@ -131,4 +132,18 @@ this.selected = selected; } + /** + * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#getInputParameter() + */ + public Collection<String> getInputParameter() { + return this.inputParameter; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#setInputParameter(java.util.Collection) + */ + public void setInputParameter(Collection<String> inputParameter) { + this.inputParameter = inputParameter; + } + }
--- 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<String> getReachableStates(); - + public Collection<String> getReachableStates(); /** @param reachableStates the reachableStates to set */ - public abstract void setReachableStates(Collection<String> reachableStates); + public void setReachableStates(Collection<String> 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<String> getInputParameter(); + + public void setInputParameter(Collection<String> inputParameter); } \ No newline at end of file
--- /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 <tim.englich@intevation.de> + * + */ +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; + } + +}
--- /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 <tim.englich@intevation.de> + * + */ +public interface InputParameter { + + public String getName(); + + public String[] getValues(); + +}
--- 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"/> </action> + <action path="/next" + type="de.intevation.gnv.action.NextArtifactStepAction" + scope="request" + validate="false"> + <forward + name="success" + path="/WEB-INF/jsp/index.jsp"/> + </action> </action-mappings> </struts-config>
--- 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"> <xsl:output method="html" version="1.0" encoding="UTF-8" omit-xml-declaration="no"/> + + <xsl:template match="*[local-name() = 'ui']"> + <xsl:apply-templates/> + </xsl:template> <xsl:template match="*[local-name() = 'select']"> - <xsl:variable name="selectName" select="@ref"/> + <xsl:variable name="selectName" select="@ref"/> <select name="{$selectName}"> <xsl:apply-templates/></select> </xsl:template> <xsl:template match="*[local-name() = 'item']"> <xsl:variable name="optionValue" select="*[local-name() = 'value']"/> - <option value="{$optionValue}"><xsl:value-of select="*[local-name() = 'label']"></xsl:value-of></option> + <option value="{$optionValue}"><xsl:value-of select="*[local-name() = 'label']"></xsl:value-of></option> </xsl:template> + + + <xsl:template match="*[local-name() = 'input']"> + <xsl:variable name="inputValue" select="*[local-name() = 'value']"/> + <xsl:variable name="inputName" select="*[local-name() = 'label']"/> + <xsl:value-of select="*[local-name() = 'label']"/>: <input type="text" id="{$inputName}" name="{$inputName}" value="{$inputValue}" /><br/> + </xsl:template> + <xsl:template match="*[local-name() = 'label']"> </xsl:template> + </xsl:stylesheet> \ No newline at end of file
--- 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"%><html> +<%Object ui = request.getAttribute("ui"); + String action = (ui == null ? "selectArtifactFactory.do" : "next.do"); +%> <body> -<form action="selectArtifactFactory.do" method="post"> +<form action="<%=action%>" method="post"> <% - Object ui = request.getAttribute("ui"); + SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request); Collection<ArtifactObject> artifactFactories = sm.getArtifactFactories(); if (artifactFactories != null && ui == null){
--- 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> inputParameter = new ArrayList<InputParameter>(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); } }