PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/atlassian/jira/plugins/bitbucket/webwork/ConfigureBitbucketRepositories.java

https://bitbucket.org/atlassian/jira-bitbucket-connector/
Java | 186 lines | 147 code | 31 blank | 8 comment | 3 complexity | 8c387e72aac1a85c6c4566ef6ad0362e MD5 | raw file
  1. package com.atlassian.jira.plugins.bitbucket.webwork;
  2. import com.atlassian.jira.plugins.bitbucket.api.SourceControlException;
  3. import com.atlassian.jira.plugins.bitbucket.api.SourceControlRepository;
  4. import com.atlassian.jira.plugins.bitbucket.spi.RepositoryManager;
  5. import com.atlassian.jira.project.Project;
  6. import com.atlassian.jira.security.xsrf.RequiresXsrfCheck;
  7. import com.atlassian.jira.web.action.JiraWebActionSupport;
  8. import com.atlassian.sal.api.ApplicationProperties;
  9. import org.apache.commons.lang.StringUtils;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.beans.factory.annotation.Qualifier;
  13. import java.util.List;
  14. /**
  15. * Webwork action used to configure the bitbucket repositories
  16. * TODO test this on project page (mode='single')
  17. */
  18. public class ConfigureBitbucketRepositories extends JiraWebActionSupport
  19. {
  20. private final Logger logger = LoggerFactory.getLogger(ConfigureBitbucketRepositories.class);
  21. private String mode = "";
  22. private String repositoryUrl = "";
  23. private String postCommitUrl = "";
  24. private String projectKey = "";
  25. private String nextAction = "";
  26. private String addedRepositoryId="";
  27. private int repositoryId;
  28. private final String baseUrl;
  29. private final RepositoryManager globalRepositoryManager;
  30. private String postCommitRepositoryType;
  31. public ConfigureBitbucketRepositories(
  32. @Qualifier("globalRepositoryManager") RepositoryManager globalRepositoryManager,
  33. ApplicationProperties applicationProperties)
  34. {
  35. this.globalRepositoryManager = globalRepositoryManager;
  36. this.baseUrl = applicationProperties.getBaseUrl();
  37. }
  38. @Override
  39. protected void doValidation()
  40. {
  41. }
  42. @Override
  43. @RequiresXsrfCheck
  44. protected String doExecute() throws Exception
  45. {
  46. logger.debug("configure repository [ " + nextAction + " ]");
  47. try
  48. {
  49. if (getErrorMessages().isEmpty())
  50. {
  51. if (nextAction.equals("ShowPostCommitURL"))
  52. {
  53. try
  54. {
  55. SourceControlRepository repo = globalRepositoryManager.getRepository(repositoryId);
  56. postCommitUrl = baseUrl + "/rest/bitbucket/1.0/repository/" + repositoryId + "/sync";
  57. postCommitRepositoryType = StringUtils.capitalize(repo.getRepositoryType());
  58. } catch (Exception e)
  59. {
  60. // do nothing. repository not found. it may be deleted
  61. // TODO instead of catching exception we should make sure this action is not
  62. // called on deleted repositories BBC-48
  63. }
  64. }
  65. if (nextAction.equals("DeleteRepository"))
  66. {
  67. SourceControlRepository repo = globalRepositoryManager.getRepository(repositoryId);
  68. globalRepositoryManager.removeRepository(repositoryId);
  69. globalRepositoryManager.removePostcommitHook(repo);
  70. }
  71. }
  72. } catch (SourceControlException e)
  73. {
  74. addErrorMessage(e.getMessage());
  75. }
  76. return INPUT;
  77. }
  78. public List<Project> getProjects()
  79. {
  80. return getProjectManager().getProjectObjects();
  81. }
  82. // Stored Repository + JIRA Projects
  83. public List<SourceControlRepository> getProjectRepositories(String projectKey)
  84. {
  85. return globalRepositoryManager.getRepositories(projectKey);
  86. }
  87. public String getProjectName()
  88. {
  89. return getProjectManager().getProjectObjByKey(projectKey).getName();
  90. }
  91. public void setMode(String value)
  92. {
  93. this.mode = value;
  94. }
  95. public String getMode()
  96. {
  97. return mode;
  98. }
  99. public void setRepositoryUrl(String value)
  100. {
  101. this.repositoryUrl = value;
  102. }
  103. public String getRepositoryUrl()
  104. {
  105. return repositoryUrl;
  106. }
  107. public void setPostCommitUrl(String value)
  108. {
  109. this.postCommitUrl = value;
  110. }
  111. public String getPostCommitUrl()
  112. {
  113. return postCommitUrl;
  114. }
  115. public void setProjectKey(String value)
  116. {
  117. this.projectKey = value;
  118. }
  119. public String getProjectKey()
  120. {
  121. return projectKey;
  122. }
  123. public void setNextAction(String value)
  124. {
  125. this.nextAction = value;
  126. }
  127. public String getNextAction()
  128. {
  129. return this.nextAction;
  130. }
  131. public int getRepositoryId()
  132. {
  133. return repositoryId;
  134. }
  135. public void setRepositoryId(int repositoryId)
  136. {
  137. this.repositoryId = repositoryId;
  138. }
  139. public String getAddedRepositoryId()
  140. {
  141. return addedRepositoryId;
  142. }
  143. public void setAddedRepositoryId(String addedRepositoryId)
  144. {
  145. this.addedRepositoryId = addedRepositoryId;
  146. }
  147. public String getPostCommitRepositoryType()
  148. {
  149. return postCommitRepositoryType;
  150. }
  151. public void setPostCommitRepositoryType(String postCommitRepositoryType)
  152. {
  153. this.postCommitRepositoryType = postCommitRepositoryType;
  154. }
  155. }