Search in sources :

Example 1 with ResourceObjectDefinition

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

the class ResourceDetailsTabPanel method getTaskFor.

private List<TaskType> getTaskFor(List<PrismObject<TaskType>> tasks, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
    List<TaskType> syncTasks = new ArrayList<>();
    for (PrismObject<TaskType> task : tasks) {
        ShadowKindType taskKindValue = null;
        String taskIntentValue = null;
        QName taskObjectClassValue = null;
        @Nullable ResourceObjectSetType resourceSet = ResourceObjectSetUtil.fromTask(task.asObjectable());
        if (!java.util.Objects.isNull(resourceSet)) {
            taskKindValue = resourceSet.getKind();
            taskIntentValue = resourceSet.getIntent();
            taskObjectClassValue = resourceSet.getObjectclass();
        }
        // is not accessible in admin-gui)
        if (taskObjectClassValue == null) {
            ResourceObjectDefinition taskObjectClassDef = null;
            ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resource);
            if (schema == null) {
                throw new SchemaException("No schema defined in resource. Possible configuration problem?");
            }
            if (taskKindValue == null && taskIntentValue == null) {
                // TODO ok?
                taskObjectClassDef = schema.findObjectDefinition(ShadowKindType.ACCOUNT, null);
            }
            if (taskKindValue != null) {
                if (StringUtils.isEmpty(taskIntentValue)) {
                    // TODO ok?
                    taskObjectClassDef = schema.findObjectDefinition(taskKindValue, null);
                } else {
                    taskObjectClassDef = schema.findObjectDefinition(taskKindValue, taskIntentValue);
                }
            }
            if (taskObjectClassDef != null) {
                taskObjectClassValue = taskObjectClassDef.getTypeName();
            }
        }
        if (SynchronizationUtils.isPolicyApplicable(taskObjectClassValue, taskKindValue, taskIntentValue, synchronizationPolicy, resource, true)) {
            syncTasks.add(task.asObjectable());
        }
    }
    return syncTasks;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ResourceObjectDefinition

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

the class ProjectionValuesProcessor method checkSchemaAndPolicies.

/**
 * Check that the primary deltas do not violate schema and policies
 * TODO: implement schema check
 */
private void checkSchemaAndPolicies(LensProjectionContext accountContext, String activityDescription) throws SchemaException, PolicyViolationException {
    ObjectDelta<ShadowType> primaryDelta = accountContext.getPrimaryDelta();
    if (primaryDelta == null || primaryDelta.isDelete()) {
        return;
    }
    ResourceObjectDefinition rAccountDef = accountContext.getCompositeObjectDefinition();
    if (rAccountDef == null) {
        throw new SchemaException("No definition for account type '" + accountContext.getResourceShadowDiscriminator() + "' in " + accountContext.getResource());
    }
    if (primaryDelta.isAdd()) {
        PrismObject<ShadowType> accountToAdd = primaryDelta.getObjectToAdd();
        ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(accountToAdd);
        if (attributesContainer != null) {
            for (ResourceAttribute<?> attribute : attributesContainer.getAttributes()) {
                ResourceAttributeDefinition<?> rAttrDef = requireNonNull(rAccountDef.findAttributeDefinition(attribute.getElementName()));
                if (!rAttrDef.isTolerant()) {
                    throw new PolicyViolationException("Attempt to add object with non-tolerant attribute " + attribute.getElementName() + " in " + "account " + accountContext.getResourceShadowDiscriminator() + " during " + activityDescription);
                }
            }
        }
    } else if (primaryDelta.isModify()) {
        for (ItemDelta<?, ?> modification : primaryDelta.getModifications()) {
            if (modification.getParentPath().equivalent(SchemaConstants.PATH_ATTRIBUTES)) {
                PropertyDelta<?> attrDelta = (PropertyDelta<?>) modification;
                ResourceAttributeDefinition<?> rAttrDef = requireNonNull(rAccountDef.findAttributeDefinition(attrDelta.getElementName()));
                if (!rAttrDef.isTolerant()) {
                    throw new PolicyViolationException("Attempt to modify non-tolerant attribute " + attrDelta.getElementName() + " in " + "account " + accountContext.getResourceShadowDiscriminator() + " during " + activityDescription);
                }
            }
        }
    } else {
        throw new IllegalStateException("Whoops!");
    }
}
Also used : ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Example 3 with ResourceObjectDefinition

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

