/
RAccessCertificationCase.java
390 lines (331 loc) · 14.5 KB
/
RAccessCertificationCase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/*
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.repo.sql.data.common.container;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.repo.sql.SqlRepositoryServiceImpl;
import com.evolveum.midpoint.repo.sql.data.RepositoryContext;
import com.evolveum.midpoint.repo.sql.data.common.RAccessCertificationCampaign;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RActivation;
import com.evolveum.midpoint.repo.sql.data.common.embedded.REmbeddedReference;
import com.evolveum.midpoint.repo.sql.data.common.id.RContainerId;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbName;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbType;
import com.evolveum.midpoint.repo.sql.query.definition.OwnerGetter;
import com.evolveum.midpoint.repo.sql.query.definition.OwnerIdGetter;
import com.evolveum.midpoint.repo.sql.query2.definition.IdQueryProperty;
import com.evolveum.midpoint.repo.sql.util.DtoTranslationException;
import com.evolveum.midpoint.repo.sql.util.MidPointSingleTablePersister;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Persister;
import org.jetbrains.annotations.NotNull;
import javax.persistence.*;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import static com.evolveum.midpoint.schema.util.CertCampaignTypeUtil.norm;
/**
* @author lazyman
* @author mederly
*/
@JaxbType(type = AccessCertificationCaseType.class)
@Entity
@IdClass(RContainerId.class)
@Table(name = "m_acc_cert_case", indexes = {
@Index(name = "iCaseObjectRefTargetOid", columnList = "objectRef_targetOid"),
@Index(name = "iCaseTargetRefTargetOid", columnList = "targetRef_targetOid"),
@Index(name = "iCaseTenantRefTargetOid", columnList = "tenantRef_targetOid"),
@Index(name = "iCaseOrgRefTargetOid", columnList = "orgRef_targetOid")
})
@Persister(impl = MidPointSingleTablePersister.class)
public class RAccessCertificationCase implements Container<RAccessCertificationCampaign> {
private static final Trace LOGGER = TraceManager.getTrace(RAccessCertificationCase.class);
public static final String F_OWNER = "owner";
private Boolean trans;
private byte[] fullObject;
private RAccessCertificationCampaign owner;
private String ownerOid;
private Integer id;
private Set<RAccessCertificationWorkItem> workItems = new HashSet<>();
private REmbeddedReference objectRef;
private REmbeddedReference targetRef;
private REmbeddedReference tenantRef;
private REmbeddedReference orgRef;
private RActivation activation; // we need mainly validFrom + validTo + maybe adminStatus; for simplicity we added whole ActivationType here
private XMLGregorianCalendar reviewRequestedTimestamp;
private XMLGregorianCalendar reviewDeadline;
private XMLGregorianCalendar remediedTimestamp;
private String currentStageOutcome;
private Integer iteration;
private Integer stageNumber;
private String outcome;
public RAccessCertificationCase() {
}
@Id
@JoinColumn(foreignKey = @ForeignKey(name = "fk_acc_cert_case_owner"))
@MapsId("owner")
@ManyToOne(fetch = FetchType.LAZY)
@OwnerGetter(ownerClass = RAccessCertificationCampaign.class)
public RAccessCertificationCampaign getOwner() {
return owner;
}
@Column(name = "owner_oid", length = RUtil.COLUMN_LENGTH_OID, nullable = false)
@OwnerIdGetter()
public String getOwnerOid() {
return ownerOid;
}
@Id
@GeneratedValue(generator = "ContainerIdGenerator")
@GenericGenerator(name = "ContainerIdGenerator", strategy = "com.evolveum.midpoint.repo.sql.util.ContainerIdGenerator")
@Column(name = "id")
@IdQueryProperty
public Integer getId() {
return id;
}
@JaxbName(localPart = "workItem")
@OneToMany(mappedBy = "owner", orphanRemoval = true)
@Cascade({org.hibernate.annotations.CascadeType.ALL})
public Set<RAccessCertificationWorkItem> getWorkItems() {
return workItems;
}
public void setWorkItems(Set<RAccessCertificationWorkItem> workItems) {
this.workItems = workItems != null ? workItems : new HashSet<>();
}
@Embedded
public REmbeddedReference getTargetRef() {
return targetRef;
}
@Embedded
public REmbeddedReference getObjectRef() {
return objectRef;
}
@Embedded
public REmbeddedReference getTenantRef() {
return tenantRef;
}
@Embedded
public REmbeddedReference getOrgRef() {
return orgRef;
}
@Embedded
public RActivation getActivation() {
return activation;
}
@JaxbName(localPart = "currentStageCreateTimestamp")
public XMLGregorianCalendar getReviewRequestedTimestamp() {
return reviewRequestedTimestamp;
}
@JaxbName(localPart = "currentStageDeadline")
public XMLGregorianCalendar getReviewDeadline() {
return reviewDeadline;
}
public XMLGregorianCalendar getRemediedTimestamp() {
return remediedTimestamp;
}
public String getCurrentStageOutcome() {
return currentStageOutcome;
}
@Column(nullable = false)
public Integer getIteration() {
return iteration;
}
public Integer getStageNumber() {
return stageNumber;
}
public String getOutcome() {
return outcome;
}
public void setOwner(RAccessCertificationCampaign owner) {
this.owner = owner;
if (owner != null) { // sometimes we are called with null owner but non-null ownerOid
this.ownerOid = owner.getOid();
}
}
public void setOwnerOid(String ownerOid) {
this.ownerOid = ownerOid;
}
public void setId(Integer id) {
this.id = id;
}
public void setTargetRef(REmbeddedReference targetRef) {
this.targetRef = targetRef;
}
public void setObjectRef(REmbeddedReference objectRef) {
this.objectRef = objectRef;
}
public void setTenantRef(REmbeddedReference tenantRef) {
this.tenantRef = tenantRef;
}
public void setOrgRef(REmbeddedReference orgRef) {
this.orgRef = orgRef;
}
public void setActivation(RActivation activation) {
this.activation = activation;
}
public void setReviewRequestedTimestamp(XMLGregorianCalendar reviewRequestedTimestamp) {
this.reviewRequestedTimestamp = reviewRequestedTimestamp;
}
public void setReviewDeadline(XMLGregorianCalendar reviewDeadline) {
this.reviewDeadline = reviewDeadline;
}
public void setRemediedTimestamp(XMLGregorianCalendar remediedTimestamp) {
this.remediedTimestamp = remediedTimestamp;
}
public void setCurrentStageOutcome(String currentStageOutcome) {
this.currentStageOutcome = currentStageOutcome;
}
public void setIteration(Integer iteration) {
this.iteration = iteration;
}
public void setStageNumber(Integer stageNumber) {
this.stageNumber = stageNumber;
}
public void setOutcome(String outcome) {
this.outcome = outcome;
}
@Lob
public byte[] getFullObject() {
return fullObject;
}
public void setFullObject(byte[] fullObject) {
this.fullObject = fullObject;
}
// Notes to equals/hashCode: don't include trans nor owner
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof RAccessCertificationCase))
return false;
RAccessCertificationCase that = (RAccessCertificationCase) o;
return Arrays.equals(fullObject, that.fullObject) &&
Objects.equals(ownerOid, that.ownerOid) &&
Objects.equals(id, that.id) &&
Objects.equals(workItems, that.workItems) &&
Objects.equals(objectRef, that.objectRef) &&
Objects.equals(targetRef, that.targetRef) &&
Objects.equals(tenantRef, that.tenantRef) &&
Objects.equals(orgRef, that.orgRef) &&
Objects.equals(activation, that.activation) &&
Objects.equals(reviewRequestedTimestamp, that.reviewRequestedTimestamp) &&
Objects.equals(reviewDeadline, that.reviewDeadline) &&
Objects.equals(remediedTimestamp, that.remediedTimestamp) &&
currentStageOutcome == that.currentStageOutcome &&
Objects.equals(iteration, that.iteration) &&
Objects.equals(stageNumber, that.stageNumber) &&
Objects.equals(outcome, that.outcome);
}
@Override
public int hashCode() {
return Objects.hash(fullObject, ownerOid, id, workItems, objectRef, targetRef, tenantRef, orgRef, activation,
reviewRequestedTimestamp, reviewDeadline, remediedTimestamp, currentStageOutcome, iteration, stageNumber,
outcome);
}
@Override
public String toString() {
return "RAccessCertificationCase{" +
"id=" + id +
", ownerOid='" + ownerOid + '\'' +
", targetRef=" + targetRef +
", targetRef=" + targetRef +
", objectRef=" + objectRef +
'}';
}
@Override
@Transient
public Boolean isTransient() {
return trans;
}
@Override
public void setTransient(Boolean trans) {
this.trans = trans;
}
public static RAccessCertificationCase toRepo(@NotNull RAccessCertificationCampaign owner, AccessCertificationCaseType case1, RepositoryContext context) throws DtoTranslationException {
RAccessCertificationCase rCase = new RAccessCertificationCase();
rCase.setOwner(owner);
toRepo(rCase, case1, context);
return rCase;
}
public static RAccessCertificationCase toRepo(String ownerOid, AccessCertificationCaseType case1, RepositoryContext context) throws DtoTranslationException {
RAccessCertificationCase rCase = new RAccessCertificationCase();
rCase.setOwnerOid(ownerOid);
toRepo(rCase, case1, context);
return rCase;
}
private static RAccessCertificationCase toRepo(RAccessCertificationCase rCase, AccessCertificationCaseType case1,
RepositoryContext context) throws DtoTranslationException {
rCase.setTransient(null); // we don't try to advise hibernate - let it do its work, even if it would cost some SELECTs
rCase.setId(RUtil.toInteger(case1.getId()));
rCase.setObjectRef(RUtil.jaxbRefToEmbeddedRepoRef(case1.getObjectRef(), context.relationRegistry));
rCase.setTargetRef(RUtil.jaxbRefToEmbeddedRepoRef(case1.getTargetRef(), context.relationRegistry));
rCase.setTenantRef(RUtil.jaxbRefToEmbeddedRepoRef(case1.getTenantRef(), context.relationRegistry));
rCase.setOrgRef(RUtil.jaxbRefToEmbeddedRepoRef(case1.getOrgRef(), context.relationRegistry));
if (case1.getActivation() != null) {
RActivation activation = new RActivation();
RActivation.fromJaxb(case1.getActivation(), activation, context);
rCase.setActivation(activation);
}
for (AccessCertificationWorkItemType workItem : case1.getWorkItem()) {
rCase.getWorkItems().add(RAccessCertificationWorkItem.toRepo(rCase, workItem, context));
}
rCase.setReviewRequestedTimestamp(case1.getCurrentStageCreateTimestamp());
rCase.setReviewDeadline(case1.getCurrentStageDeadline());
rCase.setRemediedTimestamp(case1.getRemediedTimestamp());
rCase.setCurrentStageOutcome(case1.getCurrentStageOutcome());
rCase.setIteration(norm(case1.getIteration()));
rCase.setStageNumber(case1.getStageNumber());
rCase.setOutcome(case1.getOutcome());
PrismContainerValue<AccessCertificationCaseType> cvalue = case1.asPrismContainerValue();
String xml;
try {
xml = context.prismContext.serializerFor(SqlRepositoryServiceImpl.DATA_LANGUAGE).serialize(cvalue, SchemaConstantsGenerated.C_VALUE);
} catch (SchemaException e) {
throw new IllegalStateException("Couldn't serialize certification case to string", e);
}
LOGGER.trace("RAccessCertificationCase full object\n{}", xml);
byte[] fullObject = RUtil.getByteArrayFromXml(xml, false);
rCase.setFullObject(fullObject);
return rCase;
}
public AccessCertificationCaseType toJAXB(PrismContext prismContext) throws SchemaException {
return createJaxb(fullObject, prismContext, true);
}
// TODO find appropriate name
public static AccessCertificationCaseType createJaxb(byte[] fullObject, PrismContext prismContext, boolean removeCampaignRef) throws SchemaException {
String xml = RUtil.getXmlFromByteArray(fullObject, false);
LOGGER.trace("RAccessCertificationCase full object to be parsed\n{}", xml);
try {
return prismContext.parserFor(xml).language(SqlRepositoryServiceImpl.DATA_LANGUAGE).compat().parseRealValue(AccessCertificationCaseType.class);
} catch (SchemaException e) {
LOGGER.debug("Couldn't parse certification case because of schema exception ({}):\nData: {}", e, xml);
throw e;
} catch (RuntimeException e) {
LOGGER.debug("Couldn't parse certification case because of unexpected exception ({}):\nData: {}", e, xml);
throw e;
}
//aCase.asPrismContainerValue().removeReference(AccessCertificationCaseType.F_CAMPAIGN_REF);
}
}