use of com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractWorkItemOutputType in project midpoint by Evolveum.
the class SqaleRepoAddDeleteObjectTest method test850Case.
@Test
public void test850Case() throws Exception {
OperationResult result = createOperationResult();
given("case");
String objectName = "case" + getTestNumber();
UUID parentOid = UUID.randomUUID();
QName parentRelation = QName.valueOf("{https://random.org/ns}case-parent-rel");
UUID objectOid = UUID.randomUUID();
QName objectRelation = QName.valueOf("{https://random.org/ns}case-object-rel");
UUID requestorOid = UUID.randomUUID();
QName requestorRelation = QName.valueOf("{https://random.org/ns}case-requestor-rel");
UUID targetOid = UUID.randomUUID();
QName targetRelation = QName.valueOf("{https://random.org/ns}case-target-rel");
UUID originalAssignee1Oid = UUID.randomUUID();
QName originalAssignee1Relation = QName.valueOf("{https://random.org/ns}original-assignee1-rel");
UUID performer1Oid = UUID.randomUUID();
QName performer1Relation = QName.valueOf("{https://random.org/ns}performer1-rel");
UUID originalAssignee2Oid = UUID.randomUUID();
QName originalAssignee2Relation = QName.valueOf("{https://random.org/ns}original-assignee2-rel");
UUID performer2Oid = UUID.randomUUID();
QName performer2Relation = QName.valueOf("{https://random.org/ns}performer2-rel");
// explicit UUID, to ensure ordering
UUID wi1AssigneeRef1Oid = UUID.fromString("4be487d2-c833-11eb-ba67-6768439d49a8");
QName wi1AssigneeRef1Relation = QName.valueOf("{https://random.org/ns}wi-1-assignee-1-rel");
// explicit UUID, to ensure ordering
UUID wi1CandidateRef1Oid = UUID.fromString("ac4d4a54-c834-11eb-ba57-8b9fef95c25d");
QName wi1CandidateRef1Relation = QName.valueOf("{https://random.org/ns}wi-1-candidate-1-rel");
// explicit UUID, to ensure ordering
UUID wi1CandidateRef2Oid = UUID.fromString("9dc675dc-c834-11eb-b31a-17ac6f7bab4f");
QName wi1CandidateRef2Relation = QName.valueOf("{https://random.org/ns}wi-1-candidate-2-rel");
// explicit UUID, to ensure ordering
UUID wi2AssigneeRef1Oid = UUID.fromString("d867f3e0-c830-11eb-b7cf-abba51968ecb");
QName wi2AssigneeRef1Relation = QName.valueOf("{https://random.org/ns}wi-2-assignee-1-rel");
// explicit UUID, to ensure ordering
UUID wi2AssigneeRef2Oid = UUID.fromString("6a92b1ec-c831-11eb-a075-5f6be1e16c34");
QName wi2AssigneeRef2Relation = QName.valueOf("{https://random.org/ns}wi-2-assignee-2-rel");
// explicit UUID, to ensure ordering
UUID wi2CandidateRef1Oid = UUID.fromString("df6388b8-c834-11eb-946a-efa73de3615b");
QName wi2CandidateRef1Relation = QName.valueOf("{https://random.org/ns}wi-2-candidate-1-rel");
CaseType acase = new CaseType(prismContext).name(objectName).state("closed").closeTimestamp(MiscUtil.asXMLGregorianCalendar(321L)).parentRef(parentOid.toString(), CaseType.COMPLEX_TYPE, parentRelation).objectRef(objectOid.toString(), RoleType.COMPLEX_TYPE, objectRelation).requestorRef(requestorOid.toString(), UserType.COMPLEX_TYPE, requestorRelation).targetRef(targetOid.toString(), OrgType.COMPLEX_TYPE, targetRelation).workItem(new CaseWorkItemType(prismContext).id(41L).createTimestamp(MiscUtil.asXMLGregorianCalendar(10000L)).closeTimestamp(MiscUtil.asXMLGregorianCalendar(10100L)).deadline(MiscUtil.asXMLGregorianCalendar(10200L)).originalAssigneeRef(originalAssignee1Oid.toString(), OrgType.COMPLEX_TYPE, originalAssignee1Relation).performerRef(performer1Oid.toString(), UserType.COMPLEX_TYPE, performer1Relation).stageNumber(1).assigneeRef(wi1AssigneeRef1Oid.toString(), UserType.COMPLEX_TYPE, wi1AssigneeRef1Relation).candidateRef(wi1CandidateRef1Oid.toString(), UserType.COMPLEX_TYPE, wi1CandidateRef1Relation).candidateRef(wi1CandidateRef2Oid.toString(), UserType.COMPLEX_TYPE, wi1CandidateRef2Relation).output(new AbstractWorkItemOutputType(prismContext).outcome("OUTCOME one"))).workItem(new CaseWorkItemType(prismContext).id(42L).createTimestamp(MiscUtil.asXMLGregorianCalendar(20000L)).closeTimestamp(MiscUtil.asXMLGregorianCalendar(20100L)).deadline(MiscUtil.asXMLGregorianCalendar(20200L)).originalAssigneeRef(originalAssignee2Oid.toString(), UserType.COMPLEX_TYPE, originalAssignee2Relation).performerRef(performer2Oid.toString(), UserType.COMPLEX_TYPE, performer2Relation).stageNumber(2).assigneeRef(wi2AssigneeRef1Oid.toString(), UserType.COMPLEX_TYPE, wi2AssigneeRef1Relation).assigneeRef(wi2AssigneeRef2Oid.toString(), UserType.COMPLEX_TYPE, wi2AssigneeRef2Relation).candidateRef(wi2CandidateRef1Oid.toString(), UserType.COMPLEX_TYPE, wi2CandidateRef1Relation).output(new AbstractWorkItemOutputType(prismContext).outcome("OUTCOME two")));
when("adding it to the repository");
repositoryService.addObject(acase.asPrismObject(), null, result);
then("it is stored and relevant attributes are in columns");
assertThatOperationResult(result).isSuccess();
MCase caseRow = selectObjectByOid(QCase.class, acase.getOid());
assertThat(caseRow.state).isEqualTo("closed");
assertThat(caseRow.closeTimestamp).isEqualTo(Instant.ofEpochMilli(321));
assertThat(caseRow.parentRefTargetOid).isEqualTo(parentOid);
assertThat(caseRow.parentRefTargetType).isEqualTo(MObjectType.CASE);
assertCachedUri(caseRow.parentRefRelationId, parentRelation);
assertThat(caseRow.objectRefTargetOid).isEqualTo(objectOid);
assertThat(caseRow.objectRefTargetType).isEqualTo(MObjectType.ROLE);
assertCachedUri(caseRow.objectRefRelationId, objectRelation);
assertThat(caseRow.requestorRefTargetOid).isEqualTo(requestorOid);
assertThat(caseRow.requestorRefTargetType).isEqualTo(MObjectType.USER);
assertCachedUri(caseRow.requestorRefRelationId, requestorRelation);
assertThat(caseRow.targetRefTargetOid).isEqualTo(targetOid);
assertThat(caseRow.targetRefTargetType).isEqualTo(MObjectType.ORG);
assertCachedUri(caseRow.targetRefRelationId, targetRelation);
QCaseWorkItem wiAlias = aliasFor(QCaseWorkItem.class);
List<MCaseWorkItem> wiRows = select(wiAlias, wiAlias.ownerOid.eq(UUID.fromString(acase.getOid())));
assertThat(wiRows).hasSize(2);
wiRows.sort(comparing(tr -> tr.cid));
MCaseWorkItem wiRow = wiRows.get(0);
// assigned in advance
assertThat(wiRow.cid).isEqualTo(41);
assertThat(wiRow.ownerOid.toString()).isEqualTo(acase.getOid());
assertThat(wiRow.containerType).isEqualTo(MContainerType.CASE_WORK_ITEM);
assertThat(wiRow.createTimestamp).isEqualTo(Instant.ofEpochMilli(10000));
assertThat(wiRow.closeTimestamp).isEqualTo(Instant.ofEpochMilli(10100));
assertThat(wiRow.deadline).isEqualTo(Instant.ofEpochMilli(10200));
assertThat(wiRow.originalAssigneeRefTargetOid).isEqualTo(originalAssignee1Oid);
assertThat(wiRow.originalAssigneeRefTargetType).isEqualTo(MObjectType.ORG);
assertCachedUri(wiRow.originalAssigneeRefRelationId, originalAssignee1Relation);
assertThat(wiRow.outcome).isEqualTo("OUTCOME one");
assertThat(wiRow.performerRefTargetOid).isEqualTo(performer1Oid);
assertThat(wiRow.performerRefTargetType).isEqualTo(MObjectType.USER);
assertCachedUri(wiRow.performerRefRelationId, performer1Relation);
assertThat(wiRow.stageNumber).isEqualTo(1);
wiRow = wiRows.get(1);
// assigned in advance
assertThat(wiRow.cid).isEqualTo(42);
assertThat(wiRow.ownerOid.toString()).isEqualTo(acase.getOid());
assertThat(wiRow.containerType).isEqualTo(MContainerType.CASE_WORK_ITEM);
assertThat(wiRow.createTimestamp).isEqualTo(Instant.ofEpochMilli(20000));
assertThat(wiRow.closeTimestamp).isEqualTo(Instant.ofEpochMilli(20100));
assertThat(wiRow.deadline).isEqualTo(Instant.ofEpochMilli(20200));
assertThat(wiRow.originalAssigneeRefTargetOid).isEqualTo(originalAssignee2Oid);
assertThat(wiRow.originalAssigneeRefTargetType).isEqualTo(MObjectType.USER);
assertCachedUri(wiRow.originalAssigneeRefRelationId, originalAssignee2Relation);
assertThat(wiRow.outcome).isEqualTo("OUTCOME two");
assertThat(wiRow.performerRefTargetOid).isEqualTo(performer2Oid);
assertThat(wiRow.performerRefTargetType).isEqualTo(MObjectType.USER);
assertCachedUri(wiRow.performerRefRelationId, performer2Relation);
assertThat(wiRow.stageNumber).isEqualTo(2);
QCaseWorkItemReference assigneeRefAlias = QCaseWorkItemReferenceMapping.getForCaseWorkItemAssignee().defaultAlias();
List<MCaseWorkItemReference> assigneeRefRows = select(assigneeRefAlias, assigneeRefAlias.ownerOid.eq(UUID.fromString(acase.getOid())));
assertThat(assigneeRefRows).hasSize(3);
assigneeRefRows.sort(comparing(tr -> tr.targetOid));
MCaseWorkItemReference assigneeRefRow = assigneeRefRows.get(0);
assertThat(assigneeRefRow.ownerOid).isEqualTo(UUID.fromString(acase.getOid()));
assertThat(assigneeRefRow.ownerType).isEqualTo(MObjectType.CASE);
assertThat(assigneeRefRow.referenceType).isEqualTo(MReferenceType.CASE_WI_ASSIGNEE);
assertThat(assigneeRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(assigneeRefRow.targetOid).isEqualTo(wi2AssigneeRef1Oid);
assertCachedUri(assigneeRefRow.relationId, wi2AssigneeRef1Relation);
assertThat(assigneeRefRow.workItemCid).isEqualTo(42);
assigneeRefRow = assigneeRefRows.get(2);
assertThat(assigneeRefRow.ownerOid).isEqualTo(UUID.fromString(acase.getOid()));
assertThat(assigneeRefRow.ownerType).isEqualTo(MObjectType.CASE);
assertThat(assigneeRefRow.referenceType).isEqualTo(MReferenceType.CASE_WI_ASSIGNEE);
assertThat(assigneeRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(assigneeRefRow.targetOid).isEqualTo(wi2AssigneeRef2Oid);
assertCachedUri(assigneeRefRow.relationId, wi2AssigneeRef2Relation);
assertThat(assigneeRefRow.workItemCid).isEqualTo(42);
assigneeRefRow = assigneeRefRows.get(1);
assertThat(assigneeRefRow.ownerOid).isEqualTo(UUID.fromString(acase.getOid()));
assertThat(assigneeRefRow.ownerType).isEqualTo(MObjectType.CASE);
assertThat(assigneeRefRow.referenceType).isEqualTo(MReferenceType.CASE_WI_ASSIGNEE);
assertThat(assigneeRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(assigneeRefRow.targetOid).isEqualTo(wi1AssigneeRef1Oid);
assertCachedUri(assigneeRefRow.relationId, wi1AssigneeRef1Relation);
assertThat(assigneeRefRow.workItemCid).isEqualTo(41);
QCaseWorkItemReference candidateRefAlias = QCaseWorkItemReferenceMapping.getForCaseWorkItemCandidate().defaultAlias();
List<MCaseWorkItemReference> candidateRefRows = select(candidateRefAlias, candidateRefAlias.ownerOid.eq(UUID.fromString(acase.getOid())));
assertThat(candidateRefRows).hasSize(3);
candidateRefRows.sort(comparing(tr -> tr.targetOid));
MCaseWorkItemReference candidateRefRow = candidateRefRows.get(0);
assertThat(candidateRefRow.ownerOid).isEqualTo(UUID.fromString(acase.getOid()));
assertThat(candidateRefRow.ownerType).isEqualTo(MObjectType.CASE);
assertThat(candidateRefRow.referenceType).isEqualTo(MReferenceType.CASE_WI_CANDIDATE);
assertThat(candidateRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(candidateRefRow.targetOid).isEqualTo(wi1CandidateRef2Oid);
assertCachedUri(candidateRefRow.relationId, wi1CandidateRef2Relation);
assertThat(candidateRefRow.workItemCid).isEqualTo(41);
candidateRefRow = candidateRefRows.get(1);
assertThat(candidateRefRow.ownerOid).isEqualTo(UUID.fromString(acase.getOid()));
assertThat(candidateRefRow.ownerType).isEqualTo(MObjectType.CASE);
assertThat(candidateRefRow.referenceType).isEqualTo(MReferenceType.CASE_WI_CANDIDATE);
assertThat(candidateRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(candidateRefRow.targetOid).isEqualTo(wi1CandidateRef1Oid);
assertCachedUri(candidateRefRow.relationId, wi1CandidateRef1Relation);
assertThat(candidateRefRow.workItemCid).isEqualTo(41);
candidateRefRow = candidateRefRows.get(2);
assertThat(candidateRefRow.ownerOid).isEqualTo(UUID.fromString(acase.getOid()));
assertThat(candidateRefRow.ownerType).isEqualTo(MObjectType.CASE);
assertThat(candidateRefRow.referenceType).isEqualTo(MReferenceType.CASE_WI_CANDIDATE);
assertThat(candidateRefRow.targetType).isEqualTo(MObjectType.USER);
assertThat(candidateRefRow.targetOid).isEqualTo(wi2CandidateRef1Oid);
assertCachedUri(candidateRefRow.relationId, wi2CandidateRef1Relation);
assertThat(candidateRefRow.workItemCid).isEqualTo(42);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractWorkItemOutputType in project midpoint by Evolveum.
the class AbstractWfTestPolicy method executeTest.
protected <F extends FocusType> OperationResult executeTest(TestDetails testDetails, int expectedSubTaskCount) throws Exception {
// GIVEN
prepareNotifications();
dummyAuditService.clear();
Task opTask = getTestTask();
boolean USE_FULL_TRACING = false;
// noinspection ConstantConditions
if (USE_FULL_TRACING) {
setModelAndWorkflowLoggingTracing(opTask);
} else {
testDetails.setTracing(opTask);
}
opTask.setOwner(userAdministrator);
OperationResult result = opTask.getResult();
LensContext<F> modelContext = testDetails.createModelContext(result);
displayDumpable("Model context at test start", modelContext);
// this has problems with deleting assignments by ID
// assertFocusModificationSanity(modelContext);
// WHEN
HookOperationMode mode;
clockworkMedic.enterModelMethod(true);
try {
mode = clockwork.run(modelContext, opTask, result);
} finally {
clockworkMedic.exitModelMethod(true);
}
// THEN
displayDumpable("Model context after first clockwork.run", modelContext);
assertEquals("Unexpected state of the context", ModelState.PRIMARY, modelContext.getState());
assertEquals("Wrong mode after clockwork.run in " + modelContext.getState(), HookOperationMode.BACKGROUND, mode);
opTask.refresh(result);
display("Model task after first clockwork.run", opTask);
CaseType rootCase = testHelper.getRootCase(result);
List<CaseType> subcases = miscHelper.getSubcases(rootCase, result);
CaseType case0 = WfTestHelper.findAndRemoveCase0(subcases);
assertEquals("Incorrect number of subtasks", expectedSubTaskCount, subcases.size());
final Collection<SelectorOptions<GetOperationOptions>> options1 = schemaService.getOperationOptionsBuilder().item(T_PARENT, F_OBJECT_REF).resolve().item(T_PARENT, F_TARGET_REF).resolve().item(F_ASSIGNEE_REF).resolve().item(F_ORIGINAL_ASSIGNEE_REF).resolve().item(T_PARENT, F_REQUESTOR_REF).resolve().build();
List<CaseWorkItemType> workItems = new // to assure modifiable result list
ArrayList<>(modelService.searchContainers(CaseWorkItemType.class, getOpenItemsQuery(), options1, opTask, result));
displayDumpable("changes by state after first clockwork run", approvalsManager.getChangesByState(rootCase, modelInteractionService, prismContext, opTask, result));
testDetails.afterFirstClockworkRun(rootCase, case0, subcases, workItems, opTask, result);
if (testDetails.executeImmediately()) {
if (case0 != null) {
testHelper.waitForCaseClose(case0, 20000);
}
displayDumpable("changes by state after case0 finishes", approvalsManager.getChangesByState(rootCase, modelInteractionService, prismContext, opTask, result));
testDetails.afterCase0Finishes(rootCase, opTask, result);
}
for (int i = 0; i < subcases.size(); i++) {
CaseType subcase = subcases.get(i);
PrismProperty<ObjectTreeDeltasType> deltas = subcase.asPrismObject().findProperty(ItemPath.create(F_APPROVAL_CONTEXT, F_DELTAS_TO_APPROVE));
assertNotNull("There are no modifications in subcase #" + i + ": " + subcase, deltas);
assertEquals("Incorrect number of modifications in subcase #" + i + ": " + subcase, 1, deltas.getRealValues().size());
// todo check correctness of the modification?
// now check the workflow state
String caseOid = subcase.getOid();
List<CaseWorkItemType> caseWorkItems = getWorkItemsForCase(caseOid, null, result);
assertFalse("work item not found", caseWorkItems.isEmpty());
for (CaseWorkItemType caseWorkItem : caseWorkItems) {
Boolean approve = testDetails.decideOnApproval(caseWorkItem);
if (approve != null) {
caseManager.completeWorkItem(WorkItemId.create(caseOid, caseWorkItem.getId()), new AbstractWorkItemOutputType(prismContext).outcome(ApprovalUtils.toUri(approve)), null, opTask, result);
login(userAdministrator);
break;
}
}
}
// alternative way of approvals executions
if (CollectionUtils.isNotEmpty(testDetails.getApprovalSequence())) {
List<ApprovalInstruction> instructions = new ArrayList<>(testDetails.getApprovalSequence());
while (!instructions.isEmpty()) {
List<CaseWorkItemType> currentWorkItems = modelService.searchContainers(CaseWorkItemType.class, getOpenItemsQuery(), options1, opTask, result);
boolean matched = false;
Collection<ApprovalInstruction> instructionsToConsider = testDetails.strictlySequentialApprovals() ? singleton(instructions.get(0)) : instructions;
main: for (ApprovalInstruction approvalInstruction : instructionsToConsider) {
for (CaseWorkItemType workItem : currentWorkItems) {
if (approvalInstruction.matches(workItem)) {
if (approvalInstruction.beforeApproval != null) {
approvalInstruction.beforeApproval.run();
}
login(getUserFromRepo(approvalInstruction.approverOid));
System.out.println("Completing work item " + WorkItemId.of(workItem) + " using " + approvalInstruction);
caseManager.completeWorkItem(WorkItemId.of(workItem), new AbstractWorkItemOutputType(prismContext).outcome(ApprovalUtils.toUri(approvalInstruction.approval)).comment(approvalInstruction.comment), null, opTask, result);
if (approvalInstruction.afterApproval != null) {
approvalInstruction.afterApproval.run();
}
login(userAdministrator);
matched = true;
instructions.remove(approvalInstruction);
break main;
}
}
}
if (!matched) {
fail("None of approval instructions " + instructionsToConsider + " matched any of current work items: " + currentWorkItems);
}
}
}
CaseType rootCaseAfter = testHelper.waitForCaseClose(rootCase, 60000);
subcases = miscHelper.getSubcases(rootCaseAfter, result);
WfTestHelper.findAndRemoveCase0(subcases);
displayDumpable("changes by state after root case finishes", approvalsManager.getChangesByState(rootCaseAfter, modelInteractionService, prismContext, opTask, result));
testDetails.afterRootCaseFinishes(rootCaseAfter, subcases, opTask, result);
notificationManager.setDisabled(true);
// Check audit
displayDumpable("Audit", dummyAuditService);
displayDumpable("Output context", modelContext);
return result;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractWorkItemOutputType in project midpoint by Evolveum.
the class QAccessCertificationWorkItemMapping method insert.
// about duplication see the comment in QObjectMapping.toRowObjectWithoutFullObject
@Override
@SuppressWarnings("DuplicatedCode")
public MAccessCertificationWorkItem insert(AccessCertificationWorkItemType workItem, MAccessCertificationCase caseRow, JdbcSession jdbcSession) {
MAccessCertificationWorkItem row = initRowObject(workItem, caseRow);
row.closeTimestamp = MiscUtil.asInstant(workItem.getCloseTimestamp());
// TODO: iteration -> campaignIteration
row.campaignIteration = workItem.getIteration();
AbstractWorkItemOutputType output = workItem.getOutput();
if (output != null) {
row.outcome = output.getOutcome();
}
row.outputChangeTimestamp = MiscUtil.asInstant(workItem.getOutputChangeTimestamp());
setReference(workItem.getPerformerRef(), o -> row.performerRefTargetOid = o, t -> row.performerRefTargetType = t, r -> row.performerRefRelationId = r);
row.stageNumber = workItem.getStageNumber();
insert(row, jdbcSession);
storeRefs(row, workItem.getAssigneeRef(), QAccessCertificationWorkItemReferenceMapping.getForCaseWorkItemAssignee(), jdbcSession);
storeRefs(row, workItem.getCandidateRef(), QAccessCertificationWorkItemReferenceMapping.getForCaseWorkItemCandidate(), jdbcSession);
return row;
}
Aggregations