Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.80 KB | None | 0 0
  1. package com.intenso.jira.plugins.tms.action;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Collection;
  6. import java.util.List;
  7.  
  8. import com.atlassian.crowd.embedded.api.Group;
  9. import com.atlassian.jira.component.ComponentAccessor;
  10. import com.atlassian.jira.issue.CustomFieldManager;
  11. import com.atlassian.jira.issue.fields.CustomField;
  12. import com.atlassian.jira.issue.search.SearchRequest;
  13. import com.atlassian.jira.issue.search.SearchRequestManager;
  14. import com.atlassian.jira.project.Project;
  15. import com.atlassian.jira.project.ProjectManager;
  16. import com.atlassian.jira.security.groups.GroupManager;
  17. import com.atlassian.jira.security.roles.ProjectRole;
  18. import com.atlassian.jira.security.roles.ProjectRoleManager;
  19. import com.atlassian.jira.user.ApplicationUser;
  20. import com.atlassian.jira.user.util.UserManager;
  21. import com.atlassian.jira.web.action.JiraWebActionSupport;
  22. import com.atlassian.plugin.webresource.UrlMode;
  23. import com.intenso.jira.plugins.tms.service.template.imports.ImportTctProgress;
  24. import com.intenso.jira.plugins.tms.service.template.imports.ImportTctService;
  25. import com.intenso.jira.plugins.tms.service.TmsConfig;
  26. import com.intenso.jira.plugins.tms.service.TmsService;
  27.  
  28. public class TctImportSetupPage extends JiraWebActionSupport {
  29.  
  30. private static final long serialVersionUID = -8673359392616035330L;
  31.  
  32. private static final String INPUT_FILE_NAME = "input-file-name";
  33.  
  34. private static final String DEFAULT_CSV_FIELD_DELIMITER = ",";
  35.  
  36. private static final String DONE = "done";
  37. private static final String PROGRESS = "progress";
  38.  
  39. private static final String DYNAMIC_TABLE_CUSTOM_FIELD = "com.intenso.jira.plugins.suiTest:dyntable-dynamicTable";
  40.  
  41. private ImportTctService importTctService;
  42.  
  43. private GroupManager groupManager;
  44. private ProjectRoleManager projectRoleManager;
  45. private ProjectManager projectManager;
  46. private UserManager userManager;
  47. private CustomFieldManager customFieldManager;
  48. private String errorMessage;
  49.  
  50. private TmsService tmsService;
  51.  
  52. private List<String> canImportTestCaseRolesList;
  53. private List<String> canImportTestCaseGroupsList;
  54. private String canImportTestCaseUsersArray;
  55. private List<String>canImportTestCaseUsersList;
  56.  
  57. private String[] canImportTestCaseRolesArray = new String[] {};
  58. private String[] canImportTestCaseGroupsArray = new String[] {};
  59.  
  60. private List<Group> groups;
  61. private List<ProjectRole> projectRoles;
  62.  
  63. private String delimiter;
  64. private String resultCf;
  65.  
  66. private Long filterId;
  67.  
  68. private String stepsCf;
  69.  
  70. public TctImportSetupPage(ProjectManager projectManager, UserManager userManager, CustomFieldManager customFieldManager,TmsService tmsService,ProjectRoleManager projectRoleManager,GroupManager groupManager) {
  71. this.projectManager = projectManager;
  72. this.userManager = userManager;
  73. this.customFieldManager = customFieldManager;
  74. this.tmsService=tmsService;
  75. this.projectRoleManager=projectRoleManager;
  76. this.groupManager=groupManager;
  77. }
  78.  
  79. public String doPermission() {
  80.  
  81. //Save permission settings
  82.  
  83. /*
  84. * save canImportTestCaseRolesArray
  85. * canImportTestCaseGroupsArray
  86. * canImportTestCaseUsersArray
  87. */
  88.  
  89. TmsConfig config=this.tmsService.getConfig();
  90. config.setCanImportTestCaseGroups(Arrays.asList(canImportTestCaseGroupsArray));
  91. config.setCanImportTestCaseRoles(Arrays.asList(canImportTestCaseRolesArray));
  92. config.setCanImportTestCaseUsers(Arrays.asList(canImportTestCaseUsersArray.split(",")));
  93. tmsService.saveConfig(config);
  94.  
  95. return getRedirect("/secure/admin/TctImportSetupPage.jspa");
  96. }
  97.  
  98.  
  99. @Override
  100. protected String doExecute() throws Exception {
  101. TmsConfig config=tmsService.getConfig();
  102. this.canImportTestCaseGroupsList=config.getCanImportTestCaseGroups();
  103. this.canImportTestCaseRolesList=config.getCanImportTestCaseRoles();
  104. this.canImportTestCaseUsersList=config.getCanImportTestCaseUsers();
  105.  
  106. if(canImportTestCaseUsersList!=null){
  107. StringBuilder sb=new StringBuilder();
  108. int i=0;
  109. for(String uk:canImportTestCaseUsersList){
  110. if(i>0)sb.append(",");
  111. sb.append(uk);
  112. i++;
  113. }
  114.  
  115. canImportTestCaseUsersArray = sb.toString();
  116. }
  117.  
  118. setErrorMessage(null);
  119. return INPUT_FILE_NAME;
  120. }
  121.  
  122. public String doExport() {
  123. if (delimiter == null || delimiter.equals("")) {
  124. delimiter = ",";
  125. }
  126. if (filterId == -1) {
  127. return getRedirect("/secure/admin/TctImportSetupPage.jspa");
  128. }
  129. if (stepsCf.equals("-1")) {
  130. return getRedirect("/secure/admin/TctImportSetupPage.jspa");
  131. }
  132. importTctService = ComponentAccessor.getOSGiComponentInstanceOfType(ImportTctService.class);
  133. // importTctService.exportIssues(filterId, outputFileName, delimiter);
  134.  
  135. return getRedirect("/plugins/servlet/exportIssues?filterId=" + filterId + "&delimiter=" + delimiter + "&stepsCf=" + stepsCf + "&cf=" + resultCf, true);
  136. }
  137.  
  138. public Collection<SearchRequest> getFilters(){
  139. SearchRequestManager searchRequestManager = ComponentAccessor.getOSGiComponentInstanceOfType(SearchRequestManager.class);
  140. return searchRequestManager.getAllOwnedSearchRequests(getLoggedInApplicationUser());
  141. }
  142.  
  143. public String getDefaultCsvFieldDelimiter() {
  144. return DEFAULT_CSV_FIELD_DELIMITER;
  145. }
  146.  
  147. public String doProgress() {
  148.  
  149. ImportTctProgress progress = getImportTctService().getImportProgress();
  150. synchronized (progress) {
  151. boolean startDateIsNull = progress.getStartDate() == null;
  152. boolean endDateIsNull = progress.getEndDate() == null;
  153. if (!startDateIsNull && !endDateIsNull && progress.getEndDate().after(progress.getStartDate())) {
  154. setErrorMessage(progress.getErrorMessage());
  155. progress.setErrorMessage(null);
  156. progress.endImport();
  157. return DONE;
  158. } else {
  159. return PROGRESS;
  160. }
  161. }
  162. }
  163.  
  164. public ImportTctProgress getCurrentCopyProgress() {
  165. return getImportTctService().getImportProgress();
  166. }
  167.  
  168. public ImportTctService getImportTctService() {
  169. if (importTctService == null) {
  170. importTctService = ComponentAccessor.getOSGiComponentInstanceOfType(ImportTctService.class);
  171. }
  172. return importTctService;
  173. }
  174.  
  175. public List<Project> getProjects() {
  176. return projectManager.getProjectObjects();
  177. }
  178.  
  179. public Collection<ApplicationUser> getUsers() {
  180. return userManager.getUsers();
  181. }
  182.  
  183. public List<CustomField> getDynamicTableCfs() {
  184. List<CustomField> customFields = customFieldManager.getCustomFieldObjects();
  185. List<CustomField> dynamicTableCustomFields = new ArrayList<>(customFields.size());
  186. for (CustomField customField : customFields) {
  187. if (DYNAMIC_TABLE_CUSTOM_FIELD.equals(customField.getCustomFieldType().getKey())) {
  188. dynamicTableCustomFields.add(customField);
  189. }
  190. }
  191. return dynamicTableCustomFields;
  192. }
  193.  
  194. public List<CustomField> getCustomFields() {
  195. return customFieldManager.getCustomFieldObjects();
  196. }
  197.  
  198. public String getErrorMessage() {
  199. return errorMessage;
  200. }
  201.  
  202. public void setErrorMessage(String errorMessage) {
  203. this.errorMessage = errorMessage;
  204. }
  205.  
  206. public String getExampleCSVURL() {
  207. return ComponentAccessor.getWebResourceManager().getStaticPluginResource("com.intenso.jira.plugins.suiTest:treeTable.resource", "data/ExampleFileImportTestCaseTemplate.csv", UrlMode.AUTO);
  208. }
  209.  
  210. public String getAddress(){
  211. return getClass().getSimpleName();
  212. }
  213.  
  214. public List<String> getCanImportTestCaseRolesList() {
  215. return canImportTestCaseRolesList;
  216. }
  217.  
  218. public void setCanImportTestCaseRolesList(
  219. List<String> canImportTestCaseRolesList) {
  220. this.canImportTestCaseRolesList = canImportTestCaseRolesList;
  221. }
  222.  
  223. public List<String> getCanImportTestCaseGroupsList() {
  224. return canImportTestCaseGroupsList;
  225. }
  226.  
  227. public void setCanImportTestCaseGroupsList(
  228. List<String> canImportTestCaseGroupsList) {
  229. this.canImportTestCaseGroupsList = canImportTestCaseGroupsList;
  230. }
  231.  
  232. public String getCanImportTestCaseUsersArray() {
  233. return canImportTestCaseUsersArray;
  234. }
  235.  
  236. public void setCanImportTestCaseUsersArray(String canImportTestCaseUsersArray) {
  237. this.canImportTestCaseUsersArray = canImportTestCaseUsersArray;
  238. }
  239.  
  240. public List<String> getCanImportTestCaseUsersList() {
  241. return canImportTestCaseUsersList;
  242. }
  243.  
  244. public void setCanImportTestCaseUsersList(
  245. List<String> canImportTestCaseUsersList) {
  246. this.canImportTestCaseUsersList = canImportTestCaseUsersList;
  247. }
  248.  
  249. public TmsService getTmsService() {
  250. return tmsService;
  251. }
  252.  
  253. public void setTmsService(TmsService tmsService) {
  254. this.tmsService = tmsService;
  255. }
  256.  
  257. public List<ProjectRole> getProjectRoles() {
  258. if (projectRoles == null) {
  259. projectRoles = new ArrayList<>(projectRoleManager.getProjectRoles());
  260. }
  261. return projectRoles;
  262. }
  263.  
  264. public List<Group> getGroups() {
  265. if (groups == null) {
  266. groups = new ArrayList<>(groupManager.getAllGroups());
  267. }
  268. return groups;
  269. }
  270.  
  271. public String[] getCanImportTestCaseRolesArray() {
  272. return canImportTestCaseRolesArray;
  273. }
  274.  
  275. public void setCanImportTestCaseRolesArray(String[] canImportTestCaseRolesArray) {
  276. this.canImportTestCaseRolesArray = canImportTestCaseRolesArray;
  277. }
  278.  
  279. public String[] getCanImportTestCaseGroupsArray() {
  280. return canImportTestCaseGroupsArray;
  281. }
  282.  
  283. public void setCanImportTestCaseGroupsArray(
  284. String[] canImportTestCaseGroupsArray) {
  285. this.canImportTestCaseGroupsArray = canImportTestCaseGroupsArray;
  286. }
  287.  
  288. public String getDelimiter() {
  289. return delimiter;
  290. }
  291.  
  292. public void setDelimiter(String delimiter) {
  293. this.delimiter = delimiter;
  294. }
  295.  
  296. public Long getFilterId() {
  297. return filterId;
  298. }
  299.  
  300. public void setFilterId(Long filterId) {
  301. this.filterId = filterId;
  302. }
  303.  
  304. public String getResultCf() {
  305. return resultCf;
  306. }
  307.  
  308. public void setResultCf(String resultCf) {
  309. this.resultCf = resultCf;
  310. }
  311.  
  312. public String getStepsCf() {
  313. return stepsCf;
  314. }
  315.  
  316. public void setStepsCf(String stepscf) {
  317. this.stepsCf = stepscf;
  318. }
  319.  
  320. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement