Search in sources :

Example 1 with PrismContainerValue

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

the class InOidFilter method match.

@Override
public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException {
    if (value == null) {
        // just for sure
        return false;
    }
    // are we a prism object?
    if (value.getParent() instanceof PrismObject) {
        if (considerOwner) {
            return false;
        }
        String oid = ((PrismObject) (value.getParent())).getOid();
        return StringUtils.isNotBlank(oid) && oids != null && oids.contains(oid);
    }
    final PrismContainerValue pcvToConsider;
    if (considerOwner) {
        if (!(value.getParent() instanceof PrismContainer)) {
            return false;
        }
        PrismContainer container = (PrismContainer) value.getParent();
        if (!(container.getParent() instanceof PrismContainerValue)) {
            return false;
        }
        pcvToConsider = (PrismContainerValue) container.getParent();
    } else {
        pcvToConsider = value;
    }
    return pcvToConsider.getId() != null && oids.contains(pcvToConsider.getId());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer)

Example 2 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue 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 3 with PrismContainerValue

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

the class ProjectionCredentialsProcessor method applyMetadata.

private <F extends FocusType> void applyMetadata(LensContext<F> context, final LensProjectionContext projectionContext, XMLGregorianCalendar now, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException {
    ObjectDelta<ShadowType> accountDelta = projectionContext.getDelta();
    if (projectionContext.isDelete()) {
        return;
    }
    if (accountDelta == null) {
        LOGGER.trace("Skipping application of password metadata. Shadow delta not specified.");
        return;
    }
    PropertyDelta<ProtectedStringType> passwordValueDelta = accountDelta.findPropertyDelta(SchemaConstants.PATH_PASSWORD_VALUE);
    if (passwordValueDelta == null) {
        LOGGER.trace("Skipping application of password metadata. No password change.");
        return;
    }
    if (projectionContext.isAdd()) {
        MetadataType metadataType = operationalDataManager.createCreateMetadata(context, now, task);
        ContainerDelta<MetadataType> metadataDelta = ContainerDelta.createDelta(SchemaConstants.PATH_PASSWORD_METADATA, projectionContext.getObjectDefinition());
        PrismContainerValue cval = metadataType.asPrismContainerValue();
        cval.setOriginTypeRecursive(OriginType.OUTBOUND);
        metadataDelta.addValuesToAdd(metadataType.asPrismContainerValue());
        projectionContext.swallowToSecondaryDelta(metadataDelta);
    } else if (projectionContext.isModify()) {
        ContainerDelta<MetadataType> metadataDelta = accountDelta.findContainerDelta(SchemaConstants.PATH_PASSWORD_METADATA);
        if (metadataDelta == null) {
            Collection<? extends ItemDelta<?, ?>> modifyMetadataDeltas = operationalDataManager.createModifyMetadataDeltas(context, SchemaConstants.PATH_PASSWORD_METADATA, projectionContext.getObjectDefinition(), now, task);
            for (ItemDelta itemDelta : modifyMetadataDeltas) {
                itemDelta.setOriginTypeRecursive(OriginType.OUTBOUND);
                projectionContext.swallowToSecondaryDelta(itemDelta);
            }
        }
    }
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) MetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType) Collection(java.util.Collection) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 4 with PrismContainerValue

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

the class SimpleParametricRoleSelector method getParamValue.

