1   package com.atlassian.maven.plugins.amps.codegen.prompter.jira;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import com.atlassian.maven.plugins.amps.codegen.annotations.ModuleCreatorClass;
7   import com.atlassian.maven.plugins.amps.codegen.prompter.common.AbstractResourcePrompter;
8   import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
9   import com.atlassian.plugins.codegen.modules.common.Label;
10  import com.atlassian.plugins.codegen.modules.common.Resource;
11  import com.atlassian.plugins.codegen.modules.jira.ReportModuleCreator;
12  import com.atlassian.plugins.codegen.modules.jira.ReportProperties;
13  import com.atlassian.plugins.codegen.util.ClassnameUtil;
14  
15  import org.codehaus.plexus.components.interactivity.Prompter;
16  import org.codehaus.plexus.components.interactivity.PrompterException;
17  
18  /**
19   * @since 3.6
20   */
21  @ModuleCreatorClass(ReportModuleCreator.class)
22  public class ReportPrompter extends AbstractResourcePrompter<ReportProperties>
23  {
24  
25      public ReportPrompter(Prompter prompter)
26      {
27          super(prompter);
28  
29      }
30  
31      @Override
32      public ReportProperties promptForBasicProperties(PluginModuleLocation moduleLocation) throws PrompterException
33      {
34          String className = promptJavaClassname("Enter New Classname", "MyReport");
35          String packageName = promptJavaPackagename("Enter Package Name", getDefaultBasePackage() + ".jira.reports");
36  
37          String fqClass = ClassnameUtil.fullyQualifiedName(packageName, className);
38  
39          ReportProperties props = new ReportProperties(fqClass);
40  
41          List<Resource> resources = new ArrayList<Resource>(2);
42  
43          String templatePath = "/templates/reports/" + props.getModuleKey() + "/";
44  
45          Resource view = new Resource();
46          view.setName("view");
47          view.setType("velocity");
48          view.setLocation(templatePath + "view.vm");
49  
50          resources.add(view);
51  
52          props.setResources(resources);
53  
54          addI18nResource(props);
55  
56          Label label = new Label(props.getModuleKey() + ".label", props.getModuleName());
57          props.setLabel(label);
58  
59          return props;
60      }
61  
62      @Override
63      public void promptForAdvancedProperties(ReportProperties props, PluginModuleLocation moduleLocation) throws PrompterException
64      {
65          props.setResources(promptForResources());
66          addI18nResource(props);
67  
68          //LABEL
69          Label label = props.getLabel();
70          String labelKey = promptNotBlank("Enter Label Key", props.getLabel()
71                  .getKey());
72          String labelValue = promptNotBlank("Enter Label Value", props.getLabel()
73                  .getValue());
74  
75          label.setKey(labelKey);
76          label.setValue(labelValue);
77  
78          props.addI18nProperty(labelKey, labelValue);
79  
80          List<String> labelParamVals = promptForList("Add Label Param?", "Enter Param Value");
81          if (!labelParamVals.isEmpty())
82          {
83              for (String labelVal : labelParamVals)
84              {
85                  label.addParam(labelVal);
86              }
87          }
88      }
89  
90      @Override
91      protected Resource promptForResource() throws PrompterException
92      {
93          Resource resource = new Resource();
94          resource.setName(promptNotBlank("Enter Resource Name"));
95  
96          resource.setType("velocity");
97          resource.setLocation(promptNotBlank("Enter Location (path to resource file)"));
98  
99          return resource;
100     }
101 
102     protected void addI18nResource(ReportProperties props)
103     {
104         Resource resource = new Resource();
105         resource.setName("i18n");
106         resource.setLocation(props.getClassId().getName());
107         resource.setType("i18n");
108 
109         props.addResource(resource);
110     }
111 }