Search in sources :

Example 16 with PrismValue

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

the class ReportUtils method getItemRealValue.

public static Object getItemRealValue(PrismContainerValue containerValue, String itemName) {
    Item item = containerValue.findItem(new QName(itemName));
    if (item == null || item.size() == 0) {
        return null;
    }
    if (item.size() > 1) {
        throw new IllegalStateException("More than one value in item " + item);
    }
    PrismValue value = item.getValue(0);
    if (value == null) {
        return null;
    }
    if (value instanceof PrismPropertyValue) {
        return ((PrismPropertyValue) value).getValue();
    } else if (value instanceof PrismReferenceValue) {
        ObjectReferenceType ort = new ObjectReferenceType();
        ort.setupReferenceValue((PrismReferenceValue) value);
        return ort;
    } else if (value instanceof PrismContainerValue) {
        // questionable
        return ((PrismContainerValue) value).asContainerable();
    } else {
        throw new IllegalStateException("Unknown PrismValue: " + value);
    }
}
Also used : Item(com.evolveum.midpoint.prism.Item) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) QName(javax.xml.namespace.QName) PrismValue(com.evolveum.midpoint.prism.PrismValue) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 17 with PrismValue

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

the class AssignmentTablePanel method handleModifyAssignmentDelta.

private void handleModifyAssignmentDelta(AssignmentEditorDto assDto, PrismContainerDefinition assignmentDef, PrismContainerValue newValue, ObjectDelta<T> userDelta) throws SchemaException {
    LOGGER.debug("Handling modified assignment '{}', computing delta.", new Object[] { assDto.getName() });
    PrismValue oldValue = assDto.getOldValue();
    Collection<? extends ItemDelta> deltas = oldValue.diff(newValue);
    for (ItemDelta delta : deltas) {
        ItemPath deltaPath = delta.getPath().rest();
        ItemDefinition deltaDef = assignmentDef.findItemDefinition(deltaPath);
        delta.setParentPath(WebComponentUtil.joinPath(oldValue.getPath(), delta.getPath().allExceptLast()));
        delta.applyDefinition(deltaDef);
        userDelta.addModification(delta);
    }
}
Also used : ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 18 with PrismValue

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

the class ModelWebService method prepareXmlData.

public static PipelineDataType prepareXmlData(List<PipelineItem> output, ScriptingExpressionEvaluationOptionsType options) throws JAXBException, SchemaException {
    boolean hideResults = options != null && Boolean.TRUE.equals(options.isHideOperationResults());
    PipelineDataType rv = new PipelineDataType();
    if (output != null) {
        for (PipelineItem item : output) {
            PipelineItemType itemType = new PipelineItemType();
            PrismValue value = item.getValue();
            if (value instanceof PrismReferenceValue) {
                // This is a bit of hack: value.getRealValue() would return unserializable object (PRV$1 - does not have type QName)
                ObjectReferenceType ort = new ObjectReferenceType();
                ort.setupReferenceValue((PrismReferenceValue) value);
                itemType.setValue(ort);
            } else {
                // TODO - ok?
                itemType.setValue(value.getRealValue());
            }
            if (!hideResults) {
                itemType.setResult(item.getResult().createOperationResultType());
            }
            rv.getItem().add(itemType);
        }
    }
    return rv;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PipelineItemType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType) PipelineDataType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 19 with PrismValue

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

the class ObjectTemplateProcessor method computeItemDeltas.

