use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.
the class ExpressionUtil method parseSearchFilter.
// TODO move somewhere else? generalize a bit?
public static RootXNode parseSearchFilter(String data, PrismContext context) throws SchemaException {
String xml = WebXmlUtil.wrapInElement("root", data, false);
RootXNode rootXNode = context.parserFor(xml).xml().parseToXNode();
if (rootXNode.getSubnode() instanceof MapXNode) {
MapXNode mapXNode = (MapXNode) rootXNode.getSubnode();
if (mapXNode.size() != 1) {
throw new SchemaException("Content cannot be parsed as a search filter: " + mapXNode.debugDump());
}
return mapXNode.getEntryAsRoot(mapXNode.keySet().iterator().next());
} else {
throw new SchemaException("Content cannot be parsed as a search filter: " + DebugUtil.debugDump(rootXNode.getSubnode()));
}
}
use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.
the class TestBeanSerialization method testPipelineItemXsdType.
@Test
public void testPipelineItemXsdType() throws SchemaException {
PipelineDataType bean = new PipelineDataType();
bean.beginItem().value("s1");
PrismContext prismContext = PrismTestUtil.getPrismContext();
RootXNode xnode = prismContext.xnodeSerializer().root(new QName("output")).serializeRealValue(bean);
MapXNode output = (MapXNode) xnode.toMapXNode().get(new QName("output"));
XNode item = ((ListXNode) output.get(PipelineDataType.F_ITEM)).get(0);
assertTrue(item instanceof MapXNode);
XNode value = ((MapXNode) item).get(PipelineItemType.F_VALUE);
assertTrue(value instanceof PrimitiveXNodeImpl);
assertTrue(value.isExplicitTypeDeclaration());
assertEquals(value.getTypeQName(), DOMUtil.XSD_STRING);
// displayValue("output in XML", prismContext.xmlSerializer().root(new QName("output")).serializeRealValue(bean));
}
use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.
the class TestDeltaConverter method testProtectedStringObjectDelta.
@Test
public void testProtectedStringObjectDelta() throws Exception {
System.out.println("===[ testProtectedStringObjectDelta ]====");
// GIVEN
ItemPath path = CREDENTIALS_PASSWORD_VALUE_PATH;
ProtectedStringType protectedString = new ProtectedStringType();
protectedString.setClearValue("abrakadabra");
ObjectDelta<UserType> objectDelta = getPrismContext().deltaFactory().object().createModificationReplaceProperty(UserType.class, "12345", path, protectedString);
System.out.println("ObjectDelta");
System.out.println(objectDelta.debugDump());
// WHEN
ObjectDeltaType objectDeltaType = toObjectDeltaType(objectDelta);
// THEN
System.out.println("ObjectDeltaType (XML)");
System.out.println(PrismTestUtil.serializeAnyDataWrapped(objectDeltaType));
assertEquals("Wrong changetype", ChangeTypeType.MODIFY, objectDeltaType.getChangeType());
assertEquals("Wrong OID", "12345", objectDeltaType.getOid());
List<ItemDeltaType> modifications = objectDeltaType.getItemDelta();
assertNotNull("null modifications", modifications);
assertEquals("Wrong number of modifications", 1, modifications.size());
ItemDeltaType mod1 = modifications.iterator().next();
assertEquals("Wrong mod type", ModificationTypeType.REPLACE, mod1.getModificationType());
// XPathHolder xpath = new XPathHolder(mod1.getPath());
ItemPathType itemPathType = mod1.getPath();
assertNotNull("Wrong path (must not be null)", itemPathType);
assertEquals("Wrong path", path, itemPathType.getItemPath());
List<RawType> valueElements = mod1.getValue();
assertEquals("Wrong number of value elements", 1, valueElements.size());
RawType val = valueElements.get(0);
MapXNode valXNode = (MapXNode) val.serializeToXNode();
PrimitiveXNode<?> clearValueNode = (PrimitiveXNode<?>) valXNode.get(ProtectedStringType.F_CLEAR_VALUE);
val.getParsedValue(null, null);
// System.out.println("clear value " + clearValueNode);
assertEquals("Wrong element value", protectedString.getClearValue(), clearValueNode.getParsedValue(DOMUtil.XSD_STRING, String.class));
// List<Object> values = val.getContent();
// assertEquals("Wrong number of values", 1, values.size());
// JAXBElement<ProtectedStringType> valueElement = (JAXBElement<ProtectedStringType>)values.iterator().next();
// // assertEquals("Wrong element name", PasswordType.F_VALUE, valueElement.getName());
// assertEquals("Wrong element value", protectedString, valueElement.getValue());
}
use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.
the class TestJaxbConstruction method testUserConstruction.
@Test
public void testUserConstruction() throws SchemaException {
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
UserType userType = new UserType();
prismContext.adopt(userType);
PrismObject<UserType> user = userType.asPrismObject();
assertNotNull("No object definition after adopt", user.getDefinition());
SchemaTestUtil.assertUserDefinition(user.getDefinition());
// fullName: PolyString
userType.setFullName(new PolyStringType("Čučoriedka"));
PrismProperty<PolyString> fullNameProperty = user.findProperty(UserType.F_FULL_NAME);
PolyString fullName = fullNameProperty.getRealValue();
assertEquals("Wrong fullName orig", "Čučoriedka", fullName.getOrig());
assertEquals("Wrong fullName norm", "cucoriedka", fullName.getNorm());
// description: setting null value
userType.setDescription(null);
PrismProperty<String> descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
assertNull("Unexpected description property " + descriptionProperty, descriptionProperty);
// description: setting null value
userType.setDescription("blah blah");
descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
// description: resetting null value
userType.setDescription(null);
descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
assertNull("Unexpected description property (after reset) " + descriptionProperty, descriptionProperty);
// Extension
ExtensionType extension = new ExtensionType();
userType.setExtension(extension);
user.checkConsistence();
PrismContainer<Containerable> extensionContainer = user.findContainer(GenericObjectType.F_EXTENSION);
checkExtension(extensionContainer, "user extension after setExtension");
checkExtension(extension, "user extension after setExtension");
AssignmentType assignmentType = new AssignmentType();
userType.getAssignment().add(assignmentType);
user.checkConsistence();
user.assertDefinitions();
// Assignment
ExtensionType assignmentExtension = new ExtensionType();
assignmentType.setExtension(assignmentExtension);
user.assertDefinitions();
user.checkConsistence();
checkExtension(assignmentExtension, "assignment extension after setExtension");
user.checkConsistence();
user.assertDefinitions();
// accountRef/account
ObjectReferenceType accountRefType = new ObjectReferenceType();
accountRefType.setOid(USER_ACCOUNT_REF_1_OID);
MapXNode filterElement = createFilter();
SearchFilterType filter = new SearchFilterType();
filter.setFilterClauseXNode(filterElement);
accountRefType.setFilter(filter);
userType.getLinkRef().add(accountRefType);
assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID);
user.checkConsistence();
user.assertDefinitions();
PrismReference accountRef = user.findReference(UserType.F_LINK_REF);
assertEquals("1/ Wrong accountRef values", 1, accountRef.getValues().size());
PrismReferenceValue accountRefVal0 = accountRef.getAnyValue();
SearchFilterType prismFilter = accountRefVal0.getFilter();
assertNotNull("Filter have not passed", prismFilter);
// assertTrue("Bad filter in reference", prismFilter instanceof EqualsFilter);
// assertEquals("Difference filter", filterElement, prismFilter);
ShadowType accountShadowType = new ShadowType();
prismContext.adopt(accountShadowType);
accountShadowType.setOid(USER_ACCOUNT_REF_1_OID);
ObjectReferenceType accountRef1 = new ObjectReferenceType();
accountRef1.asReferenceValue().setObject(accountShadowType.asPrismObject());
userType.getLinkRef().add(accountRef1);
// value still should be only one... (reference was only resolved)
assertEquals("2/ Wrong accountRef values", 1, user.findReference(UserType.F_LINK_REF).getValues().size());
ObjectReferenceType accountRef2 = new ObjectReferenceType();
accountRef2.setOid(USER_ACCOUNT_REF_2_OID);
userType.getLinkRef().add(accountRef2);
assertEquals("3/ Wrong accountRef values", 2, user.findReference(UserType.F_LINK_REF).getValues().size());
assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
user.checkConsistence();
user.assertDefinitions();
assertEquals("4/ Wrong accountRef values", 2, accountRef.getValues().size());
PrismAsserts.assertReferenceValues(accountRef, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
}
use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.
the class TestJaxbConstruction method createFilter.
private MapXNode createFilter() {
XNodeFactory factory = getPrismContext().xnodeFactory();
Map<QName, XNode> equalsElementSource = new HashMap<>();
PrimitiveXNode<ItemPathType> pathElement = factory.primitive(new ItemPathType(new ItemName("name")));
equalsElementSource.put(new QName(SchemaConstantsGenerated.NS_QUERY, "path"), pathElement);
PrimitiveXNode<String> valueElement = factory.primitive("čučoriedka");
equalsElementSource.put(new QName(SchemaConstantsGenerated.NS_QUERY, "value"), valueElement);
MapXNode equalsElement = factory.map(equalsElementSource);
return factory.map(new QName(SchemaConstantsGenerated.NS_QUERY, "equal"), equalsElement);
}
Aggregations