Search in sources :

Example 6 with AccessCertificationCaseType

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

the class SqaleRepoModifyObjectTest method test332ModifiedCertificationCaseStoresIt.

@Test
public void test332ModifiedCertificationCaseStoresIt() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
    OperationResult result = createOperationResult();
    MAccessCertificationCampaign originalRow = selectObjectByOid(QAccessCertificationCampaign.class, accessCertificationCampaign1Oid);
    given("delta adding case for campaign 1");
    ObjectDelta<AccessCertificationCampaignType> delta = prismContext.deltaFor(AccessCertificationCampaignType.class).item(ItemPath.create(AccessCertificationCampaignType.F_CASE, CAMPAIGN_1_CASE_2_ID, AccessCertificationCaseType.F_OUTCOME)).replace("People are the problem").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("People are the problem");
    assertThat(aRow.stageNumber).isEqualTo(5);
    assertThat(aRow.campaignIteration).isEqualTo(7);
    // Check that case (container) fullObject was updated, as opposed to campaign (object) fullObject
    PrismContainerValue<AccessCertificationCaseType> fullObjectCval = prismContext.parserFor(new String(aRow.fullObject, StandardCharsets.UTF_8)).parseItemValue();
    // Unchanged
    assertThat(fullObjectCval.asContainerable().getStageNumber()).isEqualTo(5);
    assertThat(fullObjectCval.asContainerable().getIteration()).isEqualTo(7);
    // Changed
    assertThat(fullObjectCval.asContainerable().getOutcome()).isEqualTo("People are the problem");
}
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) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 7 with AccessCertificationCaseType

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

the class CertificationCaseHelper method updateLoadedCampaign.

