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.rest.api.beans;
20  
21  import io.swagger.v3.oas.annotations.ExternalDocumentation;
22  import io.swagger.v3.oas.annotations.Parameter;
23  import io.swagger.v3.oas.annotations.media.Schema;
24  import java.util.Optional;
25  import javax.ws.rs.DefaultValue;
26  import javax.ws.rs.QueryParam;
27  import org.apache.commons.lang3.builder.EqualsBuilder;
28  import org.apache.commons.lang3.builder.HashCodeBuilder;
29  import org.apache.syncope.common.lib.SyncopeConstants;
30  import org.apache.syncope.common.rest.api.service.JAXRSService;
31  
32  public class AnyQuery extends AbstractQuery {
33  
34      private static final long serialVersionUID = -6736562952418964707L;
35  
36      public static class Builder extends AbstractQuery.Builder<AnyQuery, Builder> {
37  
38          @Override
39          protected AnyQuery newInstance() {
40              return new AnyQuery();
41          }
42  
43          public Builder recursive(final boolean recursive) {
44              getInstance().setRecursive(recursive);
45              return this;
46          }
47  
48          public Builder details(final boolean details) {
49              getInstance().setDetails(details);
50              return this;
51          }
52  
53          public Builder realm(final String realm) {
54              getInstance().setRealm(realm);
55              return this;
56          }
57  
58          public Builder fiql(final String fiql) {
59              getInstance().setFiql(fiql);
60  
61              return this;
62          }
63      }
64  
65      private String realm;
66  
67      private Boolean recursive;
68  
69      private Boolean details;
70  
71      private String fiql;
72  
73      @Parameter(name = JAXRSService.PARAM_REALM, description = "realms define a hierarchical security domain tree, "
74              + "primarily meant for containing Users, Groups and Any Objects", schema =
75              @Schema(implementation = String.class, defaultValue = SyncopeConstants.ROOT_REALM, externalDocs =
76                      @ExternalDocumentation(description = "Apache Syncope Reference Guide",
77                              url = "https://syncope.apache.org/docs/3.0/reference-guide.html#realms")))
78      public String getRealm() {
79          return realm;
80      }
81  
82      @DefaultValue(SyncopeConstants.ROOT_REALM)
83      @QueryParam(JAXRSService.PARAM_REALM)
84      public void setRealm(final String realm) {
85          this.realm = realm;
86      }
87  
88      @Parameter(name = JAXRSService.PARAM_RECURSIVE, description = "whether search results shall be returned from "
89              + "given realm and all children realms, or just the given realm", schema =
90              @Schema(implementation = Boolean.class))
91      public Boolean getRecursive() {
92          return Optional.ofNullable(recursive).orElse(Boolean.TRUE);
93      }
94  
95      @QueryParam(JAXRSService.PARAM_RECURSIVE)
96      @DefaultValue("true")
97      public void setRecursive(final Boolean recursive) {
98          this.recursive = recursive;
99      }
100 
101     @Parameter(name = JAXRSService.PARAM_DETAILS, description = "whether detailed information is to be included, "
102             + "if applicable, about virtual attributes, (dynamic) roles, privileges, relationships, "
103             + "(dynamic) memberships or linked accounts", schema =
104             @Schema(implementation = Boolean.class))
105     public Boolean getDetails() {
106         return Optional.ofNullable(details).orElse(Boolean.TRUE);
107     }
108 
109     @QueryParam(JAXRSService.PARAM_DETAILS)
110     @DefaultValue("true")
111     public void setDetails(final Boolean details) {
112         this.details = details;
113     }
114 
115     public String getFiql() {
116         return fiql;
117     }
118 
119     @Parameter(name = JAXRSService.PARAM_FIQL, description = "Feed Item Query Language (FIQL, pronounced “fickle”) is "
120             + "a simple but flexible, URI-friendly syntax for expressing filters across the entries in a syndicated "
121             + "feed.", example = "username==rossini", schema =
122             @Schema(implementation = String.class, externalDocs =
123                     @ExternalDocumentation(description = "Apache Syncope Reference Guide",
124                             url = "https://syncope.apache.org/docs/3.0/reference-guide.html#search")))
125     @QueryParam(JAXRSService.PARAM_FIQL)
126     public void setFiql(final String fiql) {
127         this.fiql = fiql;
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         AnyQuery other = (AnyQuery) obj;
142         return new EqualsBuilder().
143                 appendSuper(super.equals(obj)).
144                 append(realm, other.realm).
145                 append(details, other.details).
146                 append(fiql, other.fiql).
147                 build();
148     }
149 
150     @Override
151     public int hashCode() {
152         return new HashCodeBuilder().
153                 appendSuper(super.hashCode()).
154                 append(realm).
155                 append(details).
156                 append(fiql).
157                 build();
158     }
159 }