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.AnyObjectFormLayoutInfo;
25 import org.apache.syncope.client.console.rest.AnyObjectRestClient;
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.common.lib.to.AnyObjectTO;
29 import org.apache.syncope.common.lib.to.RealmTO;
30 import org.apache.syncope.common.lib.to.TemplatableTO;
31 import org.apache.wicket.PageReference;
32
33 public class AnyObjectTemplateWizardBuilder extends AnyObjectWizardBuilder
34 implements TemplateWizardBuilder<AnyObjectTO> {
35
36 private static final long serialVersionUID = 6716803168859873877L;
37
38 protected final TemplatableTO templatable;
39
40 public AnyObjectTemplateWizardBuilder(
41 final TemplatableTO templatable,
42 final String anyType,
43 final List<String> anyTypeClasses,
44 final AnyObjectFormLayoutInfo formLayoutInfo,
45 final AnyObjectRestClient anyObjectRestClient,
46 final PageReference pageRef) {
47
48 super(null, anyTypeClasses, formLayoutInfo, anyObjectRestClient, pageRef);
49
50 this.templatable = templatable;
51
52 if (templatable.getTemplates().containsKey(anyType)) {
53 setItem(new AnyObjectWrapper(AnyObjectTO.class.cast(templatable.getTemplates().get(anyType))));
54 } else {
55 AnyObjectTO anyObjectTO = new AnyObjectTO();
56 anyObjectTO.setType(anyType);
57 if (templatable instanceof RealmTO) {
58 anyObjectTO.setRealm(
59 String.format("'%s'", RealmsUtils.getFullPath(RealmTO.class.cast(templatable).getFullPath())));
60 }
61 setItem(new AnyObjectWrapper(anyObjectTO));
62 }
63 }
64
65 @Override
66 protected Optional<Details<AnyObjectTO>> addOptionalDetailsPanel(final AnyWrapper<AnyObjectTO> modelObject) {
67 Optional<Details<AnyObjectTO>> details = super.addOptionalDetailsPanel(modelObject);
68 if (templatable instanceof RealmTO) {
69 details.ifPresent(Details::disableRealmSpecification);
70 }
71 return details;
72 }
73
74 @Override
75 public AjaxWizard<AnyWrapper<AnyObjectTO>> build(final String id) {
76 return super.build(id, AjaxWizard.Mode.TEMPLATE);
77 }
78 }