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;
20
21 import java.io.Serializable;
22 import java.util.List;
23 import java.util.stream.Collectors;
24 import org.apache.syncope.client.console.panels.CSVConfPanel;
25 import org.apache.syncope.client.console.rest.ImplementationRestClient;
26 import org.apache.syncope.client.console.rest.ReconciliationRestClient;
27 import org.apache.syncope.client.console.wicket.ajax.form.AjaxDownloadBehavior;
28 import org.apache.syncope.client.ui.commons.Constants;
29 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxCheckBoxPanel;
30 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDropDownChoicePanel;
31 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPalettePanel;
32 import org.apache.syncope.client.ui.commons.rest.ResponseHolder;
33 import org.apache.syncope.common.lib.to.ImplementationTO;
34 import org.apache.syncope.common.lib.types.IdMImplementationType;
35 import org.apache.syncope.common.lib.types.MatchingRule;
36 import org.apache.syncope.common.lib.types.UnmatchingRule;
37 import org.apache.syncope.common.rest.api.beans.AnyQuery;
38 import org.apache.syncope.common.rest.api.beans.CSVPushSpec;
39 import org.apache.wicket.PageReference;
40 import org.apache.wicket.ajax.AjaxRequestTarget;
41 import org.apache.wicket.event.IEventSink;
42 import org.apache.wicket.extensions.wizard.WizardModel;
43 import org.apache.wicket.extensions.wizard.WizardStep;
44 import org.apache.wicket.model.IModel;
45 import org.apache.wicket.model.LoadableDetachableModel;
46 import org.apache.wicket.model.PropertyModel;
47 import org.apache.wicket.model.util.ListModel;
48 import org.apache.wicket.request.cycle.RequestCycle;
49
50 public class CSVPushWizardBuilder extends BaseAjaxWizardBuilder<CSVPushSpec> {
51
52 private static final long serialVersionUID = -8890710681835661962L;
53
54 protected final AnyQuery query;
55
56 protected final AjaxDownloadBehavior downloadBehavior;
57
58 protected final ReconciliationRestClient reconciliationRestClient;
59
60 protected final ImplementationRestClient implementationRestClient;
61
62 public CSVPushWizardBuilder(
63 final CSVPushSpec defaultItem,
64 final AnyQuery query,
65 final AjaxDownloadBehavior downloadBehavior,
66 final ReconciliationRestClient reconciliationRestClient,
67 final ImplementationRestClient implementationRestClient,
68 final PageReference pageRef) {
69
70 super(defaultItem, pageRef);
71
72 this.query = query;
73 this.downloadBehavior = downloadBehavior;
74 this.reconciliationRestClient = reconciliationRestClient;
75 this.implementationRestClient = implementationRestClient;
76 }
77
78 @Override
79 public CSVPushWizardBuilder setEventSink(final IEventSink eventSink) {
80 super.setEventSink(eventSink);
81 return this;
82 }
83
84 @Override
85 protected Serializable onApplyInternal(final CSVPushSpec modelObject) {
86 return RequestCycle.get().find(AjaxRequestTarget.class).map(target -> {
87 try {
88 downloadBehavior.setResponse(new ResponseHolder(reconciliationRestClient.push(query, modelObject)));
89 downloadBehavior.initiate(target);
90
91 return Constants.OPERATION_SUCCEEDED;
92 } catch (Exception e) {
93 LOG.error("While dowloading CSV export", e);
94 return e;
95 }
96 }).orElse(Constants.ERROR);
97 }
98
99 @Override
100 protected WizardModel buildModelSteps(final CSVPushSpec modelObject, final WizardModel wizardModel) {
101 wizardModel.add(new Details(modelObject));
102 wizardModel.add(new PushTask(modelObject));
103 return wizardModel;
104 }
105
106 public class Details extends WizardStep {
107
108 private static final long serialVersionUID = -2368995286051427297L;
109
110 public Details(final CSVPushSpec spec) {
111 add(new CSVConfPanel("csvconf", spec));
112 }
113 }
114
115 public class PushTask extends WizardStep {
116
117 private static final long serialVersionUID = -2747583614435078452L;
118
119 private final IModel<List<String>> propActions = new LoadableDetachableModel<>() {
120
121 private static final long serialVersionUID = 4659376149825914247L;
122
123 @Override
124 protected List<String> load() {
125 return implementationRestClient.list(IdMImplementationType.PROPAGATION_ACTIONS).stream().
126 map(ImplementationTO::getKey).sorted().collect(Collectors.toList());
127 }
128 };
129
130 private final IModel<List<String>> pushActions = new LoadableDetachableModel<>() {
131
132 private static final long serialVersionUID = 4659376149825914247L;
133
134 @Override
135 protected List<String> load() {
136 return implementationRestClient.list(IdMImplementationType.PUSH_ACTIONS).stream().
137 map(ImplementationTO::getKey).sorted().collect(Collectors.toList());
138 }
139 };
140
141 public PushTask(final CSVPushSpec spec) {
142 AjaxCheckBoxPanel ignorePaging = new AjaxCheckBoxPanel(
143 "ignorePaging", "ignorePaging", new PropertyModel<>(spec, "ignorePaging"), true);
144 add(ignorePaging);
145
146 AjaxPalettePanel<String> propagationActions =
147 new AjaxPalettePanel.Builder<String>().build("propagationActions",
148 new PropertyModel<>(spec, "propagationActions"), new ListModel<>(propActions.getObject()));
149 add(propagationActions);
150
151 AjaxDropDownChoicePanel<MatchingRule> matchingRule = new AjaxDropDownChoicePanel<>(
152 "matchingRule", "matchingRule", new PropertyModel<>(spec, "matchingRule"), false);
153 matchingRule.setChoices(List.of(MatchingRule.values()));
154 add(matchingRule);
155
156 AjaxDropDownChoicePanel<UnmatchingRule> unmatchingRule = new AjaxDropDownChoicePanel<>(
157 "unmatchingRule", "unmatchingRule", new PropertyModel<>(spec, "unmatchingRule"),
158 false);
159 unmatchingRule.setChoices(List.of(UnmatchingRule.values()));
160 add(unmatchingRule);
161
162 AjaxPalettePanel<String> provisioningActions =
163 new AjaxPalettePanel.Builder<String>().build("provisioningActions",
164 new PropertyModel<>(spec, "provisioningActions"), new ListModel<>(pushActions.getObject()));
165 add(provisioningActions);
166 }
167 }
168 }