use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestParseDiffPatch method testAssignmentActivationDiff.
//@Test
public void testAssignmentActivationDiff() throws Exception {
System.out.println("===[ testUserCredentialsDiff ]===");
PrismObject<UserType> userBefore = PrismTestUtil.parseObject(new File(TEST_DIR, "user-before.xml"));
PrismObject<UserType> userAfter = userBefore.clone();
AssignmentType assignmentBefore = new AssignmentType();
ActivationType activation = new ActivationType();
activation.setAdministrativeStatus(ActivationStatusType.DISABLED);
assignmentBefore.setActivation(activation);
userBefore.asObjectable().getAssignment().add(assignmentBefore);
AssignmentType assignmentAfter = new AssignmentType();
activation = new ActivationType();
activation.setAdministrativeStatus(ActivationStatusType.ENABLED);
assignmentAfter.setActivation(activation);
userAfter.asObjectable().getAssignment().add(assignmentAfter);
Collection<? extends ItemDelta> userDelta = assignmentBefore.asPrismContainerValue().diff(assignmentAfter.asPrismContainerValue());
// ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
System.out.println("DELTA:");
// System.out.println(userDelta.debugDump());
// userBefore.checkConsistence();
// userAfter.checkConsistence();
// userDelta.checkConsistence();
// userDelta.assertDefinitions();
ItemDelta assignmentDelta = userDelta.iterator().next();
System.out.println("Assignment delta: " + assignmentDelta);
System.out.println("Assignment delta: " + assignmentDelta.debugDump());
ItemPath path = new ItemPath(SchemaConstantsGenerated.C_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS);
// PrismAsserts.assertPropertyAdd(assignmentDelta, path, 1);
// path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
// CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS);
PropertyDelta propertyDelta = ItemDelta.findPropertyDelta(userDelta, path);
assertNotNull("Property delta for " + path + " not found", propertyDelta);
// assertEquals(1, propertyDelta.getValuesToAdd().size());
assignmentAfter = new AssignmentType();
activation = new ActivationType();
activation.setAdministrativeStatus(null);
assignmentAfter.setActivation(activation);
userDelta = assignmentBefore.asPrismContainerValue().diff(assignmentAfter.asPrismContainerValue());
// ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
System.out.println("DELTA:");
// System.out.println(userDelta.debugDump());
// userBefore.checkConsistence();
// userAfter.checkConsistence();
// userDelta.checkConsistence();
// userDelta.assertDefinitions();
assignmentDelta = userDelta.iterator().next();
System.out.println("Assignment delta: " + assignmentDelta);
System.out.println("Assignment delta: " + assignmentDelta.debugDump());
path = new ItemPath(SchemaConstantsGenerated.C_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS);
// PrismAsserts.assertPropertyAdd(assignmentDelta, path, 1);
// path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
// CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS);
propertyDelta = ItemDelta.findPropertyDelta(userDelta, path);
userDelta = assignmentAfter.asPrismContainerValue().diff(assignmentBefore.asPrismContainerValue());
// ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
System.out.println("DELTA:");
// System.out.println(userDelta.debugDump());
// userBefore.checkConsistence();
// userAfter.checkConsistence();
// userDelta.checkConsistence();
// userDelta.assertDefinitions();
assignmentDelta = userDelta.iterator().next();
System.out.println("Assignment delta: " + assignmentDelta);
System.out.println("Assignment delta: " + assignmentDelta.debugDump());
path = new ItemPath(SchemaConstantsGenerated.C_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS);
// PrismAsserts.assertPropertyAdd(assignmentDelta, path, 1);
// path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
// CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS);
propertyDelta = ItemDelta.findPropertyDelta(userDelta, path);
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestParseDiffPatch method assertConfigurationPropertyChange.
private void assertConfigurationPropertyChange(ObjectDelta<ResourceType> resourceDelta, String propName) {
resourceDelta.checkConsistence();
PropertyDelta propertyDelta = resourceDelta.findPropertyDelta(pathConfigProperties(propName));
assertNotNull("No delta for configuration property " + propName, propertyDelta);
// TODO
resourceDelta.checkConsistence();
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestParseDiffPatch method testUserCredentialsDiff.
@Test
public void testUserCredentialsDiff() throws Exception {
System.out.println("===[ testUserCredentialsDiff ]===");
PrismObject<UserType> userBefore = PrismTestUtil.parseObject(new File(TEST_DIR, "user-before.xml"));
userBefore.checkConsistence();
PrismObject<UserType> userAfter = PrismTestUtil.parseObject(new File(TEST_DIR, "user-after.xml"));
userAfter.checkConsistence();
ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
System.out.println("DELTA:");
System.out.println(userDelta.debugDump());
userBefore.checkConsistence();
userAfter.checkConsistence();
userDelta.checkConsistence();
userDelta.assertDefinitions();
ItemPath path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS);
PrismAsserts.assertPropertyAdd(userDelta, path, 1);
path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS);
PropertyDelta propertyDelta = userDelta.findPropertyDelta(path);
assertNotNull("Property delta for " + path + " not found", propertyDelta);
assertEquals(1, propertyDelta.getValuesToAdd().size());
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ChangeExecutor method updateSituationInShadow.
private <F extends ObjectType> void updateSituationInShadow(Task task, SynchronizationSituationType situation, LensFocusContext<F> focusContext, LensProjectionContext projectionCtx, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
String projectionOid = projectionCtx.getOid();
OperationResult result = new OperationResult(OPERATION_UPDATE_SITUATION_ACCOUNT);
result.addParam("situation", situation);
result.addParam("accountRef", projectionOid);
PrismObject<ShadowType> account = null;
GetOperationOptions getOptions = GetOperationOptions.createNoFetch();
getOptions.setAllowNotFound(true);
try {
account = provisioning.getObject(ShadowType.class, projectionOid, SelectorOptions.createCollection(getOptions), task, result);
} catch (Exception ex) {
LOGGER.trace("Problem with getting account, skipping modifying situation in account.");
return;
}
List<PropertyDelta<?>> syncSituationDeltas = SynchronizationUtils.createSynchronizationSituationAndDescriptionDelta(account, situation, task.getChannel(), projectionCtx.hasFullShadow());
try {
Utils.setRequestee(task, focusContext);
ProvisioningOperationOptions options = ProvisioningOperationOptions.createCompletePostponed(false);
options.setDoNotDiscovery(true);
String changedOid = provisioning.modifyObject(ShadowType.class, projectionOid, syncSituationDeltas, null, options, task, result);
// modifyProvisioningObject(AccountShadowType.class, accountRef,
// syncSituationDeltas,
// ProvisioningOperationOptions.createCompletePostponed(false),
// task, result);
projectionCtx.setSynchronizationSituationResolved(situation);
LOGGER.trace("Situation in projection {} was updated to {}.", projectionCtx, situation);
} catch (ObjectNotFoundException ex) {
// if the object not found exception is thrown, it's ok..probably
// the account was deleted by previous execution of changes..just
// log in the trace the message for the user..
LOGGER.trace("Situation in account could not be updated. Account not found on the resource. Skipping modifying situation in account");
return;
} catch (Exception ex) {
throw new SystemException(ex.getMessage(), ex);
} finally {
Utils.clearRequestee(task);
}
// if everything is OK, add result of the situation modification to the
// parent result
result.recordSuccess();
parentResult.addSubresult(result);
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ShadowIntegrityCheckResultHandler method doCheckNormalization.
private void doCheckNormalization(ShadowCheckResult checkResult, RefinedAttributeDefinition<?> identifier, String value, ObjectTypeContext context) throws SchemaException {
QName matchingRuleQName = identifier.getMatchingRuleQName();
if (matchingRuleQName == null) {
return;
}
MatchingRule<Object> matchingRule;
try {
matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, identifier.getTypeName());
} catch (SchemaException e) {
checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("Couldn't retrieve matching rule for identifier " + identifier.getName() + " (rule name = " + matchingRuleQName + ")"));
return;
}
Object normalizedValue = matchingRule.normalize(value);
if (!(normalizedValue instanceof String)) {
checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("Normalized value is not a string, it's " + normalizedValue.getClass() + " (identifier " + identifier.getName() + ", value " + value));
return;
}
if (value.equals(normalizedValue)) {
// OK
return;
}
String normalizedStringValue = (String) normalizedValue;
checkResult.recordError(Statistics.NON_NORMALIZED_IDENTIFIER_VALUE, new SchemaException("Non-normalized value of identifier " + identifier.getName() + ": " + value + " (normalized form: " + normalizedValue + ")"));
if (fixNormalization) {
PropertyDelta delta = identifier.createEmptyDelta(new ItemPath(ShadowType.F_ATTRIBUTES, identifier.getName()));
delta.setValueToReplace(new PrismPropertyValue<>(normalizedStringValue));
checkResult.addFixDelta(delta, Statistics.NON_NORMALIZED_IDENTIFIER_VALUE);
}
}
Aggregations