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.HTTPCLIENT_TEST;
8   import static com.atlassian.plugins.codegen.modules.Dependencies.MOCKITO_TEST;
9   import static com.atlassian.plugins.codegen.modules.Dependencies.SLF4J;
10  
11  /**
12   * @since 3.6
13   */
14  @JiraPluginModuleCreator
15  public class WorkflowValidatorModuleCreator extends AbstractPluginModuleCreator<WorkflowElementProperties>
16  {
17      public static final String MODULE_NAME = "Workflow Validator";
18      private static final String TEMPLATE_PREFIX = "templates/jira/workflow/validator/";
19  
20      //stub
21      private static final String FACTORY_TEMPLATE = TEMPLATE_PREFIX + "WorkflowValidatorFactory.java.vtl";
22      private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "WorkflowValidator.java.vtl";
23      private static final String UNIT_TEST_TEMPLATE = TEMPLATE_PREFIX + "WorkflowValidatorTest.java.vtl";
24      private static final String VIEW_TEMPLATE = TEMPLATE_PREFIX + "workflow-validator.vm.vtl";
25      private static final String INPUT_TEMPLATE = TEMPLATE_PREFIX + "workflow-validator-input.vm.vtl";
26      private static final String TEMPLATE_PATH = "validators";
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-validator-plugin.xml.vtl";
32  
33      @Override
34      public PluginProjectChangeset createModule(WorkflowElementProperties props) throws Exception
35      {
36          PluginProjectChangeset ret = new PluginProjectChangeset()
37              .with(HTTPCLIENT_TEST,
38                    SLF4J,
39                    MOCKITO_TEST)
40              .with(createModule(props, PLUGIN_MODULE_TEMPLATE));
41  
42          if (props.includeExamples())
43          {
44              return ret.with(createClass(props, EXAMPLE_CLASS_TEMPLATE));
45          }
46          else
47          {
48              String moduleKey = props.getModuleKey();
49              String viewFileName = moduleKey + ".vm";
50              String inputFileName = moduleKey + "-input.vm";
51              return ret.with(createClassAndTests(props, CLASS_TEMPLATE, UNIT_TEST_TEMPLATE))
52                  .with(createClass(props, props.getFactoryClassId(), FACTORY_TEMPLATE))
53                  .with(createTemplateResource(props, TEMPLATE_PATH, viewFileName, VIEW_TEMPLATE))
54                  .with(createTemplateResource(props, TEMPLATE_PATH, inputFileName, INPUT_TEMPLATE));
55          }
56      }
57  
58      @Override
59      public String getModuleName()
60      {
61          return MODULE_NAME;
62      }
63  }