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;
}
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);
}
}
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));
}
}
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);
}
}
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);
}
}
Aggregations