1   package com.atlassian.plugins.codegen.modules.jira;
2   
3   import com.atlassian.plugins.codegen.PluginProjectChangeset;
4   import com.atlassian.plugins.codegen.annotations.JiraPluginModuleCreator;
5   import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
6   
7   import static com.atlassian.plugins.codegen.modules.Dependencies.MOCKITO_TEST;
8   import static com.atlassian.plugins.codegen.modules.Dependencies.SLF4J;
9   
10  /**
11   *
12   */
13  @JiraPluginModuleCreator
14  public class WorkflowPostFunctionModuleCreator extends AbstractPluginModuleCreator<WorkflowPostFunctionProperties>
15  {
16      public static final String MODULE_NAME = "Workflow Post Function";
17      private static final String TEMPLATE_PREFIX = "templates/jira/workflow/function/";
18  
19      private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "PostFunction.java.vtl";
20      private static final String FACTORY_TEMPLATE = TEMPLATE_PREFIX + "PostFunctionFactory.java.vtl";
21      private static final String UNIT_TEST_TEMPLATE = TEMPLATE_PREFIX + "PostFunctionTest.java.vtl";
22      private static final String VIEW_TEMPLATE = TEMPLATE_PREFIX + "post-function.vm.vtl";
23      private static final String INPUT_TEMPLATE = TEMPLATE_PREFIX + "post-function-input.vm.vtl";
24      private static final String PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "post-function-plugin.xml.vtl";
25      private static final String TEMPLATE_PATH = "postfunctions";
26      
27      @Override
28      public PluginProjectChangeset createModule(WorkflowPostFunctionProperties props) throws Exception
29      {
30          PluginProjectChangeset ret = new PluginProjectChangeset()
31              .with(SLF4J,
32                    MOCKITO_TEST)
33              .with(createModule(props, PLUGIN_MODULE_TEMPLATE));
34  
35          String moduleKey = props.getModuleKey();
36          String viewFileName = moduleKey + ".vm";
37          String inputFileName = moduleKey + "-input.vm";
38          return ret.with(createClassAndTests(props, CLASS_TEMPLATE, UNIT_TEST_TEMPLATE))
39              .with(createClass(props, props.getFactoryClassId(), FACTORY_TEMPLATE))
40              .with(createTemplateResource(props, TEMPLATE_PATH, viewFileName, VIEW_TEMPLATE))
41              .with(createTemplateResource(props, TEMPLATE_PATH, inputFileName, INPUT_TEMPLATE));
42      }
43  
44      @Override
45      public String getModuleName()
46      {
47          return MODULE_NAME;
48      }
49  }