Search in sources :

Example 86 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class CertificationManagerImpl method openNextStage.

@Override
public void openNextStage(String campaignOid, int requestedStageNumber, 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_OPEN_NEXT_STAGE);
    result.addParam("campaignOid", campaignOid);
    result.addParam("requestedStageNumber", requestedStageNumber);
    try {
        AccessCertificationCampaignType campaign = generalHelper.getCampaign(campaignOid, null, task, result);
        result.addParam("campaign", ObjectTypeUtil.toShortString(campaign));
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("openNextStage starting for {}", ObjectTypeUtil.toShortString(campaign));
        }
        securityEnforcer.authorize(ModelAuthorizationAction.OPEN_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("openNextStage: currentStageNumber={}, stages={}, requestedStageNumber={}, state={}", currentStageNumber, stages, requestedStageNumber, state);
        if (IN_REVIEW_STAGE.equals(state)) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the stage " + currentStageNumber + " is currently open.");
        } else if (IN_REMEDIATION.equals(state)) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the campaign is currently in the remediation phase.");
        } else if (CLOSED.equals(state)) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the campaign is already closed.");
        } else if (!REVIEW_STAGE_DONE.equals(state) && !CREATED.equals(state)) {
            throw new IllegalStateException("Unexpected campaign state: " + state);
        } else if (REVIEW_STAGE_DONE.equals(state) && requestedStageNumber != currentStageNumber + 1) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the campaign is currently in stage " + currentStageNumber);
        } else if (CREATED.equals(state) && requestedStageNumber != 1) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the campaign was just created");
        } else if (requestedStageNumber > stages) {
            result.recordFatalError("Couldn't advance to review stage " + requestedStageNumber + " as the campaign has only " + stages + " stages");
        } else {
            final CertificationHandler handler = findCertificationHandler(campaign);
            final AccessCertificationStageType stage = updateHelper.createStage(campaign, currentStageNumber + 1);
            final List<ItemDelta<?, ?>> deltas = updateHelper.getDeltasForStageOpen(campaign, stage, handler, task, result);
            updateHelper.modifyObjectViaModel(AccessCertificationCampaignType.class, campaignOid, deltas, task, result);
            updateHelper.afterStageOpen(campaignOid, stage, task, result);
        }
    } catch (RuntimeException e) {
        result.recordFatalError("Couldn't move to certification campaign stage " + requestedStageNumber + ": unexpected exception: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : CertificationHandler(com.evolveum.midpoint.certification.impl.handlers.CertificationHandler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) AccessCertificationCampaignStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType)

Example 87 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class CertificationManagerImpl method createCampaign.

@Override
public AccessCertificationCampaignType createCampaign(String definitionOid, Task task, OperationResult parentResult) throws SchemaException, SecurityViolationException, ObjectNotFoundException, ObjectAlreadyExistsException {
    Validate.notNull(definitionOid, "definitionOid");
    Validate.notNull(task, "task");
    Validate.notNull(parentResult, "parentResult");
    OperationResult result = parentResult.createSubresult(OPERATION_CREATE_CAMPAIGN);
    try {
        PrismObject<AccessCertificationDefinitionType> definition = repositoryService.getObject(AccessCertificationDefinitionType.class, definitionOid, null, result);
        securityEnforcer.authorize(ModelAuthorizationAction.CREATE_CERTIFICATION_CAMPAIGN.getUrl(), null, definition, null, null, null, result);
        AccessCertificationCampaignType newCampaign = updateHelper.createCampaignObject(definition.asObjectable(), task, result);
        updateHelper.addObject(newCampaign, task, result);
        return newCampaign;
    } catch (RuntimeException e) {
        result.recordFatalError("Couldn't create certification campaign: unexpected exception: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 88 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class TestCertificationBasic method test005CreateCampaignDenied.

@Test
public void test005CreateCampaignDenied() throws Exception {
    final String TEST_NAME = "test005CreateCampaignDenied";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestCertificationBasic.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // elaine is a reviewer, not authorized to create campaigns
    login(getUserFromRepo(USER_ELAINE_OID));
    // WHEN/THEN
    TestUtil.displayWhen(TEST_NAME);
    try {
        certificationService.createCampaign(certificationDefinition.getOid(), task, result);
        fail("Unexpected success");
    } catch (SecurityViolationException e) {
        System.out.println("Expected security violation exception: " + e.getMessage());
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 89 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class TestCertificationBasic method test054SearchDecisionsByOrgRef.

@Test
public void test054SearchDecisionsByOrgRef() throws Exception {
    final String TEST_NAME = "test054SearchDecisionsByOrgRef";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(getUserFromRepo(USER_ADMINISTRATOR_OID));
    // GIVEN
    Task task = taskManager.createTaskInstance(TestCertificationBasic.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    ObjectQuery query = QueryBuilder.queryFor(AccessCertificationWorkItemType.class, prismContext).exists(T_PARENT).block().item(AccessCertificationCaseType.F_ORG_REF).ref(ORG_SCUMM_BAR_OID).and().ownerId(campaignOid).endBlock().build();
    List<AccessCertificationWorkItemType> workItems = certificationService.searchOpenWorkItems(query, false, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    display("workItems", workItems);
    assertEquals("Wrong number of certification work items", 1, workItems.size());
    checkWorkItem(workItems, USER_JACK_OID, ROLE_CEO_OID, userJack, campaignOid, ORG_GOVERNOR_OFFICE_OID, ORG_SCUMM_BAR_OID, ENABLED);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 90 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class TestCertificationBasic method test020OpenFirstStageDenied.

@Test
public void test020OpenFirstStageDenied() throws Exception {
    final String TEST_NAME = "test020OpenFirstStageDenied";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestCertificationBasic.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    login(getUserFromRepo(USER_ELAINE_OID));
    // WHEN+THEN
    TestUtil.displayWhen(TEST_NAME);
    try {
        certificationService.openNextStage(campaignOid, 1, task, result);
        fail("Unexpected success");
    } catch (SecurityViolationException e) {
        System.out.println("Got expected denial exception: " + e.getMessage());
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3475 Test (org.testng.annotations.Test)2435 Task (com.evolveum.midpoint.task.api.Task)2390 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1059 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)725 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)637 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)414 PrismObject (com.evolveum.midpoint.prism.PrismObject)388 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)376 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)320 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)288 ArrayList (java.util.ArrayList)262 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)252 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)250 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)231 QName (javax.xml.namespace.QName)198 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)197 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)182 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)171 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)149