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.api.domain;
18  
19  import com.atlassian.jira.rest.client.api.GetCreateIssueMetadataOptions;
20  import com.atlassian.jira.rest.client.api.IdentifiableEntity;
21  import com.atlassian.jira.rest.client.api.IssueRestClient;
22  import com.atlassian.jira.rest.client.api.NamedEntity;
23  import com.google.common.base.Objects;
24  
25  import javax.annotation.Nullable;
26  import java.net.URI;
27  import java.util.Set;
28  
29  /**
30   * Contains information about field in IssueType.<br/>
31   * The CIM prefix stands for CreateIssueMetadata as this class is used in output of {@link IssueRestClient#getCreateIssueMetadata(GetCreateIssueMetadataOptions)}
32   *
33   * @since v1.0
34   */
35  public class CimFieldInfo implements NamedEntity, IdentifiableEntity<String> {
36  
37  	private final String id;
38  	private final boolean required;
39  	@Nullable
40  	private final String name;
41  	private final FieldSchema schema;
42  	private final Set<StandardOperation> operations;
43  	@Nullable
44  	private final Iterable<Object> allowedValues;
45  	@Nullable
46  	private final URI autoCompleteUri;
47  
48  
49  	public CimFieldInfo(String id, boolean required, @Nullable String name, FieldSchema schema,
50  			Set<StandardOperation> operations, @Nullable Iterable<Object> allowedValues, @Nullable URI autoCompleteUri) {
51  		this.id = id;
52  		this.required = required;
53  		this.name = name;
54  		this.schema = schema;
55  		this.operations = operations;
56  		this.allowedValues = allowedValues;
57  		this.autoCompleteUri = autoCompleteUri;
58  	}
59  
60  	public String getId() {
61  		return id;
62  	}
63  
64  	public boolean isRequired() {
65  		return required;
66  	}
67  
68  	@Nullable
69  	public String getName() {
70  		return name;
71  	}
72  
73  	/**
74  	 * Returns schema of this field that describes type of that field and contained items type.
75  	 *
76  	 * @return schema of this field.
77  	 */
78  	public FieldSchema getSchema() {
79  		return schema;
80  	}
81  
82  	/**
83  	 * Returns set of operations allowed for this field.
84  	 *
85  	 * @return set of operations allowed for this field.
86  	 */
87  	public Set<StandardOperation> getOperations() {
88  		return operations;
89  	}
90  
91  	/**
92  	 * Returns list of values that are allowed to be used as value to this field.
93  	 *
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 }