Search in sources :

Example 11 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class OutboundProcessor method processOutbound.

public <F extends FocusType> void processOutbound(LensContext<F> context, LensProjectionContext projCtx, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    ResourceShadowDiscriminator discr = projCtx.getResourceShadowDiscriminator();
    ObjectDelta<ShadowType> projectionDelta = projCtx.getDelta();
    if (projectionDelta != null && projectionDelta.getChangeType() == ChangeType.DELETE) {
        LOGGER.trace("Processing outbound expressions for {} skipped, DELETE account delta", discr);
        // No point in evaluating outbound
        return;
    }
    LOGGER.trace("Processing outbound expressions for {} starting", discr);
    RefinedObjectClassDefinition rOcDef = projCtx.getStructuralObjectClassDefinition();
    if (rOcDef == null) {
        LOGGER.error("Definition for {} not found in the context, but it should be there, dumping context:\n{}", discr, context.debugDump());
        throw new IllegalStateException("Definition for " + discr + " not found in the context, but it should be there");
    }
    ObjectDeltaObject<F> focusOdo = context.getFocusContext().getObjectDeltaObject();
    ObjectDeltaObject<ShadowType> projectionOdo = projCtx.getObjectDeltaObject();
    Construction<F> outboundConstruction = new Construction<>(null, projCtx.getResource());
    outboundConstruction.setRefinedObjectClassDefinition(rOcDef);
    Collection<RefinedObjectClassDefinition> auxiliaryObjectClassDefinitions = rOcDef.getAuxiliaryObjectClassDefinitions();
    if (auxiliaryObjectClassDefinitions != null) {
        for (RefinedObjectClassDefinition auxiliaryObjectClassDefinition : auxiliaryObjectClassDefinitions) {
            outboundConstruction.addAuxiliaryObjectClassDefinition(auxiliaryObjectClassDefinition);
        }
    }
    String operation = projCtx.getOperation().getValue();
    for (QName attributeName : rOcDef.getNamesOfAttributesWithOutboundExpressions()) {
        RefinedAttributeDefinition<?> refinedAttributeDefinition = rOcDef.findAttributeDefinition(attributeName);
        final MappingType outboundMappingType = refinedAttributeDefinition.getOutboundMappingType();
        if (outboundMappingType == null) {
            continue;
        }
        if (refinedAttributeDefinition.isIgnored(LayerType.MODEL)) {
            LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", attributeName);
            continue;
        }
        Mapping.Builder<PrismPropertyValue<?>, RefinedAttributeDefinition<?>> builder = mappingFactory.createMappingBuilder(outboundMappingType, "outbound mapping for " + PrettyPrinter.prettyPrint(refinedAttributeDefinition.getName()) + " in " + rOcDef.getResourceType());
        builder = builder.originObject(rOcDef.getResourceType()).originType(OriginType.OUTBOUND);
        Mapping<PrismPropertyValue<?>, RefinedAttributeDefinition<?>> evaluatedMapping = evaluateMapping(builder, attributeName, refinedAttributeDefinition, focusOdo, projectionOdo, operation, rOcDef, null, context, projCtx, task, result);
        if (evaluatedMapping != null) {
            outboundConstruction.addAttributeMapping(evaluatedMapping);
        }
    }
    for (QName assocName : rOcDef.getNamesOfAssociationsWithOutboundExpressions()) {
        RefinedAssociationDefinition associationDefinition = rOcDef.findAssociationDefinition(assocName);
        final MappingType outboundMappingType = associationDefinition.getOutboundMappingType();
        if (outboundMappingType == null) {
            continue;
        }
        //			if (associationDefinition.isIgnored(LayerType.MODEL)) {
        //				LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", assocName);
        //				continue;
        //			}
        Mapping.Builder<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> mappingBuilder = mappingFactory.createMappingBuilder(outboundMappingType, "outbound mapping for " + PrettyPrinter.prettyPrint(associationDefinition.getName()) + " in " + rOcDef.getResourceType());
        PrismContainerDefinition<ShadowAssociationType> outputDefinition = getAssociationContainerDefinition();
        Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluatedMapping = (Mapping) evaluateMapping(mappingBuilder, assocName, outputDefinition, focusOdo, projectionOdo, operation, rOcDef, associationDefinition.getAssociationTarget(), context, projCtx, task, result);
        if (evaluatedMapping != null) {
            outboundConstruction.addAssociationMapping(evaluatedMapping);
        }
    }
    projCtx.setOutboundConstruction(outboundConstruction);
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Construction(com.evolveum.midpoint.model.impl.lens.Construction) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

Example 12 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class AbstractManualResourceTest method test004Configuration.

@Test
public void test004Configuration() throws Exception {
    final String TEST_NAME = "test004Configuration";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(AbstractManualResourceTest.class.getName() + "." + TEST_NAME);
    // WHEN
    resource = modelService.getObject(ResourceType.class, getResourceOid(), null, null, result);
    resourceType = resource.asObjectable();
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertNotNull("No configuration container", configurationContainer);
    PrismContainerDefinition confContDef = configurationContainer.getDefinition();
    assertNotNull("No configuration container definition", confContDef);
    PrismProperty<String> propDefaultAssignee = configurationContainer.findProperty(CONF_PROPERTY_DEFAULT_ASSIGNEE_QNAME);
    assertNotNull("No defaultAssignee conf prop", propDefaultAssignee);
//		assertNotNull("No configuration properties container", confingurationPropertiesContainer);
//		PrismContainerDefinition confPropDef = confingurationPropertiesContainer.getDefinition();
//		assertNotNull("No configuration properties container definition", confPropDef);
}
Also used : PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) Test(org.testng.annotations.Test) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Example 13 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class AddAssignmentAspect method assignmentToDelta.

