use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestTolerantAttributes method test101ModifyAddAttributesIntolerantPattern.
/**
* We are trying to add value to the resource (through a mapping). This value matches
* intolerant pattern. But as this value is explicitly added by a mapping from a primary
* delta then the value should be set to resource even in that case.
*/
@Test
public void test101ModifyAddAttributesIntolerantPattern() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, USER_JACK_OID);
PropertyDelta propertyDelta = prismContext.deltaFactory().property().createModificationAddProperty(UserType.F_DESCRIPTION, getUserDefinition().findPropertyDefinition(UserType.F_DESCRIPTION), "This value will be not added");
userDelta.addModification(propertyDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
// WHEN
when();
modelService.executeChanges(deltas, executeOptions().reconcile(), task, result);
// THEN
then();
assertSuccess(result);
// Check value in "quote attribute"
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
assertUserJack(userJack);
accountOid = getSingleLinkOid(userJack);
assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
// Check account in dummy resource
assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
// Check value of quote attribute
assertDummyAccountAttribute(RESOURCE_DUMMY_BLACK_NAME, "jack", "quote", "This value will be not added");
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestTolerantAttributes method test102modifyAddAttributeTolerantPattern.
@Test
public void test102modifyAddAttributeTolerantPattern() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, USER_JACK_OID);
PropertyDelta propertyDelta = prismContext.deltaFactory().property().createModificationAddProperty(UserType.F_DESCRIPTION, getUserDefinition().findPropertyDefinition(UserType.F_DESCRIPTION), "res-thiIsOk");
userDelta.addModification(propertyDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
modelService.executeChanges(deltas, executeOptions().reconcile(), task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
// Check value in "quote attribute"
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
assertUserJack(userJack);
UserType userJackType = userJack.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size());
ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0);
accountOid = accountRefType.getOid();
assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid());
assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
// Check account in dummy resource
assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
// Check value of quote attribute
assertDummyAccountAttribute(RESOURCE_DUMMY_BLACK_NAME, "jack", "quote", "res-thiIsOk");
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method generateValue.
@Override
public <O extends ObjectType> void generateValue(PrismObject<O> object, PolicyItemsDefinitionType policyItemsDefinition, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException {
OperationResult result = parentResult.createSubresult(OPERATION_GENERATE_VALUE);
ValuePolicyType valuePolicy;
try {
valuePolicy = getValuePolicy(object, task, result);
} catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
LOGGER.error("Failed to get value policy for generating value. ", e);
result.recordFatalError("Error while getting value policy. Reason: " + e.getMessage(), e);
throw e;
}
Collection<PropertyDelta<?>> deltasToExecute = new ArrayList<>();
for (PolicyItemDefinitionType policyItemDefinition : policyItemsDefinition.getPolicyItemDefinition()) {
OperationResult generateValueResult = parentResult.createSubresult(OPERATION_GENERATE_VALUE);
LOGGER.trace("Default value policy: {}", valuePolicy);
try {
generateValue(object, valuePolicy, policyItemDefinition, task, generateValueResult);
} catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
LOGGER.error("Failed to generate value for {} ", policyItemDefinition, e);
generateValueResult.recordFatalError("Failed to generate value for " + policyItemDefinition + ". Reason: " + e.getMessage(), e);
policyItemDefinition.setResult(generateValueResult.createOperationResultType());
continue;
}
// TODO: not sure about the bulk actions here
ItemPath path = getPath(policyItemDefinition);
if (path == null) {
if (isExecute(policyItemDefinition)) {
LOGGER.error("No item path defined in the target for policy item definition. Cannot generate value");
generateValueResult.recordFatalError("No item path defined in the target for policy item definition. Cannot generate value");
continue;
}
}
PrismPropertyDefinition<?> propertyDef = null;
if (path != null) {
result.addArbitraryObjectAsParam("policyItemPath", path);
propertyDef = getItemDefinition(object, path);
if (propertyDef == null) {
if (isExecute(policyItemDefinition)) {
LOGGER.error("No definition for property {} in object. Is the path referencing prism property?" + path, object);
generateValueResult.recordFatalError("No definition for property " + path + " in object " + object + ". Is the path referencing prism property?");
continue;
}
}
}
// end of not sure
collectDeltasForGeneratedValuesIfNeeded(object, policyItemDefinition, deltasToExecute, path, propertyDef, generateValueResult);
generateValueResult.computeStatusIfUnknown();
}
result.computeStatus();
if (!result.isAcceptable()) {
return;
}
try {
if (!deltasToExecute.isEmpty()) {
if (object == null) {
LOGGER.error("Cannot execute changes for generated values, no object specified in request.");
result.recordFatalError("Cannot execute changes for generated values, no object specified in request.");
throw new SchemaException("Cannot execute changes for generated values, no object specified in request.");
}
String oid = object.getOid();
Class<O> clazz = (Class<O>) object.asObjectable().getClass();
modelCrudService.modifyObject(clazz, oid, deltasToExecute, null, task, result);
}
} catch (ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | ObjectAlreadyExistsException | PolicyViolationException | SecurityViolationException e) {
LOGGER.error("Could not execute deltas for generated values. Reason: " + e.getMessage(), e);
result.recordFatalError("Could not execute deltas for gegenerated values. Reason: " + e.getMessage(), e);
throw e;
}
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ShadowIntegrityCheckItemProcessor method doCheckNormalization.
private void doCheckNormalization(ShadowCheckResult checkResult, ResourceAttributeDefinition<?> identifier, String value) throws SchemaException {
QName matchingRuleQName = identifier.getMatchingRuleQName();
if (matchingRuleQName == null) {
return;
}
MatchingRule<Object> matchingRule;
try {
matchingRule = activityRun.getBeans().matchingRuleRegistry.getMatchingRule(matchingRuleQName, identifier.getTypeName());
} catch (SchemaException e) {
checkResult.recordError(ShadowStatistics.OTHER_FAILURE, new SchemaException("Couldn't retrieve matching rule for identifier " + identifier.getItemName() + " (rule name = " + matchingRuleQName + ")"));
return;
}
Object normalizedValue = matchingRule.normalize(value);
if (!(normalizedValue instanceof String)) {
checkResult.recordError(ShadowStatistics.OTHER_FAILURE, new SchemaException("Normalized value is not a string, it's " + normalizedValue.getClass() + " (identifier " + identifier.getItemName() + ", value " + value));
return;
}
if (value.equals(normalizedValue)) {
return;
}
String normalizedStringValue = (String) normalizedValue;
checkResult.recordError(ShadowStatistics.NON_NORMALIZED_IDENTIFIER_VALUE, new SchemaException("Non-normalized value of identifier " + identifier.getItemName() + ": " + value + " (normalized form: " + normalizedValue + ")"));
if (getConfiguration().fixNormalization) {
// noinspection rawtypes
PropertyDelta delta = identifier.createEmptyDelta(ItemPath.create(ShadowType.F_ATTRIBUTES, identifier.getItemName()));
// noinspection unchecked
delta.setRealValuesToReplace(normalizedStringValue);
checkResult.addFixDelta(delta, ShadowStatistics.NON_NORMALIZED_IDENTIFIER_VALUE);
}
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestUserTemplate method test160ModifyUserGivenNameAgain.
@Test
public void test160ModifyUserGivenNameAgain() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = getTestOperationResult();
dummyAuditService.clear();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createModificationReplaceProperty(UserType.class, USER_JACK_OID, UserType.F_GIVEN_NAME, new PolyString("JACKIE"));
deltas.add(userDelta);
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
assertSuccess(result);
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
PrismAsserts.assertPropertyValue(userJack.findContainer(UserType.F_EXTENSION), PIRACY_BAD_LUCK, 123L);
displayDumpable("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(2);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
ObjectDeltaOperation<?> objectDeltaOperation = dummyAuditService.getExecutionDelta(0, ChangeType.MODIFY, UserType.class);
assertEquals("unexpected number of modifications in audited delta", 10, // givenName + badLuck + modifyTimestamp
objectDeltaOperation.getObjectDelta().getModifications().size());
PropertyDelta badLuckDelta = objectDeltaOperation.getObjectDelta().findPropertyDelta(ItemPath.create(UserType.F_EXTENSION, PIRACY_BAD_LUCK));
assertNotNull("badLuck delta was not found", badLuckDelta);
// noinspection unchecked
List<PrismValue> oldValues = (List<PrismValue>) badLuckDelta.getEstimatedOldValues();
assertNotNull("badLuck delta has null estimatedOldValues field", oldValues);
ItemFactory factory = prismContext.itemFactory();
PrismAsserts.assertEqualsCollectionUnordered("badLuck delta has wrong estimatedOldValues", oldValues, factory.createPropertyValue(123L), factory.createPropertyValue(456L));
}
Aggregations