-
Notifications
You must be signed in to change notification settings - Fork 188
/
ApprovalProcessExecutionInformationDto.java
119 lines (102 loc) · 4.92 KB
/
ApprovalProcessExecutionInformationDto.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
/*
* 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.web.page.admin.workflow.dto;
import com.evolveum.midpoint.repo.common.ObjectResolver;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ApprovalContextUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalLevelOutcomeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalSchemaExecutionInformationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Extract from ApprovalSchemaExecutionInformationType that could be directly displayed via the GUI as "approval process preview"
* (either for the whole process or only the future stages).
*
* @author mederly
*/
public class ApprovalProcessExecutionInformationDto implements Serializable {
private static final long serialVersionUID = 1L;
public static final String F_PROCESS_NAME = "processName";
public static final String F_TARGET_NAME = "targetName";
public static final String F_STAGES = "stages";
public static final String F_TRIGGERS = "triggers";
private final boolean wholeProcess; // do we represent whole process or only the future stages?
private final int currentStageNumber; // current stage number (0 if there's no current stage, i.e. process has not started yet)
private final int numberOfStages;
private final String processName;
private final String targetName;
private final List<ApprovalStageExecutionInformationDto> stages = new ArrayList<>();
private final EvaluatedTriggerGroupDto triggers;
private final boolean running;
private ApprovalProcessExecutionInformationDto(boolean wholeProcess, int currentStageNumber, int numberOfStages,
String processName, String targetName,
EvaluatedTriggerGroupDto triggers, boolean running) {
this.wholeProcess = wholeProcess;
this.currentStageNumber = currentStageNumber;
this.numberOfStages = numberOfStages;
this.processName = processName;
this.targetName = targetName;
this.triggers = triggers;
this.running = running;
}
@NotNull
public static ApprovalProcessExecutionInformationDto createFrom(ApprovalSchemaExecutionInformationType info,
ObjectResolver resolver, boolean wholeProcess, Task opTask,
OperationResult result) {
int currentStageNumber = info.getCurrentStageNumber() != null ? info.getCurrentStageNumber() : 0;
int numberOfStages = info.getStage().size();
ObjectResolver.Session session = resolver.openResolutionSession(null);
String processName = ApprovalContextUtil.getProcessName(info);
String targetName = ApprovalContextUtil.getTargetName(info);
CaseType aCase = ApprovalContextUtil.getCase(info);
boolean running = aCase != null && !SchemaConstants.CASE_STATE_CLOSED.equals(aCase.getState());
EvaluatedTriggerGroupDto triggers = EvaluatedTriggerGroupDto.initializeFromRules(ApprovalContextUtil.getAllRules(info.getPolicyRules()), false, new EvaluatedTriggerGroupDto.UniquenessFilter());
ApprovalProcessExecutionInformationDto rv =
new ApprovalProcessExecutionInformationDto(wholeProcess, currentStageNumber, numberOfStages, processName,
targetName, triggers, running);
int startingStageNumber = wholeProcess ? 1 : currentStageNumber;
boolean reachable = true;
for (int i = startingStageNumber; i <= numberOfStages; i++) {
ApprovalStageExecutionInformationDto stage = ApprovalStageExecutionInformationDto.createFrom(info, i, resolver, session, opTask, result);
stage.setReachable(reachable);
rv.stages.add(stage);
if (stage.getOutcome() == ApprovalLevelOutcomeType.REJECT) {
reachable = false; // for following stages
}
}
return rv;
}
public boolean isWholeProcess() {
return wholeProcess;
}
public int getCurrentStageNumber() {
return currentStageNumber;
}
public int getNumberOfStages() {
return numberOfStages;
}
public List<ApprovalStageExecutionInformationDto> getStages() {
return stages;
}
public String getProcessName() {
return processName;
}
public String getTargetName() {
return targetName;
}
public boolean isRunning() {
return running;
}
public EvaluatedTriggerGroupDto getTriggers() {
return triggers;
}
}