Search in sources :

Example 26 with AccessCertificationCaseType

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

the class AccCertCaseOperationsHelper method createOutcomeDeltas.

// computes outcomes at stage close (stage-level and overall) and creates appropriate deltas
List<ItemDelta<?, ?>> createOutcomeDeltas(AccessCertificationCampaignType campaign, OperationResult result) throws ObjectNotFoundException, SchemaException {
    List<ItemDelta<?, ?>> rv = new ArrayList<>();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Updating current outcome for cases in {}", toShortString(campaign));
    }
    List<AccessCertificationCaseType> caseList = queryHelper.searchCases(campaign.getOid(), null, null, result);
    for (AccessCertificationCaseType _case : caseList) {
        if (_case.getStageNumber() != campaign.getStageNumber()) {
            continue;
        }
        String newStageOutcome = OutcomeUtils.toUri(computationHelper.computeOutcomeForStage(_case, campaign, campaign.getStageNumber()));
        if (!Objects.equals(newStageOutcome, _case.getCurrentStageOutcome())) {
            rv.add(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext).item(F_CASE, _case.asPrismContainerValue().getId(), F_CURRENT_STAGE_OUTCOME).replace(newStageOutcome).asItemDelta());
        }
        rv.add(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext).item(F_CASE, _case.asPrismContainerValue().getId(), F_EVENT).add(new StageCompletionEventType().timestamp(clock.currentTimeXMLGregorianCalendar()).stageNumber(campaign.getStageNumber()).outcome(newStageOutcome)).asItemDelta());
        String newOverallOutcome = OutcomeUtils.toUri(computationHelper.computeOverallOutcome(_case, campaign, newStageOutcome));
        if (!Objects.equals(newOverallOutcome, _case.getOutcome())) {
            rv.add(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext).item(F_CASE, _case.asPrismContainerValue().getId(), F_OUTCOME).replace(newOverallOutcome).asItemDelta());
        }
    }
    return rv;
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectTypeUtil.toShortString(com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString)

Example 27 with AccessCertificationCaseType

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

the class AccCertGeneralHelper method isRevoke.

// TODO move to OutcomeUtils
public boolean isRevoke(AccessCertificationCaseType aCase, AccessCertificationCampaignType campaign) {
    AccessCertificationResponseType outcome = OutcomeUtils.fromUri(aCase.getOutcome());
    List<AccessCertificationResponseType> revokes;
    if (campaign.getRemediationDefinition() != null && !campaign.getRemediationDefinition().getRevokeOn().isEmpty()) {
        revokes = campaign.getRemediationDefinition().getRevokeOn();
    } else {
        revokes = Collections.singletonList(REVOKE);
    }
    return revokes.contains(outcome);
}
Also used : AccessCertificationResponseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType)

Example 28 with AccessCertificationCaseType

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

the class CertCaseDtoProvider method internalIterator.

