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.util.List;
22 import org.apache.syncope.client.console.rest.AnyTypeClassRestClient;
23 import org.apache.syncope.client.console.rest.SchemaRestClient;
24 import org.apache.syncope.client.ui.commons.Constants;
25 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPalettePanel;
26 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
27 import org.apache.syncope.common.lib.to.AnyTypeClassTO;
28 import org.apache.syncope.common.lib.types.SchemaType;
29 import org.apache.wicket.markup.html.WebMarkupContainer;
30 import org.apache.wicket.markup.html.form.Form;
31 import org.apache.wicket.markup.html.panel.Panel;
32 import org.apache.wicket.model.CompoundPropertyModel;
33 import org.apache.wicket.model.PropertyModel;
34 import org.apache.wicket.model.util.ListModel;
35
36 public class AnyTypeClassDetailsPanel extends Panel {
37
38 private static final long serialVersionUID = 3321861543207340469L;
39
40 protected static final List<String> LAYOUT_PARAMETERS = List.of(Constants.ENDUSER_ANYLAYOUT);
41
42 protected final AnyTypeClassTO anyTypeClassTO;
43
44 protected final List<String> availablePlainSchemas;
45
46 protected final List<String> availableDerSchemas;
47
48 protected final List<String> availableVirSchemas;
49
50 protected final AnyTypeClassRestClient anyTypeClassRestClient;
51
52 public AnyTypeClassDetailsPanel(
53 final String id,
54 final AnyTypeClassTO anyTypeClassTO,
55 final SchemaRestClient schemaRestClient,
56 final AnyTypeClassRestClient anyTypeClassRestClient) {
57
58 super(id);
59
60 this.anyTypeClassTO = anyTypeClassTO;
61
62 availablePlainSchemas = schemaRestClient.getSchemaNames(SchemaType.PLAIN);
63 availableDerSchemas = schemaRestClient.getSchemaNames(SchemaType.DERIVED);
64 availableVirSchemas = schemaRestClient.getSchemaNames(SchemaType.VIRTUAL);
65
66 this.anyTypeClassRestClient = anyTypeClassRestClient;
67
68 buildAvailableSchemas(anyTypeClassTO.getKey());
69
70 Form<AnyTypeClassTO> antTypeClassForm = new Form<>("form");
71 antTypeClassForm.setModel(new CompoundPropertyModel<>(anyTypeClassTO));
72 antTypeClassForm.setOutputMarkupId(true);
73 add(antTypeClassForm);
74
75 AjaxTextFieldPanel key = new AjaxTextFieldPanel(
76 Constants.KEY_FIELD_NAME,
77 getString(Constants.KEY_FIELD_NAME),
78 new PropertyModel<>(this.anyTypeClassTO, Constants.KEY_FIELD_NAME));
79 key.addRequiredLabel();
80 key.setEnabled(anyTypeClassTO.getKey() == null || this.anyTypeClassTO.getKey().isEmpty());
81 antTypeClassForm.add(key);
82
83 WebMarkupContainer container = new WebMarkupContainer("container");
84 container.setOutputMarkupId(true);
85 antTypeClassForm.add(container);
86
87 AjaxPalettePanel<String> plainSchema = new AjaxPalettePanel.Builder<String>().
88 setAllowOrder(true).
89 setAllowMoveAll(true).
90 build("plainSchemas",
91 new PropertyModel<>(this.anyTypeClassTO, "plainSchemas"),
92 new ListModel<>(availablePlainSchemas));
93 plainSchema.hideLabel();
94 plainSchema.setOutputMarkupId(true);
95 container.add(plainSchema);
96
97 AjaxPalettePanel<String> derSchema = new AjaxPalettePanel.Builder<String>().
98 setAllowOrder(true).
99 setAllowMoveAll(true).
100 build("derSchemas",
101 new PropertyModel<>(this.anyTypeClassTO, "derSchemas"),
102 new ListModel<>(availableDerSchemas));
103 derSchema.hideLabel();
104 derSchema.setOutputMarkupId(true);
105 container.add(derSchema);
106
107 AjaxPalettePanel<String> virSchema = new AjaxPalettePanel.Builder<String>().
108 setAllowOrder(true).
109 setAllowMoveAll(true).
110 build("virSchemas",
111 new PropertyModel<>(this.anyTypeClassTO, "virSchemas"),
112 new ListModel<>(availableVirSchemas));
113 virSchema.hideLabel();
114 virSchema.setOutputMarkupId(true);
115 container.add(virSchema);
116 }
117
118 protected void buildAvailableSchemas(final String key) {
119 anyTypeClassRestClient.list().stream().
120 filter(item -> key == null || !item.getKey().equals(key)).
121 forEach(item -> {
122 availablePlainSchemas.removeAll(item.getPlainSchemas());
123 availableDerSchemas.removeAll(item.getDerSchemas());
124 availableVirSchemas.removeAll(item.getVirSchemas());
125 });
126
127 availablePlainSchemas.removeAll(LAYOUT_PARAMETERS);
128 }
129 }