diff gwt-client/src/main/java/org/dive4elements/river/client/server/FLYSArtifactCreator.java @ 9071:a561b882436d

create module bundu (Betrieb & Unterhaltung) incl. original Fixierungsanalyse+Ausgelagerte Wasserspiegellage
author gernotbelger
date Wed, 16 May 2018 11:08:56 +0200
parents 8c3e5682cb60
children 02739b8c010d
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/FLYSArtifactCreator.java	Tue May 15 18:04:36 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/FLYSArtifactCreator.java	Wed May 16 11:08:56 2018 +0200
@@ -13,30 +13,25 @@
 
 import javax.xml.xpath.XPathConstants;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
 import org.apache.log4j.Logger;
-
-import org.dive4elements.artifacts.common.utils.XMLUtils;
 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
-
+import org.dive4elements.artifacts.common.utils.XMLUtils;
 import org.dive4elements.artifacts.httpclient.utils.ArtifactCreator;
-
 import org.dive4elements.river.client.shared.model.Artifact;
 import org.dive4elements.river.client.shared.model.CalculationMessage;
 import org.dive4elements.river.client.shared.model.ChartArtifact;
 import org.dive4elements.river.client.shared.model.DefaultArtifact;
 import org.dive4elements.river.client.shared.model.FixAnalysisArtifact;
 import org.dive4elements.river.client.shared.model.GaugeDischargeCurveArtifact;
+import org.dive4elements.river.client.shared.model.MINFOArtifact;
 import org.dive4elements.river.client.shared.model.MapArtifact;
 import org.dive4elements.river.client.shared.model.SINFOArtifact;
-import org.dive4elements.river.client.shared.model.MINFOArtifact;
 import org.dive4elements.river.client.shared.model.StaticSQRelationArtifact;
 import org.dive4elements.river.client.shared.model.UINFOArtifact;
 import org.dive4elements.river.client.shared.model.WINFOArtifact;
