Author: mattmann
Date: Sun Aug 30 01:32:43 2015
New Revision: 1700084

URL: http://svn.apache.org/r1700084
Log:
Fix for OODT-686: AddProductTypeCliAction should prompt for ProductTypeId 
contributedy by rverma and mattmann.

Modified:
    oodt/trunk/CHANGES.txt
    
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AddProductTypeCliAction.java
    
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlStructFactory.java
    oodt/trunk/filemgr/src/main/resources/cmd-line-options.xml
    
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/cli/TestFileManagerCli.java
    
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/cli/action/TestAddProductTypeCliAction.java
    
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/repository/TestXMLRepositoryManager.java
    oodt/trunk/filemgr/src/test/resources/cmd-line-options.xml

Modified: oodt/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1700084&r1=1700083&r2=1700084&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Sun Aug 30 01:32:43 2015
@@ -2,6 +2,8 @@ Apache OODT Change Log
 ======================
 Release 0.10 - Current Development
 
+* OODT-686 AddProductTypeCliAction should prompt for ProductTypeId (rverma, 
mattmann)
+
 * OODT-302 Add support in the xmlquery package to handle HTTP Redirection 
(Michael Cayanan via mattmann)
 
 * OODT-303 Add support in the Grid Package to throw an HTTP Servlet Response 
(Michael Cayanan via mattmann)

Modified: 
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AddProductTypeCliAction.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AddProductTypeCliAction.java?rev=1700084&r1=1700083&r2=1700084&view=diff
==============================================================================
--- 
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AddProductTypeCliAction.java
 (original)
+++ 
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AddProductTypeCliAction.java
 Sun Aug 30 01:32:43 2015
@@ -27,9 +27,11 @@ import org.apache.oodt.cas.filemgr.struc
  * A {@link CmdLineAction} which adds a {@link ProductType} to the file 
manager.
  * 
  * @author bfoster (Brian Foster)
+ * @author riverma (Rishi Verma)
  */
 public class AddProductTypeCliAction extends FileManagerCliAction {
 
+   private String productTypeId;
    private String productTypeName;
    private String productTypeDescription;
    private String fileRepositoryPath;
@@ -39,6 +41,7 @@ public class AddProductTypeCliAction ext
    public void execute(ActionMessagePrinter printer)
          throws CmdLineActionException {
       try {
+         Validate.notNull(productTypeId, "Must specify productTypeId");
          Validate.notNull(productTypeName, "Must specify productTypeName");
          Validate.notNull(productTypeDescription,
                "Must specify productTypeDescription");
@@ -47,6 +50,7 @@ public class AddProductTypeCliAction ext
          Validate.notNull(versioner, "Must specify versioner");
 
          ProductType type = new ProductType();
+         type.setProductTypeId(productTypeId);
          type.setName(productTypeName);
          type.setDescription(productTypeDescription);
          type.setProductRepositoryPath(fileRepositoryPath);
@@ -56,13 +60,17 @@ public class AddProductTypeCliAction ext
                + getClient().addProductType(type));
       } catch (Exception e) {
          throw new CmdLineActionException("Failed to add product type with "
-               + "name '" + productTypeName + "', description '"
+               + "id '" + productTypeId + "', name '" + productTypeName + "', 
description '"
                + productTypeDescription + "', repository '"
                + fileRepositoryPath + ", and versioner '" + versioner + "' : "
                + e.getMessage(), e);
       }
    }
 
+   public void setProductTypeId(String productTypeId) {
+      this.productTypeId = productTypeId;
+   }
+       
    public void setProductTypeName(String productTypeName) {
       this.productTypeName = productTypeName;
    }

Modified: 
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlStructFactory.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlStructFactory.java?rev=1700084&r1=1700083&r2=1700084&view=diff
==============================================================================
--- 
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlStructFactory.java
 (original)
+++ 
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlStructFactory.java
 Sun Aug 30 01:32:43 2015
