Search in sources :

Example 1 with CaseWorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.

the class TestPolicyDrivenRoleLifecycle method test070ActivateCorrectHighRiskRole.

@Test
public void test070ActivateCorrectHighRiskRole() throws Exception {
    // GIVEN
    Task task = getTestTask();
    task.setOwner(userAdministrator.asPrismObject());
    OperationResult result = task.getResult();
    // WHEN
    when();
    Holder<LensContext<?>> contextHolder = new Holder<>();
    activateRole(roleCorrectHighRiskOid, contextHolder, task, result);
    // THEN
    then();
    PrismObject<RoleType> roleAfter = getRole(roleCorrectHighRiskOid);
    display("role after", roleAfter);
    assertEquals("Wrong (changed) lifecycle state", SchemaConstants.LIFECYCLE_DRAFT, roleAfter.asObjectable().getLifecycleState());
    dumpRules(contextHolder);
    assertEquals("Wrong policy situation", emptyList(), roleAfter.asObjectable().getPolicySituation());
    assertEquals("Wrong triggered policy rules", emptyList(), roleAfter.asObjectable().getTriggeredPolicyRule());
    Collection<SelectorOptions<GetOperationOptions>> options = schemaService.getOperationOptionsBuilder().build();
    List<PrismObject<CaseType>> cases = getCasesForObject(roleCorrectHighRiskOid, RoleType.COMPLEX_TYPE, options, task, result);
    display("cases for role", cases);
    assertEquals("Wrong # of approval cases for role", 2, cases.size());
    CaseType approvalCase = getApprovalCase(cases);
    ApprovalContextType wfc = approvalCase.getApprovalContext();
    // assertEquals("Modification of correct-high-risk", wfc.getProcessInstanceName());             // MID-4200
    assertEquals("wrong # of work items", 1, approvalCase.getWorkItem().size());
    CaseWorkItemType workItem = approvalCase.getWorkItem().get(0);
    assertEquals("wrong # of approval stages", 2, wfc.getApprovalSchema().getStage().size());
    assertEquals("wrong # of attached policy rules", 2, wfc.getPolicyRules().getEntry().size());
    caseService.completeWorkItem(WorkItemId.of(workItem), ApprovalUtils.createApproveOutput(prismContext), task, result);
    approvalCase = modelService.getObject(CaseType.class, approvalCase.getOid(), options, task, result).asObjectable();
    List<CaseWorkItemType> openWorkItems = approvalCase.getWorkItem().stream().filter(i -> i.getCloseTimestamp() == null).collect(Collectors.toList());
    assertEquals("wrong # of open work items", 1, openWorkItems.size());
    workItem = openWorkItems.get(0);
    caseService.completeWorkItem(WorkItemId.of(workItem), ApprovalUtils.createApproveOutput(prismContext), task, result);
    CaseType rootCase = getRootCase(cases);
    waitForCaseClose(rootCase, 60000);
    PrismObject<RoleType> roleAfterApproval = getRole(roleCorrectHighRiskOid);
    display("role after approval", roleAfterApproval);
    assertEquals("Wrong (unchanged) lifecycle state", SchemaConstants.LIFECYCLE_ACTIVE, roleAfterApproval.asObjectable().getLifecycleState());
    assertEquals("Wrong policy situation", singletonList(SITUATION_ACTIVE_ROLE_WITH_NO_IDENTIFIER), roleAfterApproval.asObjectable().getPolicySituation());
    // recording rules = none
    assertEquals("Wrong triggered policy rules", emptyList(), roleAfterApproval.asObjectable().getTriggeredPolicyRule());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.testng.annotations.Test) DebugUtil(com.evolveum.midpoint.util.DebugUtil) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) AbstractUninitializedCertificationTest(com.evolveum.midpoint.certification.test.AbstractUninitializedCertificationTest) Collections.singletonList(java.util.Collections.singletonList) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) Collections.singleton(java.util.Collections.singleton) PrismContext(com.evolveum.midpoint.prism.PrismContext) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) ApprovalUtils(com.evolveum.midpoint.schema.util.cases.ApprovalUtils) CaseService(com.evolveum.midpoint.model.api.CaseService) RecordingProgressListener(com.evolveum.midpoint.model.impl.util.RecordingProgressListener) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Holder(com.evolveum.midpoint.util.Holder) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) WorkItemId(com.evolveum.midpoint.schema.util.WorkItemId) File(java.io.File) TestResource(com.evolveum.midpoint.test.TestResource) List(java.util.List) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NotNull(org.jetbrains.annotations.NotNull) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) SKIP(com.evolveum.midpoint.xml.ns._public.common.common_3.PartialProcessingTypeType.SKIP) Task(com.evolveum.midpoint.task.api.Task) Holder(com.evolveum.midpoint.util.Holder) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Test(org.testng.annotations.Test) AbstractUninitializedCertificationTest(com.evolveum.midpoint.certification.test.AbstractUninitializedCertificationTest)

Example 2 with CaseWorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.

the class CaseStageClosing method determineIfShouldContinue.