@Override
public Iterator<CertCaseOrWorkItemDto> internalIterator(long first, long count) {
    LOGGER.trace("begin::iterator() from {} count {}.", first, count);
    getAvailableData().clear();
    Task task = getPageBase().createSimpleTask(OPERATION_SEARCH_OBJECTS);
    OperationResult result = task.getResult();
    try {
        ObjectPaging paging = createPaging(first, count);
        Collection<SelectorOptions<GetOperationOptions>> resolveNames = createCollection(createResolveNames());
        List<AccessCertificationCaseType> caseList = searchCases(campaignOid, paging, resolveNames, getPageBase().getPrismContext(), task, result);
        for (AccessCertificationCaseType acase : caseList) {
            getAvailableData().add(new CertCaseDto(acase, getPageBase(), task, result));
        }
    } catch (Exception ex) {
        result.recordFatalError(getPageBase().createStringResource("CertCaseDtoProvider.message.internalIterator.fatalError").getString(), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't list decisions", ex);
    } finally {
        result.computeStatusIfUnknown();
    }
    if (!WebComponentUtil.isSuccessOrHandledError(result)) {
        handleNotSuccessOrHandledErrorInIterator(result);
    }
    LOGGER.trace("end::iterator()");
    return getAvailableData().iterator();
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) RestartResponseException(org.apache.wicket.RestartResponseException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException)

Example 29 with AccessCertificationCaseType

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

the class SqaleRepoModifyObjectTest method test331AddedCertificationCaseStoresItFixedId.

@Test
public void test331AddedCertificationCaseStoresItFixedId() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
    OperationResult result = createOperationResult();
    MAccessCertificationCampaign originalRow = selectObjectByOid(QAccessCertificationCampaign.class, accessCertificationCampaign1Oid);
    given("delta adding case for campaign 1");
    accCertCampaign1Case2ObjectOid = UUID.randomUUID();
    AccessCertificationCaseType caseBefore = new AccessCertificationCaseType(prismContext).id(CAMPAIGN_1_CASE_2_ID).stageNumber(5).iteration(7).objectRef(accCertCampaign1Case2ObjectOid.toString(), UserType.COMPLEX_TYPE).outcome("anyone who is capable of getting themselves made" + " President should on no account be allowed to do the job");
    ObjectDelta<AccessCertificationCampaignType> delta = prismContext.deltaFor(AccessCertificationCampaignType.class).item(AccessCertificationCampaignType.F_CASE).add(caseBefore).asObjectDelta(accessCertificationCampaign1Oid);
    when("modifyObject is called");
    repositoryService.modifyObject(AccessCertificationCampaignType.class, accessCertificationCampaign1Oid, delta.getModifications(), result);
    then("operation is successful");
    assertThatOperationResult(result).isSuccess();
    and("serialized form (fullObject) is updated");
    AccessCertificationCampaignType campaignObjectAfter = repositoryService.getObject(AccessCertificationCampaignType.class, accessCertificationCampaign1Oid, retrieveWithCases(), result).asObjectable();
    assertThat(campaignObjectAfter.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
    List<AccessCertificationCaseType> casesAfter = campaignObjectAfter.getCase();
    assertThat(casesAfter).isNotNull();
    assertThat(casesAfter.get(1).getId()).isEqualTo(CAMPAIGN_1_CASE_2_ID);
    and("campaign row is created");
    MAccessCertificationCampaign row = selectObjectByOid(QAccessCertificationCampaign.class, accessCertificationCampaign1Oid);
    assertThat(row.version).isEqualTo(originalRow.version + 1);
    and("case row is created");
    QAccessCertificationCase a = QAccessCertificationCaseMapping.getAccessCertificationCaseMapping().defaultAlias();
    List<MAccessCertificationCase> caseRows = select(a, a.ownerOid.eq(UUID.fromString(accessCertificationCampaign1Oid)));
    assertThat(caseRows).hasSize(2);
    caseRows.sort(comparing(tr -> tr.cid));
    MAccessCertificationCase aRow = caseRows.get(1);
    assertThat(aRow.cid).isEqualTo(CAMPAIGN_1_CASE_2_ID);
    assertThat(aRow.containerType).isEqualTo(MContainerType.ACCESS_CERTIFICATION_CASE);
    assertThat(aRow.targetRefTargetOid).isNull();
    assertThat(aRow.objectRefTargetOid).isEqualTo(accCertCampaign1Case2ObjectOid);
    assertThat(aRow.objectRefTargetType).isEqualTo(MObjectType.USER);
    assertCachedUri(aRow.objectRefRelationId, relationRegistry.getDefaultRelation());
    assertThat(aRow.outcome).isEqualTo("anyone who is capable of getting themselves made" + " President should on no account be allowed to do the job");
    assertThat(aRow.stageNumber).isEqualTo(5);
    assertThat(aRow.campaignIteration).isEqualTo(7);
    assertCertificationCaseFullObject(aRow, caseBefore);
}
Also used : QService(com.evolveum.midpoint.repo.sqale.qmodel.role.QService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SqaleUtils(com.evolveum.midpoint.repo.sqale.SqaleUtils) MService(com.evolveum.midpoint.repo.sqale.qmodel.role.MService) JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) BigDecimal(java.math.BigDecimal) Assertions(org.assertj.core.api.Assertions) MReference(com.evolveum.midpoint.repo.sqale.qmodel.ref.MReference) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) QUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) BeforeClass(org.testng.annotations.BeforeClass) MContainerType(com.evolveum.midpoint.repo.sqale.qmodel.common.MContainerType) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) MTask(com.evolveum.midpoint.repo.sqale.qmodel.task.MTask) QConnector(com.evolveum.midpoint.repo.sqale.qmodel.connector.QConnector) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) MObject(com.evolveum.midpoint.repo.sqale.qmodel.object.MObject) QUserMapping(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUserMapping) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Item(com.evolveum.midpoint.prism.Item) Jsonb(com.evolveum.midpoint.repo.sqale.jsonb.Jsonb) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Assert.assertEquals(org.testng.Assert.assertEquals) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) QObjectReferenceMapping(com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReferenceMapping) MShadow(com.evolveum.midpoint.repo.sqale.qmodel.shadow.MShadow) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) TestUtil(com.evolveum.midpoint.test.util.TestUtil) Comparator.comparing(java.util.Comparator.comparing) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) MObjectType(com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType) QObjectReference(com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReference) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) com.evolveum.midpoint.repo.sqale.qmodel.assignment(com.evolveum.midpoint.repo.sqale.qmodel.assignment) PrismObject(com.evolveum.midpoint.prism.PrismObject) QShadow(com.evolveum.midpoint.repo.sqale.qmodel.shadow.QShadow) MUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ItemName(com.evolveum.midpoint.prism.path.ItemName) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) Assert.assertTrue(org.testng.Assert.assertTrue) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) QTask(com.evolveum.midpoint.repo.sqale.qmodel.task.QTask) com.evolveum.midpoint.repo.sqale.qmodel.accesscert(com.evolveum.midpoint.repo.sqale.qmodel.accesscert) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 30 with AccessCertificationCaseType

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

