use of com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto in project midpoint by Evolveum.
the class PreviewChangesTabPanel method initModels.
private void initModels() {
final List<ObjectDelta<? extends ObjectType>> primaryDeltas = new ArrayList<>();
final List<ObjectDelta<? extends ObjectType>> secondaryDeltas = new ArrayList<>();
final List<? extends Scene> primaryScenes;
final List<? extends Scene> secondaryScenes;
ModelContext<O> modelContext = getModelObject();
try {
if (modelContext != null) {
if (modelContext.getFocusContext() != null) {
addIgnoreNull(primaryDeltas, CloneUtil.clone(modelContext.getFocusContext().getPrimaryDelta()));
ObjectDelta<O> summarySecondaryDelta = CloneUtil.clone(modelContext.getFocusContext().getSummarySecondaryDelta());
if (summarySecondaryDelta != null && !summarySecondaryDelta.getModifications().isEmpty()) {
secondaryDeltas.add(summarySecondaryDelta);
}
}
for (ModelProjectionContext projCtx : modelContext.getProjectionContexts()) {
ObjectDelta<ShadowType> primaryDelta = CloneUtil.clone(projCtx.getPrimaryDelta());
addIgnoreNull(primaryDeltas, primaryDelta);
if (!isEquivalentWithoutOperationAttr(primaryDelta, CloneUtil.clone(projCtx.getExecutableDelta()))) {
addIgnoreNull(secondaryDeltas, CloneUtil.clone(projCtx.getExecutableDelta()));
}
}
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Primary deltas:\n{}", DebugUtil.debugDump(primaryDeltas));
LOGGER.trace("Secondary deltas:\n{}", DebugUtil.debugDump(secondaryDeltas));
}
Task task = getPageBase().createSimpleTask("visualize");
primaryScenes = getPageBase().getModelInteractionService().visualizeDeltas(primaryDeltas, task, task.getResult());
secondaryScenes = getPageBase().getModelInteractionService().visualizeDeltas(secondaryDeltas, task, task.getResult());
} catch (SchemaException | ExpressionEvaluationException e) {
// TODO
throw new SystemException(e);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Creating context DTO for primary deltas:\n{}", DebugUtil.debugDump(primaryScenes));
LOGGER.trace("Creating context DTO for secondary deltas:\n{}", DebugUtil.debugDump(secondaryScenes));
}
final WrapperScene primaryScene = new WrapperScene(primaryScenes, primaryScenes.size() != 1 ? "PagePreviewChanges.primaryChangesMore" : "PagePreviewChanges.primaryChangesOne", primaryScenes.size());
final WrapperScene secondaryScene = new WrapperScene(secondaryScenes, secondaryScenes.size() != 1 ? "PagePreviewChanges.secondaryChangesMore" : "PagePreviewChanges.secondaryChangesOne", secondaryScenes.size());
final SceneDto primarySceneDto = new SceneDto(primaryScene);
final SceneDto secondarySceneDto = new SceneDto(secondaryScene);
primaryDeltasModel = (IModel<SceneDto>) () -> primarySceneDto;
secondaryDeltasModel = (IModel<SceneDto>) () -> secondarySceneDto;
PolicyRuleEnforcerPreviewOutputType enforcements = modelContext != null ? modelContext.getPolicyRuleEnforcerPreviewOutput() : null;
List<EvaluatedTriggerGroupDto> triggerGroups = enforcements != null ? Collections.singletonList(EvaluatedTriggerGroupDto.initializeFromRules(enforcements.getRule(), false, null)) : Collections.emptyList();
policyViolationsModel = Model.ofList(triggerGroups);
List<ApprovalSchemaExecutionInformationType> approvalsExecutionList = modelContext != null ? modelContext.getHookPreviewResults(ApprovalSchemaExecutionInformationType.class) : Collections.emptyList();
List<ApprovalProcessExecutionInformationDto> approvals = new ArrayList<>();
if (!approvalsExecutionList.isEmpty()) {
// TODO
Task opTask = getPageBase().createSimpleTask(PagePreviewChanges.class + ".createApprovals");
OperationResult result = opTask.getResult();
ObjectResolver modelObjectResolver = getPageBase().getModelObjectResolver();
try {
for (ApprovalSchemaExecutionInformationType execution : approvalsExecutionList) {
approvals.add(ApprovalProcessExecutionInformationDto.createFrom(execution, modelObjectResolver, true, opTask, // TODO reuse session
result));
}
result.computeStatus();
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare approval information", t);
result.recordFatalError(createStringResource("PreviewChangesTabPanel.message.prepareApproval.fatalError", t.getMessage()).getString(), t);
}
if (WebComponentUtil.showResultInPage(result)) {
getPageBase().showResult(result);
}
}
approvalsModel = Model.ofList(approvals);
}
use of com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto in project midpoint by Evolveum.
the class ApprovalProcessesPreviewPanel method initLayout.
private void initLayout() {
ListView<ApprovalProcessExecutionInformationDto> list = new ListView<ApprovalProcessExecutionInformationDto>(ID_PROCESSES, getModel()) {
@Override
protected void populateItem(ListItem<ApprovalProcessExecutionInformationDto> item) {
item.add(new Label(ID_NAME, LoadableModel.create(() -> {
String targetName = item.getModelObject().getTargetName();
if (targetName != null) {
return ApprovalProcessesPreviewPanel.this.getString("ApprovalProcessesPreviewPanel.processRelatedTo", targetName);
} else {
return getString("ApprovalProcessesPreviewPanel.process");
}
}, false)));
item.add(new ApprovalProcessExecutionInformationPanel(ID_PREVIEW, item.getModel()));
item.add(new EvaluatedTriggerGroupPanel(ID_TRIGGERS, new PropertyModel<>(item.getModel(), ApprovalProcessExecutionInformationDto.F_TRIGGERS)));
}
};
add(list);
}
use of com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto in project midpoint by Evolveum.
the class ApprovalProcessExecutionInformationPanelTextOnly method initLayout.
protected void initLayout() {
add(new TextAreaPanel<>(ID_TEXT, new IModel<String>() {
@Override
public String getObject() {
ApprovalProcessExecutionInformationDto processInfo = getModelObject();
if (processInfo == null) {
return null;
}
int currentStageNumber = processInfo.getCurrentStageNumber();
int numberOfStages = processInfo.getNumberOfStages();
StringBuilder sb = new StringBuilder();
List<ApprovalStageExecutionInformationDto> stages = processInfo.getStages();
for (ApprovalStageExecutionInformationDto stageInfo : stages) {
if (stageInfo.getStageNumber() == currentStageNumber) {
sb.append("====> ");
}
sb.append(stageInfo.getNiceStageName(numberOfStages));
sb.append(" ");
if (stageInfo.getAutomatedOutcome() != null) {
sb.append("[").append(stageInfo.getAutomatedOutcome()).append("] because of ").append(// the reason is localizable
stageInfo.getAutomatedCompletionReason());
} else {
for (ApproverEngagementDto engagement : stageInfo.getApproverEngagements()) {
sb.append("[").append(WebComponentUtil.getDisplayNameOrName(engagement.getApproverRef())).append("] ");
if (engagement.getOutput() != null) {
sb.append("(").append(ApprovalUtils.fromUri(engagement.getOutput().getOutcome()));
if (engagement.getCompletedBy() != null && !ObjectTypeUtil.matchOnOid(engagement.getApproverRef(), engagement.getCompletedBy())) {
sb.append(" by ").append(WebComponentUtil.getDisplayNameOrName(engagement.getCompletedBy()));
}
sb.append(") ");
} else {
sb.append("(?) ");
}
}
}
sb.append("\n");
}
return sb.toString();
}
}, 8));
}
use of com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto 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);
}
use of com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto in project midpoint by Evolveum.
the class PreviewChangesTabPanel method initModels.
private void initModels() {
final List<ObjectDelta<? extends ObjectType>> primaryDeltas = new ArrayList<>();
final List<ObjectDelta<? extends ObjectType>> secondaryDeltas = new ArrayList<>();
final List<? extends Scene> primaryScenes;
final List<? extends Scene> secondaryScenes;
ModelContext<O> modelContext = getModelObject();
try {
if (modelContext != null) {
if (modelContext.getFocusContext() != null) {
addIgnoreNull(primaryDeltas, CloneUtil.clone(modelContext.getFocusContext().getPrimaryDelta()));
ObjectDelta<O> summarySecondaryDelta = CloneUtil.clone(modelContext.getFocusContext().getSummarySecondaryDelta());
if (summarySecondaryDelta != null && !summarySecondaryDelta.getModifications().isEmpty()) {
secondaryDeltas.add(summarySecondaryDelta);
}
}
for (ModelProjectionContext projCtx : modelContext.getProjectionContexts()) {
ObjectDelta<ShadowType> primaryDelta = CloneUtil.clone(projCtx.getPrimaryDelta());
addIgnoreNull(primaryDeltas, primaryDelta);
if (!isEquivalentWithoutOperationAttr(primaryDelta, CloneUtil.clone(projCtx.getExecutableDelta()))) {
addIgnoreNull(secondaryDeltas, CloneUtil.clone(projCtx.getExecutableDelta()));
}
}
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Primary deltas:\n{}", DebugUtil.debugDump(primaryDeltas));
LOGGER.trace("Secondary deltas:\n{}", DebugUtil.debugDump(secondaryDeltas));
}
Task task = getPageBase().createSimpleTask("visualize");
primaryScenes = getPageBase().getModelInteractionService().visualizeDeltas(primaryDeltas, task, task.getResult());
secondaryScenes = getPageBase().getModelInteractionService().visualizeDeltas(secondaryDeltas, task, task.getResult());
} catch (SchemaException | ExpressionEvaluationException e) {
// TODO
throw new SystemException(e);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Creating context DTO for primary deltas:\n{}", DebugUtil.debugDump(primaryScenes));
LOGGER.trace("Creating context DTO for secondary deltas:\n{}", DebugUtil.debugDump(secondaryScenes));
}
final WrapperScene primaryScene = new WrapperScene(primaryScenes, primaryScenes.size() != 1 ? "PagePreviewChanges.primaryChangesMore" : "PagePreviewChanges.primaryChangesOne", primaryScenes.size());
final WrapperScene secondaryScene = new WrapperScene(secondaryScenes, secondaryScenes.size() != 1 ? "PagePreviewChanges.secondaryChangesMore" : "PagePreviewChanges.secondaryChangesOne", secondaryScenes.size());
final SceneDto primarySceneDto = new SceneDto(primaryScene);
final SceneDto secondarySceneDto = new SceneDto(secondaryScene);
primaryDeltasModel = (IModel<SceneDto>) () -> primarySceneDto;
secondaryDeltasModel = (IModel<SceneDto>) () -> secondarySceneDto;
PolicyRuleEnforcerPreviewOutputType enforcements = modelContext != null ? modelContext.getPolicyRuleEnforcerPreviewOutput() : null;
List<EvaluatedTriggerGroupDto> triggerGroups = enforcements != null ? Collections.singletonList(EvaluatedTriggerGroupDto.initializeFromRules(enforcements.getRule(), false, null)) : Collections.emptyList();
policyViolationsModel = Model.ofList(triggerGroups);
List<ApprovalSchemaExecutionInformationType> approvalsExecutionList = modelContext != null ? modelContext.getHookPreviewResults(ApprovalSchemaExecutionInformationType.class) : Collections.emptyList();
List<ApprovalProcessExecutionInformationDto> approvals = new ArrayList<>();
if (!approvalsExecutionList.isEmpty()) {
// TODO
Task opTask = getPageBase().createSimpleTask(PageFocusPreviewChanges.class + ".createApprovals");
OperationResult result = opTask.getResult();
ObjectResolver modelObjectResolver = getPageBase().getModelObjectResolver();
try {
for (ApprovalSchemaExecutionInformationType execution : approvalsExecutionList) {
approvals.add(ApprovalProcessExecutionInformationDto.createFrom(execution, modelObjectResolver, true, opTask, // TODO reuse session
result));
}
result.computeStatus();
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare approval information", t);
result.recordFatalError(createStringResource("PreviewChangesTabPanel.message.prepareApproval.fatalError", t.getMessage()).getString(), t);
}
if (WebComponentUtil.showResultInPage(result)) {
getPageBase().showResult(result);
}
}
approvalsModel = Model.ofList(approvals);
}
Aggregations