-
Notifications
You must be signed in to change notification settings - Fork 188
/
PrismPropertyWrapperFactoryImpl.java
131 lines (109 loc) · 5.35 KB
/
PrismPropertyWrapperFactoryImpl.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.wrapper;
import java.util.Collection;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext;
import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.prism.panel.PrismPropertyPanel;
import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper;
import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyWrapperImpl;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SchemaService;
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.exception.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
/**
* @author katka
*/
@Component
public class PrismPropertyWrapperFactoryImpl<T>
extends ItemWrapperFactoryImpl<PrismPropertyWrapper<T>, PrismPropertyValue<T>, PrismProperty<T>, PrismPropertyValueWrapper<T>> {
private static final Trace LOGGER = TraceManager.getTrace(PrismPropertyWrapperFactoryImpl.class);
@Autowired protected SchemaService schemaService;
private static final String DOT_CLASS = PrismPropertyWrapperFactoryImpl.class.getSimpleName() + ".";
private static final String OPERATION_LOAD_LOOKUP_TABLE = DOT_CLASS + "loadLookupTable";
@Override
public boolean match(ItemDefinition<?> def) {
return def instanceof PrismPropertyDefinition;
}
@PostConstruct
@Override
public void register() {
getRegistry().addToRegistry(this);
}
@Override
public int getOrder() {
return Integer.MAX_VALUE;
}
@Override
protected PrismPropertyValue<T> createNewValue(PrismProperty<T> item) throws SchemaException {
PrismPropertyValue<T> newValue = getPrismContext().itemFactory().createPropertyValue();
item.add(newValue);
return newValue;
}
@Override
protected PrismPropertyWrapper<T> createWrapperInternal(PrismContainerValueWrapper<?> parent, PrismProperty<T> item,
ItemStatus status, WrapperContext wrapperContext) {
PrismPropertyWrapper<T> propertyWrapper = new PrismPropertyWrapperImpl<>(parent, item, status);
propertyWrapper.setPredefinedValues(getPredefinedValues(item, wrapperContext));
return propertyWrapper;
}
protected LookupTableType getPredefinedValues(PrismProperty<T> item, WrapperContext wrapperContext) {
PrismReferenceValue valueEnumerationRef = item.getDefinition().getValueEnumerationRef();
if (valueEnumerationRef == null) {
return null;
}
String lookupTableOid = valueEnumerationRef.getOid();
LookupTableType lookupTableType = wrapperContext.getLookuptableFromCache(lookupTableOid);
if (lookupTableType != null) {
LOGGER.trace("Loading lookuptable from cache");
return lookupTableType;
}
//TODO: task and result from context
Task task = wrapperContext.getTask();
OperationResult result = wrapperContext.getResult().createSubresult(OPERATION_LOAD_LOOKUP_TABLE);
Collection<SelectorOptions<GetOperationOptions>> options = WebModelServiceUtils
.createLookupTableRetrieveOptions(schemaService);
try {
PrismObject<LookupTableType> lookupTable = getModelService().getObject(LookupTableType.class, lookupTableOid, options, task, result);
result.computeStatusIfUnknown();
lookupTableType = lookupTable.asObjectable();
wrapperContext.rememberLookuptable(lookupTableType);
return lookupTableType;
} catch (ObjectNotFoundException | SchemaException | SecurityViolationException | CommunicationException
| ConfigurationException | ExpressionEvaluationException e) {
LOGGER.error("Cannot load lookup table for {} ", item);
result.recordFatalError("Cannot load lookupTable for " + item + ", Reason: " + e.getMessage(), e);
//TODO throw???
}
return null;
}
@Override
public PrismPropertyValueWrapper<T> createValueWrapper(PrismPropertyWrapper<T> parent, PrismPropertyValue<T> value,
ValueStatus status, WrapperContext context) {
return new PrismPropertyValueWrapper<>(parent, value, status);
}
@Override
public void registerWrapperPanel(PrismPropertyWrapper<T> wrapper) {
getRegistry().registerWrapperPanel(wrapper.getTypeName(), PrismPropertyPanel.class);
}
@Override
protected void setupWrapper(PrismPropertyWrapper<T> wrapper) {
}
}