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.ArrayList;
22 import org.apache.syncope.client.console.panels.search.AnySelectionDirectoryPanel;
23 import org.apache.syncope.client.console.panels.search.SearchClausePanel;
24 import org.apache.syncope.client.console.panels.search.SearchUtils;
25 import org.apache.syncope.client.console.panels.search.UserSearchPanel;
26 import org.apache.syncope.client.console.panels.search.UserSelectionDirectoryPanel;
27 import org.apache.syncope.client.console.rest.AnyTypeClassRestClient;
28 import org.apache.syncope.client.console.rest.AnyTypeRestClient;
29 import org.apache.syncope.client.console.rest.UserRestClient;
30 import org.apache.syncope.client.lib.SyncopeClient;
31 import org.apache.syncope.common.lib.to.AnyTO;
32 import org.apache.syncope.common.lib.to.AnyTypeTO;
33 import org.apache.syncope.common.lib.types.AnyTypeKind;
34 import org.apache.wicket.Component;
35 import org.apache.wicket.PageReference;
36 import org.apache.wicket.ajax.AjaxRequestTarget;
37 import org.apache.wicket.event.IEvent;
38 import org.apache.wicket.extensions.wizard.WizardStep;
39 import org.apache.wicket.markup.html.WebMarkupContainer;
40 import org.apache.wicket.markup.html.panel.Fragment;
41 import org.apache.wicket.model.Model;
42 import org.apache.wicket.model.StringResourceModel;
43 import org.apache.wicket.model.util.ListModel;
44 import org.apache.wicket.spring.injection.annot.SpringBean;
45
46 public class MergeLinkedAccountsSearchPanel extends WizardStep {
47
48 private static final long serialVersionUID = 1221037007528732347L;
49
50 @SpringBean
51 protected AnyTypeRestClient anyTypeRestClient;
52
53 @SpringBean
54 protected AnyTypeClassRestClient anyTypeClassRestClient;
55
56 @SpringBean
57 protected UserRestClient userRestClient;
58
59 protected final WebMarkupContainer ownerContainer;
60
61 protected final UserSearchPanel userSearchPanel;
62
63 protected final UserSelectionDirectoryPanel userDirectoryPanel;
64
65 protected final Fragment userSearchFragment;
66
67 protected final MergeLinkedAccountsWizardModel wizardModel;
68
69 public MergeLinkedAccountsSearchPanel(
70 final MergeLinkedAccountsWizardModel model,
71 final PageReference pageRef) {
72
73 super();
74 setOutputMarkupId(true);
75
76 this.wizardModel = model;
77 setTitleModel(new StringResourceModel("mergeLinkedAccounts.searchUser", Model.of(model.getBaseUser())));
78 ownerContainer = new WebMarkupContainer("ownerContainer");
79 ownerContainer.setOutputMarkupId(true);
80 add(ownerContainer);
81
82 userSearchFragment = new Fragment("search", "userSearchFragment", this);
83 userSearchPanel = UserSearchPanel.class.cast(new UserSearchPanel.Builder(
84 new ListModel<>(new ArrayList<>()), pageRef).
85 required(false).enableSearch(MergeLinkedAccountsSearchPanel.this).
86 build("usersearch"));
87 userSearchFragment.add(userSearchPanel);
88
89 AnyTypeTO anyTypeTO = anyTypeRestClient.read(AnyTypeKind.USER.name());
90 userDirectoryPanel = UserSelectionDirectoryPanel.class.cast(new UserSelectionDirectoryPanel.Builder(
91 anyTypeClassRestClient.list(anyTypeTO.getClasses()), userRestClient, anyTypeTO.getKey(), pageRef).
92 build("searchResult"));
93
94 userSearchFragment.add(userDirectoryPanel);
95 ownerContainer.add(userSearchFragment);
96 }
97
98 @Override
99 public void onEvent(final IEvent<?> event) {
100 if (event.getPayload() instanceof SearchClausePanel.SearchEvent) {
101 AjaxRequestTarget target = SearchClausePanel.SearchEvent.class.cast(event.getPayload()).getTarget();
102 String fiql = "username!~" + wizardModel.getBaseUser().getUsername() + ';'
103 + SearchUtils.buildFIQL(userSearchPanel.getModel().getObject(),
104 SyncopeClient.getUserSearchConditionBuilder());
105 userDirectoryPanel.search(fiql, target);
106 } else if (event.getPayload() instanceof AnySelectionDirectoryPanel.ItemSelection) {
107 AnySelectionDirectoryPanel.ItemSelection<?> payload =
108 (AnySelectionDirectoryPanel.ItemSelection) event.getPayload();
109
110 AnyTO sel = payload.getSelection();
111 wizardModel.setMergingUser(userRestClient.read(sel.getKey()));
112
113 String tableId = ((Component) event.getSource()).
114 get("container:content:searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable").
115 getMarkupId();
116 String js = "$('#" + tableId + " tr').removeClass('active');";
117 js += "$('#" + tableId + " td[title=" + sel.getKey() + "]').parent().addClass('active');";
118 payload.getTarget().prependJavaScript(js);
119 }
120 }
121 }