Search in sources :

Example 16 with IdItemPathSegment

use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method createReplaceAccountConstructionUserDelta.

protected ObjectDelta<UserType> createReplaceAccountConstructionUserDelta(String userOid, Long id, ConstructionType newValue) throws SchemaException {
    PrismContainerDefinition pcd = getAssignmentDefinition().findContainerDefinition(AssignmentType.F_CONSTRUCTION);
    ContainerDelta<ConstructionType> acDelta = new ContainerDelta<ConstructionType>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)), pcd, prismContext);
    //                ContainerDelta.createDelta(prismContext, ConstructionType.class, AssignmentType.F_CONSTRUCTION);
    acDelta.setValueToReplace(newValue.asPrismContainerValue());
    //        PropertyDelta.createModificationReplaceProperty(
    //                        new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)),
    //                        ppd,
    //                        newValue);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    modifications.add(acDelta);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
    return userDelta;
}
Also used : ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ArrayList(java.util.ArrayList) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 17 with IdItemPathSegment

use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.

the class ConcurrencyTest method concurrency004_TwoWriters_TwoAttributesEach__OneReader.

@Test(enabled = true)
public void concurrency004_TwoWriters_TwoAttributesEach__OneReader() throws Exception {
    ModifierThread[] mts = new ModifierThread[] { new ModifierThread(1, new ItemPath(UserType.F_GIVEN_NAME), true, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(1L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION)), true), new ModifierThread(2, new ItemPath(UserType.F_FAMILY_NAME), true, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(1L), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)), true) };
    Checker checker = new Checker() {

        @Override
        public void check(int iteration, String oid) throws Exception {
            PrismObject<UserType> userRetrieved = repositoryService.getObject(UserType.class, oid, null, new OperationResult("dummy"));
            String givenName = userRetrieved.asObjectable().getGivenName().getOrig();
            String familyName = userRetrieved.asObjectable().getFamilyName().getOrig();
            String assignmentDescription = userRetrieved.asObjectable().getAssignment().get(0).getDescription();
            String referenceDescription = userRetrieved.asObjectable().getAssignment().get(0).getConstruction().getDescription();
            LOGGER.info("[" + iteration + "] givenName = " + givenName + ", assignment description = " + assignmentDescription + ", familyName = " + familyName + ", referenceDescription = " + referenceDescription);
            if (!givenName.equals(assignmentDescription)) {
                String msg = "Inconsistent object state: GivenName = " + givenName + ", assignment description = " + assignmentDescription;
                LOGGER.error(msg);
                throw new AssertionError(msg);
            }
            if (!familyName.equals(referenceDescription)) {
                String msg = "Inconsistent object state: FamilyName = " + familyName + ", account construction description = " + referenceDescription;
                LOGGER.error(msg);
                throw new AssertionError(msg);
            }
        }
    };
    concurrencyUniversal("Test4", 60000L, 0L, mts, checker);
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 18 with IdItemPathSegment

use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.

the class ConcurrencyTest method concurrency003_OneWriter_TwoAttributes__OneReader.

@Test(enabled = true)
public void concurrency003_OneWriter_TwoAttributes__OneReader() throws Exception {
    ModifierThread[] mts = new ModifierThread[] { new ModifierThread(1, new ItemPath(UserType.F_GIVEN_NAME), true, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(1L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION)), true) };
    Checker checker = new Checker() {

        @Override
        public void check(int iteration, String oid) throws Exception {
            PrismObject<UserType> userRetrieved = repositoryService.getObject(UserType.class, oid, null, new OperationResult("dummy"));
            String givenName = userRetrieved.asObjectable().getGivenName().getOrig();
            String assignmentDescription = userRetrieved.asObjectable().getAssignment().get(0).getDescription();
            LOGGER.info("[" + iteration + "] givenName = " + givenName + ", assignment description = " + assignmentDescription);
            if (!givenName.equals(assignmentDescription)) {
                String msg = "Inconsistent object state: GivenName = " + givenName + ", assignment description = " + assignmentDescription;
                LOGGER.error(msg);
                throw new AssertionError(msg);
            }
        }
    };
    concurrencyUniversal("Test3", 60000L, 0L, mts, checker);
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 19 with IdItemPathSegment

use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.

the class JpaEntityDefinition method nextLinkDefinition.

@Override
public DataSearchResult<?> nextLinkDefinition(ItemPath path, ItemDefinition<?> itemDefinition, PrismContext prismContext) throws QueryException {
    if (ItemPath.isNullOrEmpty(path)) {
        // doesn't fulfill precondition
        return null;
    }
    ItemPathSegment first = path.first();
    if (first instanceof IdItemPathSegment) {
        throw new QueryException("ID item path segments are not allowed in query: " + path);
    } else if (first instanceof ObjectReferencePathSegment) {
        throw new QueryException("'@' path segment cannot be used in the context of an entity " + this);
    }
    JpaLinkDefinition<?> link = findRawLinkDefinition(path, JpaDataNodeDefinition.class, false);
    if (link == null) {
        return null;
    } else {
        link.resolveEntityPointer();
        return new DataSearchResult<>(link, path.tail(link.getItemPath().size()));
    }
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) DataSearchResult(com.evolveum.midpoint.repo.sql.query2.resolution.DataSearchResult) ObjectReferencePathSegment(com.evolveum.midpoint.prism.path.ObjectReferencePathSegment)

Example 20 with IdItemPathSegment

use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.

the class ComplexTypeDefinitionImpl method findItemDefinition.

@Override
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) {
    for (; ; ) {
        if (path.isEmpty()) {
            throw new IllegalArgumentException("Cannot resolve empty path on complex type definition " + this);
        }
        ItemPathSegment first = path.first();
        if (first instanceof NameItemPathSegment) {
            QName firstName = ((NameItemPathSegment) first).getName();
            return findNamedItemDefinition(firstName, path.rest(), clazz);
        } else if (first instanceof IdItemPathSegment) {
            path = path.rest();
        } else if (first instanceof ParentPathSegment) {
            ItemPath rest = path.rest();
            ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(this, rest);
            if (rest.isEmpty()) {
                // requires that the parent is defined as an item (container, object)
                return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName());
            } else {
                return parent.findItemDefinition(rest, clazz);
            }
        } else if (first instanceof ObjectReferencePathSegment) {
            throw new IllegalStateException("Couldn't use '@' path segment in this context. CTD=" + getTypeName() + ", path=" + path);
        } else {
            throw new IllegalStateException("Unexpected path segment: " + first + " in " + path);
        }
    }
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ParentPathSegment(com.evolveum.midpoint.prism.path.ParentPathSegment) QName(javax.xml.namespace.QName) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ObjectReferencePathSegment(com.evolveum.midpoint.prism.path.ObjectReferencePathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)35 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)30 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)27 Test (org.testng.annotations.Test)17 QName (javax.xml.namespace.QName)8 UserType (com.evolveum.midpoint.prism.foo.UserType)6 ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)5 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 ObjectReferencePathSegment (com.evolveum.midpoint.prism.path.ObjectReferencePathSegment)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)2