You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/11/21 01:18:25 UTC
svn commit: r1204299 - in /oodt/trunk/filemgr/src:
main/java/org/apache/oodt/cas/filemgr/util/
test/org/apache/oodt/cas/filemgr/catalog/
test/org/apache/oodt/cas/filemgr/util/
Author: bfoster
Date: Mon Nov 21 00:18:24 2011
New Revision: 1204299
URL: http://svn.apache.org/viewvc?rev=1204299&view=rev
Log:
- getXmlRpcProduct and getProductFromXmlRpc now allow null values for product member variables since Product is just a carrier
----------
OODT-353
Added:
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalog.java (with props)
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalogFactory.java (with props)
Modified:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlRpcStructFactory.java
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/util/TestXmlRpcStructFactory.java
Modified: oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlRpcStructFactory.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlRpcStructFactory.java?rev=1204299&r1=1204298&r2=1204299&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlRpcStructFactory.java (original)
+++ oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlRpcStructFactory.java Mon Nov 21 00:18:24 2011
@@ -241,29 +241,51 @@ public final class XmlRpcStructFactory {
public static Hashtable<String, Object> getXmlRpcProduct(Product product) {
Hashtable<String, Object> productHash = new Hashtable<String, Object>();
- productHash.put("id", product.getProductId() != null ? product
- .getProductId() : "");
- productHash.put("name", product.getProductName());
- productHash.put("type", getXmlRpcProductType(product.getProductType()));
- productHash.put("structure", product.getProductStructure());
- productHash.put("transferStatus",
- product.getTransferStatus() != null ? product
- .getTransferStatus() : "");
- productHash.put("references", getXmlRpcReferences(product
+ if (product.getProductId() != null) {
+ productHash.put("id", product.getProductId());
+ }
+ if (product.getProductName() != null) {
+ productHash.put("name", product.getProductName());
+ }
+ if (product.getProductType() != null) {
+ productHash.put("type", getXmlRpcProductType(product.getProductType()));
+ }
+ if (product.getProductStructure() != null) {
+ productHash.put("structure", product.getProductStructure());
+ }
+ if (product.getTransferStatus() != null) {
+ productHash.put("transferStatus", product.getTransferStatus());
+ }
+ if (product.getProductReferences() != null) {
+ productHash.put("references", getXmlRpcReferences(product
.getProductReferences()));
+ }
+ if (product.getRootRef() != null) {
+ productHash.put("rootReference", getXmlRpcReference(product
+ .getRootRef()));
+ }
return productHash;
}
public static Product getProductFromXmlRpc(Hashtable<String, Object> productHash) {
Product product = new Product();
-
product.setProductId((String) productHash.get("id"));
product.setProductName((String) productHash.get("name"));
- product.setProductType(getProductTypeFromXmlRpc((Hashtable<String, Object>) productHash.get("type")));
+ if (productHash.get("type") != null) {
+ product.setProductType(getProductTypeFromXmlRpc(
+ (Hashtable<String, Object>) productHash.get("type")));
+ }
product.setProductStructure((String) productHash.get("structure"));
product.setTransferStatus((String) productHash.get("transferStatus"));
- product.setProductReferences(getReferencesFromXmlRpc((Vector<Hashtable<String, Object>>) productHash
+ if (productHash.get("references") != null) {
+ product.setProductReferences(getReferencesFromXmlRpc(
+ (Vector<Hashtable<String, Object>>) productHash
.get("references")));
+ }
+ if (productHash.get("rootReference") != null) {
+ product.setRootRef(getReferenceFromXmlRpc(
+ (Hashtable<String, Object>) productHash.get("rootReference")));
+ }
return product;
}
@@ -323,28 +345,29 @@ public final class XmlRpcStructFactory {
public static Hashtable<String, Object> getXmlRpcProductType(ProductType type) {
Hashtable<String, Object> productTypeHash = new Hashtable<String, Object>();
+ // TODO(bfoster): ProductType ID is currently required by XmlRpcFileManager.
productTypeHash.put("id", type.getProductTypeId());
- productTypeHash.put("name", type.getName() != null ? type.getName()
- : "");
- productTypeHash.put("description", type.getDescription() != null ? type
- .getDescription() : "");
- productTypeHash.put("repositoryPath",
- type.getProductRepositoryPath() != null ? type
- .getProductRepositoryPath() : "");
- productTypeHash.put("versionerClass",
- type.getVersioner() != null ? type.getVersioner() : "");
- productTypeHash.put("typeMetadata",
- type.getTypeMetadata() != null ? type.getTypeMetadata()
- .getHashtable() : new Hashtable<String, Object>());
-
- productTypeHash.put("typeExtractors",
- type.getExtractors() != null ? getXmlRpcTypeExtractors(type
- .getExtractors()) : new Vector<Hashtable<String, Object>>());
-
- productTypeHash.put("typeHandlers",
- type.getHandlers() != null ? getXmlRpcTypeHandlers(type
- .getHandlers()) : new Vector<Hashtable<String, Object>>());
-
+ if (type.getName() != null) {
+ productTypeHash.put("name", type.getName());
+ }
+ if (type.getDescription() != null) {
+ productTypeHash.put("description", type.getDescription());
+ }
+ if (type.getProductRepositoryPath() != null) {
+ productTypeHash.put("repositoryPath",type.getProductRepositoryPath());
+ }
+ if (type.getVersioner() != null) {
+ productTypeHash.put("versionerClass", type.getVersioner());
+ }
+ if (type.getTypeMetadata() != null) {
+ productTypeHash.put("typeMetadata", type.getTypeMetadata().getHashtable());
+ }
+ if (type.getExtractors() != null) {
+ productTypeHash.put("typeExtractors", getXmlRpcTypeExtractors(type.getExtractors()));
+ }
+ if (type.getHandlers() != null) {
+ productTypeHash.put("typeHandlers", getXmlRpcTypeHandlers(type.getHandlers()));
+ }
return productTypeHash;
}
@@ -352,28 +375,24 @@ public final class XmlRpcStructFactory {
ProductType type = new ProductType();
type.setDescription((String) productTypeHash.get("description"));
type.setName((String) productTypeHash.get("name"));
- type.setProductRepositoryPath((String) productTypeHash
- .get("repositoryPath"));
+ type.setProductRepositoryPath((String) productTypeHash.get("repositoryPath"));
type.setProductTypeId((String) productTypeHash.get("id"));
type.setVersioner((String) productTypeHash.get("versionerClass"));
- Metadata typeMet = new Metadata();
if (productTypeHash.get("typeMetadata") != null) {
- typeMet
- .addMetadata((Hashtable) productTypeHash.get("typeMetadata"));
+ Metadata typeMet = new Metadata();
+ typeMet.addMetadata((Hashtable) productTypeHash.get("typeMetadata"));
+ type.setTypeMetadata(typeMet);
}
-
if (productTypeHash.get("typeExtractors") != null) {
- type
- .setExtractors(getTypeExtractorsFromXmlRpc((Vector<Hashtable<String, Object>>) productTypeHash
- .get("typeExtractors")));
+ type.setExtractors(getTypeExtractorsFromXmlRpc(
+ (Vector<Hashtable<String, Object>>) productTypeHash
+ .get("typeExtractors")));
}
-
if (productTypeHash.get("typeHandlers") != null) {
- type.setHandlers(getTypeHandlersFromXmlRpc((Vector<Hashtable<String, Object>>) productTypeHash
+ type.setHandlers(getTypeHandlersFromXmlRpc(
+ (Vector<Hashtable<String, Object>>) productTypeHash
.get("typeHandlers")));
}
-
- type.setTypeMetadata(typeMet);
return type;
}
Added: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalog.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalog.java?rev=1204299&view=auto
==============================================================================
--- oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalog.java (added)
+++ oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalog.java Mon Nov 21 00:18:24 2011
@@ -0,0 +1,187 @@
+/*
+ * 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.filemgr.catalog;
+
+//JDK imports
+import java.util.List;
+import java.util.Map;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.ProductPage;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.Query;
+import org.apache.oodt.cas.filemgr.structs.Reference;
+import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
+import org.apache.oodt.cas.filemgr.validation.ValidationLayer;
+import org.apache.oodt.cas.metadata.Metadata;
+
+//Google imports
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+/**
+ * A Mock {@link Catalog}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class MockCatalog implements Catalog {
+
+ Map<String, Product> products;
+
+ public MockCatalog() {
+ products = Maps.newHashMap();
+ }
+
+ @Override
+ public ProductPage getFirstPage(ProductType type) {
+ return null;
+ }
+
+ @Override
+ public ProductPage getLastProductPage(ProductType type) {
+ return null;
+ }
+
+ @Override
+ public ProductPage getNextPage(ProductType type, ProductPage currentPage) {
+ return null;
+ }
+
+ @Override
+ public ProductPage getPrevPage(ProductType type, ProductPage currentPage) {
+ return null;
+ }
+
+ @Override
+ public void addMetadata(Metadata m, Product product) throws CatalogException {
+ }
+
+ @Override
+ public void removeMetadata(Metadata m, Product product)
+ throws CatalogException {
+ }
+
+ @Override
+ public void addProduct(Product product) throws CatalogException {
+ products.put(product.getProductId(), product);
+ }
+
+ @Override
+ public void modifyProduct(Product product) throws CatalogException {
+ products.put(product.getProductId(), product);
+ }
+
+ @Override
+ public void removeProduct(Product product) throws CatalogException {
+ products.remove(product.getProductId());
+ }
+
+ @Override
+ public void setProductTransferStatus(Product product)
+ throws CatalogException {
+ Product ingestedProduct = products.get(product.getProductId());
+ ingestedProduct.setTransferStatus(product.getTransferStatus());
+ }
+
+ @Override
+ public void addProductReferences(Product product) throws CatalogException {
+ Product ingestedProduct = products.get(product.getProductId());
+ List<Reference> references = ingestedProduct.getProductReferences();
+ if (references == null) {
+ references = Lists.newArrayList();
+ }
+ references.addAll(product.getProductReferences());
+ ingestedProduct.setProductReferences(references);
+ }
+
+ @Override
+ public Product getProductById(String productId) throws CatalogException {
+ return products.get(productId);
+ }
+
+ @Override
+ public Product getProductByName(String productName) throws CatalogException {
+ for (Product product : products.values()) {
+ if (product.getProductName().equals(productName)) {
+ return product;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<Reference> getProductReferences(Product product)
+ throws CatalogException {
+ return null;
+ }
+
+ @Override
+ public List<Product> getProducts() throws CatalogException {
+ return Lists.newArrayList(products.values());
+ }
+
+ @Override
+ public List<Product> getProductsByProductType(ProductType type)
+ throws CatalogException {
+ return null;
+ }
+
+ @Override
+ public Metadata getMetadata(Product product) throws CatalogException {
+ return null;
+ }
+
+ @Override
+ public Metadata getReducedMetadata(Product product, List<String> elements)
+ throws CatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> query(Query query, ProductType type)
+ throws CatalogException {
+ return null;
+ }
+
+ @Override
+ public ProductPage pagedQuery(Query query, ProductType type, int pageNum)
+ throws CatalogException {
+ return null;
+ }
+
+ @Override
+ public List<Product> getTopNProducts(int n) throws CatalogException {
+ return null;
+ }
+
+ @Override
+ public List<Product> getTopNProducts(int n, ProductType type)
+ throws CatalogException {
+ return null;
+ }
+
+ @Override
+ public ValidationLayer getValidationLayer() throws CatalogException {
+ return null;
+ }
+
+ @Override
+ public int getNumProducts(ProductType type) throws CatalogException {
+ return 0;
+ }
+}
Propchange: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalog.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalogFactory.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalogFactory.java?rev=1204299&view=auto
==============================================================================
--- oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalogFactory.java (added)
+++ oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalogFactory.java Mon Nov 21 00:18:24 2011
@@ -0,0 +1,30 @@
+/*
+ * 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.filemgr.catalog;
+
+/**
+ * A Mock {@link CatalogFactory}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class MockCatalogFactory implements CatalogFactory {
+
+ @Override
+ public MockCatalog createCatalog() {
+ return new MockCatalog();
+ }
+}
Propchange: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/MockCatalogFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/util/TestXmlRpcStructFactory.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/util/TestXmlRpcStructFactory.java?rev=1204299&r1=1204298&r2=1204299&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/util/TestXmlRpcStructFactory.java (original)
+++ oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/util/TestXmlRpcStructFactory.java Mon Nov 21 00:18:24 2011
@@ -14,32 +14,47 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.oodt.cas.filemgr.util;
+//OODT imports
+import org.apache.oodt.cas.filemgr.datatransfer.InPlaceDataTransferFactory;
import org.apache.oodt.cas.filemgr.datatransfer.LocalDataTransferFactory;
import org.apache.oodt.cas.filemgr.structs.ExtractorSpec;
+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.filemgr.structs.exceptions.ConnectionException;
import org.apache.oodt.cas.filemgr.structs.exceptions.RepositoryManagerException;
import org.apache.oodt.cas.filemgr.structs.type.TypeHandler;
import org.apache.oodt.cas.filemgr.system.XmlRpcFileManager;
import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient;
+import org.apache.oodt.cas.metadata.Metadata;
+
+//Google imports
+import com.google.common.collect.Lists;
+//JDK imports
import java.io.File;
import java.io.FileInputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
+//JUnit imports
import junit.framework.TestCase;
+/**
+ * Test class for {@link XmlRpcStructFactory}.
+ *
+ * @author mattmann (Chris Mattmann)
+ * @author bfoster (Brian Foster)
+ */
public class TestXmlRpcStructFactory extends TestCase {
final int FILEMGR_PORT = 9999;
XmlRpcFileManager fmServer;
-
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -78,7 +93,73 @@ public class TestXmlRpcStructFactory ext
assertTrue(handler1.getElementName().equals(handler2.getElementName()));
}
}
-
+
+ public void testProductMethods() throws Exception {
+ XmlRpcFileManagerClient fmClient = new XmlRpcFileManagerClient(new URL("http://localhost:" + FILEMGR_PORT));
+ fmClient.setDataTransfer(new InPlaceDataTransferFactory().createDataTransfer());
+
+ Product product = new Product();
+ Product roundTripProduct = XmlRpcStructFactory.getProductFromXmlRpc(
+ XmlRpcStructFactory.getXmlRpcProduct(product));
+ assertEquals(product, roundTripProduct);
+
+ product = new Product();
+ product.setProductId("TestId");
+ product.setProductName("TestName");
+ product.setProductReferences(Lists.newArrayList(new Reference("file:///original/path", null, 2)));
+ product.setProductStructure("Flat");
+ product.setProductType(fmClient.getProductTypeByName("GenericFile"));
+ product.setRootRef(new Reference("file:///original/root", "file:///datastore/root", 3));
+ roundTripProduct = XmlRpcStructFactory.getProductFromXmlRpc(XmlRpcStructFactory.getXmlRpcProduct(product));
+ assertEquals(product, roundTripProduct);
+ Metadata m = new Metadata();
+ m.addMetadata("TestKey", "TestValue");
+
+ roundTripProduct = fmClient.getProductById(
+ fmClient.ingestProduct(product, m, true));
+ assertEquals(product, roundTripProduct);
+ }
+
+ private void assertEquals(Product product1, Product product2) {
+ if (product1 == null) {
+ assertNull(product2);
+ return;
+ }
+ assertEquals(product1.getProductId(), product2.getProductId());
+ assertEquals(product1.getProductName(), product2.getProductName());
+ assertEquals(product1.getProductStructure(), product2.getProductStructure());
+ assertEquals(product1.getTransferStatus(), product2.getTransferStatus());
+ if (product1.getProductReferences() == null) {
+ assertEquals(product1.getProductReferences(), product2.getProductReferences());
+ } else {
+ for (int i = 0; i < product1.getProductReferences().size(); i++) {
+ assertEquals(product1.getProductReferences().get(i),
+ product2.getProductReferences().get(i));
+ }
+ }
+ if (product1.getProductType() == null) {
+ assertEquals(product1.getProductType(), product2.getProductType());
+ } else {
+ assertEquals(product1.getProductType().getDescription(), product2.getProductType().getDescription());
+ assertEquals(product1.getProductType().getName(), product2.getProductType().getName());
+ assertEquals(product1.getProductType().getProductRepositoryPath(), product2.getProductType().getProductRepositoryPath());
+ assertEquals(product1.getProductType().getProductTypeId(), product2.getProductType().getProductTypeId());
+ assertEquals(product1.getProductType().getVersioner(), product2.getProductType().getVersioner());
+ }
+ assertEquals(product1.getRootRef(), product2.getRootRef());
+ }
+
+ private void assertEquals(Reference ref1, Reference ref2) {
+ if (ref1 == null) {
+ assertNull(ref2);
+ return;
+ }
+ assertNotNull(ref2.getDataStoreReference());
+ assertEquals(ref1.getFileSize(), ref2.getFileSize());
+ assertEquals(ref1.getOrigReference(), ref2.getOrigReference());
+ assertEquals(ref1.getMimeType(), ref2.getMimeType());
+ }
+
private void startXmlRpcFileManager() {
// first make sure to load properties for the file manager
// and make sure to load logging properties as well
@@ -96,10 +177,7 @@ public class TestXmlRpcStructFactory ext
}
System.setProperty("filemgr.catalog.factory",
- "org.apache.oodt.cas.filemgr.catalog.LuceneCatalogFactory");
- System.setProperty(
- "org.apache.oodt.cas.filemgr.catalog.lucene.idxPath",
- "./src/testdata/ingest/cat");
+ "org.apache.oodt.cas.filemgr.catalog.MockCatalogFactory");
// now override the repo mgr policy
try {