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.dataformat.xml.annotation.JacksonXmlElementWrapper;
22  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
23  import java.net.URI;
24  import java.util.ArrayList;
25  import java.util.List;
26  import org.apache.commons.lang3.builder.EqualsBuilder;
27  import org.apache.commons.lang3.builder.HashCodeBuilder;
28  import org.apache.syncope.common.lib.BaseBean;
29  
30  public class PagedConnObjectResult implements BaseBean {
31  
32      private static final long serialVersionUID = -2832908019064402976L;
33  
34      private URI next;
35  
36      private final List<ConnObject> result = new ArrayList<>();
37  
38      private String pagedResultsCookie;
39  
40      private int remainingPagedResults = -1;
41  
42      private boolean allResultsReturned = true;
43  
44      public URI getNext() {
45          return next;
46      }
47  
48      public void setNext(final URI next) {
49          this.next = next;
50      }
51  
52      /**
53       * Returns the opaque cookie which should be used with the next paged results search request.
54       *
55       * @return The opaque cookie which should be used with the next paged results search request, or {@code null} if
56       * paged results were not requested, or if there are not more pages to be returned.
57       */
58      public String getPagedResultsCookie() {
59          return pagedResultsCookie;
60      }
61  
62      /**
63       * @param pagedResultsCookie The opaque cookie which should be used with the next paged results search request, or
64       * {@code null} if paged results were not requested, or if there are not more pages to be returned.
65       */
66      public void setPagedResultsCookie(final String pagedResultsCookie) {
67          this.pagedResultsCookie = pagedResultsCookie;
68      }
69  
70      /**
71       * Returns an estimate of the total number of remaining results to be returned in subsequent paged results search
72       * requests.
73       *
74       * @return An estimate of the total number of remaining results to be returned in subsequent paged results search
75       * requests, or {@code -1} if paged results were not requested, or if the total number of remaining results is
76       * unknown.
77       */
78      public int getRemainingPagedResults() {
79          return remainingPagedResults;
80      }
81  
82      /**
83       * @param remainingPagedResults An estimate of the total number of remaining results to be returned in subsequent
84       * paged results search requests, or {@code -1} if paged results were not requested, or if the total number of
85       * remaining results is unknown.
86       */
87      public void setRemainingPagedResults(final int remainingPagedResults) {
88          this.remainingPagedResults = remainingPagedResults;
89      }
90  
91      /**
92       * Returns a flag indicating whether all the results other match a search query were returned.
93       *
94       * @return true if the search returned all the results other match the query, false if the returned
95       * result is not complete, e.g. if the server returned only part of the results due to server limits, errors, etc.
96       */
97      public boolean isAllResultsReturned() {
98          return allResultsReturned;
99      }
100 
101     /**
102      * @param allResultsReturned Set to true if the search returned all the results other match the query. Set to false
103      * if the returned result is not complete, e.g. if the server returned only part of the results due to server
104      * limits, errors, etc.
105      */
106     public void setAllResultsReturned(final boolean allResultsReturned) {
107         this.allResultsReturned = allResultsReturned;
108     }
109 
110     @JacksonXmlElementWrapper(localName = "result")
111     @JacksonXmlProperty(localName = "item")
112     public List<ConnObject> getResult() {
113         return result;
114     }
115 
116     @Override
117     public int hashCode() {
118         return new HashCodeBuilder().
119                 append(next).
120                 append(result).
121                 append(pagedResultsCookie).
122                 append(remainingPagedResults).
123                 append(allResultsReturned).
124                 build();
125     }
126 
127     @Override
128     public boolean equals(final Object obj) {
129         if (this == obj) {
130             return true;
131         }
132         if (obj == null) {
133             return false;
134         }
135         if (getClass() != obj.getClass()) {
136             return false;
137         }
138         final PagedConnObjectResult other = (PagedConnObjectResult) obj;
139         return new EqualsBuilder().
140                 append(next, other.next).
141                 append(result, other.result).
142                 append(pagedResultsCookie, other.pagedResultsCookie).
143                 append(remainingPagedResults, other.remainingPagedResults).
144                 append(allResultsReturned, other.allResultsReturned).
145                 build();
146     }
147 }