Search in sources :

Example 26 with RawType

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

the class ACAttributeDto method getConstruction.

public ResourceAttributeDefinitionType getConstruction(PrismContext prismContext) throws SchemaException {
    if (isEmpty()) {
        return null;
    }
    ResourceAttributeDefinitionType attrConstruction = new ResourceAttributeDefinitionType();
    if (construction != null && construction.getRef() != null) {
        // preserves original ref (including xmlns prefix!) - in order to avoid false deltas when comparing old and new values
        attrConstruction.setRef(construction.getRef());
    } else {
        attrConstruction.setRef(new ItemPathType(definition.getItemName()));
    }
    MappingType outbound;
    if (construction != null && construction.getOutbound() != null) {
        outbound = construction.getOutbound().clone();
    } else {
        outbound = new MappingType();
        outbound.setStrength(MappingStrengthType.STRONG);
    }
    attrConstruction.setOutbound(outbound);
    ExpressionType expression = new ExpressionType();
    outbound.setExpression(expression);
    List<ACValueConstructionDto> values = getValues();
    PrismProperty property = definition.instantiate();
    // needed in serializeValueElements below
    property.revive(prismContext);
    for (ACValueConstructionDto dto : values) {
        if (dto.getValue() == null) {
            continue;
        }
        property.addRealValue(dto.getValue());
    }
    List evaluators = expression.getExpressionEvaluator();
    List<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property);
    ObjectFactory of = new ObjectFactory();
    for (JAXBElement<RawType> evaluator : collection) {
        evaluators.add(evaluator);
    }
    if (evaluators.isEmpty()) {
        return null;
    }
    return attrConstruction;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) JAXBElement(javax.xml.bind.JAXBElement) List(java.util.List) ArrayList(java.util.ArrayList) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 27 with RawType

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

the class ExpressionUtil method serialize.

public static String serialize(JAXBElement<?> element, PrismContext prismContext) throws SchemaException {
    String xml;
    if (element.getValue() instanceof RawType) {
        RawType raw = (RawType) element.getValue();
        RootXNode rootNode = prismContext.xnodeFactory().root(element.getName(), raw.serializeToXNode());
        xml = prismContext.xmlSerializer().serialize(rootNode);
    } else {
        xml = prismContext.xmlSerializer().serialize(element);
    }
    return WebXmlUtil.stripNamespaceDeclarations(xml);
}
Also used : RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 28 with RawType

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

the class ExpressionUtil method getLiteralExpressionValues.

@NotNull
public static List<String> getLiteralExpressionValues(ExpressionType expression) throws SchemaException {
    List<String> values = new ArrayList<>();
    List<JAXBElement<?>> elements = ExpressionUtil.findAllEvaluatorsByName(expression, SchemaConstantsGenerated.C_VALUE);
    for (JAXBElement<?> element : elements) {
        if (element.getValue() instanceof RawType) {
            RawType raw = (RawType) element.getValue();
            if (raw != null) {
                if (raw.getXnode() != null && raw.getXnode() instanceof PrimitiveXNode) {
                    PrimitiveXNode<?> valueNode = (PrimitiveXNode<?>) raw.getXnode();
                    if (valueNode != null && valueNode.getValue() != null) {
                        values.add(valueNode.getValue().toString());
                    } else if (valueNode.getValueParser() != null) {
                        values.add(valueNode.getValueParser().getStringValue());
                    }
                } else if (raw.getParsedRealValue(String.class) != null) {
                    values.add(raw.getParsedRealValue(String.class));
                }
            }
        }
    }
    return values;
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with RawType

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

the class ExpressionUtil method removeShadowRefEvaluatorValue.

public static void removeShadowRefEvaluatorValue(ExpressionType expression, String shadowRefOid, PrismContext prismContext) {
    if (expression == null || StringUtils.isEmpty(shadowRefOid)) {
        return;
    }
    List<JAXBElement<?>> elementList = findAllEvaluatorsByName(expression, SchemaConstants.C_VALUE);
    if (CollectionUtils.isEmpty(elementList)) {
        return;
    }
    boolean removePerformed = false;
    Iterator<JAXBElement<?>> elementIterator = elementList.iterator();
    while (elementIterator.hasNext()) {
        JAXBElement element = elementIterator.next();
        if (element != null && element.getValue() instanceof RawType) {
            RawType raw = (RawType) element.getValue();
            if (raw.isParsed()) {
                try {
                    if (raw.getParsedRealValue(ShadowAssociationType.class) != null) {
                        ShadowAssociationType assoc = raw.getParsedRealValue(ShadowAssociationType.class);
                        if (assoc.getShadowRef() != null && shadowRefOid.equals(assoc.getShadowRef().getOid())) {
                            elementIterator.remove();
                            break;
                        }
                    }
                } catch (SchemaException e) {
                    LoggingUtils.logExceptionAsWarning(LOGGER, "Could not remove association value", e);
                }
            } else {
                XNode node = raw.getXnode();
                if (node instanceof MapXNode && ((MapXNode) node).containsKey(SHADOW_REF_KEY)) {
                    XNode shadowRefNodes = ((MapXNode) node).get(SHADOW_REF_KEY);
                    if (shadowRefNodes instanceof MapXNode && shadowRefOid.equals(getShadowRefNodeOid((MapXNode) shadowRefNodes))) {
                        prismContext.xnodeMutator().putToMapXNode((MapXNode) node, SHADOW_REF_KEY, null);
                        removePerformed = true;
                    // todo don't get why while using removeEvaluatorByName no changes are saved
                    // removeEvaluatorByName(expression, SchemaConstantsGenerated.C_VALUE);
                    } else if (shadowRefNodes instanceof ListXNode) {
                        Iterator<? extends XNode> it = ((ListXNode) shadowRefNodes).asList().iterator();
                        while (it.hasNext()) {
                            XNode shadowRefNode = it.next();
                            if (shadowRefNode instanceof MapXNode && shadowRefOid.equals(getShadowRefNodeOid((MapXNode) shadowRefNode))) {
                                it.remove();
                                removePerformed = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (removePerformed) {
            break;
        }
    }
    expression.getExpressionEvaluator().clear();
    expression.getExpressionEvaluator().addAll(elementList);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) JAXBElement(javax.xml.bind.JAXBElement) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 30 with RawType

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

the class TestParseObjectTemplate method assertObjectTemplateInternals.

// checks raw values of mappings
// should be called only on reparsed values in order to catch some raw-data-related serialization issues (MID-2196)
private void assertObjectTemplateInternals(PrismObject<ObjectTemplateType> object) throws SchemaException {
    int assignmentValuesFound = 0;
    for (ObjectTemplateMappingType mappingType : object.asObjectable().getMapping()) {
        if (mappingType.getExpression() != null) {
            if (mappingType.getTarget() != null && mappingType.getTarget().getPath() != null && UserType.F_ASSIGNMENT.equivalent(mappingType.getTarget().getPath().getItemPath())) {
                ItemDefinition assignmentDef = getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).findItemDefinition(UserType.F_ASSIGNMENT);
                for (JAXBElement evaluator : mappingType.getExpression().getExpressionEvaluator()) {
                    if (evaluator.getValue() instanceof RawType) {
                        RawType rawType = (RawType) evaluator.getValue();
                        System.out.println("\nraw assignment:\n" + rawType);
                        Item assignment = rawType.getParsedItem(assignmentDef);
                        System.out.println("\nassignment:\n" + assignment.debugDump());
                        assignmentValuesFound++;
                    }
                }
            }
        }
    }
    assertEquals("wrong # of assignment values found in mapping", 2, assignmentValuesFound);
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) 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