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