1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.ui.commons.wizards.any;
20
21 import org.apache.syncope.client.ui.commons.wizards.AjaxWizardBuilder;
22 import org.apache.syncope.common.lib.to.AnyTO;
23 import org.apache.syncope.common.lib.to.GroupableRelatableTO;
24 import org.apache.wicket.PageReference;
25
26 public abstract class AbstractAnyWizardBuilder<A extends AnyTO> extends AjaxWizardBuilder<AnyWrapper<A>> {
27
28 private static final long serialVersionUID = -2480279868319546243L;
29
30 public AbstractAnyWizardBuilder(final AnyWrapper<A> defaultItem, final PageReference pageRef) {
31 super(defaultItem, pageRef);
32 }
33
34 protected void fixPlainAndVirAttrs(final AnyTO updated, final AnyTO original) {
35
36
37 original.getPlainAttrs().stream().
38 filter(attr -> updated.getPlainAttr(attr.getSchema()).isPresent()).
39 forEach(attr -> updated.getPlainAttrs().add(attr));
40 original.getVirAttrs().stream().
41 filter(attr -> updated.getVirAttr(attr.getSchema()).isPresent()).
42 forEach(attr -> updated.getVirAttrs().add(attr));
43 if (updated instanceof GroupableRelatableTO && original instanceof GroupableRelatableTO) {
44 GroupableRelatableTO.class.cast(original).getMemberships()
45 .forEach(oMemb -> GroupableRelatableTO.class.cast(updated).getMembership(oMemb.getGroupKey())
46 .ifPresent(uMemb -> {
47 oMemb.getPlainAttrs().stream().
48 filter(attr -> uMemb.getPlainAttr(attr.getSchema()).isPresent()).
49 forEach(attr -> uMemb.getPlainAttrs().add(attr));
50 oMemb.getVirAttrs().stream().
51 filter(attr -> uMemb.getVirAttr(attr.getSchema()).isPresent()).
52 forEach(attr -> uMemb.getVirAttrs().add(attr));
53 }));
54 }
55
56
57
58 updated.getPlainAttrs().removeIf(attr -> attr.getValues().isEmpty());
59 updated.getVirAttrs().removeIf(attr -> attr.getValues().isEmpty());
60 if (updated instanceof GroupableRelatableTO) {
61 GroupableRelatableTO.class.cast(updated).getMemberships().forEach(memb -> {
62 memb.getPlainAttrs().removeIf(attr -> attr.getValues().isEmpty());
63 memb.getVirAttrs().removeIf(attr -> attr.getValues().isEmpty());
64 });
65 }
66 }
67 }