Search in sources :

Example 71 with ItemPathType

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

the class DomLexicalWriter method serializePrimitiveElementOrAttribute.

private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Element parentElement, QName elementOrAttributeName, boolean asAttribute) throws SchemaException {
    QName typeQName = xprim.getTypeQName();
    // TODO we should probably set typeQName when parsing the value...
    if (typeQName == null && xprim.isParsed()) {
        Object v = xprim.getValue();
        if (v != null) {
            typeQName = XsdTypeMapper.toXsdType(v.getClass());
        }
    }
    if (typeQName == null) {
        // this means that either xprim is unparsed or it is empty
        if (com.evolveum.midpoint.prism.PrismContextImpl.isAllowSchemalessSerialization()) {
            // We cannot correctly serialize without a type. But this is needed
            // sometimes. So just default to string
            String stringValue = xprim.getStringValue();
            if (stringValue != null) {
                if (asAttribute) {
                    DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), stringValue);
                    DOMUtil.setNamespaceDeclarations(parentElement, xprim.getRelevantNamespaceDeclarations());
                } else {
                    Element element;
                    try {
                        element = createElement(elementOrAttributeName, parentElement);
                        appendCommentIfPresent(element, xprim);
                    } catch (DOMException e) {
                        throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement));
                    }
                    parentElement.appendChild(element);
                    DOMUtil.setElementTextContent(element, stringValue);
                    DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations());
                }
            }
            return;
        } else {
            throw new IllegalStateException("No type for primitive element " + elementOrAttributeName + ", cannot serialize (schemaless serialization is disabled)");
        }
    }
    if (StringUtils.isBlank(typeQName.getNamespaceURI())) {
        typeQName = XsdTypeMapper.determineQNameWithNs(typeQName);
    }
    Element element = null;
    if (ItemPathType.COMPLEX_TYPE.equals(typeQName)) {
        //ItemPathType itemPathType = //ItemPathType.asItemPathType(xprim.getValue());			// TODO fix this hack
        ItemPathType itemPathType = (ItemPathType) xprim.getValue();
        if (itemPathType != null) {
            if (asAttribute) {
                throw new UnsupportedOperationException("Serializing ItemPath as an attribute is not supported yet");
            }
            XPathHolder holder = new XPathHolder(itemPathType.getItemPath());
            element = holder.toElement(elementOrAttributeName, parentElement.getOwnerDocument());
            parentElement.appendChild(element);
        }
    } else {
        if (!asAttribute) {
            try {
                element = createElement(elementOrAttributeName, parentElement);
            } catch (DOMException e) {
                throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement));
            }
            appendCommentIfPresent(element, xprim);
            parentElement.appendChild(element);
        }
        if (DOMUtil.XSD_QNAME.equals(typeQName)) {
            QName value = (QName) xprim.getParsedValueWithoutRecording(DOMUtil.XSD_QNAME);
            value = setQNamePrefixExplicitIfNeeded(value);
            if (asAttribute) {
                try {
                    DOMUtil.setQNameAttribute(parentElement, elementOrAttributeName.getLocalPart(), value);
                } catch (DOMException e) {
                    throw new DOMException(e.code, e.getMessage() + "; setting attribute " + elementOrAttributeName.getLocalPart() + " in element " + DOMUtil.getQName(parentElement) + " to QName value " + value);
                }
            } else {
                DOMUtil.setQNameValue(element, value);
            }
        } else {
            // not ItemType nor QName
            String value = xprim.getGuessedFormattedValue();
            if (asAttribute) {
                DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), value);
            } else {
                DOMUtil.setElementTextContent(element, value);
            }
        }
    }
    if (!asAttribute && xprim.isExplicitTypeDeclaration()) {
        DOMUtil.setXsiType(element, setQNamePrefixExplicitIfNeeded(typeQName));
    }
}
Also used : DOMException(org.w3c.dom.DOMException) XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) QName(javax.xml.namespace.QName) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) Element(org.w3c.dom.Element)

Example 72 with ItemPathType

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

the class FullTextSearchConfigurationUtil method getFullTextSearchItemPaths.

@NotNull
public static Set<ItemPath> getFullTextSearchItemPaths(@NotNull FullTextSearchConfigurationType config, Class<? extends ObjectType> clazz) {
    List<QName> types = ObjectTypes.getObjectType(clazz).thisAndSupertypes().stream().map(ot -> ot.getTypeQName()).collect(Collectors.toList());
    Set<ItemPath> paths = new HashSet<>();
    for (FullTextSearchIndexedItemsConfigurationType indexed : config.getIndexed()) {
        if (isApplicable(indexed, types)) {
            for (ItemPathType itemPathType : indexed.getItem()) {
                ItemPath path = itemPathType.getItemPath();
                if (!ItemPath.isNullOrEmpty(path) && !ItemPath.containsEquivalent(paths, path)) {
                    paths.add(path);
                }
            }
        }
    }
    return paths;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) FullTextSearchIndexedItemsConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchIndexedItemsConfigurationType) Set(java.util.Set) FullTextSearchConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) HashSet(java.util.HashSet) QNameUtil(com.evolveum.midpoint.util.QNameUtil) List(java.util.List) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) FullTextSearchIndexedItemsConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchIndexedItemsConfigurationType) QName(javax.xml.namespace.QName) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) HashSet(java.util.HashSet) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Example 73 with ItemPathType

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

