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();
}
}
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();
}
}
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());
}
}
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);
}
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());
}
}
Aggregations