Skip to content

Commit

Permalink
Showing stage in process instance lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jan 24, 2017
1 parent d01ea0d commit 0dfd3a9
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 69 deletions.
Expand Up @@ -105,19 +105,21 @@ private List<IColumn<ProcessInstanceDto, String>> initColumns(View view) {

if (view != TASKS_FOR_PROCESS) {
if (view == FULL_LIST) {
columns.add(new CheckBoxHeaderColumn<ProcessInstanceDto>());
columns.add(new CheckBoxHeaderColumn<>());
}
columns.add(createNameColumn());
columns.add(createTypeIconColumn(true));
columns.add(createObjectNameColumn("pageProcessInstances.item.object"));
columns.add(createTypeIconColumn(false));
columns.add(createTargetNameColumn("pageProcessInstances.item.target"));
columns.add(createStageColumn());
columns.add(createStateColumn());
columns.add(new PropertyColumn<ProcessInstanceDto, String>(createStringResource("pageProcessInstances.item.started"), F_START_FORMATTED));
columns.add(createOutcomeColumn());
columns.add(createFinishedColumn());
} else {
columns.add(createNameColumn());
columns.add(createStageColumn());
columns.add(createStateColumn());
columns.add(createOutcomeColumn());
columns.add(createFinishedColumn());
Expand All @@ -135,6 +137,11 @@ private PropertyColumn<ProcessInstanceDto, String> createStateColumn() {
return new PropertyColumn<>(createStringResource("pageProcessInstances.item.state"), F_STATE);
}

@NotNull
private PropertyColumn<ProcessInstanceDto, String> createStageColumn() {
return new PropertyColumn<>(createStringResource("pageProcessInstances.item.stage"), F_STAGE);
}

@NotNull
private IColumn<ProcessInstanceDto,String> createNameColumn() {
if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_TASKS_ALL_URL,
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.util.WfContextUtil;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.util.Selectable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
Expand All @@ -40,6 +41,7 @@ public class ProcessInstanceDto extends Selectable {
public static final String F_START_FORMATTED = "startFormatted";
public static final String F_END_FORMATTED = "endFormatted";
public static final String F_STATE = "state";
public static final String F_STAGE = "stage";
public static final String F_ANSWER = "answer";

private TaskType task;
Expand Down Expand Up @@ -106,6 +108,10 @@ public String getState() {
return task.getWorkflowContext().getState();
}

public String getStage() {
return WfContextUtil.getStageInfo(task.getWorkflowContext());
}

public String getProcessInstanceId() {
return task.getWorkflowContext().getProcessInstanceId();
}
Expand Down
Expand Up @@ -24,6 +24,7 @@
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.ObjectTreeDeltas;
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.SchemaException;
import com.evolveum.midpoint.web.component.DateLabelComponent;
Expand Down Expand Up @@ -312,47 +313,8 @@ public boolean hasHistory() {
return CollectionUtils.isNotEmpty(instanceState.getDecisions());
}

private ItemApprovalProcessStateType getItemApprovalProcessInfo() {
if (taskType == null || taskType.getWorkflowContext() == null) {
return null;
}
WfProcessSpecificStateType processSpecificState = taskType.getWorkflowContext().getProcessSpecificState();
return processSpecificState instanceof ItemApprovalProcessStateType ?
(ItemApprovalProcessStateType) processSpecificState : null;
}

private ItemApprovalWorkItemPartType getItemApprovalWorkItemInfo() {
return workItem.getProcessSpecificPart() instanceof ItemApprovalWorkItemPartType ?
(ItemApprovalWorkItemPartType) workItem.getProcessSpecificPart() : null;
}

public String getStageInfo() {
WfContextType wfc = getWorkflowContext();
Integer levelNumber = wfc.getStageNumber();
String levelName = wfc.getStageDisplayName() != null ? wfc.getStageDisplayName() : wfc.getStageName();
if (levelName == null && levelNumber == null) {
return null;
}
StringBuilder sb = new StringBuilder();
if (levelName != null) {
sb.append(levelName);
}
if (levelNumber != null) {
boolean parentheses = sb.length() > 0;
if (parentheses) {
sb.append(" (");
}
sb.append(levelNumber);
ItemApprovalProcessStateType processInfo = getItemApprovalProcessInfo();
ApprovalSchemaType schema = processInfo != null ? processInfo.getApprovalSchema() : null;
if (schema != null) {
sb.append("/").append(schema.getLevel().size());
}
if (parentheses) {
sb.append(")");
}
}
return sb.toString();
return WfContextUtil.getStageInfo(getWorkflowContext());
}

public String getApproverInstruction() {
Expand Down
Expand Up @@ -1683,6 +1683,7 @@ pageProcessInstances.item.started=Started
pageProcessInstances.item.object=Object
pageProcessInstances.item.target=Target
pageProcessInstances.item.state=State
pageProcessInstances.item.stage=Stage
pageProcessInstances.item.status=Status
pageProcessInstances.message.noStoppableItemSelected=No process instance that could be stopped has been selected.
pageProcessInstances.message.noItemSelected=No process instance has been selected.
Expand Down
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2010-2017 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.schema.util;

import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.jetbrains.annotations.Nullable;

/**
* TODO clean up these formatting methods
*
* @author mederly
*/
public class WfContextUtil {

@Nullable
public static String getStageInfo(WfContextType wfc) {
if (wfc == null) {
return null;
}
Integer stageNumber = wfc.getStageNumber();
String stageName = wfc.getStageDisplayName() != null ? wfc.getStageDisplayName() : wfc.getStageName();
if (stageName == null && stageNumber == null) {
return null;
}
StringBuilder sb = new StringBuilder();
if (stageName != null) {
sb.append(stageName);
}
appendNumber(wfc, stageNumber, sb);
return sb.toString();
}

@Nullable
public static String getCompleteStageInfo(WfContextType wfc) {
if (wfc == null) {
return null;
}
Integer stageNumber = wfc.getStageNumber();
String stageName = wfc.getStageName();
String stageDisplayName = wfc.getStageDisplayName();
if (stageNumber == null && stageName == null && stageDisplayName == null) {
return null;
}
StringBuilder sb = new StringBuilder();
if (stageName != null && stageDisplayName != null) {
sb.append(stageName).append(" (").append(stageDisplayName).append(")");
} else if (stageName != null) {
sb.append(stageName);
} else if (stageDisplayName != null) {
sb.append(stageDisplayName);
}
appendNumber(wfc, stageNumber, sb);
return sb.toString();
}

private static void appendNumber(WfContextType wfc, Integer stageNumber, 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 (parentheses) {
sb.append(")");
}
}
}

public static ItemApprovalProcessStateType getItemApprovalProcessInfo(WfContextType wfc) {
if (wfc == null) {
return null;
}
WfProcessSpecificStateType processSpecificState = wfc.getProcessSpecificState();
return processSpecificState instanceof ItemApprovalProcessStateType ?
(ItemApprovalProcessStateType) processSpecificState : null;
}

public static ItemApprovalWorkItemPartType getItemApprovalWorkItemInfo(WorkItemType workItem) {
return workItem.getProcessSpecificPart() instanceof ItemApprovalWorkItemPartType ?
(ItemApprovalWorkItemPartType) workItem.getProcessSpecificPart() : null;
}

}
Expand Up @@ -6,6 +6,7 @@
import com.evolveum.midpoint.prism.delta.builder.DeltaBuilder;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
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.task.api.TaskExecutionStatus;
import com.evolveum.midpoint.util.exception.CommunicationException;
Expand Down Expand Up @@ -209,34 +210,7 @@ public String getAnswerNice() {
}

public String getCompleteStageInfo() {
if (task.getWorkflowContext() == null) {
return null;
}
Integer number = task.getWorkflowContext().getStageNumber();
String name = task.getWorkflowContext().getStageName();
String displayName = task.getWorkflowContext().getStageDisplayName();
if (number == null && name == null && displayName == null) {
return null;
}
StringBuilder sb = new StringBuilder();
if (name != null && displayName != null) {
sb.append(name).append(" (").append(displayName).append(")");
} else if (name != null) {
sb.append(name);
} else if (displayName != null) {
sb.append(displayName);
}
if (number != null) {
boolean parentheses = sb.length() > 0;
if (parentheses) {
sb.append(" (");
}
sb.append(number);
if (parentheses) {
sb.append(")");
}
}
return sb.toString();
return WfContextUtil.getCompleteStageInfo(task.getWorkflowContext());
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 0dfd3a9

Please sign in to comment.