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