Author: rkanter
Date: Mon Feb  4 17:54:54 2013
New Revision: 1442204

URL: http://svn.apache.org/viewvc?rev=1442204&view=rev
Log:
OOZIE-972 Provide  EL function to append a string in each substring of another 
string separated by delimiter (kamrul via virag)

Modified:
    
oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java
    oozie/branches/branch-3.3/core/src/main/resources/oozie-default.xml
    
oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java
    oozie/branches/branch-3.3/docs/src/site/twiki/WorkflowFunctionalSpec.twiki
    oozie/branches/branch-3.3/release-log.txt

Modified: 
oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java
URL: 
http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java?rev=1442204&r1=1442203&r2=1442204&view=diff
==============================================================================
--- 
oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java
 (original)
+++ 
oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java
 Mon Feb  4 17:54:54 2013
@@ -119,7 +119,38 @@ public class ELConstantsFunctions {
     }
 
     /**
-     * Return the trimmed version of the given string.
+     * Add the <code>append</code> string into each splitted sub-strings of the
+     * first string ('src'). The split is performed into <code>src</code> 
string
+     * using the <code>delimiter</code>. E.g.
+     * <code>appendAll("/a/b/,/c/b/,/c/d/", "ADD", ",")</code> will return
+     * <code>"/a/b/ADD,/c/b/ADD,/c/d/ADD"</code>
+     *
+     * @param src source string.
+     * @param append - the string to be appended for each match. If null, it
+     *        will considered as ""
+     * @param delimeter the string that is used to split the 'src' into
+     *        substring before the append. null means no append.
+     * @return the appended string.
+     */
+    public static String appendAll(String src, String append, String 
delimeter) {
+        if (src != null && delimeter != null) {
+            if (append == null) {
+                append = "";
+            }
+            String[] ret = src.split(delimeter);
+            StringBuilder result = new StringBuilder();
+            for (int i = 0; i < ret.length; i++) {
+                result.append(ret[i]).append(append);
+                if (i < (ret.length - 1)) { // Don't append to the last item
+                    result.append(delimeter);
+                }
+            }
+            return result.toString();
+        }
+        return src;
+    }
+
+    /**
      *
      * @param input string to be trimmed
      * @return the trimmed version of the given string or the empty string if 
the given string was <code>null</code>

Modified: oozie/branches/branch-3.3/core/src/main/resources/oozie-default.xml
URL: 
http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/main/resources/oozie-default.xml?rev=1442204&r1=1442203&r2=1442204&view=diff
==============================================================================
--- oozie/branches/branch-3.3/core/src/main/resources/oozie-default.xml 
(original)
+++ oozie/branches/branch-3.3/core/src/main/resources/oozie-default.xml Mon Feb 
 4 17:54:54 2013
@@ -464,6 +464,7 @@
             
firstNotNull=org.apache.oozie.util.ELConstantsFunctions#firstNotNull,
             concat=org.apache.oozie.util.ELConstantsFunctions#concat,
             replaceAll=org.apache.oozie.util.ELConstantsFunctions#replaceAll,
+            appendAll=org.apache.oozie.util.ELConstantsFunctions#appendAll,
             trim=org.apache.oozie.util.ELConstantsFunctions#trim,
             timestamp=org.apache.oozie.util.ELConstantsFunctions#timestamp,
             urlEncode=org.apache.oozie.util.ELConstantsFunctions#urlEncode,

Modified: 
oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java
URL: 
http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java?rev=1442204&r1=1442203&r2=1442204&view=diff
==============================================================================
--- 
oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java
 (original)
+++ 
oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java
 Mon Feb  4 17:54:54 2013
@@ -53,6 +53,19 @@ public class TestELConstantsFunctions ex
         assertEquals("acd", ELConstantsFunctions.replaceAll("abcbcd", "bcb", 
null));
     }
 
+    public void testAppendAll() {
+        assertEquals("/a/b/ADD,/c/b/ADD,/c/d/ADD", 
ELConstantsFunctions.appendAll("/a/b/,/c/b/,/c/d/", "ADD", ","));
+        assertEquals("/a/b/ADD", ELConstantsFunctions.appendAll("/a/b/", 
"ADD", ","));
+        assertEquals(" /a/b/  ADD,/c/b/ ADD, /c/d/ ADD", 
ELConstantsFunctions.appendAll(" /a/b/  ,/c/b/ , /c/d/ ",
+                "ADD", ","));
+        assertEquals("/a/b/ADD", ELConstantsFunctions.appendAll("/a/b/", 
"ADD", ","));
+        assertEquals(null, ELConstantsFunctions.appendAll(null, "ADD", ","));
+        assertEquals("/a/b/,/c/b/,/c/d/", 
ELConstantsFunctions.appendAll("/a/b/,/c/b/,/c/d/", null, ","));
+        assertEquals("/a/b/,/c/b/,/c/d/", 
ELConstantsFunctions.appendAll("/a/b/,/c/b/,/c/d/", "ADD", null));
+        assertEquals("ADDaADDbADD", ELConstantsFunctions.appendAll("ab", 
"ADD", ""));
+        assertEquals("/a/b/ADD,/c/b/ADD,/c/d/ADD", 
ELConstantsFunctions.appendAll("/a/b/,/c/b/,/c/d/", "ADD", ","));
+    }
+
     public void testTimestamp() throws Exception {
         String s = ELConstantsFunctions.timestamp();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");

Modified: 
oozie/branches/branch-3.3/docs/src/site/twiki/WorkflowFunctionalSpec.twiki
URL: 
http://svn.apache.org/viewvc/oozie/branches/branch-3.3/docs/src/site/twiki/WorkflowFunctionalSpec.twiki?rev=1442204&r1=1442203&r2=1442204&view=diff
==============================================================================
--- oozie/branches/branch-3.3/docs/src/site/twiki/WorkflowFunctionalSpec.twiki 
(original)
+++ oozie/branches/branch-3.3/docs/src/site/twiki/WorkflowFunctionalSpec.twiki 
Mon Feb  4 17:54:54 2013
@@ -14,6 +14,9 @@ Map/Reduce and Pig jobs.
 %TOC%
 
 ---++ Changelog
+---+++!! 2012AUG30
+
+   * #4.2.2 Added two EL functions (replaceAll and appendAll)
 ---+++!! 2012JUL26
 
    * #Appendix A, updated XML schema 0.4 to include =parameters= element
@@ -1560,6 +1563,10 @@ It returns the concatenation of 2 string
 
 Replace each occurrence of regular expression match in the first string with 
the =replacement= string and return the replaced string. A 'regex' string with 
=null= value is considered as no change. A 'replacement' string with =null= 
value is consider as an empty string.
 
+*String appendAll(String src, String append, String delimeter)*
+
+ Add the =append= string into each splitted sub-strings of the first 
string(=src=). The split is performed into =src= string using the =delimiter=. 
E.g. =appendAll("/a/b/,/c/b/,/c/d/", "ADD", ",")= will return 
=/a/b/ADD,/c/b/ADD,/c/d/ADD=. A =append= string with =null= value is consider 
as an empty string. A =delimiter= string with value =null= is considered as no 
append in the string.
+
 *String trim(String s)*
 
 It returns the trimmed value of the given string. A string with =null= value 
is considered as an empty string.

Modified: oozie/branches/branch-3.3/release-log.txt
URL: 
http://svn.apache.org/viewvc/oozie/branches/branch-3.3/release-log.txt?rev=1442204&r1=1442203&r2=1442204&view=diff
==============================================================================
--- oozie/branches/branch-3.3/release-log.txt (original)
+++ oozie/branches/branch-3.3/release-log.txt Mon Feb  4 17:54:54 2013
@@ -1,5 +1,6 @@
 -- Oozie 3.3.2 (unreleased)
 
+OOZIE-972 Provide  EL function to append a string in each substring of another 
string separated by delimiter (kamrul via virag)
 OOZIE-977 NotificationXCommand (job.notification queue entry) should set a 
timeout in the HTTP connections it makes (tucu)
 OOZIE-654 Provide a way to use 'uber' jars with Oozie MR actions (rkanter via 
tucu)
 OOZIE-1186 Image load for Job DAG visualization should handle resources better 
(mona)


Reply via email to