use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestSanityLegacy method test105ModifyAccount.
@Test
public void test105ModifyAccount() throws Exception {
final String TEST_NAME = "test105ModifyAccount";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_ACCOUNT_MODIFY_ATTRS_FILE, ObjectDeltaType.class);
objectChange.setOid(accountShadowOidGuybrushOpendj);
// WHEN ObjectTypes.SHADOW.getTypeQName(),
OperationResultType result = modifyObjectViaModelWS(objectChange);
Task task = taskManager.createTaskInstance();
OperationResult parentResult = new OperationResult(TEST_NAME + "-get after first modify");
PrismObject<ShadowType> shadow = modelService.getObject(ShadowType.class, accountShadowOidGuybrushOpendj, null, task, parentResult);
assertNotNull("shadow must not be null", shadow);
ShadowType shadowType = shadow.asObjectable();
QName employeeTypeQName = new QName(resourceTypeOpenDjrepo.getNamespace(), "employeeType");
ItemPath employeeTypePath = new ItemPath(ShadowType.F_ATTRIBUTES, employeeTypeQName);
PrismProperty item = shadow.findProperty(employeeTypePath);
PropertyDelta deleteDelta = new PropertyDelta(new ItemPath(ShadowType.F_ATTRIBUTES), item.getDefinition().getName(), item.getDefinition(), prismContext);
// PropertyDelta deleteDelta = PropertyDelta.createDelta(employeeTypePath, shadow.getDefinition());
// PrismPropertyValue valToDelte = new PrismPropertyValue("A");
// valToDelte.setParent(deleteDelta);
Collection<PrismPropertyValue> values = item.getValues();
for (PrismPropertyValue val : values) {
if ("A".equals(val.getValue())) {
deleteDelta.addValueToDelete(val.clone());
}
}
ObjectDelta delta = new ObjectDelta(ShadowType.class, ChangeType.MODIFY, prismContext);
delta.addModification(deleteDelta);
delta.setOid(accountShadowOidGuybrushOpendj);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
deltas.add(delta);
LOGGER.info("-------->>EXECUTE DELETE MODIFICATION<<------------");
modelService.executeChanges(deltas, null, task, parentResult);
// THEN
assertNoRepoCache();
displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
TestUtil.assertSuccess("modifyObject has failed", result);
// check if LDAP account was modified
Entry entry = openDJController.searchAndAssertByEntryUuid(accountGuybrushOpendjEntryUuuid);
display("LDAP account", entry);
OpenDJController.assertAttribute(entry, "uid", "guybrush");
OpenDJController.assertAttribute(entry, "givenName", "Guybrush");
OpenDJController.assertAttribute(entry, "sn", "Threepwood");
OpenDJController.assertAttribute(entry, "cn", "Guybrush Threepwood");
OpenDJController.assertAttribute(entry, "displayName", "Guybrush Threepwood");
// The "l" attribute is assigned indirectly through schemaHandling and
// config object
OpenDJController.assertAttribute(entry, "l", "Deep in the Caribbean");
OpenDJController.assertAttribute(entry, "roomNumber", "captain's cabin");
// Set by the role
OpenDJController.assertAttribute(entry, "employeeType", "sailor");
OpenDJController.assertAttribute(entry, "title", "Bloody Pirate", "Honorable Captain");
OpenDJController.assertAttribute(entry, "carLicense", "C4PT41N");
OpenDJController.assertAttribute(entry, "businessCategory", "loot", "murder", "cruise", "fighting", "capsize");
// Expression in the role taking that from the user
OpenDJController.assertAttribute(entry, "destinationIndicator", "Guybrush Threepwood");
OpenDJController.assertAttribute(entry, "departmentNumber", "Department of Guybrush");
// Expression in the role taking that from the assignments (both of them)
OpenDJController.assertAttribute(entry, "physicalDeliveryOfficeName", "The Sea Monkey", "The Dainty Lady");
String guybrushPassword = OpenDJController.getAttributeValue(entry, "userPassword");
assertNotNull("Pasword disappeared", guybrushPassword);
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestUserChangeApprovalLegacy method modifyAssignmentConstruction.
protected void modifyAssignmentConstruction(LensContext<UserType> context, UserType jack, String attributeName, String value, boolean add) throws SchemaException {
assertEquals("jack's assignments", 1, jack.getAssignment().size());
PrismPropertyDefinition<ResourceAttributeDefinitionType> attributeDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).findPropertyDefinition(new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE));
assertNotNull("no attributeDef", attributeDef);
Long assignmentId = jack.getAssignment().get(0).getId();
PropertyDelta<ResourceAttributeDefinitionType> attributeDelta = new PropertyDelta<ResourceAttributeDefinitionType>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(assignmentId), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION), new NameItemPathSegment(ConstructionType.F_ATTRIBUTE)), attributeDef, prismContext);
ResourceAttributeDefinitionType attributeDefinitionType = new ResourceAttributeDefinitionType();
attributeDefinitionType.setRef(new ItemPathType(new ItemPath(new QName(RESOURCE_DUMMY_NAMESPACE, attributeName))));
MappingType outbound = new MappingType();
// to see changes on the resource
outbound.setStrength(MappingStrengthType.STRONG);
ExpressionType expression = new ExpressionType();
expression.getExpressionEvaluator().add(new ObjectFactory().createValue(value));
outbound.setExpression(expression);
attributeDefinitionType.setOutbound(outbound);
if (add) {
attributeDelta.addValueToAdd(new PrismPropertyValue<>(attributeDefinitionType));
} else {
attributeDelta.addValueToDelete(new PrismPropertyValue<>(attributeDefinitionType));
}
ObjectDelta<UserType> userDelta = new ObjectDelta<>(UserType.class, ChangeType.MODIFY, prismContext);
userDelta.setOid(USER_JACK_OID);
userDelta.addModification(attributeDelta);
addFocusDeltaToContext(context, userDelta);
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestUserChangeApprovalLegacy method modifyAssignmentValidity.
protected void modifyAssignmentValidity(LensContext<UserType> context, UserType jack, XMLGregorianCalendar validFrom, XMLGregorianCalendar validTo) throws SchemaException {
assertEquals("jack's assignments", 1, jack.getAssignment().size());
PrismContainerDefinition<ActivationType> activationDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).findContainerDefinition(new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_ACTIVATION));
assertNotNull("no activationDef", activationDef);
Long assignmentId = jack.getAssignment().get(0).getId();
PrismPropertyDefinition<XMLGregorianCalendar> validFromDef = activationDef.findPropertyDefinition(ActivationType.F_VALID_FROM);
PropertyDelta<XMLGregorianCalendar> validFromDelta = new PropertyDelta<>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(assignmentId), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_VALID_FROM)), validFromDef, prismContext);
validFromDelta.setValueToReplace(new PrismPropertyValue<>(validFrom));
PrismPropertyDefinition<XMLGregorianCalendar> validToDef = activationDef.findPropertyDefinition(ActivationType.F_VALID_TO);
PropertyDelta<XMLGregorianCalendar> validToDelta = new PropertyDelta<>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(assignmentId), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_VALID_TO)), validToDef, prismContext);
validToDelta.setValueToReplace(new PrismPropertyValue<>(validTo));
ObjectDelta<UserType> userDelta = new ObjectDelta<>(UserType.class, ChangeType.MODIFY, prismContext);
userDelta.setOid(USER_JACK_OID);
userDelta.addModification(validFromDelta);
userDelta.addModification(validToDelta);
addFocusDeltaToContext(context, userDelta);
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class SyncSituationHandler method canHandle.
@Override
public <T extends ObjectType> boolean canHandle(Class<T> type, String oid, Collection<? extends ItemDelta> modifications) {
if (!ShadowType.class.isAssignableFrom(type)) {
return false;
}
if (modifications.size() == 3 || modifications.size() == 4) {
return false;
}
PropertyDelta syncSituationDesc = PropertyDelta.findPropertyDelta(modifications, ShadowType.F_SYNCHRONIZATION_SITUATION_DESCRIPTION);
PropertyDelta syncTimestamp = PropertyDelta.findPropertyDelta(modifications, ShadowType.F_SYNCHRONIZATION_TIMESTAMP);
PropertyDelta fullSyncTimestamp = PropertyDelta.findPropertyDelta(modifications, ShadowType.F_FULL_SYNCHRONIZATION_TIMESTAMP);
if (syncSituationDesc == null || syncTimestamp == null || fullSyncTimestamp == null) {
return false;
}
return true;
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ResourceObjectConverter method convertToReplace.
/**
* Converts ADD/DELETE VALUE operations into REPLACE VALUE, if needed
*/
private Collection<Operation> convertToReplace(ProvisioningContext ctx, Collection<Operation> operations, PrismObject<ShadowType> currentShadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
List<Operation> retval = new ArrayList<>(operations.size());
for (Operation operation : operations) {
if (operation instanceof PropertyModificationOperation) {
PropertyDelta propertyDelta = ((PropertyModificationOperation) operation).getPropertyDelta();
if (isAttributeDelta(propertyDelta)) {
QName attributeName = propertyDelta.getElementName();
RefinedAttributeDefinition rad = ctx.getObjectClassDefinition().findAttributeDefinition(attributeName);
if (isReadReplaceMode(rad, ctx.getObjectClassDefinition()) && (propertyDelta.isAdd() || propertyDelta.isDelete())) {
PropertyModificationOperation newOp = convertToReplace(propertyDelta, currentShadow, rad.getMatchingRuleQName());
newOp.setMatchingRuleQName(((PropertyModificationOperation) operation).getMatchingRuleQName());
retval.add(newOp);
continue;
}
}
}
// for yet-unprocessed operations
retval.add(operation);
}
return retval;
}
Aggregations