View Javadoc

1   /*
2    * Copyright (C) 2014 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.atlassian.jira.rest.client.api.domain.input;
18  
19  import com.atlassian.jira.rest.client.api.MyPermissionsRestClient;
20  import com.google.common.base.Objects;
21  
22  import javax.annotation.Nullable;
23  
24  /**
25   * Permissions context for {@link MyPermissionsRestClient}
26   */
27  public class MyPermissionsInput {
28      @Nullable
29      private final String projectKey;
30      @Nullable
31      private final Integer projectId;
32      @Nullable
33      private final String issueKey;
34      @Nullable
35      private final Integer issueId;
36  
37      /**
38       * Creates permissions context
39       *
40       * @param projectKey key of project to scope returned permissions for
41       * @param projectId  id of project to scope returned permissions for
42       * @param issueKey   key of the issue to scope returned permissions for
43       * @param issueId    id of the issue to scope returned permissions for
44       */
45      public MyPermissionsInput(@Nullable final String projectKey, @Nullable final Integer projectId,
46                                @Nullable final String issueKey, @Nullable final Integer issueId) {
47          this.projectKey = projectKey;
48          this.projectId = projectId;
49          this.issueKey = issueKey;
50          this.issueId = issueId;
51      }
52  
53      @Nullable
54      public String getProjectKey() {
55          return projectKey;
56      }
57  
58      @Nullable
59      public Integer getProjectId() {
60          return projectId;
61      }
62  
63      @Nullable
64      public String getIssueKey() {
65          return issueKey;
66      }
67  
68      @Nullable
69      public Integer getIssueId() {
70          return issueId;
71      }
72  
73      @Override
74      public String toString() {
75          return Objects.toStringHelper(this)
76                  .add("projectKey", projectKey)
77                  .add("projectId", projectId)
78                  .add("issueKey", issueKey)
79                  .add("issueId", issueId)
80                  .toString();
81      }
82  
83      /**
84       * Creates permissions context with project defined by key
85       */
86      public static MyPermissionsInput withProject(final String projectKey) {
87          return new MyPermissionsInput(projectKey, null, null, null);
88      }
89  
90      /**
91       * Creates permissions context with project defined by id
92       */
93      public static MyPermissionsInput withProject(final int projectId) {
94          return new MyPermissionsInput(null, projectId, null, null);
95      }
96  
97      /**
98       * Creates permissions context with issue defined by key
99       */
100     public static MyPermissionsInput withIssue(final String issueKey) {
101         return new MyPermissionsInput(null, null, issueKey, null);
102     }
103 
104     /**
105      * Creates permissions context with issue defined by id
106      */
107     public static MyPermissionsInput withIssue(final int issueId) {
108         return new MyPermissionsInput(null, null, null, issueId);
109     }
110 
111     /**
112      * Creates permissions context for any project or issue
113      */
114     public static MyPermissionsInput withAny() {
115         return null;
116     }
117 }