-
Notifications
You must be signed in to change notification settings - Fork 188
/
MultiPropagationResultHandler.java
89 lines (76 loc) · 3.68 KB
/
MultiPropagationResultHandler.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
/**
* Copyright (c) 2018 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.provisioning.impl.task;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.crypto.EncryptionException;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.provisioning.impl.ShadowCache;
import com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.common.task.AbstractSearchIterativeResultHandler;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
/**
* @author semancik
*
*/
public class MultiPropagationResultHandler extends AbstractSearchIterativeResultHandler<ResourceType> {
private static final transient Trace LOGGER = TraceManager.getTrace(MultiPropagationResultHandler.class);
private final RepositoryService repositoryService;
private final ShadowCache shadowCache;
public MultiPropagationResultHandler(Task coordinatorTask, String taskOperationPrefix, TaskManager taskManager, RepositoryService repositoryService, ShadowCache shadowCache) {
super(coordinatorTask, taskOperationPrefix, "propagation", "multipropagation", taskManager);
this.repositoryService = repositoryService;
this.shadowCache = shadowCache;
}
@Override
protected boolean handleObject(PrismObject<ResourceType> resource, Task workerTask, OperationResult taskResult)
throws CommonException {
LOGGER.trace("Propagating provisioning operations on {}", resource);
ObjectQuery query = new ObjectQuery();
ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, resource.getPrismContext())
.item(ShadowType.F_RESOURCE_REF).ref(resource.getOid())
.and()
.exists(ShadowType.F_PENDING_OPERATION)
.buildFilter();
query.setFilter(filter);
ResultHandler<ShadowType> handler =
(shadow, result) -> {
propagateShadowOperations(resource, shadow, workerTask, result);
return true;
};
repositoryService.searchObjectsIterative(ShadowType.class, query, handler, null, true, taskResult);
LOGGER.trace("Propagation of {} done", resource);
return true;
}
protected void propagateShadowOperations(PrismObject<ResourceType> resource, PrismObject<ShadowType> shadow, Task workerTask, OperationResult result) {
try {
shadowCache.propagateOperations(resource, shadow, workerTask, result);
} catch (CommonException | GenericFrameworkException | EncryptionException e) {
throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e);
}
}
}