Skip to content

Commit

Permalink
Added stage info to yet another places in GUI. Added stage-related in…
Browse files Browse the repository at this point in the history
…fo to WorkItemType for easier access.
  • Loading branch information
mederly committed Jan 24, 2017
1 parent 83999b3 commit d209438
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 21 deletions.
Expand Up @@ -165,10 +165,9 @@ public Object getObject() {

@NotNull
private PropertyColumn<WorkItemDto, String> createStageColumn() {
return new PropertyColumn<>(createStringResource("WorkItemPanel.stage"), F_STAGE_INFO);
return new PropertyColumn<>(createStringResource("WorkItemsPanel.stage"), F_STAGE_INFO);
}


private BoxedTablePanel getWorkItemTable() {
return (BoxedTablePanel) get(ID_WORK_ITEMS_TABLE);
}
Expand Down
Expand Up @@ -118,7 +118,7 @@ public void prepareDeltaVisualization(String sceneNameKey, PrismContext prismCon
@Nullable
protected TaskType getTaskType() {
if (taskType == null) {
taskType = WebComponentUtil.getObjectFromReference(workItem.getTaskRef(), TaskType.class);
taskType = WebComponentUtil.getObjectFromReference(workItem.getTaskRef(), TaskType.class);
}
return taskType;
}
Expand Down Expand Up @@ -314,7 +314,8 @@ public boolean hasHistory() {
}

public String getStageInfo() {
return WfContextUtil.getStageInfo(getWorkflowContext());
WfContextType wfc = getWorkflowContext(); // wfc contains also the approval schema
return wfc != null ? WfContextUtil.getStageInfo(wfc) : WfContextUtil.getStageInfo(workItem);
}

public String getApproverInstruction() {
Expand Down
Expand Up @@ -28,25 +28,41 @@ public class WfContextUtil {

@Nullable
public static String getStageInfo(WfContextType wfc) {
if (wfc == null) {
if (wfc == null || hasFinished(wfc)) {
return null;
}
Integer stageNumber = wfc.getStageNumber();
String stageName = wfc.getStageDisplayName() != null ? wfc.getStageDisplayName() : wfc.getStageName();
if (stageName == null && stageNumber == null) {
return getStageInfo(wfc.getStageNumber(), wfc.getStageCount(), wfc.getStageName(), wfc.getStageDisplayName());
}

@Nullable
public static String getStageInfo(WorkItemType workItem) {
if (workItem == null) {
return null;
}
return getStageInfo(workItem.getStageNumber(), workItem.getStageCount(), workItem.getStageName(), workItem.getStageDisplayName());
}

// wfc is used to retrieve approval schema (if needed)
private static String getStageInfo(Integer stageNumber, Integer stageCount, String stageName, String stageDisplayName) {
String name = stageDisplayName != null ? stageDisplayName : stageName;
if (name == null && stageNumber == null) {
return null;
}
StringBuilder sb = new StringBuilder();
if (stageName != null) {
sb.append(stageName);
if (name != null) {
sb.append(name);
}
appendNumber(wfc, stageNumber, sb);
appendNumber(stageNumber, stageCount, sb);
return sb.toString();
}

public static boolean hasFinished(WfContextType wfc) {
return wfc.getEndTimestamp() != null;
}

@Nullable
public static String getCompleteStageInfo(WfContextType wfc) {
if (wfc == null) {
if (wfc == null || hasFinished(wfc)) {
return null;
}
Integer stageNumber = wfc.getStageNumber();
Expand All @@ -63,21 +79,19 @@ public static String getCompleteStageInfo(WfContextType wfc) {
} else if (stageDisplayName != null) {
sb.append(stageDisplayName);
}
appendNumber(wfc, stageNumber, sb);
appendNumber(stageNumber, wfc.getStageCount(), sb);
return sb.toString();
}

private static void appendNumber(WfContextType wfc, Integer stageNumber, StringBuilder sb) {
private static void appendNumber(Integer stageNumber, Integer stageCount, StringBuilder sb) {
if (stageNumber != null) {
boolean parentheses = sb.length() > 0;
if (parentheses) {
sb.append(" (");
}
sb.append(stageNumber);
ItemApprovalProcessStateType processInfo = getItemApprovalProcessInfo(wfc);
ApprovalSchemaType schema = processInfo != null ? processInfo.getApprovalSchema() : null;
if (schema != null) {
sb.append("/").append(schema.getLevel().size());
if (stageCount != null) {
sb.append("/").append(stageCount);
}
if (parentheses) {
sb.append(")");
Expand Down
Expand Up @@ -563,6 +563,14 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="stageCount" type="xsd:int" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Total number of stages - if process can be conceptually divided into stages.
Null if not known or applicable. (Stored in process variable "stageCount".)
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="stageName" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -949,6 +957,11 @@
</xsd:annotation>
</xsd:element>
<xsd:element name="approverInstruction" type="xsd:string" minOccurs="0" />
<!-- for work items without TaskType information -->
<xsd:element name="stageNumber" type="xsd:int" minOccurs="0" />
<xsd:element name="stageCount" type="xsd:int" minOccurs="0" />
<xsd:element name="stageName" type="xsd:string" minOccurs="0" />
<xsd:element name="stageDisplayName" type="xsd:string" minOccurs="0" />
<xsd:element name="processSpecificPart" type="tns:WfProcessSpecificWorkItemPartType" minOccurs="0" />

<!--<xsd:element name="contents" type="tns:ObjectType" minOccurs="0" maxOccurs="1">-->
Expand Down
Expand Up @@ -417,6 +417,11 @@ public WorkItemType taskExtractToWorkItemNew(TaskExtract task, boolean resolveTa
ProcessMidPointInterface pmi = processInterfaceFinder.getProcessInterface(variables);
wi.setDecision(pmi.extractDecision(variables));

wi.setStageNumber(pmi.getStageNumber(variables));
wi.setStageCount(pmi.getStageCount(variables));
wi.setStageName(pmi.getStageName(variables));
wi.setStageDisplayName(pmi.getStageDisplayName(variables));

// This is just because 'variables' switches in task query DO NOT fetch all required variables...
if (fetchAllVariables) { // TODO can we do this e.g. in the task completion listener?
Map<String, Object> allVariables = activitiEngine.getTaskService().getVariables(task.getId());
Expand Down
Expand Up @@ -44,6 +44,11 @@ public Integer getStageNumber(Map<String, Object> variables) {
return ActivitiUtil.getVariable(variables, CommonProcessVariableNames.VARIABLE_STAGE_NUMBER, Integer.class);
}

@Override
public Integer getStageCount(Map<String, Object> variables) {
return ActivitiUtil.getVariable(variables, CommonProcessVariableNames.VARIABLE_STAGE_COUNT, Integer.class);
}

@Override
public String getStageName(Map<String, Object> variables) {
return ActivitiUtil.getVariable(variables, CommonProcessVariableNames.VARIABLE_STAGE_NAME, String.class);
Expand Down
Expand Up @@ -35,6 +35,8 @@ public interface ProcessMidPointInterface {

Integer getStageNumber(Map<String, Object> variables);

Integer getStageCount(Map<String, Object> variables);

String getStageName(Map<String, Object> variables);

String getStageDisplayName(Map<String, Object> variables);
Expand Down
Expand Up @@ -88,6 +88,10 @@ public class CommonProcessVariableNames {
// Null if not applicable. [Integer]
public static final String VARIABLE_STAGE_NUMBER = "stageNumber";

// Total number of stages - if process can be conceptually divided into stages.
// Null if not applicable. [Integer]
public static final String VARIABLE_STAGE_COUNT = "stageCount";

// Stage name - if process can be conceptually divided into stages.
// Null if unknown or not applicable. [String]
public static final String VARIABLE_STAGE_NAME = "stageName";
Expand Down
Expand Up @@ -18,6 +18,8 @@

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.wf.impl.processes.common.ActivitiUtil;
import com.evolveum.midpoint.wf.impl.processes.common.CommonProcessVariableNames;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;

Expand All @@ -29,7 +31,9 @@ public class InitializeLoopThroughLevels implements JavaDelegate {

public void execute(DelegateExecution execution) {
LOGGER.trace("Executing the delegate; execution = {}", execution);
execution.setVariableLocal(ProcessVariableNames.LOOP_LEVELS_STOP, Boolean.FALSE);
ApprovalSchema schema = ActivitiUtil.getRequiredVariable(execution, ProcessVariableNames.APPROVAL_SCHEMA, ApprovalSchema.class);
execution.setVariable(CommonProcessVariableNames.VARIABLE_STAGE_COUNT, schema.getLevels().size());
execution.setVariableLocal(ProcessVariableNames.LOOP_LEVELS_STOP, Boolean.FALSE);
execution.setVariableLocal(ProcessVariableNames.ALL_DECISIONS, new ArrayList<Decision>());
}

Expand Down
Expand Up @@ -229,10 +229,11 @@ public void setAnswer(String answer) throws SchemaException {
.asItemDeltas());
}

public void setProcessInstanceStageInformation(Integer stageNumber, String stageName, String stageDisplayName)
public void setProcessInstanceStageInformation(Integer stageNumber, Integer stageCount, String stageName, String stageDisplayName)
throws SchemaException {
task.addModifications(DeltaBuilder.deltaFor(TaskType.class, getPrismContext())
.item(F_WORKFLOW_CONTEXT, F_STAGE_NUMBER).replace(stageNumber)
.item(F_WORKFLOW_CONTEXT, F_STAGE_COUNT).replace(stageCount)
.item(F_WORKFLOW_CONTEXT, F_STAGE_NAME).replace(stageName)
.item(F_WORKFLOW_CONTEXT, F_STAGE_DISPLAY_NAME).replace(stageDisplayName)
.asItemDeltas());
Expand Down
Expand Up @@ -270,7 +270,7 @@ public void onProcessEvent(ProcessEvent event, Task task, OperationResult result
if (stateDescription != null) {
wfTask.setProcessInstanceState(stateDescription);
}
wfTask.setProcessInstanceStageInformation(pmi.getStageNumber(variables),
wfTask.setProcessInstanceStageInformation(pmi.getStageNumber(variables), pmi.getStageCount(variables),
pmi.getStageName(variables), pmi.getStageDisplayName(variables));

wfTask.commitChanges(result);
Expand Down

0 comments on commit d209438

Please sign in to comment.