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.panels;
20
21 import java.io.Serializable;
22 import java.util.List;
23 import java.util.stream.Collectors;
24 import org.apache.syncope.client.console.SyncopeConsoleSession;
25 import org.apache.syncope.client.console.pages.BasePage;
26 import org.apache.syncope.client.console.rest.AnyTypeRestClient;
27 import org.apache.syncope.client.ui.commons.Constants;
28 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDropDownChoicePanel;
29 import org.apache.syncope.client.ui.commons.markup.html.form.FieldPanel;
30 import org.apache.syncope.common.lib.SyncopeClientException;
31 import org.apache.syncope.common.lib.to.GroupTO;
32 import org.apache.syncope.common.lib.types.AnyTypeKind;
33 import org.apache.wicket.PageReference;
34 import org.apache.wicket.ajax.AjaxRequestTarget;
35 import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
36 import org.apache.wicket.markup.html.form.Form;
37 import org.apache.wicket.markup.html.form.IChoiceRenderer;
38 import org.apache.wicket.model.LoadableDetachableModel;
39 import org.apache.wicket.model.Model;
40 import org.apache.wicket.model.ResourceModel;
41 import org.apache.wicket.spring.injection.annot.SpringBean;
42
43 public abstract class MembersTogglePanel extends TogglePanel<Serializable> {
44
45 private static final long serialVersionUID = -3195479265440591519L;
46
47 @SpringBean
48 protected AnyTypeRestClient anyTypeRestClient;
49
50 protected GroupTO groupTO;
51
52 protected final Form<?> form;
53
54 protected final Model<String> typeModel = new Model<>();
55
56 private final LoadableDetachableModel<List<String>> anyTypes = new LoadableDetachableModel<>() {
57
58 private static final long serialVersionUID = 5275935387613157437L;
59
60 @Override
61 protected List<String> load() {
62 return anyTypeRestClient.list().stream().
63 filter(anyType -> !AnyTypeKind.GROUP.name().equals(anyType)).collect(Collectors.toList());
64 }
65 };
66
67 public MembersTogglePanel(final PageReference pageRef) {
68 super(Constants.OUTER, "groupMembers", pageRef);
69
70 form = new Form<>("membersForm");
71 addInnerObject(form);
72
73 FieldPanel<String> type = new AjaxDropDownChoicePanel<>("type", "type", typeModel, false).
74 setChoices(anyTypes).
75 setChoiceRenderer(new IChoiceRenderer<String>() {
76
77 private static final long serialVersionUID = -200150326532439794L;
78
79 @Override
80 public Object getDisplayValue(final String anyType) {
81 return new ResourceModel("anyType." + anyType, anyType).getObject();
82 }
83 }).
84 setStyleSheet("form-control").
85 setRequired(true);
86
87 type.hideLabel();
88 form.add(type);
89
90 form.add(new AjaxSubmitLink("changeit", form) {
91
92 private static final long serialVersionUID = -7978723352517770644L;
93
94 @Override
95 protected void onSubmit(final AjaxRequestTarget target) {
96 try {
97 onApplyInternal(groupTO, typeModel.getObject(), target);
98 toggle(target, false);
99 } catch (SyncopeClientException e) {
100 LOG.error("While inspecting group memebers of type {}", typeModel.getObject(), e);
101 SyncopeConsoleSession.get().onException(e);
102 }
103 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
104 }
105
106 @Override
107 protected void onError(final AjaxRequestTarget target) {
108 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
109 }
110 });
111 }
112
113 protected abstract Serializable onApplyInternal(
114 GroupTO groupTO, String type, AjaxRequestTarget target);
115
116 public void setTargetObject(final GroupTO groupTO) {
117 this.groupTO = groupTO;
118 }
119 }