-
Notifications
You must be signed in to change notification settings - Fork 188
/
AssignmentsDetailsPanel.java
282 lines (244 loc) · 13.2 KB
/
AssignmentsDetailsPanel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
* Copyright (C) 2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.gui.impl.component;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.jetbrains.annotations.NotNull;
import com.evolveum.midpoint.gui.api.component.DisplayNamePanel;
import com.evolveum.midpoint.gui.api.component.tabs.PanelTab;
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.prism.panel.SingleContainerPanel;
import com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.assignment.AssignmentsUtil;
import com.evolveum.midpoint.web.component.assignment.ConstructionAssociationPanel;
import com.evolveum.midpoint.web.component.prism.ItemVisibility;
import com.evolveum.midpoint.web.model.PrismContainerWrapperModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
public class AssignmentsDetailsPanel extends MultivalueContainerDetailsPanel<AssignmentType> {
private static final Trace LOGGER = TraceManager.getTrace(AssignmentsDetailsPanel.class);
private boolean isEntitledAssignemnt;
public AssignmentsDetailsPanel(String id, IModel<PrismContainerValueWrapper<AssignmentType>> model, boolean isEntitledAssignment) {
super(id, model, !isEntitledAssignment);
this.isEntitledAssignemnt = isEntitledAssignment;
}
@NotNull
@Override
protected List<ITab> createTabs() {
List<ITab> tabs = super.createTabs();
if (isEntitledAssignemnt) {
tabs.add(getConstructionAssociationPanel());
return tabs;
}
AssignmentsUtil.AssignmentTypeType assignmentTypeType = AssignmentsUtil.getAssignmentType(getModelObject());
switch (assignmentTypeType) {
case CONSTRUCTION:
tabs.add(createConstructionTabs());
break;
case POLICY_RULE:
tabs.add(createTabs("AssignmentType.policyRule", AssignmentType.F_POLICY_RULE, PolicyRuleType.COMPLEX_TYPE));
break;
case FOCUS_MAPPING:
tabs.add(createTabs("AssignmentType.focusMappings", AssignmentType.F_FOCUS_MAPPINGS, MappingType.COMPLEX_TYPE));
break;
case PERSONA_CONSTRUCTION:
tabs.add(createTabs("AssignmentType.personaConstruction", AssignmentType.F_PERSONA_CONSTRUCTION, PersonaConstructionType.COMPLEX_TYPE));
break;
case ASSIGNMENT_RELATION:
tabs.add(createTabs("AssignmentType.assignmentRelation", AssignmentType.F_ASSIGNMENT_RELATION, AssignmentRelationType.COMPLEX_TYPE));
break;
}
tabs.add(createActivationTab());
tabs.add(createConditionTab());
return tabs;
}
private PanelTab getConstructionAssociationPanel() {
return new PanelTab(createStringResource("AssignmentPanel.inducedEntitlements")) {
@Override
public WebMarkupContainer createPanel(String panelId) {
IModel<PrismContainerWrapper<ConstructionType>> constructionModel = PrismContainerWrapperModel.fromContainerValueWrapper(getModel(), AssignmentType.F_CONSTRUCTION);
ConstructionAssociationPanel constructionDetailsPanel = new ConstructionAssociationPanel(panelId, constructionModel);
constructionDetailsPanel.setOutputMarkupId(true);
return constructionDetailsPanel;
}
};
}
@Override
protected ItemVisibility getBasicTabVisibity(ItemWrapper<?, ?> itemWrapper) {
return getContainerVisibility(itemWrapper);
}
@Override
protected boolean getBasicTabEditability(ItemWrapper<?, ?> itemWrapper) {
return getContainerReadability(itemWrapper);
}
@Override
protected DisplayNamePanel<AssignmentType> createDisplayNamePanel(String displayNamePanelId) {
IModel<AssignmentType> displayNameModel = getDisplayModel(getModelObject().getRealValue());
return new DisplayNamePanel<>(displayNamePanelId, displayNameModel) {
private static final long serialVersionUID = 1L;
@Override
protected QName getRelation() {
return getRelationForDisplayNamePanel(AssignmentsDetailsPanel.this.getModelObject());
}
@Override
protected IModel<String> getKindIntentLabelModel() {
return getKindIntentLabelModelForDisplayNamePanel(AssignmentsDetailsPanel.this.getModelObject());
}
};
}
@SuppressWarnings("unchecked")
private <C extends Containerable> IModel<C> getDisplayModel(AssignmentType assignment) {
return () -> {
if (assignment.getTargetRef() != null && assignment.getTargetRef().getOid() != null) {
Task task = getPageBase().createSimpleTask("Load target");
OperationResult result = task.getResult();
PrismObject<ObjectType> targetObject = WebModelServiceUtils.loadObject(assignment.getTargetRef(), getPageBase(), task, result);
return targetObject != null ? (C) targetObject.asObjectable() : null;
}
if (assignment.getConstruction() != null && assignment.getConstruction().getResourceRef() != null) {
if (assignment.getConstruction().getResourceRef().getOid() != null) {
Task task = getPageBase().createSimpleTask("Load resource");
OperationResult result = task.getResult();
PrismObject<?> object = WebModelServiceUtils.loadObject(assignment.getConstruction().getResourceRef(), getPageBase(), task, result);
if (object != null) {
return (C) object.asObjectable();
}
} else {
return (C) assignment.getConstruction();
}
} else if (assignment.getPersonaConstruction() != null) {
return (C) assignment.getPersonaConstruction();
} else if (assignment.getPolicyRule() != null) {
return (C) assignment.getPolicyRule();
}
return null;
};
}
private QName getRelationForDisplayNamePanel(PrismContainerValueWrapper<AssignmentType> modelObject) {
AssignmentType assignment = modelObject.getRealValue();
if (assignment.getTargetRef() != null) {
return assignment.getTargetRef().getRelation();
} else {
return null;
}
}
private IModel<String> getKindIntentLabelModelForDisplayNamePanel(PrismContainerValueWrapper<AssignmentType> modelObject) {
AssignmentType assignment = modelObject.getRealValue();
if (assignment.getConstruction() != null) {
PrismContainerValueWrapper<ConstructionType> constructionValue = null;
try {
PrismContainerWrapper<ConstructionType> construction = modelObject.findContainer(AssignmentType.F_CONSTRUCTION);
if (construction == null) {
return null;
}
constructionValue = construction.getValue();
} catch (SchemaException e) {
LOGGER.error("Unexpected problem during construction wrapper lookup, {}", e.getMessage(), e);
}
ShadowKindType kind;
String intent;
if (constructionValue instanceof ConstructionValueWrapper) {
kind = ((ConstructionValueWrapper) constructionValue).getKind();
intent = ((ConstructionValueWrapper) constructionValue).getIntent();
} else {
kind = assignment.getConstruction().getKind();
intent = assignment.getConstruction().getIntent();
}
return createStringResource("DisplayNamePanel.kindIntentLabel", kind, intent);
}
return Model.of();
}
protected boolean getContainerReadability(ItemWrapper<?, ?> wrapper) {
if (QNameUtil.match(ConstructionType.F_KIND, wrapper.getItemName())) {
return false;
}
return !QNameUtil.match(ConstructionType.F_INTENT, wrapper.getItemName());
}
private ItemVisibility getContainerVisibility(ItemWrapper<?, ?> wrapper) {
if (wrapper instanceof PrismContainerWrapper) {
return ItemVisibility.HIDDEN;
}
return ItemVisibility.AUTO;
}
private PanelTab createTabs(String titleKey, ItemPath path, QName type) {
return new PanelTab(createStringResource(titleKey)) {
@Override
public WebMarkupContainer createPanel(String panelId) {
return new SingleContainerPanel<>(panelId, PrismContainerWrapperModel.fromContainerValueWrapper(getModel(), path), type);
}
};
}
private PanelTab createConstructionTabs() {
return new PanelTab(createStringResource("AssignmentType.construction")) {
@Override
public WebMarkupContainer createPanel(String panelId) {
return new AssignmentConstructionPanel(panelId, PrismContainerWrapperModel.fromContainerValueWrapper(getModel(), AssignmentType.F_CONSTRUCTION));
}
};
// return createTabs("AssignmentType.construction", AssignmentType.F_CONSTRUCTION, ConstructionType.COMPLEX_TYPE);
}
private PanelTab createActivationTab() {
return new PanelTab(createStringResource("AssignmentType.activation")) {
@Override
public WebMarkupContainer createPanel(String panelId) {
return new SingleContainerPanel<>(panelId,
PrismContainerWrapperModel.fromContainerValueWrapper(getModel(), AssignmentType.F_ACTIVATION), ActivationType.COMPLEX_TYPE) {
@Override
protected ItemVisibility getVisibility(ItemPath itemPath) {
if (ItemPath.create(AssignmentHolderType.F_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_LOCKOUT_EXPIRATION_TIMESTAMP).equivalent(itemPath.namedSegmentsOnly())) {
return ItemVisibility.HIDDEN;
}
if (ItemPath.create(AssignmentHolderType.F_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS).equivalent(itemPath.namedSegmentsOnly())) {
return ItemVisibility.HIDDEN;
}
if (ItemPath.create(AbstractRoleType.F_INDUCEMENT, AssignmentType.F_ACTIVATION, ActivationType.F_LOCKOUT_EXPIRATION_TIMESTAMP).equivalent(itemPath.namedSegmentsOnly())) {
return ItemVisibility.HIDDEN;
}
if (ItemPath.create(AbstractRoleType.F_INDUCEMENT, AssignmentType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS).equivalent(itemPath.namedSegmentsOnly())) {
return ItemVisibility.HIDDEN;
}
return super.getVisibility(itemPath);
}
};
}
};
}
private PanelTab createConditionTab() {
return new PanelTab(createStringResource("AssignmentType.condition")) {
@Override
public WebMarkupContainer createPanel(String panelId) {
return new SingleContainerPanel<>(panelId, PrismContainerWrapperModel.fromContainerValueWrapper(getModel(), AssignmentType.F_CONDITION), MappingType.COMPLEX_TYPE) {
@Override
protected ItemVisibility getVisibility(ItemPath itemPath) {
ItemPath assignmentConditionExpressionPath = ItemPath.create(AssignmentHolderType.F_ASSIGNMENT, AssignmentType.F_CONDITION, MappingType.F_EXPRESSION);
ItemPath inducementConditionExpressionPath = ItemPath.create(AbstractRoleType.F_INDUCEMENT, AssignmentType.F_CONDITION, MappingType.F_EXPRESSION);
if (itemPath.namedSegmentsOnly().equivalent(assignmentConditionExpressionPath) || itemPath.namedSegmentsOnly().equivalent(inducementConditionExpressionPath)) {
return ItemVisibility.AUTO;
} else {
return ItemVisibility.HIDDEN;
}
}
};
}
};
}
}