1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.fit.core.reference;
20
21 import org.apache.syncope.common.lib.Attr;
22 import org.apache.syncope.common.lib.request.AnyCR;
23 import org.apache.syncope.common.lib.request.AnyUR;
24 import org.apache.syncope.common.lib.request.AttrPatch;
25 import org.apache.syncope.common.lib.request.UserCR;
26 import org.apache.syncope.common.lib.to.EntityTO;
27 import org.apache.syncope.common.lib.types.PatchOperation;
28 import org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException;
29 import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile;
30 import org.apache.syncope.core.provisioning.api.pushpull.PullActions;
31 import org.identityconnectors.framework.common.objects.SyncDelta;
32 import org.quartz.JobExecutionException;
33
34
35
36
37 public class TestPullActions implements PullActions {
38
39 private int counter;
40
41 @Override
42 public void beforeProvision(
43 final ProvisioningProfile<?, ?> profile, final SyncDelta delta, final AnyCR anyCR)
44 throws JobExecutionException {
45
46 Attr attrTO = anyCR.getPlainAttrs().stream().
47 filter(attr -> "fullname".equals(attr.getSchema())).findFirst().
48 orElseGet(() -> {
49 Attr a = new Attr();
50 a.setSchema("fullname");
51 return a;
52 });
53 attrTO.getValues().clear();
54 attrTO.getValues().add(String.valueOf(counter++));
55 }
56
57 @Override
58 public void beforeAssign(
59 final ProvisioningProfile<?, ?> profile, final SyncDelta delta, final AnyCR anyCR)
60 throws JobExecutionException {
61
62 if (anyCR instanceof UserCR && "test2".equals(UserCR.class.cast(anyCR).getUsername())) {
63 throw new IgnoreProvisionException();
64 }
65 }
66
67 @Override
68 public void beforeUpdate(
69 final ProvisioningProfile<?, ?> profile,
70 final SyncDelta delta,
71 final EntityTO entityTO,
72 final AnyUR anyUR) throws JobExecutionException {
73
74 AttrPatch fullnamePatch = null;
75 for (AttrPatch attrPatch : anyUR.getPlainAttrs()) {
76 if ("fullname".equals(attrPatch.getAttr().getSchema())) {
77 fullnamePatch = attrPatch;
78 }
79 }
80 if (fullnamePatch == null) {
81 fullnamePatch = new AttrPatch.Builder(new Attr.Builder("fullname").build()).
82 operation(PatchOperation.ADD_REPLACE).
83 build();
84 }
85
86 fullnamePatch.getAttr().getValues().clear();
87 fullnamePatch.getAttr().getValues().add(String.valueOf(counter++));
88 }
89 }