Search in sources :

Example 1 with ApprovalOutcomeIcon

use of com.evolveum.midpoint.web.page.admin.server.dto.ApprovalOutcomeIcon in project midpoint by Evolveum.

the class ApprovalProcessExecutionInformationPanel method initLayout.

protected void initLayout() {
    // TODO clean this code up!!!
    ListView<ApprovalStageExecutionInformationDto> stagesList = new ListView<ApprovalStageExecutionInformationDto>(ID_STAGES, new PropertyModel<>(getModel(), ApprovalProcessExecutionInformationDto.F_STAGES)) {

        @Override
        protected void populateItem(ListItem<ApprovalStageExecutionInformationDto> stagesListItem) {
            ApprovalProcessExecutionInformationDto process = ApprovalProcessExecutionInformationPanel.this.getModelObject();
            ApprovalStageExecutionInformationDto stage = stagesListItem.getModelObject();
            int stageNumber = stage.getStageNumber();
            int numberOfStages = process.getNumberOfStages();
            int currentStageNumber = process.getCurrentStageNumber();
            WebMarkupContainer arrow = new WebMarkupContainer(ID_ARROW);
            arrow.add(new VisibleBehaviour(() -> stageNumber > 1));
            stagesListItem.add(arrow);
            WebMarkupContainer currentStageMarker = new WebMarkupContainer(ID_CURRENT_STAGE_MARKER);
            currentStageMarker.add(new VisibleBehaviour(() -> stageNumber == currentStageNumber && process.isRunning()));
            stagesListItem.add(currentStageMarker);
            ListView<ApproverEngagementDto> approversList = new ListView<ApproverEngagementDto>(ID_APPROVERS, new PropertyModel<>(stagesListItem.getModel(), ApprovalStageExecutionInformationDto.F_APPROVER_ENGAGEMENTS)) {

                @Override
                protected void populateItem(ListItem<ApproverEngagementDto> approversListItem) {
                    ApproverEngagementDto ae = approversListItem.getModelObject();
                    // original approver name
                    approversListItem.add(createReferencedObjectLabel(ID_APPROVER_NAME, "ApprovalProcessExecutionInformationPanel.approver", ae.getApproverRef(), true));
                    // outcome
                    WorkItemOutcomeType outcome = ae.getOutput() != null ? ApprovalUtils.fromUri(ae.getOutput().getOutcome()) : null;
                    ApprovalOutcomeIcon outcomeIcon;
                    if (outcome != null) {
                        switch(outcome) {
                            case APPROVE:
                                outcomeIcon = ApprovalOutcomeIcon.APPROVED;
                                break;
                            case REJECT:
                                outcomeIcon = ApprovalOutcomeIcon.REJECTED;
                                break;
                            // perhaps should throw AssertionError instead
                            default:
                                outcomeIcon = ApprovalOutcomeIcon.UNKNOWN;
                                break;
                        }
                    } else {
                        if (stageNumber < currentStageNumber) {
                            // history: do not show anything for work items with no outcome
                            outcomeIcon = ApprovalOutcomeIcon.EMPTY;
                        } else if (stageNumber == currentStageNumber) {
                            outcomeIcon = process.isRunning() && stage.isReachable() ? ApprovalOutcomeIcon.IN_PROGRESS : // currently open
                            ApprovalOutcomeIcon.CANCELLED;
                        } else {
                            outcomeIcon = process.isRunning() && stage.isReachable() ? ApprovalOutcomeIcon.FUTURE : ApprovalOutcomeIcon.CANCELLED;
                        }
                    }
                    ImagePanel outcomePanel = new ImagePanel(ID_OUTCOME, Model.of(outcomeIcon.getIcon()), Model.of(getString(outcomeIcon.getTitle())));
                    outcomePanel.add(new VisibleBehaviour(() -> outcomeIcon != ApprovalOutcomeIcon.EMPTY));
                    approversListItem.add(outcomePanel);
                    // content (incl. performer)
                    WebMarkupContainer approvalBoxContent = new WebMarkupContainer(ID_APPROVAL_BOX_CONTENT);
                    approversListItem.add(approvalBoxContent);
                    approvalBoxContent.setVisible(performerVisible(ae) || attorneyVisible(ae));
                    approvalBoxContent.add(createReferencedObjectLabel(ID_PERFORMER_NAME, "ApprovalProcessExecutionInformationPanel.performer", ae.getCompletedBy(), performerVisible(ae)));
                    approvalBoxContent.add(createReferencedObjectLabel(ID_ATTORNEY_NAME, "ApprovalProcessExecutionInformationPanel.attorney", ae.getAttorney(), attorneyVisible(ae)));
                    // junction
                    // or "+" for first decides? probably not
                    Label junctionLabel = new Label(ID_JUNCTION, stage.isFirstDecides() ? "" : " & ");
                    // not showing "" to save space (if aligned vertically)
                    junctionLabel.setVisible(!stage.isFirstDecides() && !ae.isLast());
                    approversListItem.add(junctionLabel);
                }
            };
            approversList.setVisible(stage.getAutomatedCompletionReason() == null);
            stagesListItem.add(approversList);
            String autoCompletionKey;
            if (stage.getAutomatedCompletionReason() != null) {
                switch(stage.getAutomatedCompletionReason()) {
                    case AUTO_COMPLETION_CONDITION:
                        autoCompletionKey = "DecisionDto.AUTO_COMPLETION_CONDITION";
                        break;
                    case NO_ASSIGNEES_FOUND:
                        autoCompletionKey = "DecisionDto.NO_ASSIGNEES_FOUND";
                        break;
                    // or throw an exception?
                    default:
                        autoCompletionKey = null;
                }
            } else {
                autoCompletionKey = null;
            }
            Label automatedOutcomeLabel = new Label(ID_AUTOMATED_OUTCOME, autoCompletionKey != null ? getString(autoCompletionKey) : "");
            automatedOutcomeLabel.setVisible(stage.getAutomatedCompletionReason() != null);
            stagesListItem.add(automatedOutcomeLabel);
            stagesListItem.add(new Label(ID_STAGE_NAME, getStageNameLabel(stage, stageNumber, numberOfStages)));
            ApprovalLevelOutcomeType stageOutcome = stage.getOutcome();
            ApprovalOutcomeIcon stageOutcomeIcon;
            if (stageOutcome != null) {
                switch(stageOutcome) {
                    case APPROVE:
                        stageOutcomeIcon = ApprovalOutcomeIcon.APPROVED;
                        break;
                    case REJECT:
                        stageOutcomeIcon = ApprovalOutcomeIcon.REJECTED;
                        break;
                    case SKIP:
                        stageOutcomeIcon = ApprovalOutcomeIcon.SKIPPED;
                        break;
                    // perhaps should throw AssertionError instead
                    default:
                        stageOutcomeIcon = ApprovalOutcomeIcon.UNKNOWN;
                        break;
                }
            } else {
                if (stageNumber < currentStageNumber) {
                    // history: do not show anything (shouldn't occur, as historical stages are filled in)
                    stageOutcomeIcon = ApprovalOutcomeIcon.EMPTY;
                } else if (stageNumber == currentStageNumber) {
                    stageOutcomeIcon = process.isRunning() && stage.isReachable() ? ApprovalOutcomeIcon.IN_PROGRESS : // currently open
                    ApprovalOutcomeIcon.CANCELLED;
                } else {
                    stageOutcomeIcon = process.isRunning() && stage.isReachable() ? ApprovalOutcomeIcon.FUTURE : ApprovalOutcomeIcon.CANCELLED;
                }
            }
            ImagePanel stageOutcomePanel = new ImagePanel(ID_STAGE_OUTCOME, Model.of(stageOutcomeIcon.getIcon()), Model.of(getString(stageOutcomeIcon.getTitle())));
            stageOutcomePanel.add(new VisibleBehaviour(() -> stageOutcomeIcon != ApprovalOutcomeIcon.EMPTY));
            stagesListItem.add(stageOutcomePanel);
        }
    };
    add(stagesList);
}
Also used : ApproverEngagementDto(com.evolveum.midpoint.web.page.admin.workflow.dto.ApproverEngagementDto) ApprovalStageExecutionInformationDto(com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalStageExecutionInformationDto) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ApprovalProcessExecutionInformationDto(com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto) ListView(org.apache.wicket.markup.html.list.ListView) ApprovalLevelOutcomeType(com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalLevelOutcomeType) WorkItemOutcomeType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemOutcomeType) ApprovalOutcomeIcon(com.evolveum.midpoint.web.page.admin.server.dto.ApprovalOutcomeIcon) ListItem(org.apache.wicket.markup.html.list.ListItem) ImagePanel(com.evolveum.midpoint.web.component.data.column.ImagePanel)

Aggregations

ImagePanel (com.evolveum.midpoint.web.component.data.column.ImagePanel)1 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)1 ApprovalOutcomeIcon (com.evolveum.midpoint.web.page.admin.server.dto.ApprovalOutcomeIcon)1 ApprovalProcessExecutionInformationDto (com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto)1 ApprovalStageExecutionInformationDto (com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalStageExecutionInformationDto)1 ApproverEngagementDto (com.evolveum.midpoint.web.page.admin.workflow.dto.ApproverEngagementDto)1 ApprovalLevelOutcomeType (com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalLevelOutcomeType)1 WorkItemOutcomeType (com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemOutcomeType)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 Label (org.apache.wicket.markup.html.basic.Label)1 ListItem (org.apache.wicket.markup.html.list.ListItem)1 ListView (org.apache.wicket.markup.html.list.ListView)1