-
Notifications
You must be signed in to change notification settings - Fork 188
/
TaskHandlerWrapperFactory.java
131 lines (111 loc) · 6.04 KB
/
TaskHandlerWrapperFactory.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
/*
* Copyright (c) 2010-2020 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.factory;
import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.gui.api.prism.PrismObjectWrapper;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.prism.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.impl.prism.PrismPropertyPanel;
import com.evolveum.midpoint.gui.impl.prism.PrismPropertyWrapper;
import com.evolveum.midpoint.gui.impl.prism.PrismPropertyWrapperImpl;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
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.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.stream.Collectors;
@Component
public class TaskHandlerWrapperFactory extends PrismPropertyWrapperFactoryImpl<String> {
private static final transient Trace LOGGER = TraceManager.getTrace(TaskHandlerWrapperFactory.class);
private static final String OPERATION_DETERMINE_LOOKUP_TABLE = "determineLookupTable";
@Override
protected PrismPropertyWrapper<String> createWrapper(PrismContainerValueWrapper<?> parent, PrismProperty<String> item,
ItemStatus status, WrapperContext ctx) {
getRegistry().registerWrapperPanel(item.getDefinition().getTypeName(), PrismPropertyPanel.class);
PrismPropertyWrapper<String> propertyWrapper = new PrismPropertyWrapperImpl<>(parent, item, status);
PrismReferenceValue valueEnumerationRef = item.getDefinition().getValueEnumerationRef();
if (valueEnumerationRef != null) {
//TODO: task and result from context
Task task = ctx.getTask();
OperationResult result = ctx.getResult().createSubresult(OPERATION_DETERMINE_LOOKUP_TABLE);
Collection<SelectorOptions<GetOperationOptions>> options = WebModelServiceUtils
.createLookupTableRetrieveOptions(schemaHelper);
try {
PrismObject<LookupTableType> lookupTable = modelService.getObject(LookupTableType.class, valueEnumerationRef.getOid(), options, task, result);
propertyWrapper.setPredefinedValues(lookupTable.asObjectable());
} catch (ObjectNotFoundException | SchemaException | SecurityViolationException | CommunicationException
| ConfigurationException | ExpressionEvaluationException e) {
LOGGER.error("Cannot load lookup table for {} ", item);
//TODO throw???
}
return propertyWrapper;
}
if (parent != null && parent.getParent() != null) {
PrismObject<TaskType> taskPrism = (PrismObject) ctx.getObject();
TaskType task = taskPrism.asObjectable();
if (ItemStatus.ADDED == status) {
Collection<AssignmentType> assignmentTypes = task.getAssignment()
.stream()
.filter(assignmentType -> WebComponentUtil.isArchetypeAssignment(assignmentType))
.collect(Collectors.toList());
Collection<String> handlers;
if (assignmentTypes.isEmpty()) {
// TODO all handlers
handlers = taskManager.getAllHandlerUris(true);
} else if (assignmentTypes.size() == 1) {
AssignmentType archetypeAssignment = assignmentTypes.iterator().next();
handlers = taskManager.getHandlerUrisForArchetype(archetypeAssignment.getTargetRef().getOid(), true);
} else {
throw new UnsupportedOperationException("More than 1 archetype, this is not supported");
}
LookupTableType lookupTableType = new LookupTableType(getPrismContext());
handlers.forEach(handler -> {
LookupTableRowType row = new LookupTableRowType(getPrismContext());
row.setKey(handler);
handler = normalizeHandler(handler);
PolyStringType handlerLabel = new PolyStringType(handler);
PolyStringTranslationType translation = new PolyStringTranslationType();
translation.setKey(handler);
handlerLabel.setTranslation(translation);
row.setLabel(handlerLabel);
lookupTableType.getRow().add(row);
});
propertyWrapper.setPredefinedValues(lookupTableType);
}
}
return propertyWrapper;
}
private String normalizeHandler(String handler) {
handler = StringUtils.remove(handler, "-3");
handler = StringUtils.removeStart(handler, "http://midpoint.evolveum.com/xml/ns/public/").replace("-", "/").replace("#", "/");
String[] split = handler.split("/");
handler = "TaskHandlerSelector." + StringUtils.join(split, ".");
return handler;
}
@Override
public int getOrder() {
return super.getOrder() - 10;
}
@Override
public boolean match(ItemDefinition<?> def) {
return TaskType.F_HANDLER_URI.equivalent(def.getItemName());
}
}