You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/10/17 13:54:22 UTC

git commit: camel-jira: new issue producer

Repository: camel
Updated Branches:
  refs/heads/master ef38a4bb3 -> 857f55921


camel-jira: new issue producer


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

Branch: refs/heads/master
Commit: 857f5592181444a8d74e04b9676913415a310f9a
Parents: ef38a4b
Author: Brett Meyer <br...@3riverdev.com>
Authored: Thu Oct 16 13:55:30 2014 -0400
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Oct 17 16:40:21 2014 +0800

----------------------------------------------------------------------
 .../camel/component/jira/JIRAEndpoint.java      | 17 ++++++-
 .../jira/producer/AbstractJIRAProducer.java     | 45 ++++++++++++++++++
 .../jira/producer/NewIssueProducer.java         | 48 ++++++++++++++++++++
 .../component/jira/producer/ProducerType.java   | 31 +++++++++++++
 4 files changed, 140 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/857f5592/components/camel-jira/src/main/java/org/apache/camel/component/jira/JIRAEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/main/java/org/apache/camel/component/jira/JIRAEndpoint.java b/components/camel-jira/src/main/java/org/apache/camel/component/jira/JIRAEndpoint.java
index ec1199a..dd8e8bf 100644
--- a/components/camel-jira/src/main/java/org/apache/camel/component/jira/JIRAEndpoint.java
+++ b/components/camel-jira/src/main/java/org/apache/camel/component/jira/JIRAEndpoint.java
@@ -24,6 +24,8 @@ import org.apache.camel.Producer;
 import org.apache.camel.component.jira.consumer.ConsumerType;
 import org.apache.camel.component.jira.consumer.NewCommentConsumer;
 import org.apache.camel.component.jira.consumer.NewIssueConsumer;
+import org.apache.camel.component.jira.producer.NewIssueProducer;
+import org.apache.camel.component.jira.producer.ProducerType;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
@@ -61,7 +63,20 @@ public class JIRAEndpoint extends DefaultEndpoint {
     }
 
     public Producer createProducer() throws Exception {
-        throw new UnsupportedOperationException("JIRAProducer is not implemented");
+        String uri = getEndpointUri();
+        String[] uriSplit = splitUri(getEndpointUri());
+        
+        if (uriSplit.length > 0) {
+            switch (ProducerType.fromUri(uriSplit[0])) {
+            case NEWISSUE:
+                return new NewIssueProducer(this);
+            default:
+                break;
+            }
+        }
+
+        throw new IllegalArgumentException("Cannot create any producer with uri " + uri
+                + ". A producer type was not provided (or an incorrect pairing was used).");
     }
     
     public Consumer createConsumer(Processor processor) throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/857f5592/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/AbstractJIRAProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/AbstractJIRAProducer.java b/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/AbstractJIRAProducer.java
new file mode 100644
index 0000000..4805d2d
--- /dev/null
+++ b/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/AbstractJIRAProducer.java
@@ -0,0 +1,45 @@
+/**
+ * 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.jira.producer;
+
+import java.net.URI;
+
+import com.atlassian.jira.rest.client.JiraRestClient;
+import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.jira.JIRAEndpoint;
+import org.apache.camel.impl.DefaultProducer;
+
+public abstract class AbstractJIRAProducer extends DefaultProducer {
+    
+    private final JiraRestClient client;
+    
+    public AbstractJIRAProducer(JIRAEndpoint endpoint) throws Exception {
+        super(endpoint);
+        
+        final JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
+        final URI jiraServerUri = URI.create(endpoint.getServerUrl());
+        client = factory.createWithBasicHttpAuthentication(jiraServerUri, endpoint.getUsername(),
+                                                           endpoint.getPassword());
+    }
+    
+    protected JiraRestClient client() {
+        return client;
+    }
+
+    public abstract void process(Exchange exchange) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/857f5592/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/NewIssueProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/NewIssueProducer.java b/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/NewIssueProducer.java
new file mode 100644
index 0000000..be54c70
--- /dev/null
+++ b/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/NewIssueProducer.java
@@ -0,0 +1,48 @@
+/**
+ * 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.jira.producer;
+
+import com.atlassian.jira.rest.client.domain.BasicIssue;
+import com.atlassian.jira.rest.client.domain.input.IssueInputBuilder;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.jira.JIRAEndpoint;
+
+public class NewIssueProducer extends AbstractJIRAProducer {
+
+    public NewIssueProducer(JIRAEndpoint endpoint) throws Exception {
+        super(endpoint);
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        String projectKey = exchange.getIn().getHeader("ProjectKey", String.class);
+        Long issueTypeId = exchange.getIn().getHeader("IssueTypeId", Long.class);
+        String issueSummary = exchange.getIn().getHeader("IssueSummary", String.class);
+        IssueInputBuilder issueBuilder = new IssueInputBuilder(projectKey, issueTypeId);
+        issueBuilder.setDescription(exchange.getIn().getBody(String.class));
+        issueBuilder.setSummary(issueSummary);
+        BasicIssue issue = client().getIssueClient().createIssue(issueBuilder.build(), null);
+        
+        // support InOut
+        if (exchange.getPattern().isOutCapable()) {
+            // copy the header of in message to the out message
+            exchange.getOut().copyFrom(exchange.getIn());
+            exchange.getOut().setBody(issue);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/857f5592/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/ProducerType.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/ProducerType.java b/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/ProducerType.java
new file mode 100644
index 0000000..037ec1a
--- /dev/null
+++ b/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/ProducerType.java
@@ -0,0 +1,31 @@
+/**
+ * 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.jira.producer;
+
+public enum ProducerType {
+
+    NEWISSUE, UNKNOWN;
+
+    public static ProducerType fromUri(String uri) {
+        for (ProducerType producerType : ProducerType.values()) {
+            if (producerType.name().equalsIgnoreCase(uri)) {
+                return producerType;
+            }
+        }
+        return ProducerType.UNKNOWN;
+    }
+}