Search in sources :

Example 66 with ItemName

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);
}
Also used : QName(javax.xml.namespace.QName) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemName(com.evolveum.midpoint.prism.path.ItemName) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 67 with ItemName

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);
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 68 with ItemName

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());
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemName(com.evolveum.midpoint.prism.path.ItemName) File(java.io.File) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test)

Example 69 with ItemName

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);
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 70 with ItemName

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);
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Aggregations

ItemName (com.evolveum.midpoint.prism.path.ItemName)89 Test (org.testng.annotations.Test)24 QName (javax.xml.namespace.QName)19 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 NotNull (org.jetbrains.annotations.NotNull)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 Task (com.evolveum.midpoint.task.api.Task)6 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)5 MUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser)5 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)5 Element (org.w3c.dom.Element)5 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)4 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)4 ArrayList (java.util.ArrayList)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3