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.Max;
29  import javax.validation.constraints.Min;
30  import javax.ws.rs.DefaultValue;
31  import javax.ws.rs.QueryParam;
32  import org.apache.syncope.common.rest.api.service.JAXRSService;
33  
34  public class ConnObjectTOQuery implements Serializable {
35  
36      private static final long serialVersionUID = -371488230250055359L;
37  
38      private static final int MAX_SIZE = 100;
39  
40      public static class Builder {
41  
42          private final ConnObjectTOQuery instance = new ConnObjectTOQuery();
43  
44          public Builder size(final Integer size) {
45              instance.setSize(size);
46              return this;
47          }
48  
49          public Builder pagedResultsCookie(final String pagedResultsCookie) {
50              instance.setPagedResultsCookie(pagedResultsCookie);
51              return this;
52          }
53  
54          public Builder orderBy(final String orderBy) {
55              instance.setOrderBy(orderBy);
56              return this;
57          }
58  
59          public Builder fiql(final String fiql) {
60              instance.setFiql(fiql);
61              return this;
62          }
63  
64          public Builder moreAttrsToGet(final String... moreAttrsToGet) {
65              if (moreAttrsToGet != null) {
66                  Set<String> matg = Optional.ofNullable(instance.getMoreAttrsToGet()).orElseGet(HashSet::new);
67                  matg.addAll(Stream.of(moreAttrsToGet).collect(Collectors.toSet()));
68                  instance.setMoreAttrsToGet(matg);
69              }
70              return this;
71          }
72  
73          public Builder moreAttrsToGet(final Collection<String> moreAttrsToGet) {
74              if (moreAttrsToGet != null) {
75                  Set<String> matg = Optional.ofNullable(instance.getMoreAttrsToGet()).orElseGet(HashSet::new);
76                  matg.addAll(moreAttrsToGet);
77                  instance.setMoreAttrsToGet(matg);
78              }
79              return this;
80          }
81  
82          public ConnObjectTOQuery build() {
83              return instance;
84          }
85      }
86  
87      private Integer size;
88  
89      private String pagedResultsCookie;
90  
91      private String orderBy;
92  
93      private String fiql;
94  
95      private Set<String> moreAttrsToGet;
96  
97      public Integer getSize() {
98          return size == null
99                  ? 25
100                 : size > MAX_SIZE
101                         ? MAX_SIZE
102                         : size;
103     }
104 
105     @Min(1)
106     @Max(MAX_SIZE)
107     @QueryParam(JAXRSService.PARAM_SIZE)
108     @DefaultValue("25")
109     public void setSize(final Integer size) {
110         this.size = size;
111     }
112 
113     public String getPagedResultsCookie() {
114         return pagedResultsCookie;
115     }
116 
117     @QueryParam(JAXRSService.PARAM_CONNID_PAGED_RESULTS_COOKIE)
118     public void setPagedResultsCookie(final String pagedResultsCookie) {
119         this.pagedResultsCookie = pagedResultsCookie;
120     }
121 
122     @QueryParam(JAXRSService.PARAM_ORDERBY)
123     public String getOrderBy() {
124         return orderBy;
125     }
126 
127     public void setOrderBy(final String orderBy) {
128         this.orderBy = orderBy;
129     }
130 
131     public String getFiql() {
132         return fiql;
133     }
134 
135     @QueryParam(JAXRSService.PARAM_FIQL)
136     public void setFiql(final String fiql) {
137         this.fiql = fiql;
138     }
139 
140     public Set<String> getMoreAttrsToGet() {
141         return moreAttrsToGet;
142     }
143 
144     @QueryParam("moreAttrsToGet")
145     public void setMoreAttrsToGet(final Set<String> moreAttrsToGet) {
146         this.moreAttrsToGet = moreAttrsToGet;
147     }
148 }