Author: mattmann
Date: Thu Dec 30 21:09:56 2010
New Revision: 1054000
URL: http://svn.apache.org/viewvc?rev=1054000&view=rev
Log:
- progress towards OODT-72 Unable to set Metadata based off Product Versioning
during Product ingestion: add FinalFileLocationExtractor to help generate
product ref. Will still implement suggested fix by bfoster
Added:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/metadata/extractors/examples/FinalFileLocationExtractor.java
(with props)
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/metadata/extractors/examples/TestFinalFileLocationExtractor.java
(with props)
Modified:
oodt/trunk/filemgr/src/main/resources/examples/product-types.xml
Added:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/metadata/extractors/examples/FinalFileLocationExtractor.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/metadata/extractors/examples/FinalFileLocationExtractor.java?rev=1054000&view=auto
==============================================================================
---
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/metadata/extractors/examples/FinalFileLocationExtractor.java
(added)
+++
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/metadata/extractors/examples/FinalFileLocationExtractor.java
Thu Dec 30 21:09:56 2010
@@ -0,0 +1,107 @@
+/**
+ * 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.metadata.extractors.examples;
+
+//JDK imports
+import java.io.File;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
+import
org.apache.oodt.cas.filemgr.metadata.extractors.AbstractFilemgrMetExtractor;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.Reference;
+import org.apache.oodt.cas.filemgr.structs.exceptions.VersioningException;
+import org.apache.oodt.cas.filemgr.util.GenericFileManagerObjectFactory;
+import org.apache.oodt.cas.filemgr.versioning.Versioner;
+import org.apache.oodt.cas.filemgr.versioning.VersioningUtils;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.metadata.exceptions.MetExtractionException;
+
+/**
+ *
+ * Extracts the final <code>FILE_LOCATION</code> met field from the underlying
+ * {...@link Product} and sets it appropriately in the {...@link Product}
+ * {...@link Metadata}.
+ *
+ */
+public class FinalFileLocationExtractor extends AbstractFilemgrMetExtractor
+ implements CoreMetKeys {
+
+ private boolean replaceLocation;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ *
org.apache.oodt.cas.filemgr.metadata.extractors.AbstractFilemgrMetExtractor
+ * #doConfigure()
+ */
+ @Override
+ public void doConfigure() {
+ if (this.configuration != null) {
+ this.replaceLocation = Boolean.parseBoolean(this.configuration
+ .getProperty("replace"));
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ *
org.apache.oodt.cas.filemgr.metadata.extractors.AbstractFilemgrMetExtractor
+ * #doExtract(org.apache.oodt.cas.filemgr.structs.Product,
+ * org.apache.oodt.cas.metadata.Metadata)
+ */
+ @Override
+ public Metadata doExtract(Product product, Metadata met)
+ throws MetExtractionException {
+ Metadata extractMet = new Metadata();
+ merge(met, extractMet);
+ // get the Versioner
+ Versioner versioner = GenericFileManagerObjectFactory
+ .getVersionerFromClassName(product.getProductType().getVersioner());
+ try {
+ versioner.createDataStoreReferences(product, met);
+ } catch (VersioningException e) {
+ throw new MetExtractionException(
+ "Unable to generate final FileLocation: Reason: " + e.getMessage());
+ }
+
+ if (product.getProductStructure().equals(Product.STRUCTURE_FLAT)) {
+ Reference r = product.getProductReferences().get(0);
+ String finalLocation = VersioningUtils.getAbsolutePathFromUri(r
+ .getDataStoreReference());
+ if (this.replaceLocation) {
+ extractMet.replaceMetadata(FILE_LOCATION, new File(finalLocation)
+ .getParent());
+ } else {
+ extractMet.addMetadata(FILE_LOCATION, new File(finalLocation)
+ .getParent());
+ }
+
+ } else
+ throw new MetExtractionException(
+ "Unable to extract final file location from "
+ + Product.STRUCTURE_HIERARCHICAL + " products!");
+
+ return extractMet;
+
+ }
+
+}
Propchange:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/metadata/extractors/examples/FinalFileLocationExtractor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: oodt/trunk/filemgr/src/main/resources/examples/product-types.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/resources/examples/product-types.xml?rev=1054000&r1=1053999&r2=1054000&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/main/resources/examples/product-types.xml (original)
+++ oodt/trunk/filemgr/src/main/resources/examples/product-types.xml Thu Dec 30
21:09:56 2010
@@ -38,6 +38,15 @@
</configuration>
</extractor>
<extractor
class="org.apache.oodt.cas.filemgr.metadata.extractors.examples.MimeTypeExtractor"
/>
+ <extractor
class="org.apache.oodt.cas.filemgr.metadata.extractors.examples.FinalFileLocationExtractor">
+ <configuration>
+ <!-- this property specifies whether you want the FILE_LOCATION field
+ computed by this extractor to replace any other FILE_LOCATION
met
+ attribute.
+ -->
+ <property name="replace" value="true"/>
+ </configuration>
+ </extractor>
</metExtractors>
</type>
</cas:producttypes>
Added:
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/metadata/extractors/examples/TestFinalFileLocationExtractor.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/metadata/extractors/examples/TestFinalFileLocationExtractor.java?rev=1054000&view=auto
==============================================================================
---
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/metadata/extractors/examples/TestFinalFileLocationExtractor.java
(added)
+++
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/metadata/extractors/examples/TestFinalFileLocationExtractor.java
Thu Dec 30 21:09:56 2010
@@ -0,0 +1,93 @@
+/**
+ * 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.metadata.extractors.examples;
+
+//JDK imports
+import java.util.Properties;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.Reference;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.metadata.exceptions.MetExtractionException;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ *
+ * Test suite for the {...@link FinalFileLocationExtractor}.
+ *
+ * @since OODT-72
+ *
+ */
+public class TestFinalFileLocationExtractor extends TestCase {
+
+ public void testExtract() {
+ String expectedFinalLocation = "/archive/somefile.txt";
+ Product p = Product.getDefaultFlatProduct("test", "urn:oodt:GenericFile");
+ p.setProductName("somefile.txt");
+ p.getProductType().setProductRepositoryPath("file:///archive");
+ p.getProductType().setVersioner(
+ "org.apache.oodt.cas.filemgr.versioning.BasicVersioner");
+ p.getProductReferences().add(
+ new Reference("file:///tmp/somefile.txt", null, 0L));
+ Properties config = new Properties();
+ config.setProperty("replace", "false");
+ Metadata met = new Metadata();
+ met.addMetadata(CoreMetKeys.FILE_LOCATION, "/tmp");
+ FinalFileLocationExtractor extractor = new FinalFileLocationExtractor();
+ extractor.configure(config);
+ Metadata extractMet = new Metadata();
+
+ try {
+ extractMet = extractor.doExtract(p, met);
+ } catch (MetExtractionException e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(extractMet);
+ assertTrue(extractMet.containsKey(CoreMetKeys.FILE_LOCATION));
+ assertEquals(2,
extractMet.getAllMetadata(CoreMetKeys.FILE_LOCATION).size());
+ assertEquals("/tmp", extractMet.getMetadata(CoreMetKeys.FILE_LOCATION));
+ assertEquals("expected final location: [" + expectedFinalLocation
+ + "] is not equal to generated location: ["
+ + extractMet.getAllMetadata(CoreMetKeys.FILE_LOCATION).get(1) + "]",
+ expectedFinalLocation, extractMet.getAllMetadata(
+ CoreMetKeys.FILE_LOCATION).get(1));
+
+ // reconfigure to replace
+ config.setProperty("replace", "true");
+ extractor.configure(config);
+
+ try {
+ extractMet = extractor.doExtract(p, met);
+ } catch (MetExtractionException e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(extractMet);
+ assertTrue(extractMet.containsKey(CoreMetKeys.FILE_LOCATION));
+ assertEquals(1,
extractMet.getAllMetadata(CoreMetKeys.FILE_LOCATION).size());
+ assertEquals(expectedFinalLocation, extractMet
+ .getMetadata(CoreMetKeys.FILE_LOCATION));
+
+ }
+
+}
Propchange:
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/metadata/extractors/examples/TestFinalFileLocationExtractor.java
------------------------------------------------------------------------------
svn:eol-style = native