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.client.console.panels.search;
20  
21  import java.io.Serializable;
22  import org.apache.commons.lang3.builder.EqualsBuilder;
23  import org.apache.commons.lang3.builder.HashCodeBuilder;
24  import org.apache.commons.lang3.builder.ToStringBuilder;
25  
26  public final class SearchClause implements Serializable {
27  
28      private static final long serialVersionUID = 2010794463096110104L;
29  
30      public enum Operator {
31  
32          AND,
33          OR;
34  
35      }
36  
37      public enum Type {
38  
39          ATTRIBUTE,
40          GROUP_MEMBERSHIP,
41          GROUP_MEMBER,
42          ROLE_MEMBERSHIP,
43          PRIVILEGE,
44          AUX_CLASS,
45          RESOURCE,
46          RELATIONSHIP,
47          CUSTOM;
48  
49      }
50  
51      public enum Comparator {
52  
53          IS_NULL,
54          IS_NOT_NULL,
55          EQUALS,
56          NOT_EQUALS,
57          GREATER_OR_EQUALS,
58          GREATER_THAN,
59          LESS_OR_EQUALS,
60          LESS_THAN;
61  
62      }
63  
64      private Operator operator;
65  
66      private Type type;
67  
68      private String property;
69  
70      private Comparator comparator;
71  
72      private String value;
73  
74      public SearchClause() {
75          setOperator(SearchClause.Operator.AND);
76          setComparator(SearchClause.Comparator.EQUALS);
77      }
78  
79      public Operator getOperator() {
80          return operator;
81      }
82  
83      public void setOperator(final Operator operator) {
84          this.operator = operator;
85      }
86  
87      public Type getType() {
88          return type;
89      }
90  
91      public void setType(final Type type) {
92          this.type = type;
93      }
94  
95      public String getProperty() {
96          return property;
97      }
98  
99      public void setProperty(final String property) {
100         this.property = property;
101     }
102 
103     public Comparator getComparator() {
104         return comparator;
105     }
106 
107     public void setComparator(final Comparator comparator) {
108         this.comparator = comparator;
109     }
110 
111     public String getValue() {
112         return value;
113     }
114 
115     public void setValue(final String value) {
116         this.value = value;
117     }
118 
119     @Override
120     public int hashCode() {
121         return new HashCodeBuilder().
122                 append(operator).
123                 append(type).
124                 append(property).
125                 append(comparator).
126                 append(value).
127                 build();
128     }
129 
130     @Override
131     public boolean equals(final Object obj) {
132         if (this == obj) {
133             return true;
134         }
135         if (obj == null) {
136             return false;
137         }
138         if (getClass() != obj.getClass()) {
139             return false;
140         }
141         final SearchClause other = (SearchClause) obj;
142         return new EqualsBuilder().
143                 append(operator, other.operator).
144                 append(type, other.type).
145                 append(property, other.property).
146                 append(comparator, other.comparator).
147                 append(value, other.value).
148                 build();
149     }
150 
151     @Override
152     public String toString() {
153         return new ToStringBuilder(this).
154                 append(operator).
155                 append(type).
156                 append(property).
157                 append(comparator).
158                 append(value).
159                 build();
160     }
161 }