Skip to content

Commit

Permalink
Removed almost all content form ApprovalSchema/ApprovalLevel (was dup…
Browse files Browse the repository at this point in the history
…licated in ApprovalSchemaType/ApprovalLevelType).
  • Loading branch information
mederly committed Feb 4, 2017
1 parent bde650a commit 270ff00
Show file tree
Hide file tree
Showing 31 changed files with 374 additions and 725 deletions.
Expand Up @@ -20,6 +20,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -141,17 +143,27 @@ public static ApprovalLevelType getCurrentApprovalLevel(WfContextType wfc) {
if (wfc == null || wfc.getStageNumber() == null) {
return null;
}
return getApprovalLevel(wfc, wfc.getStageNumber());
}

public static ApprovalLevelType getApprovalLevel(WfContextType wfc, int stageNumber) {
ItemApprovalProcessStateType info = getItemApprovalProcessInfo(wfc);
if (info == null || info.getApprovalSchema() == null) {
return null;
}
int level = wfc.getStageNumber()-1;
if (level < 0 || level >= info.getApprovalSchema().getLevel().size()) {
return null; // TODO log something here? or leave it to the caller?
List<ApprovalLevelType> levels = info.getApprovalSchema().getLevel().stream()
.filter(level -> level.getOrder() != null && level.getOrder() == stageNumber)
.collect(Collectors.toList());
if (levels.size() > 1) {
throw new IllegalStateException("More than one level with order of " + stageNumber + ": " + levels);
} else if (levels.isEmpty()) {
return null;
} else {
return levels.get(0);
}
return info.getApprovalSchema().getLevel().get(level);
}


// we must be strict here; in case of suspicion, throw an exception
public static <T extends WfProcessEventType> List<T> getEventsForCurrentStage(@NotNull WfContextType wfc, @NotNull Class<T> clazz) {
if (wfc.getStageNumber() == null) {
Expand Down Expand Up @@ -189,4 +201,41 @@ public static ApprovalLevelOutcomeType getCurrentStageOutcome(WfContextType wfc,
}
return event.getOutcome();
}

public static String getLevelDiagName(ApprovalLevelType level) {
return level.getOrder() + ":" + level.getName()
+ (level.getDisplayName() != null ? " (" + level.getDisplayName() + ")" : "");
}

public static void orderAndRenumberLevels(ApprovalSchemaType schema) {
// Sorting uses set(..) method which is not available on prism structures. So we do sort on a copy (ArrayList).
List<ApprovalLevelType> levels = new ArrayList<>(schema.getLevel());
levels.sort(Comparator.comparing(level -> level.getOrder(), Comparator.nullsLast(Comparator.naturalOrder())));
for (int i = 0; i < levels.size(); i++) {
levels.get(i).setOrder(i+1);
}
schema.getLevel().clear();
schema.getLevel().addAll(levels);
}

public static void checkLevelsOrdering(ApprovalSchemaType schema) {
for (int i = 0; i < schema.getLevel().size(); i++) {
ApprovalLevelType level = schema.getLevel().get(i);
if (level.getOrder() == null) {
throw new IllegalStateException("Level without order: " + level);
}
if (i > 0 && schema.getLevel().get(i-1).getOrder() >= level.getOrder()) {
throw new IllegalStateException("Level #" + i + " is not before level #" + (i+1) + " in " + schema);
}
}
}

public static void checkLevelsOrderingStrict(ApprovalSchemaType schema) {
for (int i = 0; i < schema.getLevel().size(); i++) {
Integer order = schema.getLevel().get(i).getOrder();
if (order == null || order != i+1) {
throw new IllegalStateException("Level #" + (i+1) + " has an incorrect order: " + order + " in " + schema);
}
}
}
}
Expand Up @@ -57,7 +57,7 @@
<xsd:element name="level" type="c:ApprovalLevelType" minOccurs="1" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Levels, or steps, of the approval process.
Levels, or stages, of the approval process.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
Expand Down
Expand Up @@ -19,19 +19,27 @@
import com.evolveum.midpoint.model.api.expr.MidpointFunctions;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.WfContextUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
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.wf.impl.processes.itemApproval.ApprovalLevel;
import com.evolveum.midpoint.wf.impl.processes.itemApproval.ProcessVariableNames;
import com.evolveum.midpoint.wf.impl.util.SerializationSafeContainer;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalLevelType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType;
import org.activiti.engine.delegate.DelegateExecution;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getMidpointFunctions;
import static com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getTaskManager;
Expand All @@ -47,7 +55,33 @@ public class ActivitiUtil implements Serializable {

private static final Trace LOGGER = TraceManager.getTrace(ActivitiUtil.class);

public PrismContext getPrismContext() {
@NotNull
public static ApprovalLevelType getAndVerifyCurrentStage(DelegateExecution execution, Task wfTask, boolean stageInContextSet,
PrismContext prismContext) {
int levelIndex = getRequiredVariable(execution, ProcessVariableNames.LEVEL_INDEX, Integer.class, prismContext);
int stageNumber = levelIndex+1;
ApprovalLevelType level;
if (stageInContextSet) {
level = WfContextUtil.getCurrentApprovalLevel(wfTask.getWorkflowContext());
if (level == null) {
throw new IllegalStateException("No current stage information in " + wfTask);
}
} else {
level = WfContextUtil.getApprovalLevel(wfTask.getWorkflowContext(), stageNumber);
if (level == null) {
throw new IllegalStateException("No stage #" + stageNumber + " in " + wfTask);
}
}
ApprovalLevel wfLevel = getRequiredVariable(execution, ProcessVariableNames.LEVEL, ApprovalLevel.class, prismContext);
if (!level.getOrder().equals(wfLevel.getOrder()) || level.getOrder() != stageNumber) {
throw new IllegalStateException("Current stage number in " + wfTask + " (" + level.getOrder()
+ "), number present in activiti process (" + wfLevel
+ "), and the stage number according to activiti process (" + stageNumber + ") do not match.");
}
return level;
}

public PrismContext getPrismContext() {
return SpringApplicationContextHolder.getPrismContext();
}

Expand Down Expand Up @@ -133,4 +167,8 @@ public static WfContextType getWorkflowContext(Task wfTask) {
return wfTask.getWorkflowContext();
}
}

public static List<LightweightObjectRef> toLightweightReferences(Collection<ObjectReferenceType> refs) {
return refs.stream().map(ort -> new LightweightObjectRefImpl(ort)).collect(Collectors.toList());
}
}
Expand Up @@ -30,10 +30,6 @@ public class CommonProcessVariableNames {
// When the process instance was started.
public static final String VARIABLE_START_TIME = "startTime";

// [java.util.Date]
// When the work item is to be finished.
public static final String VARIABLE_DEADLINE = "deadline";

// [String]
// OID of task related to the process instance.
public static final String VARIABLE_MIDPOINT_TASK_OID = "midPointTaskOid";
Expand Down
Expand Up @@ -27,15 +27,18 @@
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DOMUtil;
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.wf.impl.util.MiscDataUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import org.activiti.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

Expand All @@ -57,22 +60,22 @@
@Component
public class WfExpressionEvaluationHelper {

public Collection<? extends LightweightObjectRef> evaluateRefExpressions(List<ExpressionType> expressions,
public Collection<ObjectReferenceType> evaluateRefExpressions(List<ExpressionType> expressions,
ExpressionVariables variables, DelegateExecution execution, String contextDescription,
Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
List<LightweightObjectRef> retval = new ArrayList<>();
List<ObjectReferenceType> retval = new ArrayList<>();
for (ExpressionType expression : expressions) {
retval.addAll(evaluateRefExpression(expression, variables, execution, contextDescription, task, result));
}
return retval;
}

public List<LightweightObjectRef> evaluateRefExpression(ExpressionType expressionType, ExpressionVariables variables,
public List<ObjectReferenceType> evaluateRefExpression(ExpressionType expressionType, ExpressionVariables variables,
DelegateExecution execution, String contextDescription, Task task, OperationResult result)
throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
return evaluateExpression(expressionType, variables, execution, contextDescription, String.class, DOMUtil.XSD_STRING,
task, result).stream()
.map(LightweightObjectRefImpl::new)
.map(oid -> ObjectTypeUtil.createObjectRef(oid, ObjectTypes.USER))
.collect(Collectors.toList());
}

Expand Down
Expand Up @@ -16,48 +16,30 @@

package com.evolveum.midpoint.wf.impl.processes.itemApproval;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.wf.impl.processes.common.LightweightObjectRef;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.io.Serializable;

/**
* TODO throw away this class completely
*
* @author mederly
*/
public interface ApprovalLevel extends DebugDumpable {

String getName();

String getDisplayName();

String getDescription();

List<? extends LightweightObjectRef> getApproverRefs();

List<ExpressionType> getApproverExpressions();

LevelEvaluationStrategyType getEvaluationStrategy();

ExpressionType getAutomaticallyApproved();

ExpressionType getAdditionalInformation();

@NotNull
ApprovalLevelOutcomeType getOutcomeIfNoApprovers();
public class ApprovalLevel implements Serializable {

@NotNull
GroupExpansionType getGroupExpansion();
private static final long serialVersionUID = -7425837742015830391L;

PrismContext getPrismContext();
private final int order;

void setPrismContext(PrismContext prismContext);
public ApprovalLevel(int order) {
this.order = order;
}

ApprovalLevelType toApprovalLevelType(PrismContext prismContext);
public int getOrder() {
return order;
}

boolean shouldBeSkipped();
@Override
public String toString() {
return "ApprovalLevelImpl(" + order + ")";
}

String getDebugName();
}

0 comments on commit 270ff00

Please sign in to comment.