private String getParamValue(AssignmentEditorDto assignmentDto) {
    PrismContainerValue newValue;
    try {
        newValue = assignmentDto.getNewValue(getPageBase().getPrismContext());
    } catch (SchemaException e) {
        throw new SystemException(e.getMessage(), e);
    }
    if (newValue != null) {
        PrismProperty<String> paramProp = newValue.findProperty(parameterPath);
        if (paramProp != null) {
            return paramProp.getRealValue();
        }
    }
    PrismContainerValue oldValue = assignmentDto.getOldValue();
    if (oldValue != null) {
        PrismProperty<String> paramProp = oldValue.findProperty(parameterPath);
        if (paramProp != null) {
            return paramProp.getRealValue();
        }
    }
    return null;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 5 with PrismContainerValue

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

the class TestIntegrationObjectWrapperFactory method test220AssignRoleLandluberToWally.

@Test
public void test220AssignRoleLandluberToWally() throws Exception {
    final String TEST_NAME = "test220AssignRoleLandluberToWally";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestIntegrationObjectWrapperFactory.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    DummyGroup mapmakers = new DummyGroup(GROUP_DUMMY_MAPMAKERS_NAME);
    dummyResource.addGroup(mapmakers);
    PrismObject<UserType> user = createUser(USER_WALLY_NAME, USER_WALLY_FULLNAME, true);
    addObject(user);
    userWallyOid = user.getOid();
    assignRole(userWallyOid, ROLE_MAPMAKER_OID, task, result);
    // preconditions
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<UserType> userAfter = getUser(userWallyOid);
    display("User after change execution", userAfter);
    accountWallyOid = getSingleLinkOid(userAfter);
    PrismObject<ShadowType> shadow = getShadowModel(accountWallyOid);
    shadow.findReference(ShadowType.F_RESOURCE_REF).getValue().setObject(resourceDummy);
    display("Shadow", shadow);
    DummyGroup dummyGroup = dummyResource.getGroupByName(GROUP_DUMMY_MAPMAKERS_NAME);
    assertNotNull("No group on dummy resource", dummyGroup);
    display("Group", dummyGroup);
    assertGroupMember(dummyGroup, USER_WALLY_NAME);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    ObjectWrapperFactory factory = new ObjectWrapperFactory(getServiceLocator());
    ObjectWrapper<ShadowType> objectWrapper = factory.createObjectWrapper("shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING, task);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, "shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING);
    assertEquals("wrong number of containers in " + objectWrapper, 9, objectWrapper.getContainers().size());
    ContainerWrapper attributesContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ATTRIBUTES));
    WrapperTestUtil.assertWrapper(attributesContainerWrapper, "prismContainer.shadow.mainPanelDisplayName", new ItemPath(ShadowType.F_ATTRIBUTES), shadow.findContainer(ShadowType.F_ATTRIBUTES), true, ContainerStatus.MODIFYING);
    WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, dummyResourceCtl.getAttributeFullnameQName(), USER_WALLY_FULLNAME);
    WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, SchemaConstants.ICFS_NAME, USER_WALLY_NAME);
    assertEquals("wrong number of items in " + attributesContainerWrapper, 16, attributesContainerWrapper.getItems().size());
    ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
    WrapperTestUtil.assertWrapper(activationContainerWrapper, "ShadowType.activation", UserType.F_ACTIVATION, shadow, ContainerStatus.MODIFYING);
    WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
    WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_LOCKOUT_STATUS, null);
    ContainerWrapper<ShadowAssociationType> associationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ASSOCIATION));
    assertNotNull("No association container wrapper", associationContainerWrapper);
    assertEquals("wrong number of items in " + associationContainerWrapper, 2, associationContainerWrapper.getItems().size());
    ItemWrapper groupAssociationWrapper = associationContainerWrapper.findPropertyWrapper(RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME);
    assertNotNull("No group association property wrapper", groupAssociationWrapper);
    assertTrue("Wrong type of group association property wrapper: " + groupAssociationWrapper.getClass(), groupAssociationWrapper instanceof AssociationWrapper);
    List<ValueWrapper> groupAssociationValues = groupAssociationWrapper.getValues();
    assertEquals("wrong number of values in " + groupAssociationWrapper, 1, groupAssociationValues.size());
    ValueWrapper groupAssociationValue = groupAssociationValues.get(0);
    PrismContainerValue<ShadowAssociationType> groupAssociationValuePVal = (PrismContainerValue<ShadowAssociationType>) groupAssociationValue.getValue();
    display("groupAssociationValuePVal", groupAssociationValuePVal);
    assertEquals("wrong number of values in " + groupAssociationValue, ValueStatus.NOT_CHANGED, groupAssociationValue.getStatus());
    assertEquals("Wrong group association name", RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME, groupAssociationValuePVal.findProperty(ShadowAssociationType.F_NAME).getRealValue());
    PrismContainer<ShadowIdentifiersType> groupAssociationValueIdentifiers = groupAssociationValuePVal.findContainer(ShadowAssociationType.F_IDENTIFIERS);
    PrismProperty<String> groupAssociationUidProp = groupAssociationValueIdentifiers.findProperty(new QName(null, "uid"));
    PrismAsserts.assertPropertyValue(groupAssociationUidProp, GROUP_DUMMY_MAPMAKERS_NAME);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ValueWrapper(com.evolveum.midpoint.web.component.prism.ValueWrapper) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ContainerWrapper(com.evolveum.midpoint.web.component.prism.ContainerWrapper) ItemWrapper(com.evolveum.midpoint.web.component.prism.ItemWrapper) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) AssociationWrapper(com.evolveum.midpoint.web.component.prism.AssociationWrapper) ShadowIdentifiersType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowIdentifiersType) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) ObjectWrapperFactory(com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)59 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)22 Task (com.evolveum.midpoint.task.api.Task)22 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)22 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)21 Test (org.testng.annotations.Test)18 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)17 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)15 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)15 ArrayList (java.util.ArrayList)14 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)13 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 QName (javax.xml.namespace.QName)10 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)9 PrismReference (com.evolveum.midpoint.prism.PrismReference)9 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)6 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)6