<F extends FocusType, T extends FocusType> Collection<ItemDelta<?, ?>> computeItemDeltas(Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> outputTripleMap, @Nullable Map<ItemPath, ObjectTemplateItemDefinitionType> itemDefinitionsMap, ObjectDelta<T> targetObjectAPrioriDelta, PrismObject<T> targetObject, PrismObjectDefinition<F> focusDefinition, String contextDesc) throws ExpressionEvaluationException, PolicyViolationException, SchemaException {
    Collection<ItemDelta<?, ?>> itemDeltas = new ArrayList<>();
    LOGGER.trace("Computing deltas in {}, focusDelta:\n{}", contextDesc, targetObjectAPrioriDelta);
    boolean addUnchangedValues = false;
    if (targetObjectAPrioriDelta != null && targetObjectAPrioriDelta.isAdd()) {
        addUnchangedValues = true;
    }
    for (Entry<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> entry : outputTripleMap.entrySet()) {
        ItemPath itemPath = entry.getKey();
        DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>> outputTriple = entry.getValue();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Computed triple for {}:\n{}", itemPath, outputTriple.debugDump());
        }
        final ObjectTemplateItemDefinitionType templateItemDefinition;
        if (itemDefinitionsMap != null) {
            templateItemDefinition = ItemPathUtil.getFromMap(itemDefinitionsMap, itemPath);
        } else {
            templateItemDefinition = null;
        }
        boolean isNonTolerant = templateItemDefinition != null && Boolean.FALSE.equals(templateItemDefinition.isTolerant());
        ItemDelta aprioriItemDelta = getAprioriItemDelta(targetObjectAPrioriDelta, itemPath);
        // if non-tolerant, we want to gather ZERO & PLUS sets
        boolean filterExistingValues = !isNonTolerant;
        ItemDefinition itemDefinition = focusDefinition.findItemDefinition(itemPath);
        ItemDelta itemDelta = LensUtil.consolidateTripleToDelta(itemPath, (DeltaSetTriple) outputTriple, itemDefinition, aprioriItemDelta, targetObject, null, null, addUnchangedValues, filterExistingValues, false, contextDesc, true);
        // Do a quick version of reconciliation. There is not much to reconcile as both the source and the target
        // is focus. But there are few cases to handle, such as strong mappings, and sourceless normal mappings. 
        Collection<? extends ItemValueWithOrigin<?, ?>> zeroSet = outputTriple.getZeroSet();
        Item<PrismValue, ItemDefinition> itemNew = null;
        if (targetObject != null) {
            itemNew = targetObject.findItem(itemPath);
        }
        for (ItemValueWithOrigin<?, ?> zeroSetIvwo : zeroSet) {
            PrismValueDeltaSetTripleProducer<?, ?> mapping = zeroSetIvwo.getMapping();
            if ((mapping.getStrength() == null || mapping.getStrength() == MappingStrengthType.NORMAL)) {
                if (aprioriItemDelta != null && !aprioriItemDelta.isEmpty()) {
                    continue;
                }
                if (!mapping.isSourceless()) {
                    continue;
                }
                LOGGER.trace("Adding zero values from normal mapping {}, a-priori delta: {}, isSourceless: {}", mapping, aprioriItemDelta, mapping.isSourceless());
            } else if (mapping.getStrength() == MappingStrengthType.WEAK) {
                if ((itemNew != null && !itemNew.isEmpty()) || (itemDelta != null && itemDelta.addsAnyValue())) {
                    continue;
                }
                LOGGER.trace("Adding zero values from weak mapping {}, itemNew: {}, itemDelta: {}", mapping, itemNew, itemDelta);
            } else {
                LOGGER.trace("Adding zero values from strong mapping {}", mapping);
            }
            PrismValue valueFromZeroSet = zeroSetIvwo.getItemValue();
            if (itemNew == null || !itemNew.containsRealValue(valueFromZeroSet)) {
                LOGGER.trace("Reconciliation will add value {} for item {}. Existing item: {}", valueFromZeroSet, itemPath, itemNew);
                itemDelta.addValuesToAdd(valueFromZeroSet.clone());
            }
        }
        if (isNonTolerant) {
            if (itemDelta.isDelete()) {
                LOGGER.trace("Non-tolerant item with values to DELETE => removing them");
                // these are useless now - we move everything to REPLACE
                itemDelta.resetValuesToDelete();
            }
            if (itemDelta.isReplace()) {
                LOGGER.trace("Non-tolerant item with resulting REPLACE delta => doing nothing");
            } else {
                for (ItemValueWithOrigin<?, ?> zeroSetIvwo : zeroSet) {
                    itemDelta.addValuesToAdd(zeroSetIvwo.getItemValue().clone());
                }
                itemDelta.addToReplaceDelta();
                LOGGER.trace("Non-tolerant item with resulting ADD delta => converted ADD to REPLACE values: {}", itemDelta.getValuesToReplace());
            }
            // under a special option "createReplaceDelta", but for the time being, let's keep it here
            if (itemDelta instanceof PropertyDelta) {
                PropertyDelta propertyDelta = ((PropertyDelta) itemDelta);
                QName matchingRuleName = templateItemDefinition != null ? templateItemDefinition.getMatchingRule() : null;
                MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleName, null);
                if (propertyDelta.isRedundant(targetObject, matchingRule)) {
                    LOGGER.trace("Computed property delta is redundant => skipping it. Delta = \n{}", propertyDelta.debugDump());
                    continue;
                }
            } else {
                if (itemDelta.isRedundant(targetObject)) {
                    LOGGER.trace("Computed item delta is redundant => skipping it. Delta = \n{}", itemDelta.debugDump());
                    continue;
                }
            }
            PrismUtil.setDeltaOldValue(targetObject, itemDelta);
        }
        itemDelta.simplify();
        itemDelta.validate(contextDesc);
        itemDeltas.add(itemDelta);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Computed delta:\n{}", itemDelta.debugDump());
        }
    }
    return itemDeltas;
}
Also used : DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ObjectTemplateItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemValueWithOrigin(com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 20 with PrismValue

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

the class AbstractModelIntegrationTest method assertFocusModificationSanity.

protected <F extends FocusType> void assertFocusModificationSanity(ModelContext<F> context) throws JAXBException {
    ModelElementContext<F> focusContext = context.getFocusContext();
    PrismObject<F> focusOld = focusContext.getObjectOld();
    if (focusOld == null) {
        return;
    }
    ObjectDelta<F> focusPrimaryDelta = focusContext.getPrimaryDelta();
    if (focusPrimaryDelta != null) {
        assertEquals("No OID in old focus object", focusOld.getOid(), focusPrimaryDelta.getOid());
        assertEquals(ChangeType.MODIFY, focusPrimaryDelta.getChangeType());
        assertNull(focusPrimaryDelta.getObjectToAdd());
        for (ItemDelta itemMod : focusPrimaryDelta.getModifications()) {
            if (itemMod.getValuesToDelete() != null) {
                Item property = focusOld.findItem(itemMod.getPath());
                assertNotNull("Deleted item " + itemMod.getParentPath() + "/" + itemMod.getElementName() + " not found in focus", property);
                for (Object valueToDelete : itemMod.getValuesToDelete()) {
                    if (!property.containsRealValue((PrismValue) valueToDelete)) {
                        display("Deleted value " + valueToDelete + " is not in focus item " + itemMod.getParentPath() + "/" + itemMod.getElementName());
                        display("Deleted value", valueToDelete);
                        display("HASHCODE: " + valueToDelete.hashCode());
                        for (Object value : property.getValues()) {
                            display("Existing value", value);
                            display("EQUALS: " + valueToDelete.equals(value));
                            display("HASHCODE: " + value.hashCode());
                        }
                        fail("Deleted value " + valueToDelete + " is not in focus item " + itemMod.getParentPath() + "/" + itemMod.getElementName());
                    }
                }
            }
        }
    }
}
Also used : Item(com.evolveum.midpoint.prism.Item) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Aggregations

PrismValue (com.evolveum.midpoint.prism.PrismValue)31 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)8 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)8 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 Item (com.evolveum.midpoint.prism.Item)6 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)6 ArrayList (java.util.ArrayList)6 PrismObjectValue (com.evolveum.midpoint.prism.PrismObjectValue)5 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)5 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 QName (javax.xml.namespace.QName)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)2 Objectable (com.evolveum.midpoint.prism.Objectable)2 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)2