Search in sources :

Example 16 with RootXNode

use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.

the class PrismProperty method createRaw.

public static <T> PrismProperty<T> createRaw(@NotNull XNode node, @NotNull QName itemName, PrismContext prismContext) throws SchemaException {
    Validate.isTrue(!(node instanceof RootXNode));
    PrismProperty<T> property = new PrismProperty<>(itemName, prismContext);
    if (node instanceof ListXNode) {
        for (XNode subnode : (ListXNode) node) {
            property.add(PrismPropertyValue.createRaw(subnode));
        }
    } else {
        property.add(PrismPropertyValue.createRaw(node));
    }
    return property;
}
Also used : ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode)

Example 17 with RootXNode

use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.

the class MiscSchemaUtil method serializeFaultMessage.

// TODO some better place
public static void serializeFaultMessage(Detail detail, FaultMessage faultMessage, PrismContext prismContext, Trace logger) {
    try {
        BeanMarshaller marshaller = ((PrismContextImpl) prismContext).getBeanMarshaller();
        // TODO
        XNode faultMessageXnode = marshaller.marshall(faultMessage.getFaultInfo());
        RootXNode xroot = new RootXNode(SchemaConstants.FAULT_MESSAGE_ELEMENT_NAME, faultMessageXnode);
        xroot.setExplicitTypeDeclaration(true);
        QName faultType = prismContext.getSchemaRegistry().determineTypeForClass(faultMessage.getFaultInfo().getClass());
        xroot.setTypeQName(faultType);
        ((PrismContextImpl) prismContext).getParserDom().serializeUnderElement(xroot, SchemaConstants.FAULT_MESSAGE_ELEMENT_NAME, detail);
    } catch (SchemaException e) {
        logger.error("Error serializing fault message (SOAP fault detail): {}", e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) BeanMarshaller(com.evolveum.midpoint.prism.marshaller.BeanMarshaller) QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode)

Example 18 with RootXNode

use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.

the class ParamsTypeUtil method createEntryElement.

private static EntryType createEntryElement(Entry<String, Serializable> entry, PrismContext prismContext) throws SchemaException {
    EntryType result = new EntryType();
    result.setKey(entry.getKey());
    if (XmlTypeConverter.canConvert(entry.getValue().getClass())) {
        return createEntryElement(entry.getKey(), entry.getValue());
    } else {
        RootXNode xnode = prismContext.xnodeSerializer().options(SerializationOptions.createSerializeReferenceNames()).serializeAnyData(entry.getValue(), SchemaConstants.C_PARAM_VALUE);
        return createEntryElement(entry.getKey(), new RawType(xnode, prismContext));
    }
}
Also used : EntryType(com.evolveum.midpoint.xml.ns._public.common.common_3.EntryType) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 19 with RootXNode

use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.

the class XNodeProcessorUtil method parseProtectedType.

public static <T> void parseProtectedType(ProtectedDataType<T> protectedType, MapXNode xmap, PrismContext prismContext, ParsingContext pc) throws SchemaException {
    RootXNode xEncryptedData = xmap.getEntryAsRoot(ProtectedDataType.F_ENCRYPTED_DATA);
    if (xEncryptedData != null) {
        if (!(xEncryptedData.getSubnode() instanceof MapXNode)) {
            throw new SchemaException("Cannot parse encryptedData from " + xEncryptedData);
        }
        EncryptedDataType encryptedDataType = prismContext.parserFor(xEncryptedData).context(pc).parseRealValue(EncryptedDataType.class);
        protectedType.setEncryptedData(encryptedDataType);
    } else {
        // Check for legacy EncryptedData
        RootXNode xLegacyEncryptedData = xmap.getEntryAsRoot(ProtectedDataType.F_XML_ENC_ENCRYPTED_DATA);
        if (xLegacyEncryptedData != null) {
            if (!(xLegacyEncryptedData.getSubnode() instanceof MapXNode)) {
                throw new SchemaException("Cannot parse EncryptedData from " + xEncryptedData);
            }
            RootXNode xConvertedEncryptedData = (RootXNode) xLegacyEncryptedData.cloneTransformKeys(in -> {
                String elementName = StringUtils.uncapitalize(in.getLocalPart());
                if (elementName.equals("type")) {
                    return null;
                }
                return new QName(null, elementName);
            });
            EncryptedDataType encryptedDataType = prismContext.parserFor(xConvertedEncryptedData).context(pc).parseRealValue(EncryptedDataType.class);
            protectedType.setEncryptedData(encryptedDataType);
            if (protectedType instanceof ProtectedStringType) {
                transformEncryptedValue(protectedType, prismContext);
            }
        }
    }
    RootXNode xHashedData = xmap.getEntryAsRoot(ProtectedDataType.F_HASHED_DATA);
    if (xHashedData != null) {
        if (!(xHashedData.getSubnode() instanceof MapXNode)) {
            throw new SchemaException("Cannot parse hashedData from " + xHashedData);
        }
        HashedDataType hashedDataType = prismContext.parserFor(xHashedData).context(pc).parseRealValue(HashedDataType.class);
        protectedType.setHashedData(hashedDataType);
    }
    // protected data empty..check for clear value
    if (protectedType.isEmpty()) {
        XNode xClearValue = xmap.get(ProtectedDataType.F_CLEAR_VALUE);
        if (xClearValue == null) {
            //TODO: try to use common namespace (only to be compatible with previous versions)
            //FIXME maybe add some warning, info...
            xClearValue = xmap.get(new QName(ProtectedDataType.F_CLEAR_VALUE.getLocalPart()));
        }
        if (xClearValue == null) {
            return;
        }
        if (!(xClearValue instanceof PrimitiveXNode)) {
            //this is maybe not good..
            throw new SchemaException("Cannot parse clear value from " + xClearValue);
        }
        // TODO: clearValue
        T clearValue = (T) ((PrimitiveXNode) xClearValue).getParsedValue(DOMUtil.XSD_STRING, String.class);
        protectedType.setClearValue(clearValue);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) HashedDataType(com.evolveum.prism.xml.ns._public.types_3.HashedDataType) Field(java.lang.reflect.Field) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) DOMUtil(com.evolveum.midpoint.util.DOMUtil) ParsingContext(com.evolveum.midpoint.prism.ParsingContext) Protector(com.evolveum.midpoint.prism.crypto.Protector) PrismContext(com.evolveum.midpoint.prism.PrismContext) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) XmlValue(javax.xml.bind.annotation.XmlValue) QName(javax.xml.namespace.QName) ProtectedDataType(com.evolveum.prism.xml.ns._public.types_3.ProtectedDataType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) EncryptedDataType(com.evolveum.prism.xml.ns._public.types_3.EncryptedDataType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) EncryptedDataType(com.evolveum.prism.xml.ns._public.types_3.EncryptedDataType) QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) HashedDataType(com.evolveum.prism.xml.ns._public.types_3.HashedDataType)

