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.util.List;
22 import java.util.Optional;
23 import org.apache.syncope.client.console.commons.RealmsUtils;
24 import org.apache.syncope.client.console.layout.UserFormLayoutInfo;
25 import org.apache.syncope.client.console.rest.UserRestClient;
26 import org.apache.syncope.client.ui.commons.wizards.AjaxWizard;
27 import org.apache.syncope.client.ui.commons.wizards.any.AnyWrapper;
28 import org.apache.syncope.client.ui.commons.wizards.any.UserWrapper;
29 import org.apache.syncope.common.lib.to.RealmTO;
30 import org.apache.syncope.common.lib.to.TemplatableTO;
31 import org.apache.syncope.common.lib.to.UserTO;
32 import org.apache.syncope.common.lib.types.AnyTypeKind;
33 import org.apache.wicket.PageReference;
34
35 public class UserTemplateWizardBuilder extends UserWizardBuilder implements TemplateWizardBuilder<UserTO> {
36
37 private static final long serialVersionUID = 6716803168859873877L;
38
39 protected final TemplatableTO templatable;
40
41 public UserTemplateWizardBuilder(
42 final UserTO template,
43 final List<String> anyTypeClasses,
44 final UserFormLayoutInfo formLayoutInfo,
45 final UserRestClient userRestClient,
46 final PageReference pageRef) {
47
48 super(anyTypeClasses, formLayoutInfo, userRestClient, pageRef);
49 templatable = null;
50
51 if (template == null) {
52 setItem(new UserWrapper(new UserTO()));
53 } else {
54 setItem(new UserWrapper(template));
55 }
56 }
57
58 public UserTemplateWizardBuilder(
59 final TemplatableTO templatable,
60 final List<String> anyTypeClasses,
61 final UserFormLayoutInfo formLayoutInfo,
62 final UserRestClient userRestClient,
63 final PageReference pageRef) {
64
65 super(anyTypeClasses, formLayoutInfo, userRestClient, pageRef);
66 this.templatable = templatable;
67
68 if (templatable.getTemplates().containsKey(AnyTypeKind.USER.name())) {
69 setItem(new UserWrapper(UserTO.class.cast(templatable.getTemplates().get(AnyTypeKind.USER.name()))));
70 } else {
71 UserTO userTO = new UserTO();
72 if (templatable instanceof RealmTO) {
73 userTO.setRealm(
74 String.format("'%s'", RealmsUtils.getFullPath(RealmTO.class.cast(templatable).getFullPath())));
75 }
76 setItem(new UserWrapper(userTO));
77 }
78 }
79
80 @Override
81 protected Optional<Details<UserTO>> addOptionalDetailsPanel(final AnyWrapper<UserTO> modelObject) {
82 Optional<Details<UserTO>> details = super.addOptionalDetailsPanel(modelObject);
83 if (templatable instanceof RealmTO) {
84 details.ifPresent(Details::disableRealmSpecification);
85 }
86 return details;
87 }
88
89 @Override
90 public AjaxWizard<AnyWrapper<UserTO>> build(final String id) {
91 return super.build(id, AjaxWizard.Mode.TEMPLATE);
92 }
93 }