Search in sources :

Example 46 with RawType

use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.

the class DeltaConvertor method addModValues.

// requires delta.prismContext to be set
private static void addModValues(ItemDelta delta, ItemDeltaType mod, Collection<PrismValue> values, DeltaConversionOptions options) throws SchemaException {
    if (values == null || values.isEmpty()) {
    //            RawType modValue = new RawType(delta.getPrismContext());
    //            mod.getValue().add(modValue);
    } else {
        for (PrismValue value : values) {
            XNode xnode = toXNode(delta, value, options);
            RawType modValue = new RawType(xnode, value.getPrismContext());
            mod.getValue().add(modValue);
        }
    }
}
Also used : XNode(com.evolveum.midpoint.prism.xnode.XNode) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 47 with RawType

use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.

the class StaticExpressionUtil method serializeValueElements.

public static <IV extends PrismValue, ID extends ItemDefinition> List<JAXBElement<RawType>> serializeValueElements(Item<IV, ID> item, String contextDescription) throws SchemaException {
    if (item == null) {
        return null;
    }
    List<JAXBElement<RawType>> elements = new ArrayList<>(item.size());
    for (PrismValue value : item.getValues()) {
        RootXNode xnode = item.getPrismContext().xnodeSerializer().serialize(value);
        RawType rawType = new RawType(xnode.getSubnode(), item.getPrismContext());
        JAXBElement<RawType> jaxbElement = new JAXBElement<>(SchemaConstants.C_VALUE, RawType.class, rawType);
        elements.add(jaxbElement);
    }
    return elements;
}
Also used : ArrayList(java.util.ArrayList) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) JAXBElement(javax.xml.bind.JAXBElement) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 48 with RawType

use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.

the class StaticExpressionUtil method parseValueElements.

public static <IV extends PrismValue, ID extends ItemDefinition> Item<IV, ID> parseValueElements(Collection<?> valueElements, ID outputDefinition, String contextDescription, PrismContext prismContext) throws SchemaException {
    Item<IV, ID> output = null;
    for (Object valueElement : valueElements) {
        if (!(valueElement instanceof JAXBElement<?>)) {
            throw new SchemaException("Literal expression cannot handle element " + valueElement + " " + valueElement.getClass().getName() + " in " + contextDescription);
        }
        QName valueElementName = JAXBUtil.getElementQName(valueElement);
        if (!valueElementName.equals(SchemaConstants.C_VALUE)) {
            throw new SchemaException("Literal expression cannot handle element <" + valueElementName + "> in " + contextDescription);
        }
        JAXBElement<?> jaxbElement = (JAXBElement<?>) valueElement;
        // not checking declaredType because it may be Object.class instead ... but actual type must be of RawType
        if (jaxbElement.getValue() != null && !(jaxbElement.getValue() instanceof RawType)) {
            throw new SchemaException("Literal expression cannot handle JAXBElement value type " + jaxbElement.getValue().getClass() + " in " + contextDescription);
        }
        RawType rawType = (RawType) jaxbElement.getValue();
        //Item<V> elementItem = xnodeProcessor.parseItem(rawType.getXnode(), outputDefinition.getName(), outputDefinition);
        Item<IV, ID> elementItem = rawType.getParsedItem(outputDefinition);
        if (output == null) {
            output = elementItem;
        } else {
            output.addAll(elementItem.getClonedValues());
        }
    }
    return output;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 49 with RawType

use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.

the class ItemDeltaBeanToNativeConversion method getParsedValues.

private Collection<IV> getParsedValues(List<RawType> values) throws SchemaException {
    List<IV> parsedValues = new ArrayList<>();
    for (RawType rawValue : values) {
        if (itemDefinition == null) {
            assert parentDefinition != null;
            // noinspection unchecked
            itemDefinition = (ID) ((PrismContextImpl) parentDefinition.getPrismContext()).getPrismUnmarshaller().locateItemDefinition(parentDefinition, itemName, rawValue.getXnode());
        }
        // Note this can be a slight problem if itemDefinition is PRD and the value is a full object.
        PrismValue parsed = rawValue.getParsedValue(itemDefinition, itemName);
        if (parsed != null) {
            PrismValue converted;
            if (itemDefinition instanceof PrismReferenceDefinition) {
                converted = convertValueForReferenceDelta(parsed);
            } else {
                converted = parsed;
            }
            // noinspection unchecked
            parsedValues.add((IV) converted.cloneComplex(CloneStrategy.LITERAL));
        }
    }
    return parsedValues;
}
Also used : ArrayList(java.util.ArrayList) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 50 with RawType

use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.

the class ParamsTypeUtil method fromParamsType.

public static Map<String, Serializable> fromParamsType(ParamsType paramsType, PrismContext prismContext) throws SchemaException {
    if (paramsType != null) {
        Map<String, Serializable> params = new HashMap<>();
        for (EntryType entry : paramsType.getEntry()) {
            Serializable realValue;
            if (entry.getEntryValue() != null) {
                Serializable value = (Serializable) entry.getEntryValue().getValue();
                if (value instanceof RawType) {
                    RawType raw = (RawType) value;
                    if (raw.isParsed()) {
                        realValue = raw.getAlreadyParsedValue().getRealValue();
                    } else {
                        realValue = raw.guessFormattedValue();
                    }
                } else {
                    realValue = value;
                }
            } else {
                realValue = null;
            }
            params.put(entry.getKey(), realValue);
        }
        return params;
    }
    return null;
}
Also used : Serializable(java.io.Serializable) EntryType(com.evolveum.midpoint.xml.ns._public.common.common_3.EntryType) HashMap(java.util.HashMap) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Aggregations

RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)62 QName (javax.xml.namespace.QName)22 Test (org.testng.annotations.Test)19 JAXBElement (javax.xml.bind.JAXBElement)18 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)16 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)10 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)9 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)9 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)9 ArrayList (java.util.ArrayList)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 Task (com.evolveum.midpoint.task.api.Task)8 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)6 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)6 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5