Author: bfoster
Date: Sat May 3 06:56:33 2014
New Revision: 1592156
URL: http://svn.apache.org/r1592156
Log:
Create configurable MetadataBasedFileVersioner ... OODT-681
Added:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/ConfigurableMetadataBasedFileVersioner.java
(with props)
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/versioning/TestConfigurableMetadataBasedFileVersioner.java
(with props)
Added:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/ConfigurableMetadataBasedFileVersioner.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/ConfigurableMetadataBasedFileVersioner.java?rev=1592156&view=auto
==============================================================================
---
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/ConfigurableMetadataBasedFileVersioner.java
(added)
+++
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/ConfigurableMetadataBasedFileVersioner.java
Sat May 3 06:56:33 2014
@@ -0,0 +1,75 @@
+/*
+ * 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.versioning;
+
+// JDK imports
+import java.util.Properties;
+
+
+// OODT imports
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.exceptions.VersioningException;
+import org.apache.oodt.cas.metadata.Metadata;
+
+
+// Google imports
+import com.google.common.base.Strings;
+
+/**
+ * A {@link MetadataBasedFileVersioner} which is configurable via java
properties. Set the
+ * following java property to configure file_spec per product type:
+ * org.apache.oodt.cas.filemgr.versioning.configuration.<product_type_name>
+ * Or set the following java property to configure all product types:
+ * org.apache.oodt.cas.filemgr.versioning.configuration.all_product_types
+ *
+ * @author [email protected] (Brian Foster)
+ */
+public class ConfigurableMetadataBasedFileVersioner extends
MetadataBasedFileVersioner {
+
+ private static final String BASE_PROPERTY =
+ "org.apache.oodt.cas.filemgr.versioning.configuration.";
+ private static final String ALL = "all_product_types";
+
+ private final Properties properties;
+
+ public ConfigurableMetadataBasedFileVersioner() {
+ this(System.getProperties());
+ }
+
+ public ConfigurableMetadataBasedFileVersioner(Properties properties) {
+ this.properties = properties;
+ }
+
+ @Override
+ public void createDataStoreReferences(Product product, Metadata metadata)
+ throws VersioningException {
+ setFilePathSpec(getFilePathSpec(product.getProductType()));
+ super.createDataStoreReferences(product, metadata);
+ }
+
+ private String getFilePathSpec(ProductType productType) throws
VersioningException {
+ String fileSpec = properties.getProperty(BASE_PROPERTY +
productType.getName().toLowerCase());
+ if (Strings.isNullOrEmpty(fileSpec)) {
+ fileSpec = properties.getProperty(BASE_PROPERTY + ALL);
+ if (Strings.isNullOrEmpty(fileSpec)) {
+ throw new VersioningException("Not defined for product type " +
productType.getName());
+ }
+ }
+ return fileSpec;
+ }
+}
Propchange:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/ConfigurableMetadataBasedFileVersioner.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/versioning/TestConfigurableMetadataBasedFileVersioner.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/versioning/TestConfigurableMetadataBasedFileVersioner.java?rev=1592156&view=auto
==============================================================================
---
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/versioning/TestConfigurableMetadataBasedFileVersioner.java
(added)
+++
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/versioning/TestConfigurableMetadataBasedFileVersioner.java
Sat May 3 06:56:33 2014
@@ -0,0 +1,129 @@
+/*
+ * 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.versioning;
+
+// JUnit static imports
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+// JDK imports
+import java.util.Properties;
+
+// OODT imports
+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.VersioningException;
+import org.apache.oodt.cas.metadata.Metadata;
+
+// JUnit imports
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+// Google imports
+import com.google.common.collect.Lists;
+
+/**
+ * Test class for {@link ConfigurableMetadataBasedFileVersioner}.
+ *
+ * @author [email protected] (Brian Foster)
+ */
+@RunWith(JUnit4.class)
+public class TestConfigurableMetadataBasedFileVersioner {
+
+ @Rule public ExpectedException expectedException = ExpectedException.none();
+
+ private Properties properties;
+ private ConfigurableMetadataBasedFileVersioner versioner;
+ private Metadata metadata;
+ private Product product;
+
+ @Before
+ public void setUp() {
+ properties = new Properties();
+
properties.setProperty("org.apache.oodt.cas.filemgr.versioning.configuration.test_type",
+ "/[Year]/[Month]/[Day]/[Filename]");
+ versioner = new ConfigurableMetadataBasedFileVersioner(properties);
+ metadata = new Metadata();
+ metadata.addMetadata("Year", "2013");
+ metadata.addMetadata("Month", "03");
+ metadata.addMetadata("Day", "23");
+ metadata.addMetadata("Filename", "test.dat");
+ product = new Product();
+ product.setProductStructure(Product.STRUCTURE_FLAT);
+ ProductType pt = new ProductType();
+ pt.setProductRepositoryPath("file:/base/path");
+ pt.setName("TEST_TYPE");
+ product.setProductType(pt);
+ Reference ref = new Reference();
+ ref.setOrigReference("/path/to/file");
+ product.setProductReferences(Lists.newArrayList(ref));
+ }
+
+ @Test
+ public void testVersioningForProductType() throws VersioningException {
+ versioner.createDataStoreReferences(product, metadata);
+
+ assertThat(product.getProductReferences().size(), is(1));
+ assertThat(product.getProductReferences().get(0).getDataStoreReference(),
+ is("file:/base/path/2013/03/23/test.dat"));
+ }
+
+ @Test
+ public void testVersioningForProductTypeNotDefined() throws
VersioningException {
+ ProductType pt = new ProductType();
+ pt.setProductRepositoryPath("file:/base/path");
+ pt.setName("TEST_TYPE2");
+ product.setProductType(pt);
+
+ expectedException.expect(VersioningException.class);
+ versioner.createDataStoreReferences(product, metadata);
+ }
+
+ @Test
+ public void testVersioningForAllProductTypesDoesntOverrideSpecific() throws
VersioningException {
+
properties.setProperty("org.apache.oodt.cas.filemgr.versioning.configuration.all_product_types",
+ "/[Year]/[Month]/[Filename]");
+
+ versioner.createDataStoreReferences(product, metadata);
+
+ assertThat(product.getProductReferences().size(), is(1));
+ assertThat(product.getProductReferences().get(0).getDataStoreReference(),
+ is("file:/base/path/2013/03/23/test.dat"));
+ }
+
+ @Test
+ public void testVersioningForAllProductTypes() throws VersioningException {
+
properties.setProperty("org.apache.oodt.cas.filemgr.versioning.configuration.all_product_types",
+ "/[Year]/[Month]/[Filename]");
+
+ ProductType pt = new ProductType();
+ pt.setProductRepositoryPath("file:/base/path");
+ pt.setName("TEST_TYPE2");
+ product.setProductType(pt);
+
+ versioner.createDataStoreReferences(product, metadata);
+
+ assertThat(product.getProductReferences().size(), is(1));
+ assertThat(product.getProductReferences().get(0).getDataStoreReference(),
+ is("file:/base/path/2013/03/test.dat"));
+ }
+}
Propchange:
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/versioning/TestConfigurableMetadataBasedFileVersioner.java
------------------------------------------------------------------------------
svn:mime-type = text/plain