Author: thomas
Date: Mon Jun  9 07:23:01 2014
New Revision: 1601319

URL: http://svn.apache.org/r1601319
Log:
OODT-703 DataUtil.createProductZipFile throws exception when creating a zipfile 
of a hierarchical product

Added:
    oodt/trunk/webapp/fmprod/src/test/java/org/apache/oodt/cas/product/data/
    
oodt/trunk/webapp/fmprod/src/test/java/org/apache/oodt/cas/product/data/TestDataUtils.java
    oodt/trunk/webapp/fmprod/src/testdata/
    oodt/trunk/webapp/fmprod/src/testdata/data/
    oodt/trunk/webapp/fmprod/src/testdata/data/test-file-1.txt
    oodt/trunk/webapp/fmprod/src/testdata/data/test-file-2.txt
    oodt/trunk/webapp/fmprod/src/testdata/data/test-file-3.txt
Modified:
    oodt/trunk/CHANGES.txt
    
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/data/DataUtils.java

Modified: oodt/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1601319&r1=1601318&r2=1601319&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Mon Jun  9 07:23:01 2014
@@ -1,9 +1,14 @@
 Apache OODT Change Log
 ======================
 
-Release 0.7 - Current Development
+Release 0.8 - Current Development
 ---------------------------------
 
+* OODT-703 DataUtil.createProductZipFile throws exception when creating a 
zipfile of a hierarchical product
+
+Release 0.7 - 08/06/2014
+--------------------------------------------
+
 * OODT-674 MoveDatafileToFailureDir fails to move files off an NFS mounted 
directory (thomas)
 
 * OODT-662 Upgrade cog-jglobus dependency in protocol-ftp (lewismc)

Modified: 
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/data/DataUtils.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/data/DataUtils.java?rev=1601319&r1=1601318&r2=1601319&view=diff
==============================================================================
--- 
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/data/DataUtils.java
 (original)
+++ 
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/data/DataUtils.java
 Mon Jun  9 07:23:01 2014
@@ -143,6 +143,11 @@ public final class DataUtils implements 
 
       try {
         File prodFile = new File(new URI(r.getDataStoreReference()));
+        if (prodFile.isDirectory()) {
+            LOG.log(Level.WARNING, "Data store reference is a directory. Not 
adding directory to the zip file: ["
+                    + r.getDataStoreReference() + "]");
+            continue;
+        }
         String filename = prodFile.getName();
         FileInputStream in = new FileInputStream(prodFile.getAbsoluteFile());
         addZipEntryFromStream(in, out, filename);

Added: 
oodt/trunk/webapp/fmprod/src/test/java/org/apache/oodt/cas/product/data/TestDataUtils.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/webapp/fmprod/src/test/java/org/apache/oodt/cas/product/data/TestDataUtils.java?rev=1601319&view=auto
==============================================================================
--- 
oodt/trunk/webapp/fmprod/src/test/java/org/apache/oodt/cas/product/data/TestDataUtils.java
 (added)
+++ 
oodt/trunk/webapp/fmprod/src/test/java/org/apache/oodt/cas/product/data/TestDataUtils.java
 Mon Jun  9 07:23:01 2014
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.cas.product.data;
+
+import java.io.File;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.Reference;
+import org.apache.oodt.cas.metadata.Metadata;
+
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests DataUtils module methods
+ *
+ * @author thomas (Thomas Bennett)
+ */
+
+public class TestDataUtils extends TestCase {
+    private File workingDir;
+       @Override
+       public void tearDown() throws Exception {
+               FileUtils.forceDelete(workingDir);
+       }
+
+       public void testCreateProductZipFileFromHierarchicalProduct(){
+               //Data store reference needs absolute path to test data
+               String cwd=System.getProperty("user.dir");
+
+               Product product = new Product();
+               product.setProductId("TestProductId");
+               product.setProductName("TestProductName");
+               product.setProductReferences(Lists.newArrayList(
+                       new Reference("file:///orig/data/", "file://" + cwd + 
"/src/testdata/data/", 4096),
+                       new Reference("file:///orig/data/test-file-1.txt", 
"file://" + cwd + "/src/testdata/data/test-file-1.txt", 20),
+                       new Reference("file:///orig/data/test-file-2.txt", 
"file://" + cwd + "/src/testdata/data/test-file-2.txt", 20),
+                       new Reference("file:///orig/data/test-file-3.txt", 
"file://" + cwd + "/src/testdata/data/test-file-3.txt", 20)));
+               product.setProductStructure(Product.STRUCTURE_HIERARCHICAL);
+               product.setTransferStatus(Product.STATUS_RECEIVED);
+               ProductType pt = new ProductType();
+               pt.setName("TestProductType");
+
+               Metadata metadata = new Metadata();
+
+               String workingDirPath = null;
+               workingDir = Files.createTempDir();
+               workingDirPath = workingDir.getAbsolutePath();
+               workingDir.deleteOnExit();
+
+               String productZipFilePath = null;
+               try {
+                       productZipFilePath = 
DataUtils.createProductZipFile(product, metadata, workingDirPath);
+               } catch (Exception e) {
+                       fail(e.getMessage());
+               }
+               String zipFileName = product.getProductName() + ".zip";
+               assertEquals(productZipFilePath, workingDirPath + "/" + 
zipFileName);
+       }
+
+}

Added: oodt/trunk/webapp/fmprod/src/testdata/data/test-file-1.txt
URL: 
http://svn.apache.org/viewvc/oodt/trunk/webapp/fmprod/src/testdata/data/test-file-1.txt?rev=1601319&view=auto
==============================================================================
--- oodt/trunk/webapp/fmprod/src/testdata/data/test-file-1.txt (added)
+++ oodt/trunk/webapp/fmprod/src/testdata/data/test-file-1.txt Mon Jun  9 
07:23:01 2014
@@ -0,0 +1 @@
+this is test-file-1

Added: oodt/trunk/webapp/fmprod/src/testdata/data/test-file-2.txt
URL: 
http://svn.apache.org/viewvc/oodt/trunk/webapp/fmprod/src/testdata/data/test-file-2.txt?rev=1601319&view=auto
==============================================================================
--- oodt/trunk/webapp/fmprod/src/testdata/data/test-file-2.txt (added)
+++ oodt/trunk/webapp/fmprod/src/testdata/data/test-file-2.txt Mon Jun  9 
07:23:01 2014
@@ -0,0 +1 @@
+this is test-file-2

Added: oodt/trunk/webapp/fmprod/src/testdata/data/test-file-3.txt
URL: 
http://svn.apache.org/viewvc/oodt/trunk/webapp/fmprod/src/testdata/data/test-file-3.txt?rev=1601319&view=auto
==============================================================================
--- oodt/trunk/webapp/fmprod/src/testdata/data/test-file-3.txt (added)
+++ oodt/trunk/webapp/fmprod/src/testdata/data/test-file-3.txt Mon Jun  9 
07:23:01 2014
@@ -0,0 +1 @@
+this is test-file-3


Reply via email to