use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class TestActivation method test100ModifyUserJackAssignAccount.
@Test
public void test100ModifyUserJackAssignAccount() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_OID, null, true);
deltas.add(accountAssignmentUserDelta);
dummyAuditService.clear();
XMLGregorianCalendar start = clock.currentTimeXMLGregorianCalendar();
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
XMLGregorianCalendar end = clock.currentTimeXMLGregorianCalendar();
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack);
accountOid = getSingleLinkOid(userJack);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
display("Shadow (repo)", accountShadow);
assertDummyAccountShadowRepo(accountShadow, accountOid, "jack");
TestUtil.assertCreateTimestamp(accountShadow, start, end);
assertEnableTimestampShadow(accountShadow, start, end);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
display("Shadow (model)", accountModel);
assertDummyAccountShadowModel(accountModel, accountOid, "jack", "Jack Sparrow");
TestUtil.assertCreateTimestamp(accountModel, start, end);
assertEnableTimestampShadow(accountModel, start, end);
// Check account in dummy resource
assertDefaultDummyAccount("jack", "Jack Sparrow", true);
assertDummyEnabled("jack");
TestUtil.assertModifyTimestamp(userJack, start, end);
// Check audit
displayDumpable("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
Collection<ObjectDeltaOperation<? extends ObjectType>> executionDeltas = dummyAuditService.getExecutionDeltas();
boolean found = false;
for (ObjectDeltaOperation<? extends ObjectType> executionDelta : executionDeltas) {
ObjectDelta<? extends ObjectType> objectDelta = executionDelta.getObjectDelta();
if (objectDelta.getObjectTypeClass() == ShadowType.class) {
PropertyDelta<Object> enableTimestampDelta = objectDelta.findPropertyDelta(PATH_ACTIVATION_ENABLE_TIMESTAMP);
displayDumpable("Audit enableTimestamp delta", enableTimestampDelta);
assertNotNull("EnableTimestamp delta vanished from audit record", enableTimestampDelta);
found = true;
}
}
assertTrue("Shadow delta not found", found);
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class ModelEventImpl method isStatusType.
@Override
public boolean isStatusType(EventStatusType eventStatus) {
boolean allSuccess = true, anySuccess = false, allFailure = true, anyFailure = false, anyInProgress = false;
for (ObjectDeltaOperation objectDeltaOperation : getAllExecutedDeltas()) {
if (objectDeltaOperation.getExecutionResult() != null) {
switch(objectDeltaOperation.getExecutionResult().getStatus()) {
case SUCCESS:
case WARNING:
case HANDLED_ERROR:
anySuccess = true;
allFailure = false;
break;
case FATAL_ERROR:
case PARTIAL_ERROR:
allSuccess = false;
anyFailure = true;
break;
case IN_PROGRESS:
allSuccess = false;
allFailure = false;
anyInProgress = true;
break;
case NOT_APPLICABLE:
break;
case UNKNOWN:
allSuccess = false;
allFailure = false;
break;
default:
LOGGER.warn("Unknown execution result: {}", objectDeltaOperation.getExecutionResult().getStatus());
}
} else {
allSuccess = false;
allFailure = false;
anyInProgress = true;
}
}
switch(eventStatus) {
case ALSO_SUCCESS:
return anySuccess;
case SUCCESS:
return allSuccess;
case FAILURE:
return anyFailure;
case ONLY_FAILURE:
return allFailure;
case IN_PROGRESS:
return anyInProgress;
default:
throw new IllegalStateException("Invalid eventStatusType: " + eventStatus);
}
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class ClockworkAuditHelper method addRecordMessage.
/**
* Adds a message to the record by pulling the messages from individual delta results.
*/
private void addRecordMessage(AuditEventRecord auditRecord, String message) {
if (auditRecord.getMessage() != null) {
return;
}
if (!StringUtils.isEmpty(message)) {
auditRecord.setMessage(message);
return;
}
Collection<ObjectDeltaOperation<? extends ObjectType>> deltas = auditRecord.getDeltas();
if (deltas.isEmpty()) {
return;
}
StringBuilder sb = new StringBuilder();
for (ObjectDeltaOperation<? extends ObjectType> delta : deltas) {
OperationResult executionResult = delta.getExecutionResult();
if (executionResult != null) {
String deltaMessage = executionResult.getMessage();
if (!StringUtils.isEmpty(deltaMessage)) {
if (sb.length() != 0) {
sb.append("; ");
}
sb.append(deltaMessage);
}
}
}
auditRecord.setMessage(sb.toString());
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class ClockworkClick method logFinalReadable.
/**
* Logs the entire operation in a human-readable fashion.
*/
private <F extends ObjectType> void logFinalReadable(LensContext<F> context) {
if (!LOGGER.isDebugEnabled()) {
return;
}
// a priori: sync delta
boolean hasSyncDelta = false;
for (LensProjectionContext projectionContext : context.getProjectionContexts()) {
ObjectDelta<ShadowType> syncDelta = projectionContext.getSyncDelta();
if (syncDelta != null) {
hasSyncDelta = true;
break;
}
}
Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = context.getExecutedDeltas();
if (!hasSyncDelta && executedDeltas.isEmpty()) {
// Not worth mentioning
return;
}
StringBuilder sb = new StringBuilder();
String channel = context.getChannel();
if (channel != null) {
sb.append("Channel: ").append(channel).append("\n");
}
if (hasSyncDelta) {
sb.append("Triggered by synchronization delta\n");
for (LensProjectionContext projectionContext : context.getProjectionContexts()) {
ObjectDelta<ShadowType> syncDelta = projectionContext.getSyncDelta();
if (syncDelta != null) {
sb.append(syncDelta.debugDump(1));
sb.append("\n");
}
DebugUtil.debugDumpLabel(sb, "Situation", 1);
sb.append(" ");
sb.append(projectionContext.getSynchronizationSituationDetected());
sb.append(" -> ");
sb.append(projectionContext.getSynchronizationSituationResolved());
sb.append("\n");
}
}
for (LensProjectionContext projectionContext : context.getProjectionContexts()) {
if (projectionContext.isSyncAbsoluteTrigger()) {
sb.append("Triggered by absolute state of ").append(projectionContext.getHumanReadableName());
sb.append(": ");
sb.append(projectionContext.getSynchronizationSituationDetected());
sb.append(" -> ");
sb.append(projectionContext.getSynchronizationSituationResolved());
sb.append("\n");
}
}
// focus primary
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext != null) {
ObjectDelta<F> focusPrimaryDelta = focusContext.getPrimaryDelta();
if (focusPrimaryDelta != null) {
sb.append("Triggered by focus primary delta\n");
DebugUtil.indentDebugDump(sb, 1);
sb.append(focusPrimaryDelta.toString());
sb.append("\n");
}
}
// projection primary
Collection<ObjectDelta<ShadowType>> projPrimaryDeltas = new ArrayList<>();
for (LensProjectionContext projectionContext : context.getProjectionContexts()) {
ObjectDelta<ShadowType> projPrimaryDelta = projectionContext.getPrimaryDelta();
if (projPrimaryDelta != null) {
projPrimaryDeltas.add(projPrimaryDelta);
}
}
if (!projPrimaryDeltas.isEmpty()) {
sb.append("Triggered by projection primary delta\n");
for (ObjectDelta<ShadowType> projDelta : projPrimaryDeltas) {
DebugUtil.indentDebugDump(sb, 1);
sb.append(projDelta.toString());
sb.append("\n");
}
}
if (focusContext != null) {
sb.append("Focus: ").append(focusContext.getHumanReadableName()).append("\n");
}
if (!context.getProjectionContexts().isEmpty()) {
sb.append("Projections (").append(context.getProjectionContexts().size()).append("):\n");
for (LensProjectionContext projectionContext : context.getProjectionContexts()) {
DebugUtil.indentDebugDump(sb, 1);
sb.append(projectionContext.getHumanReadableName());
if (projectionContext.isGone()) {
sb.append(" GONE");
}
sb.append(": ");
sb.append(projectionContext.getSynchronizationPolicyDecision());
sb.append("\n");
}
}
if (executedDeltas.isEmpty()) {
sb.append("Executed: nothing\n");
} else {
sb.append("Executed:\n");
for (ObjectDeltaOperation<? extends ObjectType> executedDelta : executedDeltas) {
ObjectDelta<? extends ObjectType> delta = executedDelta.getObjectDelta();
OperationResult deltaResult = executedDelta.getExecutionResult();
DebugUtil.indentDebugDump(sb, 1);
sb.append(delta.toString());
sb.append(": ");
sb.append(deltaResult.getStatus());
sb.append("\n");
}
}
LOGGER.debug("\n###[ CLOCKWORK SUMMARY ]######################################\n{}" + "##############################################################", sb);
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class TestRoleEntitlement method test120AddEntitlement.
@Test
public void test120AddEntitlement() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
prepareTest(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<ShadowType> group = PrismTestUtil.parseObject(GROUP_PIRATE_DUMMY_FILE);
ObjectDelta<ShadowType> groupDelta = DeltaFactory.Object.createAddDelta(group);
// WHEN
when();
Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges = executeChanges(groupDelta, null, task, result);
// THEN
then();
assertSuccess(result);
groupOid = ObjectDeltaOperation.findAddDeltaOid(executedChanges, group);
assertNotNull("No account OID in resulting delta", groupOid);
// Check linkRef (should be none)
PrismObject<RoleType> role = getRole(ROLE_PIRATE_OID);
assertLiveLinks(role, 0);
// Check shadow
PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, groupOid, null, result);
assertDummyGroupShadowRepo(shadow, groupOid, GROUP_PIRATE_DUMMY_NAME);
// assertEnableTimestampShadow(shadow, startTime, endTime);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, groupOid, null, task, result);
assertDummyGroupShadowModel(accountModel, groupOid, GROUP_PIRATE_DUMMY_NAME);
// assertEnableTimestampShadow(accountModel, startTime, endTime);
// Check group in dummy resource
assertDummyGroup(GROUP_PIRATE_DUMMY_NAME, "Scurvy pirates");
// Check audit
displayDumpable("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(1);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
// This is add. We do not yet have OID in request phase.
dummyAuditService.assertTarget(shadow.getOid(), AuditEventStage.EXECUTION);
dummyAuditService.assertExecutionSuccess();
}
Aggregations