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