the class MiscSchemaUtil method selectorToSelectorType.

private static OptionObjectSelectorType selectorToSelectorType(ObjectSelector selector) {
    if (selector == null) {
        return null;
    }
    OptionObjectSelectorType selectorType = new OptionObjectSelectorType();
    selectorType.setPath(new ItemPathType(selector.getPath()));
    return selectorType;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType)

Example 74 with ItemPathType

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

the class AbstractSearchExpressionEvaluator method evaluatePopulateExpression.

private <IV extends PrismValue, ID extends ItemDefinition, C extends Containerable> ItemDelta<IV, ID> evaluatePopulateExpression(PopulateItemType populateItem, ExpressionVariables variables, ExpressionEvaluationContext params, PrismContainerDefinition<C> objectDefinition, String contextDescription, boolean evaluateMinus, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ExpressionType expressionType = populateItem.getExpression();
    if (expressionType == null) {
        LOGGER.warn("No expression in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
        return null;
    }
    VariableBindingDefinitionType targetType = populateItem.getTarget();
    if (targetType == null) {
        LOGGER.warn("No target in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
        return null;
    }
    ItemPathType itemPathType = targetType.getPath();
    if (itemPathType == null) {
        throw new SchemaException("No path in target definition in " + contextDescription);
    }
    ItemPath targetPath = itemPathType.getItemPath();
    ID propOutputDefinition = ExpressionUtil.resolveDefinitionPath(targetPath, variables, objectDefinition, "target definition in " + contextDescription);
    if (propOutputDefinition == null) {
        throw new SchemaException("No target item that would conform to the path " + targetPath + " in " + contextDescription);
    }
    String expressionDesc = "expression in assignment expression in " + contextDescription;
    ExpressionFactory expressionFactory = params.getExpressionFactory();
    Expression<IV, ID> expression = expressionFactory.makeExpression(expressionType, propOutputDefinition, expressionDesc, task, result);
    ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, expressionDesc, task, result);
    context.setExpressionFactory(expressionFactory);
    context.setStringPolicyResolver(params.getStringPolicyResolver());
    context.setDefaultTargetContext(params.getDefaultTargetContext());
    context.setSkipEvaluationMinus(true);
    context.setSkipEvaluationPlus(false);
    PrismValueDeltaSetTriple<IV> outputTriple = expression.evaluate(context);
    LOGGER.trace("output triple: {}", outputTriple.debugDump());
    Collection<IV> pvalues = outputTriple.getNonNegativeValues();
    // Maybe not really clean but it works. TODO: refactor later
    NameItemPathSegment first = (NameItemPathSegment) targetPath.first();
    if (first.isVariable()) {
        targetPath = targetPath.rest();
    }
    ItemDelta<IV, ID> itemDelta = propOutputDefinition.createEmptyDelta(targetPath);
    itemDelta.addValuesToAdd(PrismValue.cloneCollection(pvalues));
    LOGGER.trace("Item delta:\n{}", itemDelta.debugDump());
    return itemDelta;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) VariableBindingDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 75 with ItemPathType

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

the class Mapping method parseTimeSource.

private XMLGregorianCalendar parseTimeSource(VariableBindingDefinitionType sourceType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
    ItemPathType itemPathType = sourceType.getPath();
    if (itemPathType == null) {
        throw new SchemaException("No path in source definition in " + getMappingContextDescription());
    }
    ItemPath path = itemPathType.getItemPath();
    if (path.isEmpty()) {
        throw new SchemaException("Empty source path in " + getMappingContextDescription());
    }
    Object sourceObject = ExpressionUtil.resolvePath(path, variables, sourceContext, objectResolver, "reference time definition in " + getMappingContextDescription(), task, result);
    if (sourceObject == null) {
        return null;
    }
    PrismProperty<XMLGregorianCalendar> timeProperty;
    if (sourceObject instanceof ItemDeltaItem<?, ?>) {
        timeProperty = (PrismProperty<XMLGregorianCalendar>) ((ItemDeltaItem<?, ?>) sourceObject).getItemNew();
    } else if (sourceObject instanceof Item<?, ?>) {
        timeProperty = (PrismProperty<XMLGregorianCalendar>) sourceObject;
    } else {
        throw new IllegalStateException("Unknown resolve result " + sourceObject);
    }
    if (timeProperty == null) {
        return null;
    }
    return timeProperty.getRealValue();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)114 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)58 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)27 Test (org.testng.annotations.Test)27 QName (javax.xml.namespace.QName)25 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)24 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)21 List (java.util.List)18 NotNull (org.jetbrains.annotations.NotNull)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)15 ArrayList (java.util.ArrayList)15 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)13 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)13 Collectors (java.util.stream.Collectors)13 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)11 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)11 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)11 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)11 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)11