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