@@ -49,6 +49,7 @@ import org.apache.oodt.commons.xml.XMLUt
 /**
  * @author mattmann
  * @author bfoster
+ * @author riverma
  * @version $Revision$
  * 
  * <p>
@@ -99,12 +100,11 @@ public final class XmlStructFactory {
         repositoryPath = PathUtils.replaceEnvVariables(repositoryPath);
 
         // grab metadata
-        Metadata met = null;
+        Metadata met = new Metadata();
         Element metadataRoot = XMLUtils.getFirstElement("metadata",
                 productTypeElem);
         if (metadataRoot != null) {
             Hashtable<String, Object> metHash = new Hashtable<String, 
Object>();
-            met = new Metadata();
             NodeList keyValElems = metadataRoot.getElementsByTagName("keyval");
 
             for (int i = 0; i < keyValElems.getLength(); i++) {
@@ -117,17 +117,18 @@ public final class XmlStructFactory {
             }
 
             met.replaceMetadata(metHash);
+        } else {
+               LOG.warning("metadata node missing for product type : "+id);
         }
 
         // grab extractors
-        List<ExtractorSpec> extractors = null;
+        List<ExtractorSpec> extractors = new Vector<ExtractorSpec>();
         Element extractorRoot = XMLUtils.getFirstElement("metExtractors",
                 productTypeElem);
 
         if (extractorRoot != null) {
             NodeList extractorNodes = extractorRoot
                     .getElementsByTagName("extractor");
-            extractors = new Vector<ExtractorSpec>();
             if (extractorNodes != null && extractorNodes.getLength() > 0) {
                 for (int i = 0; i < extractorNodes.getLength(); i++) {
                     Element extractorElem = (Element) extractorNodes.item(i);
@@ -173,6 +174,8 @@ public final class XmlStructFactory {
                 }
 
             }
+        } else {
+               LOG.warning("metExtractors node missing from product type : 
"+id);
         }
         
         List<TypeHandler> handlers = null;

Modified: oodt/trunk/filemgr/src/main/resources/cmd-line-options.xml
URL: 
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/resources/cmd-line-options.xml?rev=1700084&r1=1700083&r2=1700084&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/main/resources/cmd-line-options.xml (original)
+++ oodt/trunk/filemgr/src/main/resources/cmd-line-options.xml Sun Aug 30 
01:32:43 2015
@@ -16,6 +16,7 @@
   limitations under the License.
 
   Author: bfoster (Brian Foster)
+          riverma (Rishi Verma)
 -->
 <beans xmlns="http://www.springframework.org/schema/beans";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:p="http://www.springframework.org/schema/p";
@@ -117,6 +118,30 @@
                </property>
        </bean>
 
+  <bean id="typeId" 
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
+    <property name="shortOption" value="tid" />
+    <property name="longOption" value="typeId" />
+    <property name="description" value="ProductType Id" />
+    <property name="hasArgs" value="true" />
+    <property name="argsDescription" value="product-type-id" />
+    <property name="requirementRules">
+      <list>
+        <bean 
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+          p:actionName="addProductType" p:relation="REQUIRED" />
+      </list>
+    </property>
+    <property name="handler">
+      <bean 
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler">
+        <property name="applyToActions">
+          <list>
+            <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToAction"
+              p:actionName="addProductType" p:methodName="setProductTypeId" />
+          </list>
+        </property>
+      </bean>
+    </property>
+  </bean>
+
   <bean id="typeName" 
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
     <property name="shortOption" value="tn" />
     <property name="longOption" value="typeName" />

Modified: 
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/cli/TestFileManagerCli.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/cli/TestFileManagerCli.java?rev=1700084&r1=1700083&r2=1700084&view=diff
==============================================================================
--- 
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/cli/TestFileManagerCli.java
 (original)
+++ 
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/cli/TestFileManagerCli.java
 Sun Aug 30 01:32:43 2015
@@ -95,9 +95,10 @@ public class TestFileManagerCli extends
       String productTypeDesc = "ProductTypeDesc";
       String productTypeRepo = "ProductTypeRepo";
       String productTypeVersioner = "ProductTypeVersioner";
+      String productTypeId = "MyProductTypeId";
       cmdLineUtility
             .run(("--url http://localhost:9000 --operation --addProductType"
-                  + " --typeName " + productTypeName + " --typeDesc "
+                  + " --typeName " + productTypeName + " --typeId 
"+productTypeId+" --typeDesc "
                   + productTypeDesc + " --repository " + productTypeRepo
                   + " --versionClass " + productTypeVersioner).split(" "));
       MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();

Modified: 
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/cli/action/TestAddProductTypeCliAction.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/cli/action/TestAddProductTypeCliAction.java?rev=1700084&r1=1700083&r2=1700084&view=diff
==============================================================================
--- 
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/cli/action/TestAddProductTypeCliAction.java
 (original)
+++ 
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/cli/action/TestAddProductTypeCliAction.java
 Sun Aug 30 01:32:43 2015
@@ -35,6 +35,7 @@ import junit.framework.TestCase;
  * Test class for {@link AddProductTypeCliAction}.
  * 
  * @author bfoster (Brian Foster)
+ * @author riverma (Rishi Verma)
  */
 public class TestAddProductTypeCliAction extends TestCase {
 
@@ -74,11 +75,18 @@ public class TestAddProductTypeCliAction
       } catch (CmdLineActionException ignore) {
       }
       cliAction.setVersioner(PRODUCT_TYPE_VERSIONER);
