[PATCH] Be more tolerant with not existing artifact configurations

Wald Commits scm-commit at wald.intevation.org
Tue Aug 12 10:58:05 CEST 2014


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1407833873 -7200
# Node ID 7ede7904c8a5cd24b529bbe8391b86840f524efe
# Parent  75e62ea0e3073ce87df32c2d690e0e48ce07ea18
Be more tolerant with not existing artifact configurations.

diff -r 75e62ea0e307 -r 7ede7904c8a5 artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java	Mon Aug 11 17:18:36 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java	Tue Aug 12 10:57:53 2014 +0200
@@ -206,8 +206,8 @@
     protected void configureTransitions(Document config, RiverContext context) {
         TransitionEngine engine = new TransitionEngine();
 
-        Document[] artifacts = getArtifactConfigurations(config);
-        logger.info("Found " + artifacts.length + " artifacts in the config.");
+        List<Document> artifacts = getArtifactConfigurations(config);
+        logger.info("Found " + artifacts.size() + " artifacts in the config.");
 
         for (Document doc: artifacts) {
 
@@ -248,13 +248,13 @@
      *
      * @return an array of Artifact configurations.
      */
-    protected Document[] getArtifactConfigurations(Document config) {
+    protected List<Document> getArtifactConfigurations(Document config) {
         NodeList artifacts = (NodeList) XMLUtils.xpath(
             config, XPATH_ARTIFACTS, XPathConstants.NODESET);
 
         int count = artifacts.getLength();
 
-        Document[] artifactDocs = new Document[count];
+        ArrayList<Document> docs = new ArrayList<Document>(count);
 
         for (int i = 0; i < count; i++) {
             Element tmp = (Element) artifacts.item(i);
@@ -262,11 +262,18 @@
             String xlink = tmp.getAttribute(XPATH_XLINK);
             xlink        = Config.replaceConfigDir(xlink);
 
-            File artifactFile = new File(xlink);
-            artifactDocs[i]   = XMLUtils.parseDocument(artifactFile);
+            File file = new File(xlink);
+            if (!file.isFile() || !file.canRead()) {
+                logger.warn("Artifact configuration '" + file + "' not found.");
+                continue;
+            }
+
+            Document doc = XMLUtils.parseDocument(file);
+            if (doc != null) {
+                docs.add(doc);
+            }
         }
-
-        return artifactDocs;
+        return docs;
     }
 
 
@@ -279,8 +286,8 @@
     protected void configureStates(Document config, RiverContext context) {
         StateEngine engine = new StateEngine();
 
-        Document[] artifacts = getArtifactConfigurations(config);
-        logger.info("Found " + artifacts.length + " artifacts in the config.");
+        List<Document> artifacts = getArtifactConfigurations(config);
+        logger.info("Found " + artifacts.size() + " artifacts in the config.");
 
         for (Document doc: artifacts) {
             List<State> states = new ArrayList<State>();


More information about the Dive4Elements-commits mailing list