Commits

Colin Chauvet committed 6fd2109

Added REST endpoint with a dummy create notification service

Comments (0)

Files changed (3)

     <description>This plugin uses the Confluence Notification API to allow administrators to send messages to all users of a Confluence wiki.</description>
     <packaging>atlassian-plugin</packaging>
     <dependencies>
-
         <dependency>
             <groupId>com.atlassian.confluence</groupId>
             <artifactId>confluence</artifactId>
             <scope>provided</scope>
         </dependency>
 
+
+        <dependency>
+            <groupId>com.atlassian.mywork</groupId>
+            <artifactId>mywork-api</artifactId>
+            <version>1.0.2</version>
+            <scope>provided</scope>
+        </dependency>
+
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
 
+
+        <!--REST related dependencies-->
+        <dependency>
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>jsr311-api</artifactId>
+            <version>1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.xml.bind</groupId>
+            <artifactId>jaxb-api</artifactId>
+            <version>2.1</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.plugins.rest</groupId>
+            <artifactId>atlassian-rest-common</artifactId>
+            <version>1.0.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.sal</groupId>
+            <artifactId>sal-api</artifactId>
+            <version>2.6.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.plugins.rest</groupId>
+            <artifactId>atlassian-rest-module</artifactId>
+            <version>2.7.0</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
+
     <build>
         <plugins>
             <plugin>

src/main/java/com/example/plugins/tutorial/confluence/notification/resource/NotificationResource.java

+package com.example.plugins.tutorial.confluence.notification.resource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import com.atlassian.mywork.model.Notification;
+import com.atlassian.mywork.model.NotificationBuilder;
+import com.atlassian.mywork.service.NotificationService;
+
+import org.codehaus.jackson.node.ObjectNode;
+
+import org.codehaus.jackson.map.ObjectMapper;
+
+
+/**
+ * A resource of message.
+ */
+@Path("/")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces (MediaType.APPLICATION_JSON)
+public class NotificationResource {
+
+    private final NotificationService notificationService;
+
+    public NotificationResource(final NotificationService notificationService) {
+        this.notificationService = notificationService;
+    }
+
+
+    @POST
+    // TODO handle exception
+    public Response createNotification() throws Exception{
+
+        ObjectNode metadata = new ObjectMapper().createObjectNode();
+        metadata.put("user", "Some Body");
+        metadata.put("username", "test");
+        metadata.put("custom", "My Example");
+        Notification notification = notificationService.createOrUpdate("admin", new NotificationBuilder()
+                .application("com.atlassian.mywork.example")
+                .title("Some title")
+                .itemTitle("Top level title")
+                .description("This has some example text")
+                .entity("foo")
+                .action("bar")
+                .globalId("something" )
+                .url("http://www.google.com/")
+                .metadata(metadata)
+                .applicationLinkId("TODO_CHANGE_ME")
+                .createNotification()).get();
+        return Response.ok(notification).build();
+
+//        return Response.ok("Hello World").build();
+    }
+
+}

src/main/resources/atlassian-plugin.xml

     <component-import key="loginUriProvider" interface="com.atlassian.sal.api.auth.LoginUriProvider"/>
     <component-import key="renderer"
                       interface="com.atlassian.templaterenderer.velocity.one.six.VelocityTemplateRenderer"/>
-    <component-import key='permissionManager' interface="com.atlassian.confluence.security.PermissionManager"/>
-
+    <component-import key="permissionManager" interface="com.atlassian.confluence.security.PermissionManager"/>
+    <component-import key="notificationService" interface="com.atlassian.mywork.service.NotificationService"/>
     <resource type="i18n" name="i18n"
               location="com.example.plugins.tutorial.confluence.tutorial-confluence-notification"/>
-
     <servlet name="Admin Servlet" i18n-name-key="admin-servlet.name" key="admin-servlet"
              class="com.example.plugins.tutorial.confluence.notification.servlet.AdminServlet">
         <description key="admin-servlet.description">The Admin Servlet Plugin</description>
         <url-pattern>/notification/admin</url-pattern>
     </servlet>
-
+    <rest name="Notification Resource" key="notification-resource" path="/notification" version="1.0">
+        <description key="notification-resource.description">The Notification Resource Plugin</description>
+    </rest>
 </atlassian-plugin>