-
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 /**
  * An implementation of an {@link ArtifactCreator}. This class uses the document
@@ -47,28 +42,25 @@
  */
 public class FLYSArtifactCreator implements ArtifactCreator {
 
-    private static final Logger log =
-        Logger.getLogger(FLYSArtifactCreator.class);
+    private static final Logger log = Logger.getLogger(FLYSArtifactCreator.class);
 
-
-    /** The XPath to the artifact's uuid.*/
+    /** The XPath to the artifact's uuid. */
     public static final String XPATH_UUID = "/art:result/art:uuid/@art:value";
 
-    /** The XPath to the artifact's hash value.*/
+    /** The XPath to the artifact's hash value. */
     public static final String XPATH_HASH = "/art:result/art:hash/@art:value";
 
-    /** The XPath to the artifact's name value.*/
+    /** The XPath to the artifact's name value. */
     public static final String XPATH_NAME = "/art:result/art:name/@art:value";
 
-    /** The XPath to the value that determines if the artifact is processing in
-     * background.*/
-    public static final String XPATH_BACKGROUND_VALUE =
-        "/art:result/art:background-processing/@art:value";
+    /**
+     * The XPath to the value that determines if the artifact is processing in
+     * background.
+     */
+    public static final String XPATH_BACKGROUND_VALUE = "/art:result/art:background-processing/@art:value";
 
-    /** The XPath that points to the (if existing) background messages.*/
-    public static final String XPATH_BACKGROUND =
-        "/art:result/art:background-processing";
-
+    /** The XPath that points to the (if existing) background messages. */
+    public static final String XPATH_BACKGROUND = "/art:result/art:background-processing";
 
     /**
      * Creates a new instance of an {@link ArtifactCreator}.
@@ -76,54 +68,50 @@
     public FLYSArtifactCreator() {
     }
 
-
     /**
      * This concreate implementation returns an instance of {@link Artifact}
      * that is used in the FLYS GWT Client code.
      *
-     * @param doc A document that describes the artifact that has been created
-     * in the artifact server.
+     * @param doc
+     *            A document that describes the artifact that has been created
+     *            in the artifact server.
      *
      * @return an instance if {@link Artifact}.
      */
-    public Object create(Document doc) {
-        Artifact artifact = extractArtifact(doc);
-        artifact.setArtifactDescription(
-            ArtifactDescriptionFactory.createArtifactDescription(doc));
+    @Override
+    public Object create(final Document doc) {
+        final Artifact artifact = extractArtifact(doc);
+        artifact.setArtifactDescription(ArtifactDescriptionFactory.createArtifactDescription(doc));
 
         return artifact;
     }
 
-
     /**
      * This method extracts the UUID und HASH information of the returned
      * artifact document.
      *
-     * @param doc The result of the CREATE operation.
+     * @param doc
+     *            The result of the CREATE operation.
      *
      * @return an instance of an {@link Artifact}.
      */
-    protected Artifact extractArtifact(Document doc) {
+    protected Artifact extractArtifact(final Document doc) {
         log.debug("FLYSArtifactCreator - extractArtifact()");
 
-        String uuid = XMLUtils.xpathString(
-            doc, XPATH_UUID, ArtifactNamespaceContext.INSTANCE);
+        final String uuid = XMLUtils.xpathString(doc, XPATH_UUID, ArtifactNamespaceContext.INSTANCE);
 
-        String hash = XMLUtils.xpathString(
-            doc, XPATH_HASH, ArtifactNamespaceContext.INSTANCE);
+        final String hash = XMLUtils.xpathString(doc, XPATH_HASH, ArtifactNamespaceContext.INSTANCE);
 
-        String name = XMLUtils.xpathString(
-            doc, XPATH_NAME, ArtifactNamespaceContext.INSTANCE);
+        String name = XMLUtils.xpathString(doc, XPATH_NAME, ArtifactNamespaceContext.INSTANCE);
 
-        String backgroundStr = XMLUtils.xpathString(
-            doc, XPATH_BACKGROUND_VALUE, ArtifactNamespaceContext.INSTANCE);
+        final String backgroundStr = XMLUtils.xpathString(doc, XPATH_BACKGROUND_VALUE, ArtifactNamespaceContext.INSTANCE);
 
         boolean background = false;
         if (backgroundStr != null && backgroundStr.length() > 0) {
             background = Boolean.valueOf(backgroundStr);
         }
 
-        List<CalculationMessage> msg = parseBackgroundMessages(doc);
+        final List<CalculationMessage> msg = parseBackgroundMessages(doc);
 
         log.debug("NEW Artifact UUID: " + uuid);
         log.debug("NEW Artifact HASH: " + hash);
@@ -136,7 +124,8 @@
 
         name = name.trim();
 
-        // FIXME: why do we have a super sophisticated artifact-framework if, in the end, module dependent stuff is still switched manually....
+        // FIXME: why do we have a super sophisticated artifact-framework if, in the end, module dependent stuff is still
+        // switched manually....
         if (name.equals("winfo")) {
             log.debug("+++++ NEW WINFO ARTIFACT.");
             return new WINFOArtifact(uuid, hash, background, msg);
@@ -146,27 +135,27 @@
             log.debug("+++++ NEW MAP ARTIFACT.");
             return new MapArtifact(uuid, hash, background, msg);
         }
-        
+
         if (name.equals("new_chart")) {
             log.debug("+++++ NEW CHART ARTIFACT.");
             return new ChartArtifact(uuid, hash, background, msg);
         }
-        
+
         if (name.equals("minfo")) {
             log.debug("+++++ NEW MINFO ARTIFACT.");
             return new MINFOArtifact(uuid, hash, background, msg);
         }
-        
+
         if (name.equals("fixanalysis")) {
             log.debug("+++++ NEW FIXANALYSIS ARTIFACT.");
             return new FixAnalysisArtifact(uuid, hash, background, msg);
         }
-        
+
         if (name.equals("gaugedischargecurve")) {
             log.debug("+++++ NEW GAUGEDISCHARGECURVE ARTIFACT.");
             return new GaugeDischargeCurveArtifact(uuid, hash, background, msg);
         }
-        
+
         if (name.equals("staticsqrelation")) {
             log.debug("+++++ STATICSQRELATION ARTIFACT.");
             return new StaticSQRelationArtifact(uuid, hash, background, msg);
@@ -178,28 +167,27 @@
         }
 
         if (name.equals("uinfo")) {
-        	log.debug("+++++ NEW UINFO ARTIFACT.");
-        	return new UINFOArtifact(uuid, hash, background, msg);
+            log.debug("+++++ NEW UINFO ARTIFACT.");
+            return new UINFOArtifact(uuid, hash, background, msg);
         }
-
+        if (name.equals("bundu")) {
+            log.debug("+++++ NEW BUNDU ARTIFACT.");
+            return new UINFOArtifact(uuid, hash, background, msg);
+        }
         return new DefaultArtifact(uuid, hash, background, msg);
     }
 
+    public static List<CalculationMessage> parseBackgroundMessages(final Document d) {
+        final NodeList list = (NodeList) XMLUtils.xpath(d, XPATH_BACKGROUND, XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);
 
-    public static List<CalculationMessage> parseBackgroundMessages(Document d) {
-        NodeList list = (NodeList) XMLUtils.xpath(
-            d, XPATH_BACKGROUND, XPathConstants.NODESET,
-            ArtifactNamespaceContext.INSTANCE);
-
-        int len = list != null ? list.getLength() : 0;
+        final int len = list != null ? list.getLength() : 0;
 
         log.debug("Found " + len + " background messages.");
 
-        List<CalculationMessage> res = new ArrayList<CalculationMessage>(len);
+        final List<CalculationMessage> res = new ArrayList<CalculationMessage>(len);
 
         for (int i = 0; i < len; i++) {
-            CalculationMessage msg = parseBackgroundMessage(
-                (Element) list.item(i));
+            final CalculationMessage msg = parseBackgroundMessage((Element) list.item(i));
 
             if (msg != null) {
                 res.add(msg);
@@ -209,25 +197,21 @@
         return res;
     }
 
+    public static CalculationMessage parseBackgroundMessage(final Element e) {
+        final String steps = e.getAttribute("art:steps");
+        final String currentStep = e.getAttribute("art:currentStep");
+        final String message = e.getTextContent();
 
-    public static CalculationMessage parseBackgroundMessage(Element e) {
-        String steps       = e.getAttribute("art:steps");
-        String currentStep = e.getAttribute("art:currentStep");
-        String message     = e.getTextContent();
-
-        int lenCurStep = currentStep != null ? currentStep.length() : 0;
-        int lenSteps   = steps       != null ? steps.length()       : 0;
-        int lenMessage = message     != null ? message.length()     : 0;
+        final int lenCurStep = currentStep != null ? currentStep.length() : 0;
+        final int lenSteps = steps != null ? steps.length() : 0;
+        final int lenMessage = message != null ? message.length() : 0;
 
         if (lenSteps > 0 && lenMessage > 0 && lenCurStep > 0) {
             try {
-                return new CalculationMessage(
-                    Integer.parseInt(steps),
-                    Integer.parseInt(currentStep),
-                    message);
+                return new CalculationMessage(Integer.parseInt(steps), Integer.parseInt(currentStep), message);
 
             }
-            catch (NumberFormatException nfe) {
+            catch (final NumberFormatException nfe) {
                 nfe.printStackTrace();
             }
         }

http://dive4elements.wald.intevation.org