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.entity.JSONLAPlainAttr;
32 import org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue;
33 import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
34 import org.apache.syncope.core.persistence.api.entity.PlainSchema;
35 import org.apache.syncope.core.persistence.api.entity.user.LAPlainAttrValue;
36 import org.apache.syncope.core.persistence.api.entity.user.LinkedAccount;
37 import org.apache.syncope.core.persistence.api.entity.user.User;
38 import org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttr;
39 import org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema;
40 import org.apache.syncope.core.spring.ApplicationContextProvider;
41
42 @JsonIgnoreProperties("valuesAsStrings")
43 @JsonInclude(JsonInclude.Include.NON_EMPTY)
44 public class JPAJSONLAPlainAttr extends AbstractPlainAttr<User> implements JSONLAPlainAttr {
45
46 private static final long serialVersionUID = -7712812886044037467L;
47
48
49
50
51 @JsonIgnore
52 private JPAJSONUser owner;
53
54 @JsonIgnore
55 private JPAJSONLinkedAccount account;
56
57 @JsonProperty
58 private String schema;
59
60
61
62
63 private final List<JPAJSONLAPlainAttrValue> values = new ArrayList<>();
64
65
66
67
68 @JsonProperty
69 private JPAJSONLAPlainAttrUniqueValue uniqueValue;
70
71 @Override
72 public User getOwner() {
73 return owner;
74 }
75
76 @Override
77 public void setOwner(final User owner) {
78 checkType(owner, JPAJSONUser.class);
79 this.owner = (JPAJSONUser) owner;
80 }
81
82 @Override
83 public LinkedAccount getAccount() {
84 return account;
85 }
86
87 @Override
88 public void setAccount(final LinkedAccount account) {
89 checkType(account, JPAJSONLinkedAccount.class);
90 this.account = (JPAJSONLinkedAccount) account;
91 }
92
93 @JsonIgnore
94 @Override
95 public String getSchemaKey() {
96 return schema;
97 }
98
99 @JsonIgnore
100 @Override
101 public JPAPlainSchema getSchema() {
102 return (JPAPlainSchema) ApplicationContextProvider.getBeanFactory().getBean(PlainSchemaDAO.class).find(schema);
103 }
104
105 @Override
106 public void setSchema(final PlainSchema schema) {
107 if (schema != null) {
108 this.schema = schema.getKey();
109 }
110 }
111
112 @JsonSetter("schema")
113 public void setSchema(final String schema) {
114 this.schema = schema;
115 }
116
117 @Override
118 protected boolean addForMultiValue(final PlainAttrValue attrValue) {
119 checkType(attrValue, JPAJSONLAPlainAttrValue.class);
120 return values.add((JPAJSONLAPlainAttrValue) attrValue);
121 }
122
123 @Override
124 public boolean add(final PlainAttrValue value) {
125 return addForMultiValue(value);
126 }
127
128 @Override
129 public List<? extends LAPlainAttrValue> getValues() {
130 return values;
131 }
132
133 @JsonIgnore
134 public List<JPAJSONLAPlainAttrValue> getPGValues() {
135 return values;
136 }
137
138 @Override
139 public JPAJSONLAPlainAttrUniqueValue getUniqueValue() {
140 return uniqueValue;
141 }
142
143 @JsonIgnore
144 @Override
145 public void setUniqueValue(final PlainAttrUniqueValue uniqueValue) {
146 checkType(uniqueValue, JPAJSONLAPlainAttrUniqueValue.class);
147 this.uniqueValue = (JPAJSONLAPlainAttrUniqueValue) uniqueValue;
148 }
149
150 @Override
151 public int hashCode() {
152 return new HashCodeBuilder().
153 append(schema).
154 append(account).
155 append(values).
156 append(uniqueValue).
157 build();
158 }
159
160 @Override
161 public boolean equals(final Object obj) {
162 if (this == obj) {
163 return true;
164 }
165 if (obj == null) {
166 return false;
167 }
168 if (getClass() != obj.getClass()) {
169 return false;
170 }
171 final JPAJSONLAPlainAttr other = (JPAJSONLAPlainAttr) obj;
172 return new EqualsBuilder().
173 append(schema, other.schema).
174 append(account, other.account).
175 append(values, other.values).
176 append(uniqueValue, other.uniqueValue).
177 build();
178 }
179 }