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.to;
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.Optional;
25  import java.util.Set;
26  import java.util.TreeSet;
27  import org.apache.commons.lang3.builder.EqualsBuilder;
28  import org.apache.commons.lang3.builder.HashCodeBuilder;
29  import org.apache.syncope.common.lib.Attr;
30  import org.apache.syncope.common.lib.BaseBean;
31  
32  public class ConnObject implements BaseBean {
33  
34      private static final long serialVersionUID = 5139554911265442497L;
35  
36      private String fiql;
37  
38      private final Set<Attr> attrs = new TreeSet<>();
39  
40      public String getFiql() {
41          return fiql;
42      }
43  
44      public void setFiql(final String fiql) {
45          this.fiql = fiql;
46      }
47  
48      @JacksonXmlElementWrapper(localName = "attrs")
49      @JacksonXmlProperty(localName = "attr")
50      public Set<Attr> getAttrs() {
51          return attrs;
52      }
53  
54      @JsonIgnore
55      public Optional<Attr> getAttr(final String schema) {
56          return attrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
57      }
58  
59      @Override
60      public int hashCode() {
61          return new HashCodeBuilder().
62                  append(fiql).
63                  append(attrs).
64                  build();
65      }
66  
67      @Override
68      public boolean equals(final Object obj) {
69          if (this == obj) {
70              return true;
71          }
72          if (obj == null) {
73              return false;
74          }
75          if (getClass() != obj.getClass()) {
76              return false;
77          }
78          final ConnObject other = (ConnObject) obj;
79          return new EqualsBuilder().
80                  append(fiql, other.fiql).
81                  append(attrs, other.attrs).
82                  build();
83      }
84  }