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   * @since 3.6
12   */
13  @JiraPluginModuleCreator
14  public class WorkflowConditionModuleCreator extends AbstractPluginModuleCreator<WorkflowElementProperties>
15  {
16  
17      public static final String MODULE_NAME = "Workflow Condition";
18      private static final String TEMPLATE_PREFIX = "templates/jira/workflow/condition/";
19  
20      //stub
21      private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "WorkflowCondition.java.vtl";
22      private static final String FACTORY_TEMPLATE = TEMPLATE_PREFIX + "WorkflowConditionFactory.java.vtl";
23      private static final String UNIT_TEST_TEMPLATE = TEMPLATE_PREFIX + "WorkflowConditionTest.java.vtl";
24      private static final String VIEW_TEMPLATE = TEMPLATE_PREFIX + "workflow-condition.vm.vtl";
25      private static final String INPUT_TEMPLATE = TEMPLATE_PREFIX + "workflow-condition-input.vm.vtl";
26      private static final String TEMPLATE_PATH = "conditions";
27  
28      //examples
29      private static final String EXAMPLE_CLASS_TEMPLATE = TEMPLATE_PREFIX + "Example" + CLASS_TEMPLATE;
30  
31      private static final String PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "workflow-condition-plugin.xml.vtl";
32  
33      @Override
34      public PluginProjectChangeset createModule(WorkflowElementProperties props) throws Exception
35      {
36          PluginProjectChangeset ret = new PluginProjectChangeset()
37              .with(SLF4J,
38                    MOCKITO_TEST)
39              .with(createModule(props, PLUGIN_MODULE_TEMPLATE));
40  
41          if (props.includeExamples())
42          {
43              return ret.with(createClass(props, EXAMPLE_CLASS_TEMPLATE));
44          }
45          else
46          {
47              String moduleKey = props.getModuleKey();
48              String viewFileName = moduleKey + ".vm";
49              String inputFileName = moduleKey + "-input.vm";
50              return ret.with(createClassAndTests(props, CLASS_TEMPLATE, UNIT_TEST_TEMPLATE))
51                  .with(createClass(props, props.getFactoryClassId(), FACTORY_TEMPLATE))
52                  .with(createTemplateResource(props, TEMPLATE_PATH, viewFileName, VIEW_TEMPLATE))
53                  .with(createTemplateResource(props, TEMPLATE_PATH, inputFileName, INPUT_TEMPLATE));
54          }
55      }
56  
57      @Override
58      public String getModuleName()
59      {
60          return MODULE_NAME;
61      }
62  }