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.Resource;
10  import com.atlassian.plugins.codegen.modules.jira.SearchRequestViewModuleCreator;
11  import com.atlassian.plugins.codegen.modules.jira.SearchRequestViewProperties;
12  import com.atlassian.plugins.codegen.util.ClassnameUtil;
13  
14  import org.codehaus.plexus.components.interactivity.Prompter;
15  import org.codehaus.plexus.components.interactivity.PrompterException;
16  
17  /**
18   * @since 3.5
19   */
20  @ModuleCreatorClass(SearchRequestViewModuleCreator.class)
21  public class SearchRequestViewPrompter extends AbstractResourcePrompter<SearchRequestViewProperties>
22  {
23  
24      public SearchRequestViewPrompter(Prompter prompter)
25      {
26          super(prompter);
27  
28      }
29  
30      @Override
31      public SearchRequestViewProperties promptForBasicProperties(PluginModuleLocation moduleLocation) throws PrompterException
32      {
33          String className = promptJavaClassname("Enter New Classname", "MySearchRequestView");
34          String packageName = promptJavaPackagename("Enter Package Name", getDefaultBasePackage() + ".jira.search");
35  
36          String fqClass = ClassnameUtil.fullyQualifiedName(packageName, className);
37  
38          SearchRequestViewProperties props = new SearchRequestViewProperties(fqClass);
39  
40          props.setFileExtension(promptNotBlank("Enter File Extension (i.e. html)"));
41          props.setContentType(promptNotBlank("Enter Content Type (i.e. text/html)"));
42  
43          List<Resource> resources = new ArrayList<Resource>(3);
44  
45          String templatePath = "/templates/search/" + props.getModuleKey() + "/";
46  
47          Resource header = new Resource();
48          header.setName("header");
49          header.setType("velocity");
50          header.setLocation(templatePath + "header.vm");
51  
52          Resource single = new Resource();
53          single.setName("singleissue");
54          single.setType("velocity");
55          single.setLocation(templatePath + "singleissue.vm");
56  
57          Resource footer = new Resource();
58          footer.setName("footer");
59          footer.setType("velocity");
60          footer.setLocation(templatePath + "footer.vm");
61  
62          resources.add(header);
63          resources.add(single);
64          resources.add(footer);
65  
66          props.setResources(resources);
67  
68          return props;
69      }
70  
71      @Override
72      public void promptForAdvancedProperties(SearchRequestViewProperties props, PluginModuleLocation moduleLocation) throws PrompterException
73      {
74          props.setOrder(promptForInt("Enter Order", 10));
75          props.setResources(promptForResources());
76      }
77  
78      @Override
79      protected Resource promptForResource() throws PrompterException
80      {
81          Resource resource = new Resource();
82          resource.setName(promptNotBlank("Enter Resource Name"));
83  
84          resource.setType("velocity");
85          resource.setLocation(promptNotBlank("Enter Location (path to resource file)"));
86  
87          return resource;
88      }
89  }