-
Notifications
You must be signed in to change notification settings - Fork 188
/
EvaluatedAssignmentImpl.java
262 lines (228 loc) · 8.61 KB
/
EvaluatedAssignmentImpl.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
/*
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.model.impl.lens;
import java.util.ArrayList;
import java.util.Collection;
import com.evolveum.midpoint.model.api.context.EvaluatedAssignment;
import com.evolveum.midpoint.model.common.expression.ItemDeltaItem;
import com.evolveum.midpoint.model.common.expression.ObjectDeltaObject;
import com.evolveum.midpoint.model.common.mapping.Mapping;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.delta.DeltaSetTriple;
import com.evolveum.midpoint.prism.delta.PlusMinusZero;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.Authorization;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
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.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
/**
* Evaluated assignment that contains all constructions and authorizations from the assignment
* itself and all the applicable inducements from all the roles referenced from the assignment.
*
* @author Radovan Semancik
*/
public class EvaluatedAssignmentImpl<F extends FocusType> implements EvaluatedAssignment<F> {
private static final Trace LOGGER = TraceManager.getTrace(EvaluatedAssignmentImpl.class);
private ItemDeltaItem<PrismContainerValue<AssignmentType>> assignmentIdi;
private DeltaSetTriple<Construction<F>> constructions;
private DeltaSetTriple<EvaluatedAbstractRoleImpl> roles;
private Collection<PrismReferenceValue> orgRefVals;
private Collection<Authorization> authorizations;
private Collection<Mapping<? extends PrismPropertyValue<?>>> focusMappings;
private PrismObject<?> target;
private boolean isValid;
private boolean forceRecon; // used also to force recomputation of parentOrgRefs
public EvaluatedAssignmentImpl() {
constructions = new DeltaSetTriple<>();
roles = new DeltaSetTriple<>();
orgRefVals = new ArrayList<>();
authorizations = new ArrayList<>();
focusMappings = new ArrayList<>();
}
public ItemDeltaItem<PrismContainerValue<AssignmentType>> getAssignmentIdi() {
return assignmentIdi;
}
public void setAssignmentIdi(ItemDeltaItem<PrismContainerValue<AssignmentType>> assignmentIdi) {
this.assignmentIdi = assignmentIdi;
}
/* (non-Javadoc)
* @see com.evolveum.midpoint.model.impl.lens.EvaluatedAssignment#getAssignmentType()
*/
@Override
public AssignmentType getAssignmentType() {
return assignmentIdi.getItemNew().getValue(0).asContainerable();
}
public DeltaSetTriple<Construction<F>> getConstructions() {
return constructions;
}
public Collection<Construction<F>> getConstructionSet(PlusMinusZero whichSet) {
switch (whichSet) {
case ZERO: return getConstructions().getZeroSet();
case PLUS: return getConstructions().getPlusSet();
case MINUS: return getConstructions().getMinusSet();
default: throw new IllegalArgumentException("whichSet: " + whichSet);
}
}
public void addConstructionZero(Construction<F> contruction) {
constructions.addToZeroSet(contruction);
}
public void addConstructionPlus(Construction<F> contruction) {
constructions.addToPlusSet(contruction);
}
public void addConstructionMinus(Construction<F> contruction) {
constructions.addToMinusSet(contruction);
}
@Override
public DeltaSetTriple<EvaluatedAbstractRoleImpl> getRoles() {
return roles;
}
public void addRole(EvaluatedAbstractRoleImpl role, PlusMinusZero mode) {
roles.addToSet(mode, role);
}
public Collection<PrismReferenceValue> getOrgRefVals() {
return orgRefVals;
}
public void addOrgRefVal(PrismReferenceValue org) {
orgRefVals.add(org);
}
/* (non-Javadoc)
* @see com.evolveum.midpoint.model.impl.lens.EvaluatedAssignment#getAuthorizations()
*/
@Override
public Collection<Authorization> getAuthorizations() {
return authorizations;
}
public void addAuthorization(Authorization authorization) {
authorizations.add(authorization);
}
public Collection<Mapping<? extends PrismPropertyValue<?>>> getFocusMappings() {
return focusMappings;
}
public void addFocusMapping(Mapping<? extends PrismPropertyValue<?>> focusMapping) {
this.focusMappings.add(focusMapping);
}
/* (non-Javadoc)
* @see com.evolveum.midpoint.model.impl.lens.EvaluatedAssignment#getTarget()
*/
@Override
public PrismObject<?> getTarget() {
return target;
}
public void setTarget(PrismObject<?> target) {
this.target = target;
}
/* (non-Javadoc)
* @see com.evolveum.midpoint.model.impl.lens.EvaluatedAssignment#isValid()
*/
@Override
public boolean isValid() {
return isValid;
}
public void setValid(boolean isValid) {
this.isValid = isValid;
}
public boolean isForceRecon() {
return forceRecon;
}
public void setForceRecon(boolean forceRecon) {
this.forceRecon = forceRecon;
}
public Collection<ResourceType> getResources(OperationResult result) throws ObjectNotFoundException, SchemaException {
Collection<ResourceType> resources = new ArrayList<ResourceType>();
for (Construction<F> acctConstr: constructions.getAllValues()) {
resources.add(acctConstr.getResource(result));
}
return resources;
}
public void evaluateConstructions(ObjectDeltaObject<F> focusOdo, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
for (Construction<F> construction :constructions.getAllValues()) {
construction.setFocusOdo(focusOdo);
LOGGER.trace("Evaluating construction '{}' in {}", construction, construction.getSource());
construction.evaluate(task, result);
}
}
@Override
public String debugDump() {
return debugDump(0);
}
@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.debugDumpLabel(sb, "EvaluatedAssignment", indent);
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "isValid", isValid, indent + 1);
if (forceRecon) {
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "forceRecon", forceRecon, indent + 1);
}
if (!constructions.isEmpty()) {
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "Constructions", constructions, indent+1);
}
if (!roles.isEmpty()) {
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "Roles", roles, indent+1);
}
if (!orgRefVals.isEmpty()) {
sb.append("\n");
DebugUtil.debugDumpLabel(sb, "Orgs", indent+1);
for (PrismReferenceValue org: orgRefVals) {
sb.append("\n");
DebugUtil.indentDebugDump(sb, indent+2);
sb.append(org.toString());
}
}
if (!authorizations.isEmpty()) {
sb.append("\n");
DebugUtil.debugDumpLabel(sb, "Authorizations", indent+1);
for (Authorization autz: authorizations) {
sb.append("\n");
DebugUtil.indentDebugDump(sb, indent+2);
sb.append(autz.toString());
}
}
if (!focusMappings.isEmpty()) {
sb.append("\n");
DebugUtil.debugDumpLabel(sb, "Focus Mappings", indent+1);
for (Mapping<? extends PrismPropertyValue<?>> mapping: focusMappings) {
sb.append("\n");
DebugUtil.indentDebugDump(sb, indent+2);
sb.append(mapping.toString());
}
}
if (target != null) {
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "Target", target.toString(), indent+1);
}
return sb.toString();
}
@Override
public String toString() {
return "EvaluatedAssignment(acc=" + constructions + "; org="+orgRefVals+"; autz="+authorizations+"; "+focusMappings.size()+" focus mappings)";
}
}