You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2014/08/02 22:17:54 UTC
svn commit: r1615361 - in /oodt/trunk: CHANGES.txt
workflow/src/main/java/org/apache/oodt/cas/workflow/examples/FilterTask.java
workflow/src/test/org/apache/oodt/cas/workflow/examples/TestFilterTask.java
Author: mattmann
Date: Sat Aug 2 20:17:53 2014
New Revision: 1615361
URL: http://svn.apache.org/r1615361
Log:
- fix for OODT-726 Create MetFilter Task Example
Added:
oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/FilterTask.java
oodt/trunk/workflow/src/test/org/apache/oodt/cas/workflow/examples/TestFilterTask.java
Modified:
oodt/trunk/CHANGES.txt
Modified: oodt/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1615361&r1=1615360&r2=1615361&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Sat Aug 2 20:17:53 2014
@@ -4,6 +4,8 @@ Apache OODT Change Log
Release 0.7 - Current Development
--------------------------------------------
+* OODT-726 Create MetFilter Task Example (mattmann)
+
* OODT-724 Crawler action bean config refers to WORKFLOWMGR_URL (mattmann)
* OODT-723 Fix File Manager unit tests (step 3) - fix test class in 'validation'
Added: oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/FilterTask.java
URL: http://svn.apache.org/viewvc/oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/FilterTask.java?rev=1615361&view=auto
==============================================================================
--- oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/FilterTask.java (added)
+++ oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/examples/FilterTask.java Sat Aug 2 20:17:53 2014
@@ -0,0 +1,90 @@
+/**
+ * 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.workflow.examples;
+
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskInstance;
+import org.apache.oodt.cas.workflow.structs.exceptions.WorkflowTaskInstanceException;
+
+/**
+ * Filters dynamic {@link Metadata} from the provided metadata in the
+ * {@link #run(Metadata, WorkflowTaskConfiguration)} method.
+ *
+ * The config parameter in {@link #run(Metadata, WorkflowTaskConfiguration)}
+ * defines metadata parameters to remove and rename via the following
+ * directives:
+ *
+ * <ul>
+ * <li>Remove_Key - a comma separated list of keys to remove</li>
+ * <li>Rename_[Key] - set the value of this property to the new name of the
+ * [Key] parameter. E.g., having a key in the task configuration named
+ * Rename_Filename with value set to Prior_Filename will rename the key in the
+ * dynamic metadata named Filename to the new name of Prior_Filename, preserving
+ * its prior value.</li>
+ * </ul>
+ *
+ * Note that the Rename keys will be evaluated first, before the Remove_Key
+ * configuration parameter is evaluated.
+ *
+ */
+public class FilterTask implements WorkflowTaskInstance {
+
+ private final static String REMOVE_KEY = "Remove_Key";
+ private static final Logger LOG = Logger.getLogger(FilterTask.class
+ .getName());
+
+ @Override
+ public void run(Metadata metadata, WorkflowTaskConfiguration config)
+ throws WorkflowTaskInstanceException {
+
+ // evaluate renames
+ for (Object configKey : config.getProperties().keySet()) {
+ String configKeyName = (String) configKey;
+ if (configKeyName.startsWith("Rename")) {
+ String renameOrigKeyName = configKeyName.split("_")[1];
+ String renameKeyName = config.getProperty(configKeyName);
+ LOG.log(Level.INFO,
+ "Renaming key: [" + renameOrigKeyName + "] to ["
+ + renameKeyName + "]: values: "
+ + metadata.getAllMetadata(renameOrigKeyName));
+ metadata.addMetadata(renameKeyName,
+ metadata.getAllMetadata(renameOrigKeyName));
+ metadata.removeMetadata(renameOrigKeyName);
+ }
+ }
+
+ // evaluate removes
+ if (config.getProperties().containsKey(REMOVE_KEY)) {
+ String removeMetKeyNames = config.getProperty(REMOVE_KEY);
+ for (String keyName : Arrays.asList(removeMetKeyNames.split(","))) {
+ LOG.log(Level.INFO,
+ "Removing key from workflow metadata: [" + keyName
+ + "]: values: "
+ + metadata.getAllMetadata(keyName));
+ metadata.removeMetadata(keyName);
+ }
+ }
+
+ }
+
+}
Added: oodt/trunk/workflow/src/test/org/apache/oodt/cas/workflow/examples/TestFilterTask.java
URL: http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/org/apache/oodt/cas/workflow/examples/TestFilterTask.java?rev=1615361&view=auto
==============================================================================
--- oodt/trunk/workflow/src/test/org/apache/oodt/cas/workflow/examples/TestFilterTask.java (added)
+++ oodt/trunk/workflow/src/test/org/apache/oodt/cas/workflow/examples/TestFilterTask.java Sat Aug 2 20:17:53 2014
@@ -0,0 +1,110 @@
+/**
+ * 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.workflow.examples;
+
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
+import org.apache.oodt.cas.workflow.structs.exceptions.WorkflowTaskInstanceException;
+
+import junit.framework.TestCase;
+
+/**
+ * Test harness for FilterTask.
+ *
+ */
+public class TestFilterTask extends TestCase {
+
+ private FilterTask task;
+ private Metadata dynMet;
+ private WorkflowTaskConfiguration config;
+ private static final String prodDateTime = "2014-04-07T00:00:00.000Z";
+ private static final String filename = "foo.txt";
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ task = new FilterTask();
+ dynMet = new Metadata();
+ dynMet.addMetadata("Filename", filename);
+ dynMet.addMetadata("ProductionDateTime", prodDateTime);
+ config = new WorkflowTaskConfiguration();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ task = null;
+ dynMet = null;
+ config = null;
+ }
+
+ public void testRemove() {
+ config.addConfigProperty("Remove_Key", "Filename");
+ try {
+ task.run(dynMet, config);
+ } catch (WorkflowTaskInstanceException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(dynMet);
+ assertFalse(dynMet.containsKey("Filename"));
+ }
+
+ public void testRename() {
+ config.addConfigProperty("Rename_ProductionDateTime",
+ "Prior_ProductionDateTime");
+ try {
+ task.run(dynMet, config);
+ } catch (WorkflowTaskInstanceException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(dynMet);
+ assertFalse(dynMet.containsKey("ProductionDateTime"));
+ assertTrue(dynMet.containsKey("Prior_ProductionDateTime"));
+ assertEquals(
+ "Value: [" + dynMet.getMetadata("Prior_ProductionDateTime")
+ + "] was not equal to: [" + prodDateTime + "]",
+ prodDateTime, dynMet.getMetadata("Prior_ProductionDateTime"));
+ }
+
+ public void testRemoveAfterRename() {
+ config.addConfigProperty("Rename_Filename", "FooName");
+ config.addConfigProperty("Remove_Key", "FooName");
+ try {
+ task.run(dynMet, config);
+ } catch (WorkflowTaskInstanceException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(dynMet);
+ assertFalse(dynMet.containsKey("Filename"));
+ assertFalse(dynMet.containsKey("FooName"));
+ }
+
+}