1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.wizards.any;
20
21 import java.io.Serializable;
22 import java.util.List;
23 import java.util.Optional;
24 import org.apache.syncope.client.console.layout.AnyObjectForm;
25 import org.apache.syncope.client.console.layout.AnyObjectFormLayoutInfo;
26 import org.apache.syncope.client.console.rest.AnyObjectRestClient;
27 import org.apache.syncope.client.ui.commons.wizards.AjaxWizard;
28 import org.apache.syncope.client.ui.commons.wizards.any.AnyWrapper;
29 import org.apache.syncope.common.lib.AnyOperations;
30 import org.apache.syncope.common.lib.EntityTOUtils;
31 import org.apache.syncope.common.lib.request.AnyObjectCR;
32 import org.apache.syncope.common.lib.request.AnyObjectUR;
33 import org.apache.syncope.common.lib.to.AnyObjectTO;
34 import org.apache.syncope.common.lib.to.ProvisioningResult;
35 import org.apache.wicket.PageReference;
36
37 public class AnyObjectWizardBuilder extends AnyWizardBuilder<AnyObjectTO> implements AnyObjectForm {
38
39 private static final long serialVersionUID = -2480279868319546243L;
40
41 protected AnyObjectRestClient anyObjectRestClient;
42
43 public AnyObjectWizardBuilder(
44 final AnyObjectTO anyObjectTO,
45 final List<String> anyTypeClasses,
46 final AnyObjectFormLayoutInfo formLayoutInfo,
47 final AnyObjectRestClient anyObjectRestClient,
48 final PageReference pageRef) {
49
50 super(Optional.ofNullable(anyObjectTO).map(AnyObjectWrapper::new).
51 orElse(null), anyTypeClasses, formLayoutInfo, pageRef);
52 this.anyObjectRestClient = anyObjectRestClient;
53 }
54
55
56
57
58
59
60
61
62
63
64 public AnyObjectWizardBuilder(
65 final AnyObjectTO previousAnyObjectTO,
66 final AnyObjectTO anyObjectTO,
67 final List<String> anyTypeClasses,
68 final AnyObjectFormLayoutInfo formLayoutInfo,
69 final PageReference pageRef) {
70
71 super(new AnyObjectWrapper(previousAnyObjectTO, anyObjectTO), anyTypeClasses, formLayoutInfo, pageRef);
72 }
73
74 @Override
75 protected Serializable onApplyInternal(final AnyWrapper<AnyObjectTO> modelObject) {
76 final AnyObjectTO inner = modelObject.getInnerObject();
77
78 ProvisioningResult<AnyObjectTO> result;
79 if (inner.getKey() == null) {
80 AnyObjectCR req = new AnyObjectCR();
81 EntityTOUtils.toAnyCR(inner, req);
82
83 result = anyObjectRestClient.create(req);
84 } else {
85 fixPlainAndVirAttrs(inner, getOriginalItem().getInnerObject());
86 AnyObjectUR req = AnyOperations.diff(inner, getOriginalItem().getInnerObject(), false);
87
88
89 if (req.isEmpty()) {
90 result = new ProvisioningResult<>();
91 result.setEntity(inner);
92 } else {
93 result = anyObjectRestClient.update(getOriginalItem().getInnerObject().getETagValue(), req);
94 }
95 }
96
97 return result;
98 }
99
100 @Override
101 protected Optional<Details<AnyObjectTO>> addOptionalDetailsPanel(final AnyWrapper<AnyObjectTO> modelObject) {
102 return Optional.of(new AnyObjectDetails(
103 modelObject,
104 mode == AjaxWizard.Mode.TEMPLATE,
105 modelObject.getInnerObject().getKey() != null,
106 pageRef));
107 }
108 }