1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.persistence.jpa.entity.user;
20
21 import com.fasterxml.jackson.annotation.JsonIgnore;
22 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
23 import com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import com.fasterxml.jackson.annotation.JsonSetter;
26 import java.util.ArrayList;
27 import java.util.List;
28 import org.apache.commons.lang3.builder.EqualsBuilder;
29 import org.apache.commons.lang3.builder.HashCodeBuilder;
30 import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
31 import org.apache.syncope.core.persistence.api.dao.UserDAO;
32 import org.apache.syncope.core.persistence.api.entity.JSONPlainAttr;
33 import org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue;
34 import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
35 import org.apache.syncope.core.persistence.api.entity.PlainSchema;
36 import org.apache.syncope.core.persistence.api.entity.user.UMembership;
37 import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr;
38 import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue;
39 import org.apache.syncope.core.persistence.api.entity.user.User;
40 import org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttr;
41 import org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema;
42 import org.apache.syncope.core.spring.ApplicationContextProvider;
43
44 @JsonIgnoreProperties("valuesAsStrings")
45 @JsonInclude(JsonInclude.Include.NON_EMPTY)
46 public class JPAJSONUPlainAttr extends AbstractPlainAttr<User> implements UPlainAttr, JSONPlainAttr<User> {
47
48 private static final long serialVersionUID = 806271775349587902L;
49
50
51
52
53 @JsonIgnore
54 private JPAJSONUser owner;
55
56 @JsonProperty
57 private String schema;
58
59
60
61
62 @JsonProperty
63 private String membership;
64
65
66
67
68 private final List<JPAJSONUPlainAttrValue> values = new ArrayList<>();
69
70
71
72
73 @JsonProperty
74 private JPAJSONUPlainAttrUniqueValue uniqueValue;
75
76 @Override
77 public User getOwner() {
78 return owner;
79 }
80
81 @Override
82 public void setOwner(final User owner) {
83 checkType(owner, JPAJSONUser.class);
84 this.owner = (JPAJSONUser) owner;
85 }
86
87 @JsonIgnore
88 @Override
89 public String getSchemaKey() {
90 return schema;
91 }
92
93 @JsonIgnore
94 @Override
95 public JPAPlainSchema getSchema() {
96 return (JPAPlainSchema) ApplicationContextProvider.getBeanFactory().getBean(PlainSchemaDAO.class).find(schema);
97 }
98
99 @Override
100 public void setSchema(final PlainSchema schema) {
101 if (schema != null) {
102 this.schema = schema.getKey();
103 }
104 }
105
106 @JsonSetter("schema")
107 public void setSchema(final String schema) {
108 this.schema = schema;
109 }
110
111 @JsonIgnore
112 public String getMembershipKey() {
113 return membership;
114 }
115
116 @JsonIgnore
117 @Override
118 public UMembership getMembership() {
119 return ApplicationContextProvider.getBeanFactory().getBean(UserDAO.class).findMembership(membership);
120 }
121
122 @Override
123 public void setMembership(final UMembership membership) {
124 if (membership != null) {
125 this.membership = membership.getKey();
126 }
127 }
128
129 @JsonSetter("membership")
130 public void setMembership(final String membership) {
131 this.membership = membership;
132 }
133
134 @Override
135 protected boolean addForMultiValue(final PlainAttrValue attrValue) {
136 checkType(attrValue, JPAJSONUPlainAttrValue.class);
137 return values.add((JPAJSONUPlainAttrValue) attrValue);
138 }
139
140 @Override
141 public boolean add(final PlainAttrValue value) {
142 return addForMultiValue(value);
143 }
144
145 @Override
146 public List<? extends UPlainAttrValue> getValues() {
147 return values;
148 }
149
150 @JsonIgnore
151 public List<JPAJSONUPlainAttrValue> getPGValues() {
152 return values;
153 }
154
155 @Override
156 public JPAJSONUPlainAttrUniqueValue getUniqueValue() {
157 return uniqueValue;
158 }
159
160 @JsonIgnore
161 @Override
162 public void setUniqueValue(final PlainAttrUniqueValue uniqueValue) {
163 checkType(uniqueValue, JPAJSONUPlainAttrUniqueValue.class);
164 this.uniqueValue = (JPAJSONUPlainAttrUniqueValue) uniqueValue;
165 }
166
167 @Override
168 public int hashCode() {
169 return new HashCodeBuilder().
170 append(schema).
171 append(membership).
172 append(values).
173 append(uniqueValue).
174 build();
175 }
176
177 @Override
178 public boolean equals(final Object obj) {
179 if (this == obj) {
180 return true;
181 }
182 if (obj == null) {
183 return false;
184 }
185 if (getClass() != obj.getClass()) {
186 return false;
187 }
188 final JPAJSONUPlainAttr other = (JPAJSONUPlainAttr) obj;
189 return new EqualsBuilder().
190 append(schema, other.schema).
191 append(membership, other.membership).
192 append(values, other.values).
193 append(uniqueValue, other.uniqueValue).
194 build();
195 }
196 }