Search in sources :

Example 6 with PrimitiveXNode

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

the class AbstractJsonLexicalProcessor method processSchemaNodes.

// Schema nodes can be detected only after namespaces are resolved.
// We simply convert primitive nodes to schema ones.
private void processSchemaNodes(XNode xnode) throws SchemaException, IOException {
    if (xnode instanceof MapXNode) {
        MapXNode map = (MapXNode) xnode;
        XNode schemaNode = null;
        for (Entry<QName, XNode> entry : map.entrySet()) {
            QName fieldName = entry.getKey();
            XNode subnode = entry.getValue();
            if (DOMUtil.XSD_SCHEMA_ELEMENT.equals(fieldName)) {
                schemaNode = subnode;
            } else {
                processSchemaNodes(subnode);
            }
        }
        if (schemaNode != null) {
            if (schemaNode instanceof PrimitiveXNode) {
                PrimitiveXNode<?> primitiveXNode = (PrimitiveXNode<?>) schemaNode;
                if (primitiveXNode.isParsed()) {
                    throw new SchemaException("Cannot convert from PrimitiveXNode to SchemaXNode: node is already parsed: " + primitiveXNode);
                }
                SchemaXNode schemaXNode = new SchemaXNode();
                map.replace(DOMUtil.XSD_SCHEMA_ELEMENT, schemaXNode);
                schemaXNode.setSchemaElement(((JsonValueParser) primitiveXNode.getValueParser()).asDomElement());
            } else {
                throw new SchemaException("Cannot convert 'schema' field to SchemaXNode: not a PrimitiveNode but " + schemaNode);
            }
        }
    } else if (xnode instanceof ListXNode) {
        for (XNode item : (ListXNode) xnode) {
            processSchemaNodes(item);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) QName(javax.xml.namespace.QName) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 7 with PrimitiveXNode

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

the class AbstractJsonLexicalProcessor method parseToPrimitive.

private <T> PrimitiveXNode<T> parseToPrimitive(JsonParsingContext ctx) throws IOException, SchemaException {
    PrimitiveXNode<T> primitive = new PrimitiveXNode<T>();
    Object tid = ctx.parser.getTypeId();
    if (tid != null) {
        QName typeName = tagToTypeName(tid, ctx);
        primitive.setTypeQName(typeName);
        primitive.setExplicitTypeDeclaration(true);
    } else {
    // We don't try to determine XNode type from the implicit JSON/YAML type (integer, number, ...),
    // because XNode type prescribes interpretation in midPoint. E.g. YAML string type would be interpreted
    // as xsd:string, even if the schema would expect e.g. timestamp.
    }
    JsonNode jn = ctx.parser.readValueAs(JsonNode.class);
    ValueParser<T> vp = new JsonValueParser<T>(ctx.parser, jn);
    primitive.setValueParser(vp);
    return primitive;
}
Also used : PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) QName(javax.xml.namespace.QName) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 8 with PrimitiveXNode

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

the class TestParseMappingConst method testParseSerialize.

@Test
public void testParseSerialize() throws Exception {
    displayTestTitle("testParseSerialize");
    PrismContext prismContext = getPrismContext();
    PrismParser parser = prismContext.parserFor(getFile());
    PrismPropertyValue<MappingType> mappingPval = parser.parseItemValue();
    System.out.println("\nmappingPval:\n" + mappingPval.debugDump(1));
    PrismSerializer<RootXNode> xserializer = prismContext.xnodeSerializer();
    RootXNode xnode = xserializer.root(new QName("dummy")).serialize(mappingPval);
    System.out.println("\nSerialized xnode:\n" + xnode.debugDump(1));
    MapXNode xexpression = (MapXNode) ((MapXNode) xnode.getSubnode()).get(new QName("expression"));
    ListXNode xconstList = (ListXNode) xexpression.get(new QName("const"));
    XNode xconst = xconstList.get(0);
    if (!(xconst instanceof PrimitiveXNode<?>)) {
        AssertJUnit.fail("const is not primitive: " + xconst);
    }
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) 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) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PrismParser(com.evolveum.midpoint.prism.PrismParser) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) Test(org.testng.annotations.Test)

Example 9 with PrimitiveXNode

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

the class TestUserChangeApprovalLegacy method checkAssignmentConstruction.

private void checkAssignmentConstruction(UserType jack, String attributeName, String value) throws SchemaException {
    assertEquals("jack's assignments", 1, jack.getAssignment().size());
    AssignmentType assignmentType = jack.getAssignment().get(0);
    ConstructionType constructionType = assignmentType.getConstruction();
    assertNotNull("construction is null", constructionType);
    boolean found = false;
    for (ResourceAttributeDefinitionType attributeDefinitionType : constructionType.getAttribute()) {
        if (attributeDefinitionType.getRef().equivalent(new ItemPathType(new ItemPath(new QName(attributeName))))) {
            ExpressionType expressionType = attributeDefinitionType.getOutbound().getExpression();
            assertNotNull("no expression", expressionType);
            assertEquals("wrong # of expression evaluators", 1, expressionType.getExpressionEvaluator().size());
            JAXBElement<?> element = expressionType.getExpressionEvaluator().get(0);
            PrimitiveXNode valueXNode = (PrimitiveXNode) (((RawType) element.getValue()).serializeToXNode());
            assertEquals("wrong outbound value", value, valueXNode.getStringValue());
            found = true;
        }
    }
    assertTrue("attribute " + attributeName + " mapping not found", found);
}
Also used : PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 10 with PrimitiveXNode

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

the class ConsistencyTest method test511AssignAccountMorgan.

/**
	 * assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
	 * account should be linked to the user.
	 * @throws Exception
	 */
@Test
public void test511AssignAccountMorgan() throws Exception {
    final String TEST_NAME = "test511AssignAccountMorgan";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    openDJController.assumeRunning();
    Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    //prepare new OU in opendj
    Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
    PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
    display("User Morgan: ", user);
    PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
    ExpressionType expression = new ExpressionType();
    ObjectFactory of = new ObjectFactory();
    RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), prismContext);
    JAXBElement val = of.createValue(raw);
    expression.getExpressionEvaluator().add(val);
    MappingType mapping = new MappingType();
    mapping.setExpression(expression);
    ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
    attrDefType.setRef(new ItemPathType(new ItemPath(getOpenDjSecondaryIdentifierQName())));
    attrDefType.setOutbound(mapping);
    ConstructionType construction = new ConstructionType();
    construction.getAttribute().add(attrDefType);
    construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
    AssignmentType assignment = new AssignmentType();
    assignment.setConstruction(construction);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    //		assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
    PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
    display("User morgan after", userMorgan);
    UserType userMorganType = userMorgan.asObjectable();
    assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
    String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
    assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account        
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Task(com.evolveum.midpoint.task.api.Task) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Entry(org.opends.server.types.Entry) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismReference(com.evolveum.midpoint.prism.PrismReference) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)19 QName (javax.xml.namespace.QName)13 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)10 XNode (com.evolveum.midpoint.prism.xnode.XNode)9 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)8 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)5 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)5 Test (org.testng.annotations.Test)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)3 JAXBElement (javax.xml.bind.JAXBElement)3 Element (org.w3c.dom.Element)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 DomLexicalProcessor (com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor)2 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)2 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)1 ParsingContext (com.evolveum.midpoint.prism.ParsingContext)1