1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.common.rest.api.beans;
20
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25 import javax.validation.constraints.NotNull;
26 import javax.ws.rs.PathParam;
27 import javax.ws.rs.QueryParam;
28 import org.apache.commons.lang3.builder.EqualsBuilder;
29 import org.apache.commons.lang3.builder.HashCodeBuilder;
30 import org.apache.syncope.common.lib.types.SchemaType;
31
32 public class SchemaQuery implements Serializable {
33
34 private static final long serialVersionUID = -1863334226169614417L;
35
36 public static class Builder {
37
38 private final SchemaQuery instance = new SchemaQuery();
39
40 public Builder type(final SchemaType type) {
41 instance.setType(type);
42 return this;
43 }
44
45 public Builder anyTypeClass(final String anyTypeClass) {
46 if (instance.getAnyTypeClasses() == null) {
47 instance.setAnyTypeClasses(new ArrayList<>());
48 }
49 instance.getAnyTypeClasses().add(anyTypeClass);
50
51 return this;
52 }
53
54 public Builder anyTypeClasses(final Collection<String> anyTypeClasses) {
55 anyTypeClasses.forEach(this::anyTypeClass);
56 return this;
57 }
58
59 public Builder anyTypeClasses(final String... anyTypeClasses) {
60 return anyTypeClasses(List.of(anyTypeClasses));
61 }
62
63 public Builder keyword(final String keyword) {
64 instance.setKeyword(keyword);
65 return this;
66 }
67
68 public SchemaQuery build() {
69 if (instance.type == null) {
70 throw new IllegalArgumentException("type is required");
71 }
72 return instance;
73 }
74 }
75
76 private SchemaType type;
77
78 private List<String> anyTypeClasses;
79
80 private String keyword;
81
82 public SchemaType getType() {
83 return type;
84 }
85
86 @NotNull
87 @PathParam("type")
88 public void setType(final SchemaType type) {
89 this.type = type;
90 }
91
92 public List<String> getAnyTypeClasses() {
93 return anyTypeClasses;
94 }
95
96 @QueryParam("anyTypeClass")
97 public void setAnyTypeClasses(final List<String> anyTypeClasses) {
98 this.anyTypeClasses = anyTypeClasses;
99 }
100
101 public String getKeyword() {
102 return keyword;
103 }
104
105 @QueryParam("keyword")
106 public void setKeyword(final String keyword) {
107 this.keyword = keyword;
108 }
109
110 @Override
111 public boolean equals(final Object obj) {
112 if (this == obj) {
113 return true;
114 }
115 if (obj == null) {
116 return false;
117 }
118 if (getClass() != obj.getClass()) {
119 return false;
120 }
121 SchemaQuery other = (SchemaQuery) obj;
122 return new EqualsBuilder().
123 append(type, other.type).
124 append(anyTypeClasses, other.anyTypeClasses).
125 append(keyword, other.keyword).
126 build();
127 }
128
129 @Override
130 public int hashCode() {
131 return new HashCodeBuilder().
132 append(type).
133 append(anyTypeClasses).
134 append(keyword).
135 build();
136 }
137 }