You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by lu...@apache.org on 2015/06/17 15:14:11 UTC

svn commit: r1686007 - in /oodt/trunk/filemgr/src/main: java/org/apache/oodt/cas/filemgr/repository/XMLRepositoryManagerFactory.java java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayerFactory.java resources/filemgr.properties

Author: luca
Date: Wed Jun 17 13:14:11 2015
New Revision: 1686007

URL: http://svn.apache.org/r1686007
Log:
Enabling recursive parsing of policy directories for File Manager (OODT-854)

Modified:
    oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/repository/XMLRepositoryManagerFactory.java
    oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayerFactory.java
    oodt/trunk/filemgr/src/main/resources/filemgr.properties

Modified: oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/repository/XMLRepositoryManagerFactory.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/repository/XMLRepositoryManagerFactory.java?rev=1686007&r1=1686006&r2=1686007&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/repository/XMLRepositoryManagerFactory.java (original)
+++ oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/repository/XMLRepositoryManagerFactory.java Wed Jun 17 13:14:11 2015
@@ -18,16 +18,22 @@
 package org.apache.oodt.cas.filemgr.repository;
 
 //JDK imports
-import org.apache.oodt.cas.metadata.util.PathUtils;
-
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.oodt.cas.metadata.util.PathUtils;
+import org.apache.oodt.commons.io.DirectorySelector;
+
 /**
  * @author mattmann
  * @author bfoster
+ * @author luca
  * @version $Revision$
  * 
  * <p>
@@ -50,14 +56,51 @@ public class XMLRepositoryManagerFactory
      * </p>.
      */
     public XMLRepositoryManagerFactory() {
+    	
+    	
         String productTypeDirUris = System
                 .getProperty("org.apache.oodt.cas.filemgr.repositorymgr.dirs");
+        
+        // only returns true if org.apache.oodt.cas.filemgr.repositorymgr.dirs.recursive=true
+        boolean recursive = Boolean.parseBoolean( 
+        		System.getProperty("org.apache.oodt.cas.filemgr.repositorymgr.dirs.recursive") );
 
         if (productTypeDirUris != null) {
             productTypeDirUris = PathUtils
                     .replaceEnvVariables(productTypeDirUris);
             String[] dirUris = productTypeDirUris.split(",");
-            productTypeDirList = Arrays.asList(dirUris);
+
+            // recursive directory listing
+            if (recursive) {
+            	
+            	// empty list
+            	productTypeDirList = new ArrayList<String>();
+            	
+            	// loop over specified root directories,
+            	// add directories and sub-directories that contain "product-types.xml"
+            	for (String rootDir : dirUris) {
+            		try {
+            			
+            			DirectorySelector dirsel = new DirectorySelector(
+            					Arrays.asList( 
+            							new String[] {"product-types.xml"} ));
+            			productTypeDirList.addAll( dirsel.traverseDir(new File(new URI(rootDir))) );
+            			
+            		} catch (URISyntaxException e) {
+            			LOG.log(Level.WARNING, "URISyntaxException when traversing directory: "+rootDir);
+            		}
+            	}        		
+
+        	// non-recursive directory listing
+            } else {	
+                productTypeDirList = Arrays.asList(dirUris);
+            }
+            
+            LOG.log(Level.FINE,"Collecting XML policies from the following directories:");
+            for (String pdir : productTypeDirList) {
+            	LOG.log(Level.FINE, pdir);
+            }
+            
         }
     }
 

Modified: oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayerFactory.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayerFactory.java?rev=1686007&r1=1686006&r2=1686007&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayerFactory.java (original)
+++ oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayerFactory.java Wed Jun 17 13:14:11 2015
@@ -18,10 +18,18 @@
 package org.apache.oodt.cas.filemgr.validation;
 
 //JDk imports
-import org.apache.oodt.cas.metadata.util.PathUtils;
-
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.oodt.cas.metadata.util.PathUtils;
+import org.apache.oodt.commons.io.DirectorySelector;
+
 
 /**
  * @author mattmann
@@ -40,6 +48,10 @@ public class XMLValidationLayerFactory i
      * directories
      */
     private List<String> dirList = null;
+    
+    /* our log stream */
+    private static final Logger LOG = Logger
+            .getLogger(XMLValidationLayerFactory.class.getName());
 
     /**
      * <p>
@@ -49,11 +61,47 @@ public class XMLValidationLayerFactory i
     public XMLValidationLayerFactory() {
         String dirUris = System
                 .getProperty("org.apache.oodt.cas.filemgr.validation.dirs");
+        
+        // only returns true if org.apache.oodt.cas.filemgr.validation.dirs.recursive=true
+        boolean recursive = Boolean.parseBoolean( 
+        		System.getProperty("org.apache.oodt.cas.filemgr.validation.dirs.recursive") );
 
         if (dirUris != null) {
             dirUris = PathUtils.replaceEnvVariables(dirUris);
             String[] dirUriList = dirUris.split(",");
-            dirList = Arrays.asList(dirUriList);
+            
+            // recursive directory listing
+            if (recursive) {
+            	
+            	// empty list
+            	dirList = new ArrayList<String>();
+            	
+            	// loop over specified root directories,
+            	// add directories and sub-directories that contain both
+            	// "elements.xml" and "product-type-element-map.xml"
+            	for (String rootDir : dirUriList) {
+            		try {
+            			
+            			DirectorySelector dirsel = new DirectorySelector(
+            					Arrays.asList( 
+            							new String[] {"product-type-element-map.xml", "elements.xml"} ));
+            			dirList.addAll( dirsel.traverseDir(new File(new URI(rootDir))) );
+            			
+            		} catch (URISyntaxException e) {
+            			LOG.log(Level.WARNING, "URISyntaxException when traversing directory: "+rootDir);
+            		}
+            	}        	
+
+            // non-recursive directory listing
+            } else {
+            	dirList = Arrays.asList(dirUriList);
+            }
+            
+            LOG.log(Level.FINE,"Collecting XML validation files from the following directories:");
+            for (String pdir : dirList) {
+            	LOG.log(Level.FINE, pdir);
+            }
+            
         }
     }
 

Modified: oodt/trunk/filemgr/src/main/resources/filemgr.properties
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/resources/filemgr.properties?rev=1686007&r1=1686006&r2=1686007&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/main/resources/filemgr.properties (original)
+++ oodt/trunk/filemgr/src/main/resources/filemgr.properties Wed Jun 17 13:14:11 2015
@@ -89,9 +89,13 @@ org.apache.oodt.cas.filemgr.repositorymg
 
 # XML repository manager configuration
 org.apache.oodt.cas.filemgr.repositorymgr.dirs=file:///dir1,file:///dir2
+# uncomment the following line and set the value to true to recursively parse policy directories
+#org.apache.oodt.cas.filemgr.repositorymgr.dirs.recursive=false
 
 # XML validation layer configuration
 org.apache.oodt.cas.filemgr.validation.dirs=file:///dir1,file:///dir2
+# uncomment the following line and set the value to true to recursively parse validation directories
+#org.apache.oodt.cas.filemgr.validation.dirs.recursive=false
 
 # set the following property to 'true' to allow dynamic metadata fields,
 # effectively bypassing the validation layer.