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.annotation.JsonIgnore;
22  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
23  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.Optional;
27  import org.apache.commons.lang3.builder.EqualsBuilder;
28  import org.apache.commons.lang3.builder.HashCodeBuilder;
29  import org.apache.syncope.common.lib.BaseBean;
30  
31  public class SyncopeForm implements BaseBean {
32  
33      private static final long serialVersionUID = 8388697351958834257L;
34  
35      private final List<FormProperty> properties = new ArrayList<>();
36  
37      @JsonIgnore
38      public Optional<FormProperty> getProperty(final String id) {
39          return properties.stream().filter(property -> id.equals(property.getId())).findFirst();
40      }
41  
42      @JacksonXmlElementWrapper(localName = "properties")
43      @JacksonXmlProperty(localName = "property")
44      public List<FormProperty> getProperties() {
45          return properties;
46      }
47  
48      @Override
49      public int hashCode() {
50          return new HashCodeBuilder().
51                  append(properties).
52                  build();
53      }
54  
55      @Override
56      public boolean equals(final Object obj) {
57          if (this == obj) {
58              return true;
59          }
60          if (obj == null) {
61              return false;
62          }
63          if (getClass() != obj.getClass()) {
64              return false;
65          }
66          SyncopeForm other = (SyncopeForm) obj;
67          return new EqualsBuilder().
68                  append(properties, other.properties).
69                  build();
70      }
71  }