-
Notifications
You must be signed in to change notification settings - Fork 188
/
ObjectIntegrityCheckTaskHandler.java
109 lines (91 loc) · 4.64 KB
/
ObjectIntegrityCheckTaskHandler.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
/*
* Copyright (c) 2010-2017 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.model.impl.integrity;
import com.evolveum.midpoint.model.api.ModelPublicConstants;
import com.evolveum.midpoint.model.common.SystemObjectCache;
import com.evolveum.midpoint.model.impl.util.AbstractSearchIterativeModelTaskHandler;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.RunningTask;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskCategory;
import com.evolveum.midpoint.task.api.TaskRunResult;
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.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskPartitionDefinitionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Collection;
/**
* Task handler for "Object integrity check" task.
*
* The purpose of this task is to detect and optionally fix anomalies in repository objects.
*
* However, currently its only function is to display information about objects size.
*/
@Component
public class ObjectIntegrityCheckTaskHandler extends AbstractSearchIterativeModelTaskHandler<ObjectType, ObjectIntegrityCheckResultHandler> {
public static final String HANDLER_URI = ModelPublicConstants.OBJECT_INTEGRITY_CHECK_TASK_HANDLER_URI;
// WARNING! This task handler is efficiently singleton!
// It is a spring bean and it is supposed to handle all search task instances
// Therefore it must not have task-specific fields. It can only contain fields specific to
// all tasks of a specified type
@Autowired private SystemObjectCache systemObjectCache;
private static final Trace LOGGER = TraceManager.getTrace(ObjectIntegrityCheckTaskHandler.class);
public ObjectIntegrityCheckTaskHandler() {
super("Object integrity check", OperationConstants.CHECK_OBJECT_INTEGRITY);
setLogFinishInfo(true);
setPreserveStatistics(false);
}
@PostConstruct
private void initialize() {
taskManager.registerHandler(HANDLER_URI, this);
}
@Override
protected ObjectIntegrityCheckResultHandler createHandler(TaskPartitionDefinitionType partition, TaskRunResult runResult, RunningTask coordinatorTask, OperationResult opResult) {
return new ObjectIntegrityCheckResultHandler(coordinatorTask, ObjectIntegrityCheckTaskHandler.class.getName(),
"check object integrity", "check object integrity", taskManager, prismContext,
repositoryService, systemObjectCache, opResult);
}
@Override
protected Class<? extends ObjectType> getType(Task task) {
return ObjectType.class;
}
@Override
protected ObjectQuery createQuery(ObjectIntegrityCheckResultHandler handler, TaskRunResult runResult, Task task, OperationResult opResult) throws SchemaException {
ObjectQuery query = createQueryFromTask(handler, runResult, task, opResult);
LOGGER.info("Using query:\n{}", query.debugDump());
return query;
}
@Override
protected Collection<SelectorOptions<GetOperationOptions>> createSearchOptions(
ObjectIntegrityCheckResultHandler resultHandler,
TaskRunResult runResult, Task coordinatorTask, OperationResult opResult) {
Collection<SelectorOptions<GetOperationOptions>> optionsFromTask = createSearchOptionsFromTask(resultHandler,
runResult, coordinatorTask, opResult);
return SelectorOptions.updateRootOptions(optionsFromTask, opt -> opt.setAttachDiagData(true), GetOperationOptions::new);
}
@Override
protected boolean requiresDirectRepositoryAccess(ObjectIntegrityCheckResultHandler resultHandler, TaskRunResult runResult, Task coordinatorTask, OperationResult opResult) {
return true;
}
@Override
public String getCategoryName(Task task) {
return TaskCategory.UTIL;
}
@Override
public String getArchetypeOid() {
return SystemObjectsType.ARCHETYPE_UTILITY_TASK.value();
}
}