Search in sources :

Example 41 with PrismValue

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

the class LiteralExpressionEvaluator method parseAndConvert.

private Item<V, D> parseAndConvert(ExpressionEvaluationContext context) throws SchemaException {
    // noinspection unchecked
    Item<V, D> item = outputDefinition.instantiate();
    List<Object> values = StaticExpressionUtil.parseValueElements(expressionEvaluatorBean, context.getContextDescription());
    Function<Object, Object> convertor = context.getAdditionalConvertor();
    for (Object value : values) {
        PrismValue prismValue = prismContext.itemFactory().createValue(convertor.apply(value));
        // noinspection unchecked
        item.add((V) prismValue);
    }
    return item;
}
Also used : PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 42 with PrismValue

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

the class ExtensionItemDeltaProcessor method process.

@Override
public void process(ItemDelta<?, ?> modification) throws RepositoryException, SchemaException {
    ItemPath itemPath = modification.getPath();
    if (modification.getDefinition() instanceof PrismContainerDefinition<?>) {
        // We do not index containers
        return;
    }
    Item<PrismValue, ?> item = context.findValueOrItem(itemPath);
    Collection<?> realValues = item != null ? item.getRealValues() : null;
    ItemDefinition<?> definition = modification.getDefinition();
    Objects.requireNonNull(definition, "Item '" + itemPath + "' without definition can't be saved.");
    ExtensionProcessor extProcessor = new ExtensionProcessor(context.repositoryContext());
    ExtensionProcessor.ExtItemInfo extItemInfo = extProcessor.findExtensionItem(definition, holderType);
    if (extItemInfo == null) {
        // not-indexed, no action
        return;
    }
    // If the extension is single value (and we know it now, we should proceed with deletion of
    // multivalue variant and vice-versa (this variants may be indroduced during raw import
    // or changes in multiplicity of extension definition or resource definition
    context.deleteItem(reverseCardinality(extProcessor, extItemInfo.item));
    if (realValues == null || realValues.isEmpty()) {
        context.deleteItem(extItemInfo.getId());
        return;
    }
    // changed value
    context.setChangedItem(extItemInfo.getId(), extProcessor.extItemValue(item, extItemInfo));
}
Also used : PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ExtensionProcessor(com.evolveum.midpoint.repo.sqale.ExtensionProcessor) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 43 with PrismValue

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

the class GeneralUpdate method updateBasicOrEmbedded.

private void updateBasicOrEmbedded(Attribute attribute) {
    String attributeName = attribute.getName();
    PrismValue prismValue;
    if (delta.isAdd()) {
        prismValue = getSingleValue(attribute, delta.getValuesToAdd());
    } else if (delta.isReplace()) {
        if (!delta.getValuesToReplace().isEmpty()) {
            prismValue = getSingleValue(attribute, delta.getValuesToReplace());
        } else {
            prismValue = null;
        }
    } else if (delta.isDelete()) {
        // No values to add nor to replace, only deletions. Because we narrowed the delta before, we know that this delete
        // delta is relevant - i.e. after its application, the (single) value of property will be removed.
        prismValue = null;
    } else {
        // This should not occur. The narrowing process eliminates empty deltas.
        LOGGER.warn("Empty delta {} for attribute {} of {} -- skipping it", delta, attributeName, currentBean.getClass().getName());
        return;
    }
    Object value = prismValue != null ? prismValue.getRealValue() : null;
    Class attributeValueType = getAttributeValueType(attribute);
    // noinspection unchecked
    Object valueMapped = beans.prismEntityMapper.map(value, attributeValueType);
    try {
        LOGGER.trace("Setting simple property {} to {}", attributeName, valueMapped);
        PropertyUtils.setSimpleProperty(currentBean, attributeName, valueMapped);
    } catch (Exception ex) {
        throw new SystemException("Couldn't set simple property for '" + attributeName + "'", ex);
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) PrismObject(com.evolveum.midpoint.prism.PrismObject) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) PrismValue(com.evolveum.midpoint.prism.PrismValue) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 44 with PrismValue

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

the class PasswordMetadataUpdate method handlePropertyDelta.

public void handlePropertyDelta() throws SchemaException {
    if (!(object instanceof RFocus)) {
        throw new SystemException("Bean is not instance of " + RFocus.class + ", shouldn't happen");
    }
    RFocus focus = (RFocus) object;
    if (isDelete()) {
        focus.setPasswordCreateTimestamp(null);
        focus.setModifyTimestamp(null);
        return;
    }
    PrismValue value = delta.getAnyValue();
    MapperContext context = new MapperContext();
    context.setRepositoryContext(beans.createRepositoryContext());
    context.setDelta(delta);
    context.setOwner(object);
    beans.prismEntityMapper.mapPrismValue(value, RFocus.class, context);
}
Also used : MapperContext(com.evolveum.midpoint.repo.sql.helpers.modify.MapperContext) SystemException(com.evolveum.midpoint.util.exception.SystemException) RFocus(com.evolveum.midpoint.repo.sql.data.common.RFocus) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 45 with PrismValue

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

the class ExtensionUpdate method processExtensionDeltaValueSet.

private void processExtensionDeltaValueSet(Collection<? extends PrismValue> prismValuesFromDelta, Integer itemId, RAnyConverter.ValueType valueType, RepositoryUpdater repositoryUpdater) {
    if (prismValuesFromDelta != null) {
        RAnyConverter converter = new RAnyConverter(beans.prismContext, beans.extItemDictionary);
        try {
            Collection<PrismEntityPair<RAnyValue<?>>> rValuesFromDelta = new ArrayList<>();
            for (PrismValue prismValueFromDelta : prismValuesFromDelta) {
                RAnyValue<?> rValueFromDelta = convertToRValue(itemId, converter, prismValueFromDelta);
                rValuesFromDelta.add(new PrismEntityPair<>(prismValueFromDelta, rValueFromDelta));
            }
            processExtensionValues(valueType, rValuesFromDelta, repositoryUpdater);
        } catch (SchemaException ex) {
            throw new SystemException("Couldn't process extension attributes", ex);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismEntityPair(com.evolveum.midpoint.repo.sql.helpers.modify.PrismEntityPair) SystemException(com.evolveum.midpoint.util.exception.SystemException) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Aggregations

PrismValue (com.evolveum.midpoint.prism.PrismValue)49 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)15 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)8 Item (com.evolveum.midpoint.prism.Item)7 ArrayList (java.util.ArrayList)7 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)6 QName (javax.xml.namespace.QName)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)4 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)4 MapperContext (com.evolveum.midpoint.repo.sql.helpers.modify.MapperContext)4 SystemException (com.evolveum.midpoint.util.exception.SystemException)4 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)2 Objectable (com.evolveum.midpoint.prism.Objectable)2 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)2