Search in sources :

Example 11 with PropertyDelta

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 12 with PropertyDelta

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);
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 13 with PropertyDelta

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);
}
Also used : NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 14 with PropertyDelta

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;
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Example 15 with PropertyDelta

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;
}
Also used : QName(javax.xml.namespace.QName) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Aggregations

PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)90 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)39 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)33 QName (javax.xml.namespace.QName)28 ArrayList (java.util.ArrayList)23 Test (org.testng.annotations.Test)20 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)19 Task (com.evolveum.midpoint.task.api.Task)19 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 Collection (java.util.Collection)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)14 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 SystemException (com.evolveum.midpoint.util.exception.SystemException)9 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6