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.Parameter;
22  import io.swagger.v3.oas.annotations.enums.ParameterIn;
23  import io.swagger.v3.oas.annotations.media.Schema;
24  import java.time.OffsetDateTime;
25  import javax.ws.rs.QueryParam;
26  import org.apache.commons.lang3.builder.EqualsBuilder;
27  import org.apache.commons.lang3.builder.HashCodeBuilder;
28  
29  public abstract class AbstractTimeframeQuery extends AbstractQuery {
30  
31      private static final long serialVersionUID = -6858655425207486223L;
32  
33      protected abstract static class Builder<Q extends AbstractTimeframeQuery, B extends Builder<Q, B>>
34              extends AbstractQuery.Builder<Q, B> {
35  
36          @Override
37          protected Q getInstance() {
38              return super.getInstance();
39          }
40  
41          @SuppressWarnings("unchecked")
42          public B before(final OffsetDateTime before) {
43              getInstance().setBefore(before);
44              return (B) this;
45          }
46  
47          @SuppressWarnings("unchecked")
48          public B after(final OffsetDateTime after) {
49              getInstance().setAfter(after);
50              return (B) this;
51          }
52      }
53  
54      private OffsetDateTime before;
55  
56      private OffsetDateTime after;
57  
58      @Parameter(name = "before", in = ParameterIn.QUERY, schema =
59              @Schema(implementation = OffsetDateTime.class))
60      public OffsetDateTime getBefore() {
61          return before;
62      }
63  
64      @QueryParam("before")
65      public void setBefore(final OffsetDateTime before) {
66          this.before = before;
67      }
68  
69      @Parameter(name = "after", in = ParameterIn.QUERY, schema =
70              @Schema(implementation = OffsetDateTime.class))
71      public OffsetDateTime getAfter() {
72          return after;
73      }
74  
75      @QueryParam("after")
76      public void setAfter(final OffsetDateTime after) {
77          this.after = after;
78      }
79  
80      @Override
81      public boolean equals(final Object obj) {
82          if (this == obj) {
83              return true;
84          }
85          if (obj == null) {
86              return false;
87          }
88          if (getClass() != obj.getClass()) {
89              return false;
90          }
91          AbstractTimeframeQuery other = (AbstractTimeframeQuery) obj;
92          return new EqualsBuilder().
93                  appendSuper(super.equals(obj)).
94                  append(before, other.before).
95                  append(after, other.after).
96                  build();
97      }
98  
99      @Override
100     public int hashCode() {
101         return new HashCodeBuilder().
102                 appendSuper(super.hashCode()).
103                 append(before).
104                 append(after).
105                 build();
106     }
107 }