use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.
the class SqaleRepoAddDeleteObjectTest method test842AccessCertificationCampaign.
@Test
public void test842AccessCertificationCampaign() throws Exception {
OperationResult result = createOperationResult();
given("access certification campaign");
String objectName = "acc" + getTestNumber();
UUID definitionRefOid = UUID.randomUUID();
QName definitionRefRelationUri = QName.valueOf("{https://some.uri}definition-relation");
UUID ownerRefOid = UUID.randomUUID();
QName ownerRefRelationUri = QName.valueOf("{https://strange.uri}owner-relation");
Instant startTimestamp = Instant.ofEpochMilli(1234);
Instant validFrom = Instant.ofEpochMilli(444000);
Instant validityChangeTimestamp = Instant.ofEpochMilli(444001);
Instant case1CurrentStageCreateTimestamp = Instant.ofEpochMilli(444333);
Instant case2CurrentStageCreateTimestamp = Instant.ofEpochMilli(2444333);
Instant remediedTimestamp = Instant.ofEpochMilli(444555);
Instant currentStageDeadline = Instant.ofEpochMilli(444666);
Instant validTo = Instant.ofEpochMilli(999000);
Instant enableTimestamp = Instant.ofEpochMilli(555000);
Instant disableTimestamp = Instant.ofEpochMilli(555111);
Instant archiveTimestamp = Instant.ofEpochMilli(555123);
Instant endTimestamp = Instant.ofEpochMilli(System.currentTimeMillis());
String disableReason = "Whatever!";
String case1CurrentStageOutcome = "Bada BOOM";
String case2CurrentStageOutcome = "Big bada BOOM";
Integer case1Iteration = 5;
Integer case2Iteration = 15;
UUID caseObjectRefOid = UUID.randomUUID();
QName caseObjectRefRelationUri = QName.valueOf("{https://other.uri}case-object-ref-relation");
UUID caseOrgRefOid = UUID.randomUUID();
QName caseOrgRefRelationUri = QName.valueOf("{https://other.uri}case-org-ref-relation");
String caseOutcome = "... for ever and ever";
int caseStageNumber = 8;
UUID caseTargetRefOid = UUID.randomUUID();
QName caseTargetRefRelationUri = QName.valueOf("{https://some.uri}case-target-ref-relation");
UUID caseTenantRefOid = UUID.randomUUID();
QName caseTenantRefRelationUri = QName.valueOf("{https://some.uri}case-tenant-ref-relation");
Instant wi1CloseTimestamp = Instant.ofEpochMilli(999123);
Instant wi2CloseTimestamp = Instant.ofEpochMilli(2999123);
Instant wi3CloseTimestamp = Instant.ofEpochMilli(3999123);
Instant wi1OutputChangeTimestamp = Instant.ofEpochMilli(999001);
Instant wi2OutputChangeTimestamp = Instant.ofEpochMilli(2999001);
Instant wi3OutputChangeTimestamp = Instant.ofEpochMilli(3999001);
UUID performer1Oid = UUID.randomUUID();
QName performer1Relation = QName.valueOf("{https://random.org/ns}wi-performer1-rel");
UUID performer2Oid = UUID.randomUUID();
QName performer2Relation = QName.valueOf("{https://random.org/ns}wi-performer2-rel");
UUID performer3Oid = UUID.randomUUID();
QName performer3Relation = QName.valueOf("{https://random.org/ns}wi-performer3-rel");
// explicit UUID, to ensure ordering
UUID wi1AssigneeRef1Oid = UUID.fromString("7508a482-d8d1-11eb-9435-9b077bcc684b");
QName wi1AssigneeRef1Relation = QName.valueOf("{https://random.org/ns}acwi-1-assignee-1-rel");
// explicit UUID, to ensure ordering
UUID wi1AssigneeRef2Oid = UUID.fromString("77267d0c-d8d1-11eb-9ae9-8fb4530e4e64");
QName wi1AssigneeRef2Relation = QName.valueOf("{https://random.org/ns}acwi-1-assignee-2-rel");
// explicit UUID, to ensure ordering
UUID wi1CandidateRef1Oid = UUID.fromString("754f391a-d8d1-11eb-b269-9b322a63128e");
QName wi1CandidateRef1Relation = QName.valueOf("{https://random.org/ns}acwi-1-candidate-1-rel");
// explicit UUID, to ensure ordering
UUID wi2AssigneeRef1Oid = UUID.fromString("75cde882-d8d1-11eb-841f-6b8c0f5075f8");
QName wi2AssigneeRef1Relation = QName.valueOf("{https://random.org/ns}acwi-2-assignee-1-rel");
// explicit UUID, to ensure ordering
UUID wi2CandidateRef1Oid = UUID.fromString("765709aa-d8d1-11eb-9340-33ef5ec6b0e2");
QName wi2CandidateRef1Relation = QName.valueOf("{https://random.org/ns}acwi-2-candidate-1-rel");
// explicit UUID, to ensure ordering
UUID wi2CandidateRef2Oid = UUID.fromString("7576bd0a-d8d1-11eb-9171-bf2238c132b7");
QName wi2CandidateRef2Relation = QName.valueOf("{https://random.org/ns}acwi-2-candidate-2-rel");
// explicit UUID, to ensure ordering
UUID wi3AssigneeRef1Oid = UUID.fromString("b9f969b0-d8e4-11eb-aa14-6f0a7aff9550");
QName wi3AssigneeRef1Relation = QName.valueOf("{https://random.org/ns}acwi-3-assignee-1-rel");
// explicit UUID, to ensure ordering
UUID wi3CandidateRef1Oid = UUID.fromString("bb23b638-d8e4-11eb-9601-872386b50ce3");
QName wi3CandidateRef1Relation = QName.valueOf("{https://random.org/ns}acwi-3-candidate-1-rel");
var accessCertificationCampaign = new AccessCertificationCampaignType(prismContext).name(objectName).definitionRef(definitionRefOid.toString(), UserType.COMPLEX_TYPE, definitionRefRelationUri).endTimestamp(MiscUtil.asXMLGregorianCalendar(endTimestamp)).handlerUri("c-handler-uri").iteration(3).ownerRef(ownerRefOid.toString(), UserType.COMPLEX_TYPE, ownerRefRelationUri).stageNumber(2).startTimestamp(MiscUtil.asXMLGregorianCalendar(startTimestamp)).state(AccessCertificationCampaignStateType.IN_REVIEW_STAGE)._case(new AccessCertificationCaseType(prismContext).id(48L).activation(new ActivationType(prismContext).administrativeStatus(ActivationStatusType.ARCHIVED).archiveTimestamp(MiscUtil.asXMLGregorianCalendar(archiveTimestamp)).disableReason(disableReason).disableTimestamp(MiscUtil.asXMLGregorianCalendar(disableTimestamp)).effectiveStatus(ActivationStatusType.DISABLED).enableTimestamp(MiscUtil.asXMLGregorianCalendar(enableTimestamp)).validFrom(MiscUtil.asXMLGregorianCalendar(validFrom)).validTo(MiscUtil.asXMLGregorianCalendar(validTo)).validityChangeTimestamp(MiscUtil.asXMLGregorianCalendar(validityChangeTimestamp)).validityStatus(TimeIntervalStatusType.IN)).currentStageOutcome(case1CurrentStageOutcome).iteration(case1Iteration).objectRef(caseObjectRefOid.toString(), ServiceType.COMPLEX_TYPE, caseObjectRefRelationUri).orgRef(caseOrgRefOid.toString(), OrgType.COMPLEX_TYPE, caseOrgRefRelationUri).outcome(caseOutcome).remediedTimestamp(MiscUtil.asXMLGregorianCalendar(remediedTimestamp)).currentStageDeadline(MiscUtil.asXMLGregorianCalendar(currentStageDeadline)).currentStageCreateTimestamp(MiscUtil.asXMLGregorianCalendar(case1CurrentStageCreateTimestamp)).stageNumber(caseStageNumber).targetRef(caseTargetRefOid.toString(), RoleType.COMPLEX_TYPE, caseTargetRefRelationUri).tenantRef(caseTenantRefOid.toString(), OrgType.COMPLEX_TYPE, caseTenantRefRelationUri).workItem(new AccessCertificationWorkItemType(prismContext).id(55L).closeTimestamp(MiscUtil.asXMLGregorianCalendar(wi1CloseTimestamp)).iteration(81).output(new AbstractWorkItemOutputType().outcome("almost, but not quite, entirely done")).outputChangeTimestamp(MiscUtil.asXMLGregorianCalendar(wi1OutputChangeTimestamp)).performerRef(performer1Oid.toString(), UserType.COMPLEX_TYPE, performer1Relation).stageNumber(21).assigneeRef(wi1AssigneeRef1Oid.toString(), UserType.COMPLEX_TYPE, wi1AssigneeRef1Relation).assigneeRef(wi1AssigneeRef2Oid.toString(), UserType.COMPLEX_TYPE, wi1AssigneeRef2Relation).candidateRef(wi1CandidateRef1Oid.toString(), UserType.COMPLEX_TYPE, wi1CandidateRef1Relation)).workItem(new AccessCertificationWorkItemType(prismContext).id(56L).closeTimestamp(MiscUtil.asXMLGregorianCalendar(wi2CloseTimestamp)).iteration(82).output(new AbstractWorkItemOutputType().outcome("A tad more than almost, but not quite, entirely done")).outputChangeTimestamp(MiscUtil.asXMLGregorianCalendar(wi2OutputChangeTimestamp)).performerRef(performer2Oid.toString(), UserType.COMPLEX_TYPE, performer2Relation).stageNumber(22).assigneeRef(wi2AssigneeRef1Oid.toString(), UserType.COMPLEX_TYPE, wi2AssigneeRef1Relation).candidateRef(wi2CandidateRef1Oid.toString(), UserType.COMPLEX_TYPE, wi2CandidateRef1Relation).candidateRef(wi2CandidateRef2Oid.toString(), OrgType.COMPLEX_TYPE, wi2CandidateRef2Relation)))._case(new AccessCertificationCaseType(prismContext).id(49L).currentStageOutcome(case2CurrentStageOutcome).iteration(case2Iteration).outcome("whatever").currentStageCreateTimestamp(MiscUtil.asXMLGregorianCalendar(case2CurrentStageCreateTimestamp)).stageNumber(25).targetRef(caseTargetRefOid.toString(), RoleType.COMPLEX_TYPE, caseTargetRefRelationUri).workItem(new AccessCertificationWorkItemType(prismContext).id(59L).closeTimestamp(MiscUtil.asXMLGregorianCalendar(wi3CloseTimestamp)).iteration(83).output(new AbstractWorkItemOutputType().outcome("certainly not quite done")).outputChangeTimestamp(MiscUtil.asXMLGregorianCalendar(wi3OutputChangeTimestamp)).performerRef(performer3Oid.toString(), UserType.COMPLEX_TYPE, performer3Relation).stageNumber(21).assigneeRef(wi3AssigneeRef1Oid.toString(), UserType.COMPLEX_TYPE, wi3AssigneeRef1Relation).candidateRef(wi3CandidateRef1Oid.toString(), OrgType.COMPLEX_TYPE, wi3CandidateRef1Relation)));
when("adding it to the repository");
repositoryService.addObject(accessCertificationCampaign.asPrismObject(), null, result);
then("it is stored and relevant attributes are in columns");
assertThatOperationResult(result).isSuccess();
MAccessCertificationCampaign row = selectObjectByOid(QAccessCertificationCampaign.class, accessCertificationCampaign.getOid());
assertThat(row.definitionRefTargetOid).isEqualTo(definitionRefOid);
assertThat(row.definitionRefTargetType).isEqualTo(MObjectType.USER);
assertCachedUri(row.definitionRefRelationId, definitionRefRelationUri);
assertThat(row.endTimestamp).isEqualTo(endTimestamp);
assertCachedUri(row.handlerUriId, "c-handler-uri");
assertThat(row.campaignIteration).isEqualTo(3);
assertThat(row.ownerRefTargetOid).isEqualTo(ownerRefOid);
assertThat(row.ownerRefTargetType).isEqualTo(MObjectType.USER);
assertCachedUri(row.ownerRefRelationId, ownerRefRelationUri);
assertThat(row.stageNumber).isEqualTo(2);
assertThat(row.startTimestamp).isEqualTo(startTimestamp);
assertThat(row.state).isEqualTo(AccessCertificationCampaignStateType.IN_REVIEW_STAGE);
QAccessCertificationCase caseAlias = aliasFor(QAccessCertificationCase.class);
List<MAccessCertificationCase> caseRows = select(caseAlias, caseAlias.ownerOid.eq(UUID.fromString(accessCertificationCampaign.getOid())));
assertThat(caseRows).hasSize(2);
caseRows.sort(comparing(tr -> tr.cid));
MAccessCertificationCase caseRow = caseRows.get(0);
// assigned in advance
assertThat(caseRow.cid).isEqualTo(48);
assertThat(caseRow.containerType).isEqualTo(MContainerType.ACCESS_CERTIFICATION_CASE);
assertThat(caseRow.administrativeStatus).isEqualTo(ActivationStatusType.ARCHIVED);
assertThat(caseRow.archiveTimestamp).isEqualTo(archiveTimestamp);
assertThat(caseRow.disableReason).isEqualTo(disableReason);
assertThat(caseRow.disableTimestamp).isEqualTo(disableTimestamp);
assertThat(caseRow.effectiveStatus).isEqualTo(ActivationStatusType.DISABLED);
assertThat(caseRow.enableTimestamp).isEqualTo(enableTimestamp);
assertThat(caseRow.validFrom).isEqualTo(validFrom);
assertThat(caseRow.validTo).isEqualTo(validTo);
assertThat(caseRow.validityChangeTimestamp).isEqualTo(validityChangeTimestamp);
assertThat(caseRow.validityStatus).isEqualTo(TimeIntervalStatusType.IN);
assertThat(caseRow.currentStageOutcome).isEqualTo(case1CurrentStageOutcome);
assertContainerFullObject(caseRow.fullObject, accessCertificationCampaign.getCase().get(0));
assertThat(caseRow.campaignIteration).isEqualTo(case1Iteration);
assertThat(caseRow.objectRefTargetOid).isEqualTo(caseObjectRefOid);
assertThat(caseRow.objectRefTargetType).isEqualTo(MObjectType.SERVICE);
assertCachedUri(caseRow.objectRefRelationId, caseObjectRefRelationUri);
assertThat(caseRow.orgRefTargetOid).isEqualTo(caseOrgRefOid);
assertThat(caseRow.orgRefTargetType).isEqualTo(MObjectType.ORG);
assertCachedUri(caseRow.orgRefRelationId, caseOrgRefRelationUri);
assertThat(caseRow.outcome).isEqualTo(caseOutcome);
assertThat(caseRow.remediedTimestamp).isEqualTo(remediedTimestamp);
assertThat(caseRow.currentStageDeadline).isEqualTo(currentStageDeadline);
assertThat(caseRow.currentStageCreateTimestamp).isEqualTo(case1CurrentStageCreateTimestamp);
assertThat(caseRow.stageNumber).isEqualTo(caseStageNumber);
assertThat(caseRow.targetRefTargetOid).isEqualTo(caseTargetRefOid);
assertThat(caseRow.targetRefTargetType).isEqualTo(MObjectType.ROLE);
assertCachedUri(caseRow.targetRefRelationId, caseTargetRefRelationUri);
assertThat(caseRow.tenantRefTargetOid).isEqualTo(caseTenantRefOid);
assertThat(caseRow.tenantRefTargetType).isEqualTo(MObjectType.ORG);
assertCachedUri(caseRow.tenantRefRelationId, caseTenantRefRelationUri);
caseRow = caseRows.get(1);
// assigned in advance
assertThat(caseRow.cid).isEqualTo(49);
assertThat(caseRow.containerType).isEqualTo(MContainerType.ACCESS_CERTIFICATION_CASE);
assertThat(caseRow.administrativeStatus).isNull();
assertThat(caseRow.archiveTimestamp).isNull();
assertThat(caseRow.disableReason).isNull();
assertThat(caseRow.disableTimestamp).isNull();
assertThat(caseRow.effectiveStatus).isNull();
assertThat(caseRow.enableTimestamp).isNull();
assertThat(caseRow.validFrom).isNull();
assertThat(caseRow.validTo).isNull();
assertThat(caseRow.validityChangeTimestamp).isNull();
assertThat(caseRow.validityStatus).isNull();
assertThat(caseRow.currentStageOutcome).isEqualTo(case2CurrentStageOutcome);
assertContainerFullObject(caseRow.fullObject, accessCertificationCampaign.getCase().get(1));
assertThat(caseRow.campaignIteration).isEqualTo(case2Iteration);
assertThat(caseRow.objectRefTargetOid).isNull();
assertThat(caseRow.objectRefTargetType).isNull();
assertThat(caseRow.objectRefRelationId).isNull();
assertThat(caseRow.orgRefTargetOid).isNull();
assertThat(caseRow.orgRefTargetType).isNull();
assertThat(caseRow.orgRefRelationId).isNull();
assertThat(caseRow.outcome).isEqualTo("whatever");
assertThat(caseRow.remediedTimestamp).isNull();
assertThat(caseRow.currentStageDeadline).isNull();
assertThat(caseRow.currentStageCreateTimestamp).isEqualTo(case2CurrentStageCreateTimestamp);
assertThat(caseRow.stageNumber).isEqualTo(25);
assertThat(caseRow.targetRefTargetOid).isEqualTo(caseTargetRefOid);
assertThat(caseRow.targetRefTargetType).isEqualTo(MObjectType.ROLE);
assertCachedUri(caseRow.targetRefRelationId, caseTargetRefRelationUri);
assertThat(caseRow.tenantRefTargetOid).isNull();
assertThat(caseRow.tenantRefTargetType).isNull();
assertThat(caseRow.tenantRefRelationId).isNull();
QAccessCertificationWorkItem wiAlias = aliasFor(QAccessCertificationWorkItem.class);
List<MAccessCertificationWorkItem> wiRows = select(wiAlias, wiAlias.ownerOid.eq(UUID.fromString(accessCertificationCampaign.getOid())));
assertThat(wiRows).hasSize(3);
wiRows.sort(comparing(tr -> tr.cid));
MAccessCertificationWorkItem wiRow = wiRows.get(0);
// assigned in advance
assertThat(wiRow.cid).isEqualTo(55);
assertThat(wiRow.accessCertCaseCid).isEqualTo(48);
assertThat(wiRow.containerType).isEqualTo(MContainerType.ACCESS_CERTIFICATION_WORK_ITEM);
assertThat(wiRow.closeTimestamp).isEqualTo(wi1CloseTimestamp);
assertThat(wiRow.campaignIteration).isEqualTo(81);
assertThat(wiRow.outcome).isEqualTo("almost, but not quite, entirely done");
assertThat(wiRow.outputChangeTimestamp).isEqualTo(wi1OutputChangeTimestamp);
assertThat(wiRow.performerRefTargetOid).isEqualTo(performer1Oid);
assertThat(wiRow.performerRefTargetType).isEqualTo(MObjectType.USER);
assertCachedUri(wiRow.performerRefRelationId, performer1Relation);
assertThat(wiRow.stageNumber).isEqualTo(21);
wiRow = wiRows.get(1);
// assigned in advance
assertThat(wiRow.cid).isEqualTo(56);
assertThat(wiRow.accessCertCaseCid).isEqualTo(48);
assertThat(wiRow.containerType).isEqualTo(MContainerType.ACCESS_CERTIFICATION_WORK_ITEM);
assertThat(wiRow.closeTimestamp).isEqualTo(wi2CloseTimestamp);
assertThat(wiRow.campaignIteration).isEqualTo(82);
assertThat(wiRow.outcome).isEqualTo("A tad more than almost, but not quite, entirely done");
assertThat(wiRow.outputChangeTimestamp).isEqualTo(wi2OutputChangeTimestamp);
assertThat(wiRow.performerRefTargetOid).isEqualTo(performer2Oid);
assertThat(wiRow.performerRefTargetType).isEqualTo(MObjectType.USER);
assertCachedUri(wiRow.performerRefRelationId, performer2Relation);
assertThat(wiRow.stageNumber).isEqualTo(22);
// Assignee refs
QAccessCertificationWorkItemReference assigneeRefAlias = QAccessCertificationWorkItemReferenceMapping.getForCaseWorkItemAssignee().defaultAlias();
List<MAccessCertificationWorkItemReference> assigneeRefRows = select(assigneeRefAlias, assigneeRefAlias.ownerOid.eq(UUID.fromString(accessCertificationCampaign.getOid())));
assertThat(assigneeRefRows).hasSize(4);
assigneeRefRows.sort(comparing(tr -> tr.targetOid));
MAccessCertificationWorkItemReference assigneeRefRow = assigneeRefRows.get(0);
assertThat(assigneeRefRow.ownerOid).isEqualTo(UUID.fromString(accessCertificationCampaign.getOid()));
assertThat(assigneeRefRow.ownerType).isEqualTo(MObjectType.ACCESS_CERTIFICATION_CAMPAIGN);
assertThat(assigneeRefRow.referenceType).isEqualTo(MReferenceType.ACCESS_CERT_WI_ASSIGNEE);
assertThat(assigneeRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(assigneeRefRow.targetOid).isEqualTo(wi3AssigneeRef1Oid);
assertCachedUri(assigneeRefRow.relationId, wi3AssigneeRef1Relation);
assertThat(assigneeRefRow.accessCertCaseCid).isEqualTo(49);
assertThat(assigneeRefRow.accessCertWorkItemCid).isEqualTo(59);
assigneeRefRow = assigneeRefRows.get(1);
assertThat(assigneeRefRow.ownerOid).isEqualTo(UUID.fromString(accessCertificationCampaign.getOid()));
assertThat(assigneeRefRow.ownerType).isEqualTo(MObjectType.ACCESS_CERTIFICATION_CAMPAIGN);
assertThat(assigneeRefRow.referenceType).isEqualTo(MReferenceType.ACCESS_CERT_WI_ASSIGNEE);
assertThat(assigneeRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(assigneeRefRow.targetOid).isEqualTo(wi1AssigneeRef1Oid);
assertCachedUri(assigneeRefRow.relationId, wi1AssigneeRef1Relation);
assertThat(assigneeRefRow.accessCertCaseCid).isEqualTo(48);
assertThat(assigneeRefRow.accessCertWorkItemCid).isEqualTo(55);
assigneeRefRow = assigneeRefRows.get(2);
assertThat(assigneeRefRow.ownerOid).isEqualTo(UUID.fromString(accessCertificationCampaign.getOid()));
assertThat(assigneeRefRow.ownerType).isEqualTo(MObjectType.ACCESS_CERTIFICATION_CAMPAIGN);
assertThat(assigneeRefRow.referenceType).isEqualTo(MReferenceType.ACCESS_CERT_WI_ASSIGNEE);
assertThat(assigneeRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(assigneeRefRow.targetOid).isEqualTo(wi2AssigneeRef1Oid);
assertCachedUri(assigneeRefRow.relationId, wi2AssigneeRef1Relation);
assertThat(assigneeRefRow.accessCertCaseCid).isEqualTo(48);
assertThat(assigneeRefRow.accessCertWorkItemCid).isEqualTo(56);
assigneeRefRow = assigneeRefRows.get(3);
assertThat(assigneeRefRow.ownerOid).isEqualTo(UUID.fromString(accessCertificationCampaign.getOid()));
assertThat(assigneeRefRow.ownerType).isEqualTo(MObjectType.ACCESS_CERTIFICATION_CAMPAIGN);
assertThat(assigneeRefRow.referenceType).isEqualTo(MReferenceType.ACCESS_CERT_WI_ASSIGNEE);
assertThat(assigneeRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(assigneeRefRow.targetOid).isEqualTo(wi1AssigneeRef2Oid);
assertCachedUri(assigneeRefRow.relationId, wi1AssigneeRef2Relation);
assertThat(assigneeRefRow.accessCertCaseCid).isEqualTo(48);
assertThat(assigneeRefRow.accessCertWorkItemCid).isEqualTo(55);
// Candidate refs
QAccessCertificationWorkItemReference candidateRefAlias = QAccessCertificationWorkItemReferenceMapping.getForCaseWorkItemCandidate().defaultAlias();
List<MAccessCertificationWorkItemReference> candidateRefRows = select(candidateRefAlias, candidateRefAlias.ownerOid.eq(UUID.fromString(accessCertificationCampaign.getOid())));
assertThat(candidateRefRows).hasSize(4);
candidateRefRows.sort(comparing(tr -> tr.targetOid));
MAccessCertificationWorkItemReference candidateRefRow = candidateRefRows.get(0);
assertThat(candidateRefRow.ownerOid).isEqualTo(UUID.fromString(accessCertificationCampaign.getOid()));
assertThat(candidateRefRow.ownerType).isEqualTo(MObjectType.ACCESS_CERTIFICATION_CAMPAIGN);
assertThat(candidateRefRow.referenceType).isEqualTo(MReferenceType.ACCESS_CERT_WI_CANDIDATE);
assertThat(candidateRefRow.targetType).isEqualTo(MObjectType.ORG);
assertThat(candidateRefRow.targetOid).isEqualTo(wi3CandidateRef1Oid);
assertCachedUri(candidateRefRow.relationId, wi3CandidateRef1Relation);
assertThat(candidateRefRow.accessCertCaseCid).isEqualTo(49);
assertThat(candidateRefRow.accessCertWorkItemCid).isEqualTo(59);
candidateRefRow = candidateRefRows.get(1);
assertThat(candidateRefRow.ownerOid).isEqualTo(UUID.fromString(accessCertificationCampaign.getOid()));
assertThat(candidateRefRow.ownerType).isEqualTo(MObjectType.ACCESS_CERTIFICATION_CAMPAIGN);
assertThat(candidateRefRow.referenceType).isEqualTo(MReferenceType.ACCESS_CERT_WI_CANDIDATE);
assertThat(candidateRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(candidateRefRow.targetOid).isEqualTo(wi1CandidateRef1Oid);
assertCachedUri(candidateRefRow.relationId, wi1CandidateRef1Relation);
assertThat(candidateRefRow.accessCertCaseCid).isEqualTo(48);
assertThat(candidateRefRow.accessCertWorkItemCid).isEqualTo(55);
candidateRefRow = candidateRefRows.get(2);
assertThat(candidateRefRow.ownerOid).isEqualTo(UUID.fromString(accessCertificationCampaign.getOid()));
assertThat(candidateRefRow.ownerType).isEqualTo(MObjectType.ACCESS_CERTIFICATION_CAMPAIGN);
assertThat(candidateRefRow.referenceType).isEqualTo(MReferenceType.ACCESS_CERT_WI_CANDIDATE);
assertThat(candidateRefRow.targetType).isEqualTo(MObjectType.ORG);
assertThat(candidateRefRow.targetOid).isEqualTo(wi2CandidateRef2Oid);
assertCachedUri(candidateRefRow.relationId, wi2CandidateRef2Relation);
assertThat(candidateRefRow.accessCertCaseCid).isEqualTo(48);
assertThat(candidateRefRow.accessCertWorkItemCid).isEqualTo(56);
candidateRefRow = candidateRefRows.get(3);
assertThat(candidateRefRow.ownerOid).isEqualTo(UUID.fromString(accessCertificationCampaign.getOid()));
assertThat(candidateRefRow.ownerType).isEqualTo(MObjectType.ACCESS_CERTIFICATION_CAMPAIGN);
assertThat(candidateRefRow.referenceType).isEqualTo(MReferenceType.ACCESS_CERT_WI_CANDIDATE);
assertThat(candidateRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(candidateRefRow.targetOid).isEqualTo(wi2CandidateRef1Oid);
assertCachedUri(candidateRefRow.relationId, wi2CandidateRef1Relation);
assertThat(candidateRefRow.accessCertCaseCid).isEqualTo(48);
assertThat(candidateRefRow.accessCertWorkItemCid).isEqualTo(56);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.
the class QueryInterpreterTest method test420CaseParentFilter.
@Test
public void test420CaseParentFilter() throws Exception {
Session session = open();
try {
/*
* ### AccessCertificationCaseType: Equal(../name, 'Campaign 1')
*/
ObjectQuery query = prismContext.queryFor(AccessCertificationCaseType.class).item(T_PARENT, F_NAME).eq("Campaign 1").build();
String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query);
assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" + " left join a.owner o\n" + "where\n" + " (\n" + " o.nameCopy.orig = :orig and\n" + " o.nameCopy.norm = :norm\n" + " )\n");
} finally {
close(session);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.
the class AccCertCaseOperationsHelper method recordDecision.
/**
* Records a decision. Updates necessary items like the outcomes.
*/
void recordDecision(String campaignOid, long caseId, long workItemId, AccessCertificationResponseType response, String comment, Task task, OperationResult result) throws SecurityViolationException, ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
AccessCertificationCaseType acase = queryHelper.getCase(campaignOid, caseId, task, result);
if (acase == null) {
throw new ObjectNotFoundException("Case " + caseId + " was not found in campaign " + campaignOid);
}
AccessCertificationCampaignType campaign = CertCampaignTypeUtil.getCampaign(acase);
if (campaign == null) {
throw new IllegalStateException("No owning campaign present in case " + acase);
}
AccessCertificationWorkItemType workItem = CertCampaignTypeUtil.findWorkItem(acase, workItemId);
if (workItem == null) {
throw new ObjectNotFoundException("Work item " + workItemId + " was not found in campaign " + toShortString(campaign) + ", case " + caseId);
}
ObjectReferenceType responderRef = ObjectTypeUtil.createObjectRef(securityContextManager.getPrincipal().getFocus(), prismContext);
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
ItemPath workItemPath = ItemPath.create(F_CASE, caseId, F_WORK_ITEM, workItemId);
Collection<ItemDelta<?, ?>> deltaList = prismContext.deltaFor(AccessCertificationCampaignType.class).item(workItemPath.append(AccessCertificationWorkItemType.F_OUTPUT)).replace(new AbstractWorkItemOutputType().outcome(toUri(normalizeToNull(response))).comment(comment)).item(workItemPath.append(AccessCertificationWorkItemType.F_OUTPUT_CHANGE_TIMESTAMP)).replace(now).item(workItemPath.append(AccessCertificationWorkItemType.F_PERFORMER_REF)).replace(responderRef).asItemDeltas();
// to have data for outcome computation
ItemDeltaCollectionsUtil.applyTo(deltaList, campaign.asPrismContainerValue());
AccessCertificationResponseType newCurrentOutcome = computationHelper.computeOutcomeForStage(acase, campaign, campaign.getStageNumber());
AccessCertificationResponseType newOverallOutcome = computationHelper.computeOverallOutcome(acase, campaign, campaign.getStageNumber(), newCurrentOutcome);
deltaList.addAll(prismContext.deltaFor(AccessCertificationCampaignType.class).item(F_CASE, caseId, F_CURRENT_STAGE_OUTCOME).replace(toUri(newCurrentOutcome)).item(F_CASE, caseId, F_OUTCOME).replace(toUri(newOverallOutcome)).asItemDeltas());
updateHelper.modifyObjectPreAuthorized(AccessCertificationCampaignType.class, campaignOid, deltaList, task, result);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.
the class AccCertCaseOperationsHelper method delegateWorkItems.
// region ================================ Delegation/escalation ================================
void delegateWorkItems(String campaignOid, List<AccessCertificationWorkItemType> workItems, DelegateWorkItemActionType delegateAction, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException, SecurityViolationException {
LOGGER.debug("Going to delegate {} work item(s) in campaign {}", workItems.size(), campaignOid);
MidPointPrincipal principal = securityContextManager.getPrincipal();
result.addContext("user", toShortString(principal.getFocus()));
ObjectReferenceType initiator = ObjectTypeUtil.createObjectRef(principal.getFocus(), prismContext);
ObjectReferenceType attorney = ObjectTypeUtil.createObjectRef(principal.getAttorney(), prismContext);
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
List<ItemDelta<?, ?>> deltas = new ArrayList<>();
for (AccessCertificationWorkItemType workItem : workItems) {
AccessCertificationCaseType aCase = CertCampaignTypeUtil.getCaseChecked(workItem);
AccessCertificationCampaignType campaign = CertCampaignTypeUtil.getCampaignChecked(aCase);
if (!java.util.Objects.equals(campaign.getOid(), campaignOid)) {
throw new IllegalArgumentException("Work item to delegate does not belong to specified campaign (" + campaignOid + ") but to " + campaign);
}
// TODO reload the work item here (and replace exceptions with logged warnings)
if (workItem.getCloseTimestamp() != null) {
throw new IllegalStateException("Couldn't delegate a work item that is already closed: " + workItem);
}
// actually, stage/iteration should match, as the work item is not closed
if (norm(workItem.getIteration()) != norm(campaign.getIteration())) {
throw new IllegalStateException("Couldn't delegate a work item that is not in a current iteration. Current iteration: " + norm(campaign.getIteration()) + ", work item iteration: " + norm(workItem.getIteration()));
}
if (workItem.getStageNumber() != campaign.getStageNumber()) {
throw new IllegalStateException("Couldn't delegate a work item that is not in a current stage. Current stage: " + campaign.getStageNumber() + ", work item stage: " + workItem.getStageNumber());
}
List<ObjectReferenceType> delegates = computeDelegateTo(delegateAction, workItem, aCase, campaign, task, result);
// TODO
WorkItemEventCauseInformationType causeInformation = null;
// noinspection ConstantConditions
LOGGER.trace("Delegating work item {} to {}: cause={}", workItem, delegates, causeInformation);
List<ObjectReferenceType> assigneesBefore = CloneUtil.cloneCollectionMembers(workItem.getAssigneeRef());
WorkItemDelegationMethodType method = getDelegationMethod(delegateAction);
List<ObjectReferenceType> newAssignees = new ArrayList<>();
List<ObjectReferenceType> delegatedTo = new ArrayList<>();
CaseRelatedUtils.computeAssignees(newAssignees, delegatedTo, delegates, method, workItem.getAssigneeRef());
// noinspection ConstantConditions
WorkItemDelegationEventType event = ApprovalContextUtil.createDelegationEvent(null, assigneesBefore, delegatedTo, method, causeInformation, prismContext);
event.setTimestamp(now);
event.setInitiatorRef(initiator);
event.setAttorneyRef(attorney);
event.setWorkItemId(workItem.getId());
event.setEscalationLevel(workItem.getEscalationLevel());
event.setStageNumber(campaign.getStageNumber());
event.setIteration(norm(campaign.getIteration()));
addDeltasForNewAssigneesAndEvent(deltas, workItem, aCase, newAssignees, event);
// notification (after modifications)
}
updateHelper.modifyObjectPreAuthorized(AccessCertificationCampaignType.class, campaignOid, deltas, task, result);
// TODO notifications
// AccessCertificationCampaignType updatedCampaign = refreshCampaign(campaign, task, result);
// LOGGER.info("Updated campaign state: {}", updatedCampaign.getState());
// eventHelper.onCampaignEnd(updatedCampaign, task, result);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.
the class AccCertOpenerHelper method getDeltasToUpdateCases.
/**
* Deltas to advance cases to next stage when opening it.
*/
private void getDeltasToUpdateCases(AccessCertificationCampaignType campaign, AccessCertificationStageType stage, ModificationsToExecute modifications, OpeningContext openingContext, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
int stageToBe = stage.getNumber();
int iteration = norm(campaign.getIteration());
LOGGER.trace("Updating cases in {}; current stage = {}, stageToBe = {}, iteration = {}", toShortStringLazy(campaign), campaign.getStageNumber(), stageToBe, iteration);
List<AccessCertificationCaseType> caseList = queryHelper.getAllCurrentIterationCases(campaign.getOid(), iteration, null, result);
AccessCertificationReviewerSpecificationType reviewerSpec = reviewersHelper.findReviewersSpecification(campaign, stageToBe);
LOGGER.trace("cases: {}, reviewerSpec: {}", caseList.size(), reviewerSpec);
for (AccessCertificationCaseType aCase : caseList) {
LOGGER.trace("----------------------------------------------------------------------------------------");
LOGGER.trace("Considering case: {}", aCase);
Long caseId = aCase.asPrismContainerValue().getId();
assert caseId != null;
if (aCase.getReviewFinishedTimestamp() != null) {
LOGGER.trace("Case {} review process has already finished", caseId);
continue;
}
AccessCertificationResponseType stageOutcome = computationHelper.getStageOutcome(aCase, stageToBe);
if (OutcomeUtils.normalizeToNull(stageOutcome) != null) {
LOGGER.trace("Case {} already has an outcome for stage {} - it will not be reviewed in this stage in iteration {}", caseId, stageToBe, iteration);
continue;
}
List<ObjectReferenceType> reviewers = reviewersHelper.getReviewersForCase(aCase, campaign, reviewerSpec, task, result);
List<AccessCertificationWorkItemType> workItems = createWorkItems(reviewers, stageToBe, iteration, aCase);
openingContext.workItemsCreated += workItems.size();
openingContext.casesEnteringStage++;
aCase.getWorkItem().addAll(CloneUtil.cloneCollectionMembers(workItems));
AccessCertificationResponseType currentStageOutcome = computationHelper.computeOutcomeForStage(aCase, campaign, stageToBe);
AccessCertificationResponseType overallOutcome = computationHelper.computeOverallOutcome(aCase, campaign, stageToBe, currentStageOutcome);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Computed: reviewers: {}, workItems: {}, currentStageOutcome: {}, overallOutcome: {}", PrettyPrinter.prettyPrint(reviewers), workItems.size(), currentStageOutcome, overallOutcome);
}
modifications.add(prismContext.deltaFor(AccessCertificationCampaignType.class).item(F_CASE, caseId, F_WORK_ITEM).add(PrismContainerValue.toPcvList(workItems)).item(F_CASE, caseId, F_CURRENT_STAGE_CREATE_TIMESTAMP).replace(stage.getStartTimestamp()).item(F_CASE, caseId, F_CURRENT_STAGE_DEADLINE).replace(stage.getDeadline()).item(F_CASE, caseId, F_CURRENT_STAGE_OUTCOME).replace(toUri(currentStageOutcome)).item(F_CASE, caseId, F_OUTCOME).replace(toUri(overallOutcome)).item(F_CASE, caseId, F_STAGE_NUMBER).replace(stageToBe).item(F_CASE, caseId, F_ITERATION).replace(iteration).asItemDeltas());
}
LOGGER.debug("Created {} deltas (in {} batches) to advance {} out of {} cases for campaign {}; work items created: {}", modifications.getTotalDeltasCount(), modifications.batches.size(), openingContext.casesEnteringStage, caseList.size(), toShortString(campaign), openingContext.workItemsCreated);
}
Aggregations