View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.common.lib.form;
20  
21  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
22  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
23  import java.io.Serializable;
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.regex.Pattern;
27  import org.apache.commons.lang3.builder.EqualsBuilder;
28  import org.apache.commons.lang3.builder.HashCodeBuilder;
29  
30  public class FormProperty implements Serializable {
31  
32      private static final long serialVersionUID = 9139969592634304261L;
33  
34      private String id;
35  
36      private String name;
37  
38      private FormPropertyType type;
39  
40      private boolean readable;
41  
42      private boolean writable;
43  
44      private boolean required;
45  
46      private Pattern stringRegEx;
47  
48      private String datePattern;
49  
50      private final List<FormPropertyValue> enumValues = new ArrayList<>();
51  
52      private final List<FormPropertyValue> dropdownValues = new ArrayList<>();
53  
54      private boolean dropdownSingleSelection = true;
55  
56      private boolean dropdownFreeForm;
57  
58      private String value;
59  
60      public String getId() {
61          return id;
62      }
63  
64      public void setId(final String id) {
65          this.id = id;
66      }
67  
68      public String getName() {
69          return name;
70      }
71  
72      public void setName(final String name) {
73          this.name = name;
74      }
75  
76      public boolean isReadable() {
77          return readable;
78      }
79  
80      public void setReadable(final boolean readable) {
81          this.readable = readable;
82      }
83  
84      public boolean isRequired() {
85          return required;
86      }
87  
88      public void setRequired(final boolean required) {
89          this.required = required;
90      }
91  
92      public Pattern getStringRegEx() {
93          return stringRegEx;
94      }
95  
96      public void setStringRegEx(final Pattern stringRegEx) {
97          this.stringRegEx = stringRegEx;
98      }
99  
100     public FormPropertyType getType() {
101         return type;
102     }
103 
104     public void setType(final FormPropertyType type) {
105         this.type = type;
106     }
107 
108     public boolean isWritable() {
109         return writable;
110     }
111 
112     public void setWritable(final boolean writable) {
113         this.writable = writable;
114     }
115 
116     public String getDatePattern() {
117         return datePattern;
118     }
119 
120     public void setDatePattern(final String datePattern) {
121         this.datePattern = datePattern;
122     }
123 
124     @JacksonXmlElementWrapper(localName = "enumValues")
125     @JacksonXmlProperty(localName = "enumValue")
126     public List<FormPropertyValue> getEnumValues() {
127         return enumValues;
128     }
129 
130     @JacksonXmlElementWrapper(localName = "dropdownValues")
131     @JacksonXmlProperty(localName = "dropdownValue")
132     public List<FormPropertyValue> getDropdownValues() {
133         return dropdownValues;
134     }
135 
136     public boolean isDropdownSingleSelection() {
137         return dropdownSingleSelection;
138     }
139 
140     public void setDropdownSingleSelection(final boolean dropdownSingleSelection) {
141         this.dropdownSingleSelection = dropdownSingleSelection;
142     }
143 
144     public boolean isDropdownFreeForm() {
145         return dropdownFreeForm;
146     }
147 
148     public void setDropdownFreeForm(final boolean dropdownFreeForm) {
149         this.dropdownFreeForm = dropdownFreeForm;
150     }
151 
152     public String getValue() {
153         return value;
154     }
155 
156     public void setValue(final String value) {
157         this.value = value;
158     }
159 
160     @Override
161     public int hashCode() {
162         return new HashCodeBuilder().
163                 append(id).
164                 append(name).
165                 append(type).
166                 append(readable).
167                 append(writable).
168                 append(required).
169                 append(stringRegEx).
170                 append(datePattern).
171                 append(enumValues).
172                 append(dropdownValues).
173                 append(dropdownSingleSelection).
174                 append(dropdownFreeForm).
175                 append(value).
176                 build();
177     }
178 
179     @Override
180     public boolean equals(final Object obj) {
181         if (this == obj) {
182             return true;
183         }
184         if (obj == null) {
185             return false;
186         }
187         if (getClass() != obj.getClass()) {
188             return false;
189         }
190         FormProperty other = (FormProperty) obj;
191         return new EqualsBuilder().
192                 append(id, other.id).
193                 append(name, other.name).
194                 append(type, other.type).
195                 append(readable, other.readable).
196                 append(writable, other.writable).
197                 append(required, other.required).
198                 append(stringRegEx, other.stringRegEx).
199                 append(datePattern, other.datePattern).
200                 append(enumValues, other.enumValues).
201                 append(dropdownValues, other.dropdownValues).
202                 append(dropdownSingleSelection, other.dropdownSingleSelection).
203                 append(dropdownFreeForm, other.dropdownFreeForm).
204                 append(value, other.value).
205                 build();
206     }
207 }