private boolean determineIfShouldContinue() {
    if (stageDef.getEvaluationStrategy() == LevelEvaluationStrategyType.FIRST_DECIDES) {
        if (differentOutcomes.size() > 1) {
            LOGGER.warn("Ambiguous outcome with firstDecides strategy in {}: {} response(s), providing outcomes of {}", ApprovalContextUtil.getBriefDiagInfo(operation.getCurrentCase()), answeredWorkItems.size(), differentOutcomes);
            answeredWorkItems.sort(Comparator.comparing(item -> XmlTypeConverter.toMillis(item.getCloseTimestamp()), Comparator.nullsLast(Comparator.naturalOrder())));
            CaseWorkItemType first = answeredWorkItems.get(0);
            boolean shouldContinue = ApprovalUtils.isApproved(first.getOutput());
            LOGGER.warn("Possible race condition, so taking the first one: {} ({})", shouldContinue, first);
            return shouldContinue;
        } else if (differentOutcomes.size() == 1) {
            return ApprovalUtils.isApproved(differentOutcomes.iterator().next()) && !differentOutcomes.isEmpty();
        } else {
            throw new IllegalStateException("No outcomes?");
        }
    } else {
        return allApproved && !answeredWorkItems.isEmpty();
    }
}
Also used : java.util(java.util) CaseEngineOperation(com.evolveum.midpoint.cases.api.CaseEngineOperation) Trace(com.evolveum.midpoint.util.logging.Trace) Collectors(java.util.stream.Collectors) CaseWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType) ApprovalBeans(com.evolveum.midpoint.wf.impl.ApprovalBeans) StageClosingResult(com.evolveum.midpoint.cases.api.extensions.StageClosingResult) LevelEvaluationStrategyType(com.evolveum.midpoint.xml.ns._public.common.common_3.LevelEvaluationStrategyType) ApprovalContextUtil(com.evolveum.midpoint.schema.util.cases.ApprovalContextUtil) ApprovalUtils(com.evolveum.midpoint.schema.util.cases.ApprovalUtils) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) CaseWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType)

Example 3 with CaseWorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.

the class CaseStageClosing method analyzeOutcomes.

private void analyzeOutcomes() {
    allApproved = true;
    for (CaseWorkItemType workItem : currentWorkItems) {
        allApproved &= ApprovalUtils.isApproved(workItem.getOutput());
        if (workItem.getCloseTimestamp() != null && workItem.getPerformerRef() != null) {
            answeredWorkItems.add(workItem);
            differentOutcomes.add(workItem.getOutput() != null ? workItem.getOutput().getOutcome() : null);
        }
    }
}
Also used : CaseWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType)

Example 4 with CaseWorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.

the class CaseWorkItemSummaryPanel method getDisplayNameModel.

@Override
protected IModel<String> getDisplayNameModel() {
    return new ReadOnlyModel<>(() -> {
        CaseWorkItemType caseWorkItemType = CaseWorkItemSummaryPanel.this.getModelObject();
        CaseType caseType = CaseTypeUtil.getCase(caseWorkItemType);
        return defaultIfNull(WfGuiUtil.getLocalizedProcessName(caseType != null ? caseType.getApprovalContext() : null, CaseWorkItemSummaryPanel.this), caseWorkItemType != null ? WebComponentUtil.getTranslatedPolyString(caseWorkItemType.getName()) : null);
    });
}
Also used : ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) CaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType) CaseWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType)

Example 5 with CaseWorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.

the class CaseWorkItemSummaryPanel method getTitleModel.

@Override
protected IModel<String> getTitleModel() {
    return new IModel<String>() {

        @Override
        public String getObject() {
            CaseWorkItemType caseWorkItemType = CaseWorkItemSummaryPanel.this.getModelObject();
            CaseType caseType = CaseTypeUtil.getCase(caseWorkItemType);
            Task task = CaseWorkItemSummaryPanel.this.getPageBase().createSimpleTask(OPERATION_LOAD_REQUESTOR_REFERENCE);
            OperationResult result = new OperationResult(OPERATION_LOAD_REQUESTOR_REFERENCE);
            PrismObject<UserType> requester = caseType != null ? WebModelServiceUtils.resolveReferenceNoFetch(caseType.getRequestorRef(), CaseWorkItemSummaryPanel.this.getPageBase(), task, result) : null;
            if (requester == null) {
                // MID-4539 if we don't have authorization to see requester
                return getString("TaskSummaryPanel.requestedBy", getString("TaskSummaryPanel.unknown"));
            }
            String displayName = WebComponentUtil.getDisplayName(requester, true);
            String name = WebComponentUtil.getName(requester, true);
            if (displayName != null) {
                return getString("TaskSummaryPanel.requestedByWithFullName", displayName, name);
            } else {
                return getString("TaskSummaryPanel.requestedBy", name);
            }
        }
    };
}
Also used : IModel(org.apache.wicket.model.IModel) Task(com.evolveum.midpoint.task.api.Task) CaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CaseWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

CaseWorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 Task (com.evolveum.midpoint.task.api.Task)11 List (java.util.List)8 Test (org.testng.annotations.Test)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)6 CaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType)6 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)5 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)5 Collectors (java.util.stream.Collectors)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)5 QName (javax.xml.namespace.QName)4 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)3 File (java.io.File)3 Collection (java.util.Collection)3 NotNull (org.jetbrains.annotations.NotNull)3 DirtiesContext (org.springframework.test.annotation.DirtiesContext)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3 CaseEngineOperation (com.evolveum.midpoint.cases.api.CaseEngineOperation)2