Search in sources :

Example 11 with ResourceAttributeDefinition

use of com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition in project midpoint by Evolveum.

the class DefinitionsHelper method applyDefinition.

void applyDefinition(ProvisioningContext ctx, ObjectQuery query) throws SchemaException {
    if (query == null) {
        return;
    }
    ObjectFilter filter = query.getFilter();
    if (filter == null) {
        return;
    }
    com.evolveum.midpoint.prism.query.Visitor visitor = subFilter -> {
        if (subFilter instanceof PropertyValueFilter) {
            PropertyValueFilter<?> valueFilter = (PropertyValueFilter<?>) subFilter;
            ItemDefinition<?> definition = valueFilter.getDefinition();
            if (definition instanceof ResourceAttributeDefinition) {
                // already has a resource-related definition
                return;
            }
            if (!ShadowType.F_ATTRIBUTES.equivalent(valueFilter.getParentPath())) {
                return;
            }
            QName attributeName = valueFilter.getElementName();
            ResourceAttributeDefinition<?> attributeDefinition = ctx.getObjectDefinitionRequired().findAttributeDefinition(attributeName);
            if (attributeDefinition == null) {
                throw new TunnelException(new SchemaException("No definition for attribute " + attributeName + " in query " + query));
            }
            // noinspection unchecked,rawtypes
            valueFilter.setDefinition((ResourceAttributeDefinition) attributeDefinition);
        }
    };
    try {
        filter.accept(visitor);
    } catch (TunnelException te) {
        throw (SchemaException) te.getCause();
    }
}
Also used : ProvisioningContextFactory(com.evolveum.midpoint.provisioning.impl.ProvisioningContextFactory) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) Experimental(com.evolveum.midpoint.util.annotation.Experimental) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowCaretaker(com.evolveum.midpoint.provisioning.impl.ShadowCaretaker) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) Nullable(org.jetbrains.annotations.Nullable) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter) Component(org.springframework.stereotype.Component) ResourceShadowCoordinates(com.evolveum.midpoint.schema.ResourceShadowCoordinates) MiscUtil.stateCheck(com.evolveum.midpoint.util.MiscUtil.stateCheck) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ShadowCoordinatesQualifiedObjectDelta(com.evolveum.midpoint.schema.processor.ShadowCoordinatesQualifiedObjectDelta) ShadowManager(com.evolveum.midpoint.provisioning.impl.shadows.manager.ShadowManager) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter)

Example 12 with ResourceAttributeDefinition

use of com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition in project midpoint by Evolveum.

the class AbstractLdapConnTest method test210ModifyAccountBarbossaReplaceTitle.

@Test
public void test210ModifyAccountBarbossaReplaceTitle() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
    QName attrQName = new QName(MidPointConstants.NS_RI, "title");
    // noinspection unchecked
    ResourceAttributeDefinition<String> attrDef = (ResourceAttributeDefinition<String>) accountDefinition.findAttributeDefinition(attrQName);
    PropertyDelta<String> attrDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, "Captain");
    delta.addModification(attrDelta);
    // WHEN
    when();
    modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
    assertAttribute(entry, "title", "Captain");
    PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
    String shadowOid = getSingleLinkOid(user);
    assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);
    assertLdapConnectorReasonableInstances();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Entry(org.apache.directory.api.ldap.model.entry.Entry) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 13 with ResourceAttributeDefinition

use of com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition in project midpoint by Evolveum.

the class AbstractLdapConnTest method test212ModifyAccountBarbossaAddTitleDuplicate.

/**
 * Make a duplicate modification. Add a title value that is already there.
 * Normal LDAP should fail. So check that connector and midPoint handles that.
 */
@Test
public void test212ModifyAccountBarbossaAddTitleDuplicate() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
    QName attrQName = new QName(MidPointConstants.NS_RI, "title");
    // noinspection unchecked
    ResourceAttributeDefinition<String> attrDef = (ResourceAttributeDefinition<String>) accountDefinition.findAttributeDefinition(attrQName);
    PropertyDelta<String> attrDelta = prismContext.deltaFactory().property().createModificationAddProperty(ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, "Captain");
    delta.addModification(attrDelta);
    // WHEN
    when();
    modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
    assertAttribute(entry, "title", "Captain");
    PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
    String shadowOid = getSingleLinkOid(user);
    assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);
    assertLdapConnectorReasonableInstances();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Entry(org.apache.directory.api.ldap.model.entry.Entry) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 14 with ResourceAttributeDefinition

use of com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition in project midpoint by Evolveum.

the class ShadowCaretaker method applyAttributeDefinition.

// value should be a value of attributes container
private void applyAttributeDefinition(ProvisioningContext ctx, PrismValue value) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    if (!(value instanceof PrismContainerValue)) {
        // should never occur
        return;
    }
    PrismContainerValue<ShadowAttributesType> pcv = (PrismContainerValue<ShadowAttributesType>) value;
    for (Item<?, ?> item : pcv.getItems()) {
        ItemDefinition<?> itemDef = item.getDefinition();
        if (!(itemDef instanceof ResourceAttributeDefinition)) {
            QName attributeName = item.getElementName();
            ResourceAttributeDefinition<?> attributeDefinition = ctx.findAttributeDefinitionRequired(attributeName);
            if (itemDef != null) {
                // do some basic checks first
                if (!QNameUtil.match(itemDef.getTypeName(), attributeDefinition.getTypeName())) {
                    throw new SchemaException("The value of type " + itemDef.getTypeName() + " cannot be applied to attribute " + attributeName + " which is of type " + attributeDefinition.getTypeName());
                }
            }
            // noinspection unchecked,rawtypes
            ((Item) item).applyDefinition(attributeDefinition);
        }
    }
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName)

Example 15 with ResourceAttributeDefinition

use of com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition in project midpoint by Evolveum.

the class AbstractEDirTest method test210ModifyAccountBarbossaTitle.

@Test
public void test210ModifyAccountBarbossaTitle() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
    QName attrQName = new QName(MidPointConstants.NS_RI, "title");
    // noinspection unchecked
    ResourceAttributeDefinition<String> attrDef = (ResourceAttributeDefinition<String>) accountDefinition.findAttributeDefinition(attrQName);
    PropertyDelta<String> attrDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, "Captain");
    delta.addModification(attrDelta);
    // WHEN
    when();
    modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
    assertAttribute(entry, "title", "Captain");
    PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
    String shadowOid = getSingleLinkOid(user);
    assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Entry(org.apache.directory.api.ldap.model.entry.Entry) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)32 QName (javax.xml.namespace.QName)19 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)8 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)7 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 Task (com.evolveum.midpoint.task.api.Task)7 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 ArrayList (java.util.ArrayList)6 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)5 Entry (org.apache.directory.api.ldap.model.entry.Entry)5 Test (org.testng.annotations.Test)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)3 ActivationCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType)3 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)2 Containerable (com.evolveum.midpoint.prism.Containerable)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2