+      try {
+         cliAction.execute(printer);
+         fail("Expected throw CmdLineActionException");
+      } catch (CmdLineActionException ignore) {
+      }
+      cliAction.setProductTypeId(PRODUCT_TYPE_ID);
       cliAction.execute(printer); // Should not throw exception.
    }
 
    public void testDataFlow() throws CmdLineActionException {
       MockAddProductTypeCliAction cliAction = new 
MockAddProductTypeCliAction();
+      cliAction.setProductTypeId(PRODUCT_TYPE_ID);
       cliAction.setProductTypeName(PRODUCT_TYPE_NAME);
       cliAction.setProductTypeDescription(PRODUCT_TYPE_DESC);
       cliAction.setFileRepositoryPath(PRODUCT_TYPE_REPO);
@@ -90,6 +98,7 @@ public class TestAddProductTypeCliAction
             .getPrintedMessages().get(0));
       assertEquals("\n", printer.getPrintedMessages().get(1));
 
+      assertEquals(PRODUCT_TYPE_ID, 
productTypePassedToClient.getProductTypeId());
       assertEquals(PRODUCT_TYPE_NAME, productTypePassedToClient.getName());
       assertEquals(PRODUCT_TYPE_DESC,
             productTypePassedToClient.getDescription());

Modified: 
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/repository/TestXMLRepositoryManager.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/repository/TestXMLRepositoryManager.java?rev=1700084&r1=1700083&r2=1700084&view=diff
==============================================================================
--- 
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/repository/TestXMLRepositoryManager.java
 (original)
+++ 
oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/repository/TestXMLRepositoryManager.java
 Sun Aug 30 01:32:43 2015
@@ -170,8 +170,8 @@ public class TestXMLRepositoryManager ex
         }
 
         assertNotNull(type);
-        assertNull(type.getTypeMetadata());
-
+        assertNotNull(type.getTypeMetadata());
+       assertEquals(0, type.getTypeMetadata().getKeys().size());
     }
 
     /**

Modified: oodt/trunk/filemgr/src/test/resources/cmd-line-options.xml
URL: 
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/resources/cmd-line-options.xml?rev=1700084&r1=1700083&r2=1700084&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/test/resources/cmd-line-options.xml (original)
+++ oodt/trunk/filemgr/src/test/resources/cmd-line-options.xml Sun Aug 30 
01:32:43 2015
@@ -16,6 +16,7 @@
   limitations under the License.
 
   Author: bfoster (Brian Foster)
+          riverma (Rishi Verma)
 -->
 <beans xmlns="http://www.springframework.org/schema/beans";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:p="http://www.springframework.org/schema/p";
@@ -117,6 +118,30 @@
                </property>
        </bean>
 
+  <bean id="typeId" 
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
+    <property name="shortOption" value="tid" />
+    <property name="longOption" value="typeId" />
+    <property name="description" value="ProductType Id" />
+    <property name="hasArgs" value="true" />
+    <property name="argsDescription" value="product-type-id" />
+    <property name="requirementRules">
+      <list>
+        <bean 
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+          p:actionName="addProductType" p:relation="REQUIRED" />
+      </list>
+    </property>
+    <property name="handler">
+      <bean 
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler">
+        <property name="applyToActions">
+          <list>
+            <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToAction"
+              p:actionName="addProductType" p:methodName="setProductTypeId" />
+          </list>
+        </property>
+      </bean>
+    </property>
+  </bean>
+
   <bean id="typeName" 
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
     <property name="shortOption" value="tn" />
     <property name="longOption" value="typeName" />


Reply via email to