use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class SqlQueryContext method orderingPath.
/**
* @param <CQ> current entity query path type, can change during multi-segment path resolution
* @param <CR> row type related to {@link CQ}
*/
@SuppressWarnings("unchecked")
private <CQ extends FlexibleRelationalPathBase<CR>, CR> Expression<?> orderingPath(ItemPath orderByItemPath) throws RepositoryException {
ItemPath path = orderByItemPath;
QueryModelMapping<?, CQ, CR> mapping = (QueryModelMapping<?, CQ, CR>) entityPathMapping;
SqlQueryContext<?, CQ, CR> context = (SqlQueryContext<?, CQ, CR>) this;
// We need definition for proper extension support.
// For other cases it's safe for this to become null.
PrismContainerDefinition<?> containerDefinition = (PrismContainerDefinition<?>) entityPathMapping.itemDefinition();
while (path.size() > 1) {
// Resolves only first element
ItemRelationResolver<CQ, CR, ?, ?> resolver = mapping.relationResolver(path);
ItemRelationResolver.ResolutionResult<?, ?> resolution = resolver.resolve(context);
if (resolution.subquery) {
throw new QueryException("Item path '" + orderByItemPath + "' cannot be used for ordering because subquery is used to resolve it.");
}
// CQ/CR for the next loop may be actually different from before, but that's OK
mapping = (QueryModelMapping<?, CQ, CR>) resolution.mapping;
context = (SqlQueryContext<?, CQ, CR>) resolution.context;
if (containerDefinition != null) {
containerDefinition = containerDefinition.findLocalItemDefinition(path.firstToName(), PrismContainerDefinition.class, false);
}
path = path.rest();
}
QName first = path.firstToQName();
ItemDefinition<?> definition = first instanceof ItemName && containerDefinition != null ? containerDefinition.findItemDefinition((ItemName) first) : null;
ItemSqlMapper<CQ, CR> mapper = mapping.itemMapper(first);
return mapper.primaryPath(context.path(), definition);
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class TestConsistencyMechanism method checkOpenResourceConfiguration.
private void checkOpenResourceConfiguration(PrismObject<ResourceType> resource, String connectorNamespace, String credentialsPropertyName, int numConfigProps, String source) {
PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
assertNotNull("No configuration container in " + resource + " from " + source, configurationContainer);
PrismContainer<Containerable> configPropsContainer = configurationContainer.findContainer(SchemaTestConstants.ICFC_CONFIGURATION_PROPERTIES);
assertNotNull("No configuration properties container in " + resource + " from " + source, configPropsContainer);
Collection<? extends Item<?, ?>> configProps = configPropsContainer.getValue().getItems();
assertEquals("Wrong number of config properties in " + resource + " from " + source, numConfigProps, configProps.size());
PrismProperty<Object> credentialsProp = configPropsContainer.findProperty(new ItemName(connectorNamespace, credentialsPropertyName));
if (credentialsProp == null) {
// The is the heisenbug we are looking for. Just dump the entire
// damn thing.
displayValue("Configuration with the heisenbug", configurationContainer.debugDump());
}
assertNotNull("No credentials property in " + resource + " from " + source, credentialsProp);
assertEquals("Wrong number of credentials property value in " + resource + " from " + source, 1, credentialsProp.getValues().size());
PrismPropertyValue<Object> credentialsPropertyValue = credentialsProp.getValues().iterator().next();
assertNotNull("No credentials property value in " + resource + " from " + source, credentialsPropertyValue);
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class TestParseDiffPatch method testUser.
@Test
public void testUser() throws SchemaException, IOException {
PrismObject<UserType> userBefore = PrismTestUtil.parseObject(new File(TEST_DIR, "user-jack-before.xml"));
userBefore.checkConsistence();
PrismObject<UserType> userAfter = PrismTestUtil.parseObject(new File(TEST_DIR, "user-jack-after.xml"));
userAfter.checkConsistence();
// sanity
assertFalse("Equals does not work", userBefore.equals(userAfter));
// WHEN
ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
// THEN
System.out.println("DELTA:");
System.out.println(userDelta.debugDump());
userBefore.checkConsistence();
userAfter.checkConsistence();
userDelta.checkConsistence();
userDelta.assertDefinitions();
assertEquals("Wrong delta OID", userBefore.getOid(), userDelta.getOid());
assertEquals("Wrong change type", ChangeType.MODIFY, userDelta.getChangeType());
Collection<? extends ItemDelta> modifications = userDelta.getModifications();
assertEquals("Unexpected number of modifications", 3, modifications.size());
PrismAsserts.assertPropertyReplace(userDelta, new ItemName(SchemaConstants.NS_C, "fullName"), new PolyString("Cpt. Jack Sparrow", "cpt jack sparrow"));
PrismAsserts.assertPropertyAdd(userDelta, new ItemName(SchemaConstants.NS_C, "honorificPrefix"), new PolyString("Cpt.", "cpt"));
PrismAsserts.assertPropertyAdd(userDelta, new ItemName(SchemaConstants.NS_C, "locality"), new PolyString("Tortuga", "tortuga"));
ObjectModificationType objectModificationType = DeltaConvertor.toObjectModificationType(userDelta);
System.out.println("Modification XML:");
System.out.println(PrismTestUtil.serializeAnyDataWrapped(objectModificationType));
assertEquals("Wrong delta OID", userBefore.getOid(), objectModificationType.getOid());
List<ItemDeltaType> propertyModifications = objectModificationType.getItemDelta();
assertEquals("Unexpected number of modifications", 3, propertyModifications.size());
PolyStringType polyString = new PolyStringType();
polyString.setOrig("Cpt. Jack Sparrow");
polyString.setNorm("cpt jack sparrow");
assertXmlPolyMod(objectModificationType, new ItemName(SchemaConstants.NS_C, "fullName"), ModificationTypeType.REPLACE, polyString);
polyString = new PolyStringType();
polyString.setOrig("Cpt.");
polyString.setNorm("cpt");
assertXmlPolyMod(objectModificationType, new ItemName(SchemaConstants.NS_C, "honorificPrefix"), ModificationTypeType.ADD, polyString);
polyString = new PolyStringType();
polyString.setOrig("Tortuga");
polyString.setNorm("tortuga");
assertXmlPolyMod(objectModificationType, new ItemName(SchemaConstants.NS_C, "locality"), ModificationTypeType.ADD, polyString);
userBefore.checkConsistence();
userAfter.checkConsistence();
userDelta.checkConsistence();
// ROUNDTRIP
userDelta.applyTo(userBefore);
userBefore.checkConsistence();
userAfter.checkConsistence();
userDelta.checkConsistence();
// assertEquals("Round trip failed", userAfter, userBefore);
assertTrue("Not equivalent", userBefore.equivalent(userAfter));
ObjectDelta<UserType> roundTripDelta = DiffUtil.diff(userBefore, userAfter);
System.out.println("roundtrip DELTA:");
System.out.println(roundTripDelta.debugDump());
assertTrue("Roundtrip delta is not empty", roundTripDelta.isEmpty());
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class TestParseGenericObject method assertPropertyValue.
public static void assertPropertyValue(PrismContainer<?> container, String propName, Object propValue) {
ItemName propQName = new ItemName(SchemaConstantsGenerated.NS_COMMON, propName);
PrismAsserts.assertPropertyValue(container, propQName, propValue);
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class TestParsePasswordPolicy method assertPropertyValue.
public static void assertPropertyValue(PrismContainer<?> container, String propName, Object propValue) {
ItemName propQName = new ItemName(SchemaConstantsGenerated.NS_COMMON, propName);
PrismAsserts.assertPropertyValue(container, propQName, propValue);
}
Aggregations