the class EvaluatedPlainResourceObjectConstructionImpl method getAssociationsToEvaluate.

@Override
protected List<AssociationEvaluation<AH>> getAssociationsToEvaluate(ConstructionEvaluation<AH, ?> constructionEvaluation) {
    List<AssociationEvaluation<AH>> associationsToEvaluate = new ArrayList<>();
    ResourceObjectDefinition objectDefinition = construction.getResourceObjectDefinitionRequired();
    for (ResourceAssociationDefinition associationDefinition : objectDefinition.getAssociationDefinitions()) {
        MappingType outboundMappingBean = associationDefinition.getOutboundMappingType();
        if (outboundMappingBean == null) {
            continue;
        }
        associationsToEvaluate.add(new AssociationEvaluation<>(constructionEvaluation, associationDefinition, outboundMappingBean, OriginType.OUTBOUND, MappingKindType.OUTBOUND));
    }
    return associationsToEvaluate;
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ArrayList(java.util.ArrayList) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Example 4 with ResourceObjectDefinition

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

the class PlainResourceObjectConstruction method initializeDefinitions.

protected void initializeDefinitions() throws SchemaException {
    ResourceObjectDefinition rOcDef = projectionContext.getStructuralObjectDefinition();
    if (rOcDef == null) {
        LOGGER.error("Definition for {} not found in the context, but it should be there, dumping context:\n{}", projectionContext.getResourceShadowDiscriminator(), lensContext.debugDump(1));
        throw new IllegalStateException("Definition for " + projectionContext.getResourceShadowDiscriminator() + " not found in the context, but it should be there");
    }
    setResourceObjectDefinition(rOcDef);
    Collection<ResourceObjectDefinition> auxiliaryObjectClassDefinitions = getResourceObjectDefinition().getAuxiliaryDefinitions();
    for (ResourceObjectDefinition auxiliaryObjectClassDefinition : auxiliaryObjectClassDefinitions) {
        addAuxiliaryObjectClassDefinition(auxiliaryObjectClassDefinition);
    }
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)

Example 5 with ResourceObjectDefinition

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

the class TestRefinedSchema method test120DetermineObjectClassObjectClassModel.

@Test
public void test120DetermineObjectClassObjectClassModel() throws Exception {
    OperationResult result = createOperationResult();
    importObjectFromFile(TASK_RECONCILE_DUMMY_OBJECTCLASS_FILE);
    Task task = taskManager.getTaskPlain(TASK_RECONCILE_DUMMY_OBJECTCLASS_OID, result);
    display("Task", task);
    // WHEN
    ResourceObjectDefinition objectClass = ModelImplUtils.determineObjectDefinition(refinedSchemaModel, task);
    // THEN
    displayDumpable("Object class", objectClass);
    displayValue("Object class (toString)", objectClass.toString());
    deleteObject(TaskType.class, TASK_RECONCILE_DUMMY_OBJECTCLASS_OID);
    assertObjectClass(objectClass, RESOURCE_DUMMY_ACCOUNT_OBJECTCLASS_QNAME);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)64 QName (javax.xml.namespace.QName)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 ArrayList (java.util.ArrayList)14 Task (com.evolveum.midpoint.task.api.Task)12 Test (org.testng.annotations.Test)12 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)8 NotNull (org.jetbrains.annotations.NotNull)8 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)6 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)5 Collection (java.util.Collection)5 Nullable (org.jetbrains.annotations.Nullable)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)4 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)4 AutoCompleteQNamePanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel)3 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2