PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/jira-project/jira-components/jira-api/src/main/java/com/atlassian/jira/bc/issue/label/LabelService.java

https://bitbucket.org/ahmed_bilal_360factors/jira7-core
Java | 226 lines | 82 code | 28 blank | 116 comment | 0 complexity | cb081bb7cd8f1d9ccf06f444c80a98ad MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.atlassian.jira.bc.issue.label;
  2. import com.atlassian.annotations.PublicApi;
  3. import com.atlassian.jira.bc.ServiceResultImpl;
  4. import com.atlassian.jira.issue.label.Label;
  5. import com.atlassian.jira.user.ApplicationUser;
  6. import com.atlassian.jira.util.ErrorCollection;
  7. import java.util.Set;
  8. /**
  9. * The label service is responsible for setting and getting labels for issue and custom field combinations. It can also
  10. * be used to add and remove individual labels from an isssue.
  11. *
  12. * @since v4.2
  13. */
  14. @PublicApi
  15. public interface LabelService {
  16. /**
  17. * Returns all the labels for the given issue.
  18. *
  19. * @param user The user performing the operation
  20. * @param issueId The issue id that the label is linked against
  21. * @return A set of alphabetically ordered labels for the issue.
  22. */
  23. LabelsResult getLabels(final ApplicationUser user, final Long issueId);
  24. /**
  25. * Validates that the user provided can set the labels provided for a particular issue. Validation will ensure that
  26. * the user has the EDIT_ISSUE permission for the issue in question. The labels will also be validated to ensure
  27. * that they don't contain spaces and that they don't exceed the max length of 255
  28. * characters each.
  29. *
  30. * @param user The user performing the operation
  31. * @param issueId The issue id of the issue that labels will be set on
  32. * @param labels The actual labels as strings to set on the issue
  33. * @return A validation result, that can be used to set the labels or to display errors.
  34. */
  35. SetLabelValidationResult validateSetLabels(final ApplicationUser user, final Long issueId, final Set<String> labels);
  36. /**
  37. * Validates that the user provided can set the labels provided for a particular issue. Validation will ensure that
  38. * the user has the EDIT_ISSUE permission for the issue in question. The labels will also be validated to ensure
  39. * that they don't contain spaces and that they don't exceed the max length of 255
  40. * characters each. Validation will also ensure that the custom field with the id provided exists.
  41. *
  42. * @param user The user performing the operation
  43. * @param issueId The issue id of the issue that labels will be set on
  44. * @param customFieldId The custom field id against which to set the labels
  45. * @param labels The actual labels as strings to set on the issue
  46. * @return A validation result, that can be used to set the labels or to display errors.
  47. */
  48. SetLabelValidationResult validateSetLabels(final ApplicationUser user, final Long issueId, final Long customFieldId, final Set<String> labels);
  49. /**
  50. * Returns all the labels for the given issue and custom field. The custom field may also be null, in which case
  51. * the labels for the system field will be returned.
  52. *
  53. * @param user The user performing the operation
  54. * @param issueId The issue id that the label is linked against
  55. * @param customFieldId Custom field id for the labels CF or null if it's the system field.
  56. * @return A set of alphabetically ordered labels for the issue and custom field.
  57. */
  58. LabelsResult getLabels(final ApplicationUser user, final Long issueId, final Long customFieldId);
  59. /**
  60. * Sets the labels for a particular issue to the set specified as a parameter. The set may be an empty set in order
  61. * to clear all labels for an issue.
  62. *
  63. * @param user The user performing the operation
  64. * @param result The validation result obtained by calling {@link #validateSetLabels(com.atlassian.jira.user.ApplicationUser,
  65. * Long, java.util.Set)}
  66. * @param sendNotification true if a notification e-mail should be sent, false otherwise
  67. * @param causeChangeNotification true if a change history should be created, false otherwise
  68. * @return a set of stored label objects in alphabetical order
  69. */
  70. LabelsResult setLabels(final ApplicationUser user, final SetLabelValidationResult result, final boolean sendNotification, final boolean causeChangeNotification);
  71. /**
  72. * Validates that the user provided can add the label provided for a particular issue. Validation will ensure that
  73. * the user has the EDIT_ISSUE permission for the issue in question. The label will also be validated to ensure
  74. * that it doesn't contain spaces and that it doesn't exceed the max length of 255
  75. * characters.
  76. *
  77. * @param user The user performing the operation
  78. * @param issueId The issue id of the issue that labels will be set on
  79. * @param label The actual labels as strings to set on the issue
  80. * @return A validation result, that can be used to set the labels or to display errors.
  81. */
  82. AddLabelValidationResult validateAddLabel(final ApplicationUser user, final Long issueId, final String label);
  83. /**
  84. * Validates that the user provided can add the label provided for a particular issue. Validation will ensure that
  85. * the user has the EDIT_ISSUE permission for the issue in question. The label will also be validated to ensure
  86. * that it doesn't contain spaces and that it doesn't exceed the max length of 255
  87. * characters. Validation will also ensure that the custom field with the id provided exists.
  88. *
  89. * @param user The user performing the operation
  90. * @param issueId The issue id of the issue that labels will be set on
  91. * @param customFieldId Custom field id for the labels CF or null if it's the system field.
  92. * @param label The actual labels as strings to set on the issue
  93. * @return A validation result, that can be used to set the labels or to display errors.
  94. */
  95. AddLabelValidationResult validateAddLabel(final ApplicationUser user, final Long issueId, final Long customFieldId, final String label);
  96. /**
  97. * Adds the label to the issue specified by the validation result.
  98. *
  99. * @param user The user performing the operation
  100. * @param result The validation result obtained via {@link #validateAddLabel(com.atlassian.jira.user.ApplicationUser, Long, String)}
  101. * @param sendNotification true if a notification e-mail should be sent, false otherwise
  102. * @return A result containing the new label.
  103. */
  104. LabelsResult addLabel(final ApplicationUser user, final AddLabelValidationResult result, final boolean sendNotification);
  105. /**
  106. * Given a token to search for, this method returns a number of suggestions for the label. The token may also be
  107. * null or empty in which case a list of suggestions will be returned sorted by most popular labels for the labels
  108. * system field. If a token was provided, then a list of labels sorted alphabetically starting with the token will
  109. * be returned. If provided, any labels that the issue already has will be removed from the list of suggestions.
  110. * The token needs to be at least 2 characters to generate suggestions starting with that token, otherwise an empty
  111. * collection is returned.
  112. *
  113. * @param user The user trying to get label suggestions
  114. * @param issueId The issue for which suggestions are being fetched or {@code null}
  115. * @param token The prefix for the labels to be suggested. May be null for popular label suggestions
  116. * @return suggestion result containing a set of suggestions either sorted alphabetically or by popularity depending
  117. * on the token
  118. */
  119. LabelSuggestionResult getSuggestedLabels(final ApplicationUser user, final Long issueId, String token);
  120. /**
  121. * Given a token to search for, this method returns a number of suggestions for the label. The token may also be
  122. * null or empty in which case a list of suggestions will be returned sorted by most popular labels for the labels
  123. * custom field provided. If a token was provided, then a list of labels sorted alphabetically starting with the
  124. * token will be returned. If provided, any labels that the issue already has will be removed from the list of
  125. * suggestions. The token needs to be at least 2 characters long to generate suggestions starting with that token,
  126. * otherwise an empty collection is returned.
  127. *
  128. * @param user The user trying to get label suggestions
  129. * @param issueId The issue for which suggestions are being fetched or {@code null}
  130. * @param customFieldId The labels custom field for which to provide suggestions
  131. * @param token The prefix for the labels to be suggested. May be null for popular label suggestions
  132. * @return suggestion result containing a set of suggestions either sorted alphabetically or by popularity depending
  133. * on the token
  134. */
  135. LabelSuggestionResult getSuggestedLabels(final ApplicationUser user, final Long issueId, final Long customFieldId, String token);
  136. @PublicApi
  137. public static class LabelSuggestionResult extends ServiceResultImpl {
  138. private final Set<String> suggestions;
  139. public LabelSuggestionResult(final Set<String> suggestions, final ErrorCollection errorCollection) {
  140. super(errorCollection);
  141. this.suggestions = suggestions;
  142. }
  143. public Set<String> getSuggestions() {
  144. return suggestions;
  145. }
  146. }
  147. @PublicApi
  148. public static class LabelsResult extends ServiceResultImpl {
  149. private final Set<Label> labels;
  150. public LabelsResult(final Set<Label> labels, final ErrorCollection errorCollection) {
  151. super(errorCollection);
  152. this.labels = labels;
  153. }
  154. public Set<Label> getLabels() {
  155. return labels;
  156. }
  157. }
  158. public static abstract class LabelValidationResult extends ServiceResultImpl {
  159. private final Long issueId;
  160. private final Long customFieldId;
  161. public LabelValidationResult(final Long issueId, final Long customFieldId,
  162. final ErrorCollection errorCollection) {
  163. super(errorCollection);
  164. this.issueId = issueId;
  165. this.customFieldId = customFieldId;
  166. }
  167. public Long getCustomFieldId() {
  168. return customFieldId;
  169. }
  170. public Long getIssueId() {
  171. return issueId;
  172. }
  173. }
  174. @PublicApi
  175. public static class SetLabelValidationResult extends LabelValidationResult {
  176. private final Set<String> labels;
  177. public SetLabelValidationResult(final Long issueId, final Long customFieldId, final ErrorCollection errorCollection,
  178. final Set<String> labels) {
  179. super(issueId, customFieldId, errorCollection);
  180. this.labels = labels;
  181. }
  182. public Set<String> getLabels() {
  183. return labels;
  184. }
  185. }
  186. @PublicApi
  187. public static class AddLabelValidationResult extends LabelValidationResult {
  188. private final String label;
  189. public AddLabelValidationResult(final Long issueId, final Long customFieldId, final ErrorCollection errorCollection,
  190. final String label) {
  191. super(issueId, customFieldId, errorCollection);
  192. this.label = label;
  193. }
  194. public String getLabel() {
  195. return label;
  196. }
  197. }
  198. }