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  	 * @param projectKey key of project to scope returned permissions for
40  	 * @param projectId id of project to scope returned permissions for
41  	 * @param issueKey key of the issue to scope returned permissions for
42  	 * @param issueId id of the issue to scope returned permissions for
43  	 */
44  	public MyPermissionsInput(@Nullable final String projectKey, @Nullable final Integer projectId,
45  			@Nullable final String issueKey, @Nullable final Integer issueId) {
46  		this.projectKey = projectKey;
47  		this.projectId = projectId;
48  		this.issueKey = issueKey;
49  		this.issueId = issueId;
50  	}
51  
52  	@Nullable
53  	public String getProjectKey() {
54  		return projectKey;
55  	}
56  
57  	@Nullable
58  	public Integer getProjectId() {
59  		return projectId;
60  	}
61  
62  	@Nullable
63  	public String getIssueKey() {
64  		return issueKey;
65  	}
66  
67  	@Nullable
68  	public Integer getIssueId() {
69  		return issueId;
70  	}
71  
72  	@Override
73  	public String toString() {
74  		return Objects.toStringHelper(this)
75  				.add("projectKey", projectKey)
76  				.add("projectId", projectId)
77  				.add("issueKey", issueKey)
78  				.add("issueId", issueId)
79  				.toString();
80  	}
81  
82  	/**
83  	 * Creates permissions context with project defined by key
84  	 */
85  	public static MyPermissionsInput withProject(final String projectKey) {
86  		return new MyPermissionsInput(projectKey, null, null, null);
87  	}
88  
89  	/**
90  	 * Creates permissions context with project defined by id
91  	 */
92  	public static MyPermissionsInput withProject(final int projectId) {
93  		return new MyPermissionsInput(null, projectId, null, null);
94  	}
95  
96  	/**
97  	 * Creates permissions context with issue defined by key
98  	 */
99  	public static MyPermissionsInput withIssue(final String issueKey) {
100 		return new MyPermissionsInput(null, null, issueKey, null);
101 	}
102 
103 	/**
104 	 * Creates permissions context with issue defined by id
105 	 */
106 	public static MyPermissionsInput withIssue(final int issueId) {
107 		return new MyPermissionsInput(null, null, null, issueId);
108 	}
109 
110 	/**
111 	 * Creates permissions context for any project or issue
112 	 */
113 	public static MyPermissionsInput withAny() {
114 		return null;
115 	}
116 }