// adds cases to campaign if requested by options
<T extends ObjectType> void updateLoadedCampaign(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Session session) throws SchemaException {
    if (!SelectorOptions.hasToLoadPath(AccessCertificationCampaignType.F_CASE, options)) {
        return;
    }
    LOGGER.debug("Loading certification campaign cases.");
    CriteriaBuilder cb = session.getCriteriaBuilder();
    CriteriaQuery<RAccessCertificationCase> cq = cb.createQuery(RAccessCertificationCase.class);
    cq.where(cb.equal(cq.from(RAccessCertificationCase.class).get("ownerOid"), object.getOid()));
    Query<RAccessCertificationCase> query = session.createQuery(cq);
    // TODO fetch only XML representation
    List<RAccessCertificationCase> cases = query.list();
    if (CollectionUtils.isNotEmpty(cases)) {
        AccessCertificationCampaignType campaign = (AccessCertificationCampaignType) object.asObjectable();
        List<AccessCertificationCaseType> jaxbCases = campaign.getCase();
        for (RAccessCertificationCase rCase : cases) {
            AccessCertificationCaseType jaxbCase = rCase.toJAXB(prismContext);
            jaxbCases.add(jaxbCase);
        }
        PrismContainer<AccessCertificationCaseType> caseContainer = object.findContainer(AccessCertificationCampaignType.F_CASE);
        caseContainer.setIncomplete(false);
    } else {
        PrismContainer<AccessCertificationCaseType> caseContainer = object.findContainer(AccessCertificationCampaignType.F_CASE);
        if (caseContainer != null) {
            // just in case
            caseContainer.clear();
            caseContainer.setIncomplete(false);
        }
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) RAccessCertificationCase(com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 8 with AccessCertificationCaseType

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

the class CertificationCaseHelper method updateLoadedCertificationWorkItem.

public AccessCertificationWorkItemType updateLoadedCertificationWorkItem(GetCertificationWorkItemResult result, // key=OID:ID
Map<String, PrismContainerValue<AccessCertificationCaseType>> casesCache, // key=OID
Map<String, PrismObject<AccessCertificationCampaignType>> campaignsCache, Collection<SelectorOptions<GetOperationOptions>> options, QueryEngine engine, Session session, OperationResult operationResult) throws SchemaException, QueryException {
    String campaignOid = result.getCampaignOid();
    Integer caseId = result.getCaseId();
    Integer workItemId = result.getId();
    String caseKey = campaignOid + ":" + caseId;
    PrismContainerValue<AccessCertificationCaseType> casePcv = casesCache.get(caseKey);
    if (casePcv == null) {
        ObjectQuery query = prismContext.queryFor(AccessCertificationCaseType.class).ownerId(campaignOid).and().id(caseId).build();
        RQuery caseQuery = engine.interpret(query, AccessCertificationCaseType.class, null, false, session);
        List<GetContainerableResult> cases = caseQuery.list();
        if (cases.size() > 1) {
            throw new IllegalStateException("More than one certification case found for campaign " + campaignOid + ", ID " + caseId);
        } else if (cases.isEmpty()) {
            // we need it, because otherwise we have only identifiers for the work item, no data
            throw new IllegalStateException("No certification case found for campaign " + campaignOid + ", ID " + caseId);
        }
        // TODO really use options of 'null' ?
        AccessCertificationCaseType acase = updateLoadedCertificationCase(cases.get(0), campaignsCache, null, session, operationResult);
        casePcv = acase.asPrismContainerValue();
        casesCache.put(caseKey, casePcv);
    }
    @SuppressWarnings({ "raw", "unchecked" }) PrismContainerValue<AccessCertificationWorkItemType> workItemPcv = (PrismContainerValue<AccessCertificationWorkItemType>) casePcv.find(ItemPath.create(AccessCertificationCaseType.F_WORK_ITEM, workItemId));
    if (workItemPcv == null) {
        throw new IllegalStateException("No work item " + workItemId + " in " + casePcv);
    } else {
        return workItemPcv.asContainerable();
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery) AccessCertificationWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType)

Example 9 with AccessCertificationCaseType

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

the class QAccessCertificationCampaignMapping method storeRelatedEntities.

@Override
public void storeRelatedEntities(@NotNull MAccessCertificationCampaign row, @NotNull AccessCertificationCampaignType schemaObject, @NotNull JdbcSession jdbcSession) throws SchemaException {
    super.storeRelatedEntities(row, schemaObject, jdbcSession);
    List<AccessCertificationCaseType> cases = schemaObject.getCase();
    if (!cases.isEmpty()) {
        for (AccessCertificationCaseType c : cases) {
            QAccessCertificationCaseMapping.getAccessCertificationCaseMapping().insert(c, row, jdbcSession);
        }
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)

Example 10 with AccessCertificationCaseType

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

the class QAccessCertificationCaseMapping method insert.

// about duplication see the comment in QObjectMapping.toRowObjectWithoutFullObject
@SuppressWarnings("DuplicatedCode")
@Override
public MAccessCertificationCase insert(AccessCertificationCaseType acase, MAccessCertificationCampaign ownerRow, JdbcSession jdbcSession) throws SchemaException {
    MAccessCertificationCase row = initRowObject(acase, ownerRow);
    // activation
    ActivationType activation = acase.getActivation();
    if (activation != null) {
        row.administrativeStatus = activation.getAdministrativeStatus();
        row.effectiveStatus = activation.getEffectiveStatus();
        row.enableTimestamp = MiscUtil.asInstant(activation.getEnableTimestamp());
        row.disableTimestamp = MiscUtil.asInstant(activation.getDisableTimestamp());
        row.disableReason = activation.getDisableReason();
        row.validityStatus = activation.getValidityStatus();
        row.validFrom = MiscUtil.asInstant(activation.getValidFrom());
        row.validTo = MiscUtil.asInstant(activation.getValidTo());
        row.validityChangeTimestamp = MiscUtil.asInstant(activation.getValidityChangeTimestamp());
        row.archiveTimestamp = MiscUtil.asInstant(activation.getArchiveTimestamp());
    }
    row.currentStageOutcome = acase.getCurrentStageOutcome();
    row.fullObject = createFullObject(acase);
    // TODO
    row.campaignIteration = acase.getIteration();
    setReference(acase.getObjectRef(), o -> row.objectRefTargetOid = o, t -> row.objectRefTargetType = t, r -> row.objectRefRelationId = r);
    setReference(acase.getOrgRef(), o -> row.orgRefTargetOid = o, t -> row.orgRefTargetType = t, r -> row.orgRefRelationId = r);
    row.outcome = acase.getOutcome();
    row.remediedTimestamp = MiscUtil.asInstant(acase.getRemediedTimestamp());
    row.currentStageDeadline = MiscUtil.asInstant(acase.getCurrentStageDeadline());
    row.currentStageCreateTimestamp = MiscUtil.asInstant(acase.getCurrentStageCreateTimestamp());
    row.stageNumber = acase.getStageNumber();
    setReference(acase.getTargetRef(), o -> row.targetRefTargetOid = o, t -> row.targetRefTargetType = t, r -> row.targetRefRelationId = r);
    setReference(acase.getTenantRef(), o -> row.tenantRefTargetOid = o, t -> row.tenantRefTargetType = t, r -> row.tenantRefRelationId = r);
    insert(row, jdbcSession);
    storeWorkItems(row, acase, jdbcSession);
    return row;
}
Also used : ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)

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