1   package com.atlassian.plugins.codegen.modules.jira;
2   
3   import com.atlassian.plugins.codegen.ComponentDeclaration;
4   import com.atlassian.plugins.codegen.PluginProjectChangeset;
5   import com.atlassian.plugins.codegen.annotations.JiraPluginModuleCreator;
6   import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
7   
8   import static com.atlassian.fugue.Option.option;
9   import static com.atlassian.fugue.Option.some;
10  import static com.atlassian.plugins.codegen.modules.Dependencies.HTTPCLIENT_TEST;
11  import static com.atlassian.plugins.codegen.modules.Dependencies.MOCKITO_TEST;
12  import static com.atlassian.plugins.codegen.modules.Dependencies.SLF4J;
13  
14  /**
15   * @since 3.6
16   */
17  @JiraPluginModuleCreator
18  public class RPCModuleCreator extends AbstractPluginModuleCreator<RPCProperties>
19  {
20      public static final String MODULE_NAME = "RPC Endpoint Plugin";
21      private static final String TEMPLATE_PREFIX = "templates/jira/rpc/";
22  
23      //stub
24      private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "RPCService.java.vtl";
25      private static final String INTERFACE_TEMPLATE = TEMPLATE_PREFIX + "RPCServiceInterface.java.vtl";
26      private static final String UNIT_TEST_TEMPLATE = "templates/generic/GenericTest.java.vtl";
27  
28      //examples
29      private static final String EXAMPLE_CLASS_TEMPLATE = TEMPLATE_PREFIX + "Example" + CLASS_TEMPLATE;
30  
31      private static final String SOAP_PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "soap-rpc-plugin.xml.vtl";
32      private static final String XML_PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "xml-rpc-plugin.xml.vtl";
33  
34      @Override
35      public PluginProjectChangeset createModule(RPCProperties props) throws Exception
36      {
37          String moduleKey = props.getModuleKey() + "-component";
38          String description = "Component For " + props.getModuleName();
39          String name = props.getModuleName() + " Component";
40          String nameI18nKey = props.getNameI18nKey() + ".component";
41          
42          PluginProjectChangeset ret = new PluginProjectChangeset()
43              .with(HTTPCLIENT_TEST,
44                    SLF4J,
45                    MOCKITO_TEST)
46              .with(createModule(props, props.isSoap() ? SOAP_PLUGIN_MODULE_TEMPLATE : XML_PLUGIN_MODULE_TEMPLATE));
47  
48          if (props.includeExamples())
49          {
50              ret = ret.with(createClass(props, EXAMPLE_CLASS_TEMPLATE));
51          }
52          else
53          {
54              ret = ret.with(createClassAndTests(props, CLASS_TEMPLATE, UNIT_TEST_TEMPLATE))
55                  .with(createClass(props, props.getInterfaceId(), INTERFACE_TEMPLATE));
56          }
57          
58          ComponentDeclaration component = ComponentDeclaration.builder(props.getClassId(), moduleKey)
59              .interfaceId(option(props.getInterfaceId()))
60              .description(some(description))
61              .name(some(name))
62              .nameI18nKey(some(nameI18nKey))
63              .build();
64          return ret.with(component);
65      }
66  
67      @Override
68      public String getModuleName()
69      {
70          return MODULE_NAME;
71      }
72  }