Search in sources :

Example 36 with MapXNode

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()));
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 37 with MapXNode

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));
}
Also used : ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNodeImpl(com.evolveum.midpoint.prism.impl.xnode.PrimitiveXNodeImpl) PipelineDataType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType) Test(org.testng.annotations.Test)

Example 38 with MapXNode

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());
}
Also used : PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) DeltaConvertor.toObjectDeltaType(com.evolveum.midpoint.schema.DeltaConvertor.toObjectDeltaType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 39 with MapXNode

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);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) PrismTestUtil.getPrismContext(com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 40 with MapXNode

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);
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ItemName(com.evolveum.midpoint.prism.path.ItemName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) XNodeFactory(com.evolveum.midpoint.prism.xnode.XNodeFactory)

Aggregations

MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)42 QName (javax.xml.namespace.QName)24 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)21 XNode (com.evolveum.midpoint.prism.xnode.XNode)18 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)15 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)13 Test (org.testng.annotations.Test)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 Element (org.w3c.dom.Element)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)4 Protector (com.evolveum.midpoint.prism.crypto.Protector)3 EncryptedDataType (com.evolveum.prism.xml.ns._public.types_3.EncryptedDataType)3 NotNull (org.jetbrains.annotations.NotNull)3 TestProtector (com.evolveum.midpoint.prism.crypto.TestProtector)2