View Javadoc

1   /*
2    * Copyright (C) 2012 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.domain;
18  
19  import com.atlassian.jira.rest.client.GetCreateIssueMetadataOptions;
20  import com.atlassian.jira.rest.client.IdentifiableEntity;
21  import com.atlassian.jira.rest.client.IssueRestClient;
22  import com.atlassian.jira.rest.client.NamedEntity;
23  import com.atlassian.jira.rest.client.ProgressMonitor;
24  import com.atlassian.jira.rest.client.internal.json.StandardOperation;
25  import com.atlassian.jira.rest.client.internal.json.FieldSchema;
26  import com.google.common.base.Objects;
27  
28  import javax.annotation.Nullable;
29  import java.net.URI;
30  import java.util.Set;
31  
32  /**
33   * Contains information about field in IssueType.<br/>
34   * The CIM prefix stands for CreateIssueMetadata as this class is used in output of {@link IssueRestClient#getCreateIssueMetadata(GetCreateIssueMetadataOptions, ProgressMonitor)}
35   *
36   * @since v1.0
37   */
38  public class CimFieldInfo implements NamedEntity, IdentifiableEntity<String> {
39  
40  	private final String id;
41  	private final boolean required;
42  	@Nullable
43  	private final String name;
44  	private final FieldSchema schema;
45  	private final Set<StandardOperation> operations;
46  	@Nullable
47  	private final Iterable<Object> allowedValues;
48  	@Nullable
49  	private final URI autoCompleteUri;
50  
51  
52  	public CimFieldInfo(String id, boolean required, @Nullable String name, FieldSchema schema,
53  			Set<StandardOperation> operations, @Nullable Iterable<Object> allowedValues, @Nullable URI autoCompleteUri) {
54  		this.id = id;
55  		this.required = required;
56  		this.name = name;
57  		this.schema = schema;
58  		this.operations = operations;
59  		this.allowedValues = allowedValues;
60  		this.autoCompleteUri = autoCompleteUri;
61  	}
62  
63  	public String getId() {
64  		return id;
65  	}
66  
67  	public boolean isRequired() {
68  		return required;
69  	}
70  
71  	@Nullable
72  	public String getName() {
73  		return name;
74  	}
75  
76  	/**
77  	 * Returns schema of this field that describes type of that field and contained items type.
78  	 * @return schema of this field.
79  	 */
80  	public FieldSchema getSchema() {
81  		return schema;
82  	}
83  
84  	/**
85  	 * Returns set of operations allowed for this field.
86  	 * @return set of operations allowed for this field.
87  	 */
88  	public Set<StandardOperation> getOperations() {
89  		return operations;
90  	}
91  
92  	/**
93  	 * Returns list of values that are allowed to be used as value to this field.
94  	 * @return list of allowed values.
95  	 */
96  	@Nullable
97  	public Iterable<Object> getAllowedValues() {
98  		return allowedValues;
99  	}
100 
101 	/**
102 	 * Returns URI to Auto Complete feature for this field. To make use of it append searched text to returned address.<br/>
103 	 * Example:<br/>
104 	 * {@code URI uriToGetResponseFrom = new URI(getAutoCompleteUri() + "typedLetters"); }
105 	 *
106 	 * @return URI to Auto Complete feature for this field
107 	 */
108 	@SuppressWarnings("UnusedDeclaration")
109 	@Nullable
110 	public URI getAutoCompleteUri() {
111 		return autoCompleteUri;
112 	}
113 
114 	/**
115 	 * Returns ToStringHelper with all fields inserted. Override this method to insert additional fields.
116 	 *
117 	 * @return ToStringHelper
118 	 */
119 	protected Objects.ToStringHelper getToStringHelper() {
120 		return Objects.toStringHelper(this).
121 				add("id", id).
122 				add("name", name).
123 				add("required", required).
124 				add("schema", schema).
125 				add("operations", operations).
126 				add("allowedValues", allowedValues).
127 				add("autoCompleteUri", autoCompleteUri);
128 	}
129 
130 	@Override
131 	public String toString() {
132 		return getToStringHelper().toString();
133 	}
134 
135 
136 	@Override
137 	public boolean equals(Object obj) {
138 		if (obj instanceof CimFieldInfo) {
139 			CimFieldInfo that = (CimFieldInfo) obj;
140 			return Objects.equal(this.id, that.id)
141 					&& Objects.equal(this.name, that.name)
142 					&& Objects.equal(this.required, that.required)
143 					&& Objects.equal(this.schema, that.schema)
144 					&& Objects.equal(this.operations, that.operations)
145 					&& Objects.equal(this.allowedValues, that.allowedValues)
146 					&& Objects.equal(this.autoCompleteUri, that.autoCompleteUri);
147 		}
148 		return false;
149 	}
150 
151 	@Override
152 	public int hashCode() {
153 		return Objects.hashCode(id, name, required, schema, operations, allowedValues, autoCompleteUri);
154 	}
155 }