Commits

jmort  committed 67e08c4

AUTOPLAN-2: initial plan creation from a servlet

git-svn-id: https://adaptavist.jira.com/svn/AUTOPLAN/trunk@8722e6edf6fb-f266-4316-afb4-e53d95876a76

  • Participants
  • Parent commits ed1683b

Comments (0)

Files changed (4)

 
     <properties>
         <bamboo.version>3.2.2</bamboo.version>
-        <bamboo.data.version>2.6.1</bamboo.data.version>
+        <bamboo.data.version>3.2.2</bamboo.data.version>
     </properties>
 
     <dependencies>

File src/main/java/com/adaptavist/bamboo/autoplan/TestServlet.java

+package com.adaptavist.bamboo.autoplan;
+
+import com.atlassian.bamboo.build.PlanCreationDeniedException;
+import com.atlassian.bamboo.build.creation.PlanCreationService;
+import com.atlassian.bamboo.plan.PlanKeys;
+import com.atlassian.bamboo.template.TemplateRenderer;
+import com.atlassian.bamboo.webwork.util.ActionParametersMapImpl;
+import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
+import com.atlassian.spring.container.ContainerManager;
+import com.google.common.collect.Maps;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+
+public class TestServlet extends HttpServlet {
+    private static final String PROJECT_KEY = "projectKey";
+    private static final String PROJECT_NAME = "projectName";
+    private static final String NEW_PROJECT_MARKER = "newProject";
+    private static final String CHAIN_KEY = "chainKey";
+    private static final String CHAIN_NAME = "chainName";
+
+
+    private final TemplateRenderer templateRenderer;
+
+    public TestServlet(TemplateRenderer templateRenderer) {
+        this.templateRenderer = templateRenderer;
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+        final PlanCreationService chainCreationService = (PlanCreationService) ContainerManager.getComponent("chainCreationService");
+        resp.setStatus(200);
+        resp.getWriter().println(templateRenderer.renderWithoutActionContext("templates/success.ftl", new HashMap<String, Object>()));
+        ActionParametersMapImpl actionParametersMap = new ActionParametersMapImpl(Maps.<String, Object>newHashMap());
+        actionParametersMap.put(NEW_PROJECT_MARKER, true);
+        actionParametersMap.put(PROJECT_KEY, "JONPROJ");
+        actionParametersMap.put(PROJECT_NAME, "Jon's Project");
+        actionParametersMap.put(CHAIN_KEY, "JON");
+        actionParametersMap.put(CHAIN_NAME, "Jon plan");
+
+
+        try {
+            String newPlanKey = chainCreationService.createPlan(new BuildConfiguration(), actionParametersMap, PlanCreationService.EnablePlan.DISABLED);
+            chainCreationService.triggerCreationCompleteEvents(PlanKeys.getPlanKey(newPlanKey));
+        } catch (PlanCreationDeniedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

File src/main/resources/atlassian-plugin.xml

     <plugin-info>
         <description>${project.description}</description>
         <version>${project.version}</version>
-        <vendor name="${project.organization.name}" url="${project.organization.url}" />
+        <vendor name="${project.organization.name}" url="${project.organization.url}"/>
     </plugin-info>
 
     <resource type="i18n" name="i18n" location="i18n"/>
 
+    <servlet key="test-servlet" name="Test Servlet" class="com.adaptavist.bamboo.autoplan.TestServlet">
+        <url-pattern>/autoplan*</url-pattern>
+    </servlet>
 </atlassian-plugin>

File src/main/resources/templates/success.ftl

+Hello world from a template