Example 20 with RootXNode

use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.

the class ExpressionHandlerImplTest method testEvaluateExpression.

@Test
public void testEvaluateExpression() throws Exception {
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(TEST_FOLDER, "account.xml"));
    ShadowType accountType = account.asObjectable();
    PrismObject<ResourceType> resource = PrismTestUtil.parseObject(new File(TEST_FOLDER_COMMON, "resource-dummy.xml"));
    ResourceType resourceType = resource.asObjectable();
    ObjectReferenceType resourceRef = new ObjectReferenceType();
    resourceRef.asReferenceValue().setObject(resource);
    accountType.setResourceRef(resourceRef);
    ObjectSynchronizationType synchronization = resourceType.getSynchronization().getObjectSynchronization().get(0);
    for (ConditionalSearchFilterType filter : synchronization.getCorrelation()) {
        MapXNode clauseXNode = filter.getFilterClauseXNode();
        // key = q:equal, value = map (path + expression)
        RootXNode expressionNode = ((MapXNode) clauseXNode.getSingleSubEntry("filter value").getValue()).getEntryAsRoot(new QName(SchemaConstants.NS_C, "expression"));
        ExpressionType expression = PrismTestUtil.getPrismContext().parserFor(expressionNode).parseRealValue(ExpressionType.class);
        logger.debug("Expression: {}", SchemaDebugUtil.prettyPrint(expression));
        OperationResult result = createOperationResult();
        String name = expressionHandler.evaluateExpression(accountType, expression, "test expression", null, result);
        logger.info(result.debugDump());
        assertEquals("Wrong expression result", "hbarbossa", name);
    }
}
Also used : QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) File(java.io.File) Test(org.testng.annotations.Test) AbstractSpringTest(com.evolveum.midpoint.test.util.AbstractSpringTest)

Aggregations

RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)51 Test (org.testng.annotations.Test)22 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)14 QName (javax.xml.namespace.QName)13 XNode (com.evolveum.midpoint.prism.xnode.XNode)12 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)7 NotNull (org.jetbrains.annotations.NotNull)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)4 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)3 ArrayList (java.util.ArrayList)3 ResourceType (com.evolveum.midpoint.prism.foo.ResourceType)2 UserType (com.evolveum.midpoint.prism.foo.UserType)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 Element (org.w3c.dom.Element)2