use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestPrismContext method testCompileTimeClassmap.
@Test
public void testCompileTimeClassmap() throws SchemaException, SAXException, IOException {
System.out.println("===[ testCompileTimeClassmap ]===");
// WHEN
PrismContext prismContext = constructInitializedPrismContext();
// THEN
assertNotNull("No prism context", prismContext);
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
assertNotNull("No schema registry in context", schemaRegistry);
SchemaDescription fooDesc = schemaRegistry.findSchemaDescriptionByNamespace(NS_FOO);
Map<QName, Class<?>> map = fooDesc.getXsdTypeTocompileTimeClassMap();
assertNotNull("No XsdTypeTocompileTimeClassMap", map);
assertFalse("Empty XsdTypeTocompileTimeClassMap", map.isEmpty());
assertMapping(map, UserType.class, USER_TYPE_QNAME);
assertMapping(map, AccountType.class, ACCOUNT_TYPE_QNAME);
assertMapping(map, AssignmentType.class, ASSIGNMENT_TYPE_QNAME);
assertMapping(map, ActivationType.class, ACTIVATION_TYPE_QNAME);
// This is not a container, but it should be in the map anyway
assertMapping(map, AccountConstructionType.class, ACCOUNT_CONSTRUCTION_TYPE_QNAME);
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestPrismContext method testBasicSchemas.
@Test
public void testBasicSchemas() throws SchemaException, SAXException, IOException {
System.out.println("===[ testBasicSchemas ]===");
// WHEN
PrismContext prismContext = constructInitializedPrismContext();
// THEN
assertNotNull("No prism context", prismContext);
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
assertNotNull("No schema registry in context", schemaRegistry);
System.out.println("Schema registry:");
System.out.println(schemaRegistry.debugDump());
PrismSchema fooSchema = schemaRegistry.findSchemaByNamespace(NS_FOO);
System.out.println("Foo schema:");
System.out.println(fooSchema.debugDump());
// Assert USER definition
PrismObjectDefinition<UserType> userDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
assertNotNull("No user definition", userDefinition);
System.out.println("User definition:");
System.out.println(userDefinition.debugDump());
PrismObjectDefinition<UserType> userDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(UserType.class);
assertTrue("Different user def", userDefinition == userDefinitionByClass);
assertUserDefinition(userDefinition);
// Assert ACCOUNT definition
PrismObjectDefinition<AccountType> accountDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO, "account"));
assertNotNull("No account definition", accountDefinition);
System.out.println("Account definition:");
System.out.println(accountDefinition.debugDump());
PrismObjectDefinition<AccountType> accountDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(AccountType.class);
assertTrue("Different user def", accountDefinition == accountDefinitionByClass);
assertAccountDefinition(accountDefinition);
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestPath method testPathNormalize.
@Test
public void testPathNormalize() throws Exception {
System.out.println("\n\n===[ testPathNormalize ]===\n");
// GIVEN
ItemPath path1 = new ItemPath(new QName(NS, "foo"), new QName(NS, "bar"));
ItemPath path2 = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(123L), new NameItemPathSegment(new QName(NS, "bar")));
ItemPath path22 = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(123L), new NameItemPathSegment(new QName(NS, "bar")), new IdItemPathSegment(null));
ItemPath path3 = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(123L), new NameItemPathSegment(new QName(NS, "bar")), new IdItemPathSegment(333L));
ItemPath path4 = new ItemPath(new QName(NS, "x"));
ItemPath path5 = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(123L));
ItemPath pathE = new ItemPath();
// WHEN
ItemPath normalized1 = path1.normalize();
ItemPath normalized2 = path2.normalize();
ItemPath normalized22 = path22.normalize();
ItemPath normalized3 = path3.normalize();
ItemPath normalized4 = path4.normalize();
ItemPath normalized5 = path5.normalize();
ItemPath normalizedE = pathE.normalize();
// THEN
System.out.println("Normalized path 1:" + normalized1);
System.out.println("Normalized path 2:" + normalized2);
System.out.println("Normalized path 22:" + normalized22);
System.out.println("Normalized path 3:" + normalized3);
System.out.println("Normalized path 4:" + normalized4);
System.out.println("Normalized path 5:" + normalized5);
System.out.println("Normalized path E:" + normalizedE);
assertNormalizedPath(normalized1, "foo", null, "bar");
assertNormalizedPath(normalized2, "foo", 123L, "bar");
assertNormalizedPath(normalized22, "foo", 123L, "bar", null);
assertNormalizedPath(normalized3, "foo", 123L, "bar", 333L);
assertNormalizedPath(normalized4, "x");
assertNormalizedPath(normalized5, "foo", 123L);
assert normalizedE.isEmpty() : "normalizedE is not empty";
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestObjectQuery method testMatchEqualMultivalue.
@Test
public void testMatchEqualMultivalue() throws Exception {
PrismObject user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML);
PrismPropertyDefinitionImpl def = new PrismPropertyDefinitionImpl(new QName("indexedString"), DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext());
ObjectFilter filter = QueryBuilder.queryFor(UserType.class, PrismTestUtil.getPrismContext()).item(new ItemPath(UserType.F_EXTENSION, "indexedString"), def).eq("alpha").buildFilter();
boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry);
AssertJUnit.assertTrue("filter does not match object", match);
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class DeltaConvertor method createItemDelta.
public static <IV extends PrismValue, ID extends ItemDefinition> ItemDelta<IV, ID> createItemDelta(ItemDeltaType propMod, PrismContainerDefinition<?> pcDef, boolean allowRawValues) throws SchemaException {
ItemPathType parentPathType = propMod.getPath();
ItemPath parentPath = null;
if (parentPathType != null) {
parentPath = parentPathType.getItemPath();
} else {
throw new IllegalStateException("Path argument in the itemDelta HAVE TO BE specified.");
}
if (propMod.getValue() == null) {
throw new IllegalArgumentException("No value in item delta (path: " + parentPath + ") while creating a property delta");
}
ItemDefinition containingPcd = pcDef.findItemDefinition(parentPath);
PrismContainerDefinition containerDef = null;
if (containingPcd == null) {
containerDef = pcDef.findContainerDefinition(parentPath.allUpToLastNamed());
if (containerDef == null) {
if (allowRawValues) {
return null;
}
throw new SchemaException("No definition for " + parentPath.allUpToLastNamed().lastNamed().getName() + " (while creating delta for " + pcDef + ")");
}
}
QName elementName = parentPath.lastNamed().getName();
//propMod.getValue().getParsedValue(containingPcd);
Item item = RawTypeUtil.getParsedItem(containingPcd, propMod.getValue(), elementName, containerDef);
ItemDelta<IV, ID> itemDelta = item.createDelta(parentPath);
if (propMod.getModificationType() == ModificationTypeType.ADD) {
itemDelta.addValuesToAdd(PrismValue.resetParentCollection(PrismValue.cloneCollection(item.getValues())));
} else if (propMod.getModificationType() == ModificationTypeType.DELETE) {
itemDelta.addValuesToDelete(PrismValue.resetParentCollection(PrismValue.cloneCollection(item.getValues())));
} else if (propMod.getModificationType() == ModificationTypeType.REPLACE) {
itemDelta.setValuesToReplace(PrismValue.resetParentCollection(PrismValue.cloneCollection(item.getValues())));
}
if (!propMod.getEstimatedOldValue().isEmpty()) {
Item oldItem = RawTypeUtil.getParsedItem(containingPcd, propMod.getEstimatedOldValue(), elementName, containerDef);
itemDelta.addEstimatedOldValues(PrismValue.resetParentCollection(PrismValue.cloneCollection(oldItem.getValues())));
}
return itemDelta;
}
Aggregations