// creates an ObjectDelta that will be executed after successful approval of the given assignment
@SuppressWarnings("unchecked")
private ObjectDelta<? extends FocusType> assignmentToDelta(ModelContext<?> modelContext, AssignmentType assignmentType, String objectOid) {
    PrismObject<FocusType> focus = (PrismObject<FocusType>) modelContext.getFocusContext().getObjectNew();
    PrismContainerDefinition<AssignmentType> prismContainerDefinition = focus.getDefinition().findContainerDefinition(FocusType.F_ASSIGNMENT);
    ItemDelta<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> addRoleDelta = new ContainerDelta<>(new ItemPath(), FocusType.F_ASSIGNMENT, prismContainerDefinition, prismContext);
    PrismContainerValue<AssignmentType> assignmentValue = assignmentType.asPrismContainerValue().clone();
    addRoleDelta.addValueToAdd(assignmentValue);
    Class focusClass = primaryChangeAspectHelper.getFocusClass(modelContext);
    return ObjectDelta.createModifyDelta(objectOid, addRoleDelta, focusClass, modelContext.getPrismContext());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 14 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method createReplaceAccountConstructionUserDelta.

protected ObjectDelta<UserType> createReplaceAccountConstructionUserDelta(String userOid, Long id, ConstructionType newValue) throws SchemaException {
    PrismContainerDefinition pcd = getAssignmentDefinition().findContainerDefinition(AssignmentType.F_CONSTRUCTION);
    ContainerDelta<ConstructionType> acDelta = new ContainerDelta<ConstructionType>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)), pcd, prismContext);
    //                ContainerDelta.createDelta(prismContext, ConstructionType.class, AssignmentType.F_CONSTRUCTION);
    acDelta.setValueToReplace(newValue.asPrismContainerValue());
    //        PropertyDelta.createModificationReplaceProperty(
    //                        new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)),
    //                        ppd,
    //                        newValue);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    modifications.add(acDelta);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
    return userDelta;
}
Also used : ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ArrayList(java.util.ArrayList) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 15 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class ItemWrapperModel method getItemWrapperForHeader.

<ID extends ItemDefinition> ItemWrapper getItemWrapperForHeader(Class<ID> type, PageBase pageBase) {
    if (path.isEmpty()) {
        return null;
    }
    if (fromContainerValue) {
        return null;
    }
    try {
        PrismContainerDefinition container = (PrismContainerDefinition) this.parent.getObject();
        ItemDefinition<?> def = container.findItemDefinition(path, type);
        if (!type.isAssignableFrom(def.getClass())) {
            return null;
        }
        // keys are mostly useless (unless nicely specified in XSD, which is not very often)
        return createItemWrapper(def.instantiate(), pageBase);
    } catch (SchemaException e) {
        LOGGER.error("Cannot get {} with path {} from parent {}\nReason: {}", ItemWrapper.class, path, this.parent.getObject(), e.getMessage(), e);
        return null;
    }
}
Also used : ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition)

Aggregations

PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)41 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)23 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)18 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)17 Task (com.evolveum.midpoint.task.api.Task)16 Test (org.testng.annotations.Test)16 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)15 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)14 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)13 QName (javax.xml.namespace.QName)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ArrayList (java.util.ArrayList)8 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)6 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)5 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)5 List (java.util.List)5 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)4 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)4 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)4