Search in sources :

Example 41 with AccessCertificationCampaignType

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

the class TestCriticalRolesCertification method test900StartRemediation.

@Test
public void test900StartRemediation() throws Exception {
    final String TEST_NAME = "test900StartRemediation";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestCriticalRolesCertification.class.getName() + "." + TEST_NAME);
    task.setOwner(userAdministrator.asPrismObject());
    OperationResult result = task.getResult();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    certificationManager.startRemediation(campaignOid, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertInProgressOrSuccess(result);
    AccessCertificationCampaignType campaign = getCampaignWithCases(campaignOid);
    display("campaign after remediation start", campaign);
    assertTrue("wrong campaign state: " + campaign.getState(), campaign.getState() == CLOSED || campaign.getState() == IN_REMEDIATION);
    ObjectQuery query = QueryBuilder.queryFor(TaskType.class, prismContext).item(TaskType.F_OBJECT_REF).ref(campaign.getOid()).build();
    List<PrismObject<TaskType>> tasks = taskManager.searchObjects(TaskType.class, query, null, result);
    assertEquals("unexpected number of related tasks", 1, tasks.size());
    waitForTaskFinish(tasks.get(0).getOid(), true);
    campaign = getCampaignWithCases(campaignOid);
    assertEquals("wrong campaign state", CLOSED, campaign.getState());
    assertEquals("wrong campaign stage", 5, campaign.getStageNumber());
    assertDefinitionAndOwner(campaign, certificationDefinition);
    assertApproximateTime("end time", new Date(), campaign.getEndTimestamp());
    assertEquals("wrong # of stages", 4, campaign.getStage().size());
    List<AccessCertificationCaseType> caseList = queryHelper.searchCases(campaignOid, null, null, result);
    assertEquals("wrong # of cases", 6, caseList.size());
    AccessCertificationCaseType elaineCeoCase = findCase(caseList, USER_ELAINE_OID, ROLE_CEO_OID);
    AccessCertificationCaseType guybrushCooCase = findCase(caseList, USER_GUYBRUSH_OID, ROLE_COO_OID);
    assertNull("elaineCeoCase.remediedTimestamp", elaineCeoCase.getRemediedTimestamp());
    assertApproximateTime("guybrushCooCase.remediedTimestamp", new Date(), guybrushCooCase.getRemediedTimestamp());
    userElaine = getUser(USER_ELAINE_OID).asObjectable();
    display("userElaine", userElaine);
    assertEquals("wrong # of userElaine's assignments", 5, userElaine.getAssignment().size());
    userGuybrush = getUser(USER_GUYBRUSH_OID).asObjectable();
    display("userGuybrush", userGuybrush);
    assertEquals("wrong # of userGuybrush's assignments", 2, userGuybrush.getAssignment().size());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) Task(com.evolveum.midpoint.task.api.Task) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Date(java.util.Date) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType) Test(org.testng.annotations.Test)

Example 42 with AccessCertificationCampaignType

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

the class TestCriticalRolesCertification method test010CreateCampaign.

