camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject camel git commit: CAMEL-8560 - allow sort terms to be specified textually on the URI
Date Fri, 08 May 2015 13:40:56 GMT
Repository: camel
Updated Branches:
  refs/heads/master f3ba4cf62 -> edabde20e


CAMEL-8560 - allow sort terms to be specified textually on the URI


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/edabde20
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/edabde20
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/edabde20

Branch: refs/heads/master
Commit: edabde20ee1c0908551a1adf8eb948301f746025
Parents: f3ba4cf
Author: Jonathan Anstey <janstey@gmail.com>
Authored: Fri May 8 11:09:55 2015 -0230
Committer: Jonathan Anstey <janstey@gmail.com>
Committed: Fri May 8 11:10:06 2015 -0230

----------------------------------------------------------------------
 .../camel/component/mail/MailConverters.java    | 42 ++++++++++++++++++++
 .../mail/MailSortTermThreeUriConfigTest.java    | 32 +++++++++++++++
 .../mail/MailSortTermTwoUriConfigTest.java      | 32 +++++++++++++++
 .../mail/MailSortTermUriConfigTest.java         | 32 +++++++++++++++
 4 files changed, 138 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/edabde20/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
index 8262c14..d98c4f0 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
@@ -20,9 +20,11 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+
 import javax.mail.BodyPart;
 import javax.mail.Message;
 import javax.mail.MessagingException;
@@ -30,6 +32,8 @@ import javax.mail.Multipart;
 import javax.mail.internet.MimeMultipart;
 import javax.mail.search.SearchTerm;
 
+import com.sun.mail.imap.SortTerm;
+
 import org.apache.camel.Converter;
 import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.TypeConverter;
@@ -178,6 +182,44 @@ public final class MailConverters {
         return builder.build();
     }
 
+    /*
+     * Converts from comma separated list of sort terms to SortTerm obj array
+     */
+    @Converter
+    public static SortTerm[] toSortTerm(String sortTerm) {
+        ArrayList<SortTerm> result = new ArrayList<SortTerm>();
+        
+        if (sortTerm == null) {
+            return null;
+        }
+        
+        String[] sortTerms = sortTerm.split(",");
+        for (String key : sortTerms) {          
+            if ("arrival".equals(key)) {
+                result.add(SortTerm.ARRIVAL);
+            } else if ("cc".equals(key)) {
+                result.add(SortTerm.CC);
+            } else if ("date".equals(key)) {
+                result.add(SortTerm.DATE);
+            } else if ("from".equals(key)) {
+                result.add(SortTerm.FROM);
+            } else if ("reverse".equals(key)) {
+                result.add(SortTerm.REVERSE);
+            } else if ("size".equals(key)) {
+                result.add(SortTerm.SIZE);
+            } else if ("subject".equals(key)) {
+                result.add(SortTerm.SUBJECT);
+            } else if ("to".equals(key)) {
+                result.add(SortTerm.TO);
+            }
+        }
+        if (result.size() > 0) {
+            return result.toArray(new SortTerm[result.size()]);
+        } else {
+            return null;
+        }
+    }
+    
     private static long extractOffset(String now, TypeConverter typeConverter) throws NoTypeConversionAvailableException
{
         Matcher matcher = NOW_PATTERN.matcher(now);
         if (matcher.matches()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/edabde20/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermThreeUriConfigTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermThreeUriConfigTest.java
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermThreeUriConfigTest.java
new file mode 100644
index 0000000..290490b
--- /dev/null
+++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermThreeUriConfigTest.java
@@ -0,0 +1,32 @@
+/**
+ * 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.camel.component.mail;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MailSortTermThreeUriConfigTest extends MailSortTermThreeTest {
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                context.setAutoStartup(false);
+
+                from("pop3://bill@localhost?password=secret&sortTerm=reverse,date").to("mock:resultDescendingImap");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/edabde20/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTwoUriConfigTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTwoUriConfigTest.java
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTwoUriConfigTest.java
new file mode 100644
index 0000000..cc1f3e4
--- /dev/null
+++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTwoUriConfigTest.java
@@ -0,0 +1,32 @@
+/**
+ * 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.camel.component.mail;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MailSortTermTwoUriConfigTest extends MailSortTermTwoTest {
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                context.setAutoStartup(false);
+
+                from("pop3://bill@localhost?password=secret&sortTerm=reverse,date").to("mock:resultDescending");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/edabde20/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermUriConfigTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermUriConfigTest.java
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermUriConfigTest.java
new file mode 100644
index 0000000..04b08db
--- /dev/null
+++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermUriConfigTest.java
@@ -0,0 +1,32 @@
+/**
+ * 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.camel.component.mail;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MailSortTermUriConfigTest extends MailSortTermTest {
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                context.setAutoStartup(false);
+
+                from("pop3://bill@localhost?password=secret&searchTerm=#searchTerm&sortTerm=date").to("mock:resultAscending");
+            }
+        };
+    }
+}


Mime
View raw message