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 2014/10/10 10:02:41 UTC
svn commit: r1630709 -
/oodt/trunk/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/ParentKeyDataSourceMetExtractor.java
Author: bfoster
Date: Fri Oct 10 08:02:40 2014
New Revision: 1630709
URL: http://svn.apache.org/r1630709
Log:
- Allow for pushpull fileretriction parsered metadata to be used in renaming convention
-----------
OODT-760
Added:
oodt/trunk/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/ParentKeyDataSourceMetExtractor.java (with props)
Added: oodt/trunk/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/ParentKeyDataSourceMetExtractor.java
URL: http://svn.apache.org/viewvc/oodt/trunk/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/ParentKeyDataSourceMetExtractor.java?rev=1630709&view=auto
==============================================================================
--- oodt/trunk/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/ParentKeyDataSourceMetExtractor.java (added)
+++ oodt/trunk/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/ParentKeyDataSourceMetExtractor.java Fri Oct 10 08:02:40 2014
@@ -0,0 +1,78 @@
+package org.apache.oodt.cas.metadata.extractors;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.metadata.exceptions.MetExtractionException;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+
+/**
+ * Supports data source key look via parent key if files key is no good.
+ *
+ * Expected file name:
+ * <parent_key>-<primary_key>.<post_fix>
+ *
+ * @author bfoster@apache.com (Brian Foster)
+ */
+public class ParentKeyDataSourceMetExtractor extends DataSourceMetExtractor {
+
+ private String key;
+
+ @Override
+ protected Metadata extrMetadata(File file) throws MetExtractionException {
+ try {
+ key = getPrimaryKey(file);
+ return extrMetadata(file);
+ } catch (MetExtractionException e) {
+ key = getParentKey(file);
+ if (key != null) {
+ return extrMetadata(file);
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ @VisibleForTesting
+ protected String getKey(File file) {
+ return key;
+ }
+
+ private String getPrimaryKey(File file) {
+ String key = getKeyAtIndex(file, Index.PRIMARY);
+ return key == null ? super.getKey(file) : key;
+ }
+
+ private String getParentKey(File file) {
+ return getKeyAtIndex(file, Index.PARENT);
+ }
+
+ private String getKeyAtIndex(File file, Index index) {
+ String key = super.getKey(file);
+ List<String> splitKey = Lists.newArrayList(Splitter.on("-").split(key));
+ if (splitKey.size() == 2) {
+ return splitKey.get(index.getNumeric());
+ } else {
+ return null;
+ }
+ }
+
+ private enum Index {
+ PRIMARY(1),
+ PARENT(0);
+
+ private int index;
+
+ Index(int index) {
+ this.index = index;
+ }
+
+ public int getNumeric() {
+ return index;
+ }
+ }
+}
Propchange: oodt/trunk/metadata/src/main/java/org/apache/oodt/cas/metadata/extractors/ParentKeyDataSourceMetExtractor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain