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

/jira-project/jira-components/jira-plugins/jira-rest/jira-rest-plugin/src/main/java/com/atlassian/jira/rest/v2/issue/IssuePropertyResource.java

https://bitbucket.org/ahmed_bilal_360factors/jira7-core
Java | 139 lines | 67 code | 8 blank | 64 comment | 0 complexity | 26d28ff57120549e09784b3dcacce194 MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.atlassian.jira.rest.v2.issue;
  2. import com.atlassian.annotations.ExperimentalApi;
  3. import com.atlassian.jira.bc.issue.properties.IssuePropertyService;
  4. import com.atlassian.jira.entity.property.EntityPropertyType;
  5. import com.atlassian.jira.issue.Issue;
  6. import com.atlassian.jira.issue.IssueKey;
  7. import com.atlassian.jira.issue.fields.rest.json.beans.EntityPropertyBean;
  8. import com.atlassian.jira.issue.fields.rest.json.beans.EntityPropertyBeanSelfFunctions;
  9. import com.atlassian.jira.issue.fields.rest.json.beans.JiraBaseUrls;
  10. import com.atlassian.jira.rest.v2.entity.property.BasePropertyWithKeyResource;
  11. import com.atlassian.jira.rest.v2.entity.property.EntityPropertiesKeysBean;
  12. import com.atlassian.jira.security.JiraAuthenticationContext;
  13. import com.atlassian.jira.util.I18nHelper;
  14. import com.atlassian.plugins.rest.common.security.AnonymousAllowed;
  15. import com.atlassian.rest.annotation.ResponseType;
  16. import javax.servlet.http.HttpServletRequest;
  17. import javax.ws.rs.Consumes;
  18. import javax.ws.rs.DELETE;
  19. import javax.ws.rs.GET;
  20. import javax.ws.rs.PUT;
  21. import javax.ws.rs.Path;
  22. import javax.ws.rs.PathParam;
  23. import javax.ws.rs.Produces;
  24. import javax.ws.rs.core.Context;
  25. import javax.ws.rs.core.MediaType;
  26. import javax.ws.rs.core.Response;
  27. /**
  28. * @since v6.2
  29. */
  30. @Path("issue/{issueIdOrKey}/properties")
  31. @AnonymousAllowed
  32. @Consumes({MediaType.APPLICATION_JSON})
  33. @Produces({MediaType.APPLICATION_JSON})
  34. public class IssuePropertyResource {
  35. private final BasePropertyWithKeyResource<Issue> delegate;
  36. public IssuePropertyResource(IssuePropertyService issuePropertyService, JiraAuthenticationContext authContext,
  37. JiraBaseUrls jiraBaseUrls, I18nHelper i18n) {
  38. this.delegate = new BasePropertyWithKeyResource<Issue>(issuePropertyService, authContext, jiraBaseUrls,
  39. i18n, new IssueKey.IsValidIssueKeyPredicate(), new EntityPropertyBeanSelfFunctions.IssuePropertySelfFunction(), EntityPropertyType.ISSUE_PROPERTY);
  40. }
  41. /**
  42. * Returns the keys of all properties for the issue identified by the key or by the id.
  43. *
  44. * @param issueIdOrKey the issue from which keys will be returned.
  45. * @return a response containing EntityPropertiesKeysBean.
  46. * @response.representation.200.qname issue-properties-keys
  47. * @response.representation.200.doc Returned if the issue was found.
  48. * @response.representation.200.mediaType application/json
  49. * @response.representation.200.example {@link com.atlassian.jira.rest.v2.entity.property.EntityPropertyResourceExamples#GET_PROPERTIES_KEYS_RESPONSE_200}
  50. * @response.representation.400.doc Returned if the issue key or id is invalid.
  51. * @response.representation.401.doc Returned if the calling user is not authenticated.
  52. * @response.representation.403.doc Returned if the calling user does not have permission to view the issue.
  53. * @response.representation.404.doc Returned if the issue with given key or id does not exist or if the property with given key is not found.
  54. */
  55. @ExperimentalApi
  56. @GET
  57. @ResponseType(EntityPropertiesKeysBean.class)
  58. public Response getPropertiesKeys(@PathParam("issueIdOrKey") final String issueIdOrKey) {
  59. return delegate.getPropertiesKeys(issueIdOrKey);
  60. }
  61. /**
  62. * Sets the value of the specified issue's property.
  63. * <p>
  64. * You can use this resource to store a custom data against the issue identified by the key or by the id. The user
  65. * who stores the data is required to have permissions to edit the issue.
  66. * </p>
  67. *
  68. * @param issueIdOrKey the issue on which the property will be set.
  69. * @param issuePropertyKey the key of the issue's property. The maximum length of the key is 255 bytes.
  70. * @param request the request containing value of the issue's property. The value has to a valid, non-empty JSON conforming
  71. * to http://tools.ietf.org/html/rfc4627. The maximum length of the property value is 32768 bytes.
  72. * @response.representation.200.doc Returned if the issue property is successfully updated.
  73. * @response.representation.201.doc Returned if the issue property is successfully created.
  74. * @response.representation.400.doc Returned if the issue key or id is invalid.
  75. * @response.representation.401.doc Returned if the calling user is not authenticated.
  76. * @response.representation.403.doc Returned if the calling user does not have permission to edit the issue.
  77. * @response.representation.404.doc Returned if the issue with given key or id does not exist.
  78. */
  79. @ExperimentalApi
  80. @PUT
  81. @Path("/{propertyKey}")
  82. @ResponseType(Void.class)
  83. public Response setProperty(@PathParam("issueIdOrKey") final String issueIdOrKey,
  84. @PathParam("propertyKey") final String issuePropertyKey, @Context final HttpServletRequest request) {
  85. return delegate.setProperty(issueIdOrKey, issuePropertyKey, request);
  86. }
  87. /**
  88. * Returns the value of the property with a given key from the issue identified by the key or by the id. The user who retrieves
  89. * the property is required to have permissions to read the issue.
  90. *
  91. * @param issueIdOrKey the issue from which the property will be returned.
  92. * @param issuePropertyKey the key of the property to return.
  93. * @return a response containing {@link com.atlassian.jira.issue.fields.rest.json.beans.EntityPropertyBean}.
  94. * @response.representation.200.qname issue-property
  95. * @response.representation.200.doc Returned if the issue property was found.
  96. * @response.representation.200.mediaType application/json
  97. * @response.representation.200.example {@link com.atlassian.jira.rest.v2.entity.property.EntityPropertyResourceExamples#GET_PROPERTY_RESPONSE_200}
  98. * @response.representation.400.doc Returned if the issue key or id is invalid.
  99. * @response.representation.401.doc Returned if the calling user is not authenticated.
  100. * @response.representation.403.doc Returned if the calling user does not have permission to view the issue.
  101. * @response.representation.404.doc Returned if the issue with given key or id does not exist or if the property with given key is not found.
  102. */
  103. @ExperimentalApi
  104. @GET
  105. @Path("/{propertyKey}")
  106. @ResponseType(EntityPropertyBean.class)
  107. public Response getProperty(@PathParam("issueIdOrKey") final String issueIdOrKey,
  108. @PathParam("propertyKey") final String issuePropertyKey) {
  109. return delegate.getProperty(issueIdOrKey, issuePropertyKey);
  110. }
  111. /**
  112. * Removes the property from the issue identified by the key or by the id. Ths user removing the property is required
  113. * to have permissions to edit the issue.
  114. *
  115. * @param issueIdOrKey the issue from which the property will be removed.
  116. * @param propertyKey the key of the property to remove.
  117. * @return a 204 HTTP status if everything goes well.
  118. * @response.representation.204.doc Returned if the issue property was removed successfully.
  119. * @response.representation.400.doc Returned if the issue key or id is invalid.
  120. * @response.representation.401.doc Returned if the calling user is not authenticated.
  121. * @response.representation.403.doc Returned if the calling user does not have permission to edit the issue.
  122. * @response.representation.404.doc Returned if the issue with given key or id does not exist or if the property with given key is not found.
  123. */
  124. @ExperimentalApi
  125. @DELETE
  126. @Path("/{propertyKey}")
  127. public Response deleteProperty(@PathParam("issueIdOrKey") String issueIdOrKey,
  128. @PathParam("propertyKey") String propertyKey) {
  129. return delegate.deleteProperty(issueIdOrKey, propertyKey);
  130. }
  131. }