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 java.io.Serializable;
22  import java.util.Collection;
23  import java.util.HashSet;
24  import java.util.Optional;
25  import java.util.Set;
26  import java.util.stream.Collectors;
27  import java.util.stream.Stream;
28  import javax.validation.constraints.NotNull;
29  import javax.ws.rs.QueryParam;
30  import org.apache.syncope.common.rest.api.service.JAXRSService;
31  
32  public class ReconQuery implements Serializable {
33  
34      private static final long serialVersionUID = -3797021989909461591L;
35  
36      public static class Builder {
37  
38          private final ReconQuery instance;
39  
40          public Builder(final String anyTypeKey, final String resourceKey) {
41              instance = new ReconQuery();
42              instance.setAnyTypeKey(anyTypeKey);
43              instance.setResourceKey(resourceKey);
44          }
45  
46          public Builder anyKey(final String anyKey) {
47              instance.setAnyKey(anyKey);
48              return this;
49          }
50  
51          public Builder fiql(final String fiql) {
52              instance.setFiql(fiql);
53              return this;
54          }
55  
56          public Builder moreAttrsToGet(final String... moreAttrsToGet) {
57              if (moreAttrsToGet != null) {
58                  Set<String> matg = Optional.ofNullable(instance.getMoreAttrsToGet()).orElseGet(HashSet::new);
59                  matg.addAll(Stream.of(moreAttrsToGet).collect(Collectors.toSet()));
60                  instance.setMoreAttrsToGet(matg);
61              }
62              return this;
63          }
64  
65          public Builder moreAttrsToGet(final Collection<String> moreAttrsToGet) {
66              if (moreAttrsToGet != null) {
67                  Set<String> matg = Optional.ofNullable(instance.getMoreAttrsToGet()).orElseGet(HashSet::new);
68                  matg.addAll(moreAttrsToGet);
69                  instance.setMoreAttrsToGet(matg);
70              }
71              return this;
72          }
73  
74          public ReconQuery build() {
75              return instance;
76          }
77      }
78  
79      private String anyTypeKey;
80  
81      private String anyKey;
82  
83      private String resourceKey;
84  
85      private String fiql;
86  
87      private Set<String> moreAttrsToGet;
88  
89      public String getAnyTypeKey() {
90          return anyTypeKey;
91      }
92  
93      @NotNull
94      @QueryParam(JAXRSService.PARAM_ANYTYPEKEY)
95      public void setAnyTypeKey(final String anyTypeKey) {
96          this.anyTypeKey = anyTypeKey;
97      }
98  
99      public String getAnyKey() {
100         return anyKey;
101     }
102 
103     @QueryParam("anyKey")
104     public void setAnyKey(final String anyKey) {
105         this.anyKey = anyKey;
106     }
107 
108     public String getResourceKey() {
109         return resourceKey;
110     }
111 
112     @NotNull
113     @QueryParam("resourceKey")
114     public void setResourceKey(final String resourceKey) {
115         this.resourceKey = resourceKey;
116     }
117 
118     public String getFiql() {
119         return fiql;
120     }
121 
122     @QueryParam(JAXRSService.PARAM_FIQL)
123     public void setFiql(final String fiql) {
124         this.fiql = fiql;
125     }
126 
127     public Set<String> getMoreAttrsToGet() {
128         return moreAttrsToGet;
129     }
130 
131     @QueryParam("moreAttrsToGet")
132     public void setMoreAttrsToGet(final Set<String> moreAttrsToGet) {
133         this.moreAttrsToGet = moreAttrsToGet;
134     }
135 }