the class AccCertCloserHelper method createCaseDeltasOnStageClose.

// computes cases outcomes (stage-level and overall) at stage close and creates appropriate deltas
private void createCaseDeltasOnStageClose(AccessCertificationCampaignType campaign, ModificationsToExecute modifications, XMLGregorianCalendar now, List<AccessCertificationResponseType> outcomesToStopOn, OperationResult result) throws SchemaException {
    LOGGER.debug("Updating current outcome for cases in {}", toShortStringLazy(campaign));
    List<AccessCertificationCaseType> caseList = queryHelper.getAllCurrentIterationCases(campaign.getOid(), norm(campaign.getIteration()), null, result);
    for (AccessCertificationCaseType aCase : caseList) {
        long caseId = aCase.getId();
        if (aCase.getReviewFinishedTimestamp() != null) {
            LOGGER.trace("Review process of case {} has already finished, skipping to the next one", caseId);
            continue;
        }
        LOGGER.trace("Updating current outcome for case {}", caseId);
        AccessCertificationResponseType newStageOutcome = computationHelper.computeOutcomeForStage(aCase, campaign, campaign.getStageNumber());
        String newStageOutcomeUri = toUri(newStageOutcome);
        String newOverallOutcomeUri = toUri(computationHelper.computeOverallOutcome(aCase, campaign, campaign.getStageNumber(), newStageOutcome));
        List<ItemDelta<?, ?>> deltas = new ArrayList<>(prismContext.deltaFor(AccessCertificationCampaignType.class).item(F_CASE, caseId, F_CURRENT_STAGE_OUTCOME).replace(newStageOutcomeUri).item(F_CASE, caseId, F_OUTCOME).replace(newOverallOutcomeUri).item(F_CASE, caseId, F_EVENT).add(new StageCompletionEventType(prismContext).timestamp(clock.currentTimeXMLGregorianCalendar()).stageNumber(campaign.getStageNumber()).iteration(campaign.getIteration()).outcome(newStageOutcomeUri)).asItemDeltas());
        LOGGER.trace("Stage outcome = {}, overall outcome = {}", newStageOutcome, newOverallOutcomeUri);
        if (outcomesToStopOn.contains(newStageOutcome)) {
            deltas.add(prismContext.deltaFor(AccessCertificationCampaignType.class).item(F_CASE, caseId, F_REVIEW_FINISHED_TIMESTAMP).replace(now).asItemDelta());
            LOGGER.debug("Marking case {} as review-finished because stage outcome = {}", caseId, newStageOutcome);
        }
        modifications.add(deltas);
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Aggregations

AccessCertificationCaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)31 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)6 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)5 Task (com.evolveum.midpoint.task.api.Task)5 CertificationHandler (com.evolveum.midpoint.certification.impl.handlers.CertificationHandler)4 ObjectTypeUtil (com.evolveum.midpoint.schema.util.ObjectTypeUtil)4 java.util (java.util)4 NotNull (org.jetbrains.annotations.NotNull)4 Test (org.testng.annotations.Test)4 XmlTypeConverter (com.evolveum.midpoint.prism.xml.XmlTypeConverter)3