@Test
public void test010CreateCampaign() throws Exception {
    final String TEST_NAME = "test010CreateCampaign";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestCriticalRolesCertification.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    certificationDefinition = repoAddObjectFromFile(CERT_DEF_FILE, AccessCertificationDefinitionType.class, result).asObjectable();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    AccessCertificationCampaignType campaign = certificationManager.createCampaign(certificationDefinition.getOid(), task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull("Created campaign is null", campaign);
    campaignOid = campaign.getOid();
    campaign = getCampaignWithCases(campaignOid);
    display("campaign", campaign);
    assertAfterCampaignCreate(campaign, certificationDefinition);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType) Test(org.testng.annotations.Test)

Example 43 with AccessCertificationCampaignType

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

the class CertificationManagerImpl method closeCurrentStage.

@Override
public void closeCurrentStage(String campaignOid, int stageNumberToClose, Task task, OperationResult parentResult) throws SchemaException, SecurityViolationException, ObjectNotFoundException, ObjectAlreadyExistsException {
    Validate.notNull(campaignOid, "campaignOid");
    Validate.notNull(task, "task");
    Validate.notNull(parentResult, "parentResult");
    OperationResult result = parentResult.createSubresult(OPERATION_CLOSE_CURRENT_STAGE);
    result.addParam("campaignOid", campaignOid);
    result.addParam("stageNumber", stageNumberToClose);
    try {
        AccessCertificationCampaignType campaign = generalHelper.getCampaign(campaignOid, null, task, result);
        result.addParam("campaign", ObjectTypeUtil.toShortString(campaign));
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("closeCurrentStage starting for {}", ObjectTypeUtil.toShortString(campaign));
        }
        securityEnforcer.authorize(ModelAuthorizationAction.CLOSE_CERTIFICATION_CAMPAIGN_REVIEW_STAGE.getUrl(), null, campaign.asPrismObject(), null, null, null, result);
        final int currentStageNumber = campaign.getStageNumber();
        final int stages = CertCampaignTypeUtil.getNumberOfStages(campaign);
        final AccessCertificationCampaignStateType state = campaign.getState();
        LOGGER.trace("closeCurrentStage: currentStageNumber={}, stages={}, stageNumberToClose={}, state={}", currentStageNumber, stages, stageNumberToClose, state);
        if (stageNumberToClose != currentStageNumber) {
            result.recordFatalError("Couldn't close review stage " + stageNumberToClose + " as the campaign is not in that stage");
        } else if (!IN_REVIEW_STAGE.equals(state)) {
            result.recordFatalError("Couldn't close review stage " + stageNumberToClose + " as it is currently not open");
        } else {
            List<ItemDelta<?, ?>> deltas = updateHelper.getDeltasForStageClose(campaign, result);
            updateHelper.modifyObjectViaModel(AccessCertificationCampaignType.class, campaignOid, deltas, task, result);
            updateHelper.afterStageClose(campaignOid, task, result);
        }
    } catch (RuntimeException e) {
        result.recordFatalError("Couldn't close certification campaign stage " + stageNumberToClose + ": unexpected exception: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AccessCertificationCampaignStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType)

Example 44 with AccessCertificationCampaignType

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

the class CertificationManagerImpl method startRemediation.

@Override
public void startRemediation(String campaignOid, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, SecurityViolationException, ObjectAlreadyExistsException {
    Validate.notNull(campaignOid, "campaignOid");
    Validate.notNull(task, "task");
    Validate.notNull(parentResult, "parentResult");
    OperationResult result = parentResult.createSubresult(OPERATION_CLOSE_CURRENT_STAGE);
    result.addParam("campaignOid", campaignOid);
    try {
        AccessCertificationCampaignType campaign = generalHelper.getCampaign(campaignOid, null, task, result);
        result.addParam("campaign", ObjectTypeUtil.toShortString(campaign));
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("startRemediation starting for {}", ObjectTypeUtil.toShortString(campaign));
        }
        securityEnforcer.authorize(ModelAuthorizationAction.START_CERTIFICATION_REMEDIATION.getUrl(), null, campaign.asPrismObject(), null, null, null, result);
        final int currentStageNumber = campaign.getStageNumber();
        final int lastStageNumber = CertCampaignTypeUtil.getNumberOfStages(campaign);
        final AccessCertificationCampaignStateType state = campaign.getState();
        LOGGER.trace("startRemediation: currentStageNumber={}, stages={}, state={}", currentStageNumber, lastStageNumber, state);
        if (currentStageNumber != lastStageNumber) {
            result.recordFatalError("Couldn't start the remediation as the campaign is not in its last stage (" + lastStageNumber + "); current stage: " + currentStageNumber);
        } else if (!REVIEW_STAGE_DONE.equals(state)) {
            result.recordFatalError("Couldn't start the remediation as the last stage was not properly closed.");
        } else {
            List<ItemDelta<?, ?>> deltas = updateHelper.createDeltasForStageNumberAndState(lastStageNumber + 1, IN_REMEDIATION);
            updateHelper.modifyObjectViaModel(AccessCertificationCampaignType.class, campaignOid, deltas, task, result);
            if (CertCampaignTypeUtil.isRemediationAutomatic(campaign)) {
                remediationTaskHandler.launch(campaign, task, result);
            } else {
                result.recordWarning("The automated remediation is not configured. The campaign state was set to IN REMEDIATION, but all remediation actions have to be done by hand.");
            }
            campaign = updateHelper.refreshCampaign(campaign, result);
            eventHelper.onCampaignStageStart(campaign, task, result);
        }
    } catch (RuntimeException e) {
        result.recordFatalError("Couldn't start the remediation: unexpected exception: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AccessCertificationCampaignStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType)

Example 45 with AccessCertificationCampaignType

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

the class AccCertUpdateHelper method createDeltasToRecordStageOpen.

// some bureaucracy... stage#, state, start time, triggers
List<ItemDelta<?, ?>> createDeltasToRecordStageOpen(AccessCertificationCampaignType campaign, AccessCertificationStageType newStage) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
    final List<ItemDelta<?, ?>> itemDeltaList = new ArrayList<>();
    itemDeltaList.add(createStageNumberDelta(newStage.getNumber()));
    final PropertyDelta<AccessCertificationCampaignStateType> stateDelta = createStateDelta(IN_REVIEW_STAGE);
    itemDeltaList.add(stateDelta);
    final boolean campaignJustCreated = newStage.getNumber() == 1;
    if (campaignJustCreated) {
        PropertyDelta<XMLGregorianCalendar> startDelta = createStartTimeDelta(XmlTypeConverter.createXMLGregorianCalendar(new Date()));
        itemDeltaList.add(startDelta);
    }
    final XMLGregorianCalendar stageDeadline = newStage.getDeadline();
    if (stageDeadline != null) {
        // auto-closing and notifications triggers
        final AccessCertificationStageDefinitionType stageDef = CertCampaignTypeUtil.findStageDefinition(campaign, newStage.getNumber());
        List<TriggerType> triggers = new ArrayList<>();
        // pseudo-random ID so this trigger will not be deleted by trigger task handler (if this code itself is executed as part of previous trigger firing)
        // TODO implement this more seriously!
        long lastId = (long) (Math.random() * 1000000000);
        final TriggerType triggerClose = new TriggerType(prismContext);
        triggerClose.setHandlerUri(AccessCertificationCloseStageTriggerHandler.HANDLER_URI);
        triggerClose.setTimestamp(stageDeadline);
        triggerClose.setId(lastId);
        triggers.add(triggerClose);
        for (Duration beforeDeadline : stageDef.getNotifyBeforeDeadline()) {
            final XMLGregorianCalendar beforeEnd = CloneUtil.clone(stageDeadline);
            beforeEnd.add(beforeDeadline.negate());
            if (XmlTypeConverter.toMillis(beforeEnd) > System.currentTimeMillis()) {
                final TriggerType triggerBeforeEnd = new TriggerType(prismContext);
                triggerBeforeEnd.setHandlerUri(AccessCertificationCloseStageApproachingTriggerHandler.HANDLER_URI);
                triggerBeforeEnd.setTimestamp(beforeEnd);
                triggerBeforeEnd.setId(++lastId);
                triggers.add(triggerBeforeEnd);
            }
        }
        ContainerDelta<TriggerType> triggerDelta = ContainerDelta.createModificationReplace(ObjectType.F_TRIGGER, AccessCertificationCampaignType.class, prismContext, triggers);
        itemDeltaList.add(triggerDelta);
    }
    return itemDeltaList;
}
Also used : ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Duration(javax.xml.datatype.Duration) AccessCertificationCampaignStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)31 AccessCertificationCampaignType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)28 AccessCertificationCaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)27 Task (com.evolveum.midpoint.task.api.Task)22 Test (org.testng.annotations.Test)18 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 AccessCertificationCampaignStateType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType)5 Date (java.util.Date)5 CertificationHandler (com.evolveum.midpoint.certification.impl.handlers.CertificationHandler)4 ObjectTypeUtil.toShortString (com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString)4 AccessCertificationWorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 DeltaBuilder (com.evolveum.midpoint.prism.delta.builder.DeltaBuilder)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3