Search in sources :

Example 76 with PrismReferenceValue

use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.

the class SearchTest method delegatedSearchTest.

@Test
public void delegatedSearchTest() throws Exception {
    PrismReferenceValue r789 = new PrismReferenceValue("r789", RoleType.COMPLEX_TYPE);
    // intentionally without relation (meaning "member")
    ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_DELEGATED_REF).ref(r789).build();
    OperationResult result = new OperationResult("search");
    List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, query, null, result);
    result.recomputeStatus();
    assertTrue(result.isSuccess());
    assertEquals("Should find one user", 1, users.size());
    assertEquals("Wrong user name", "atestuserX00003", users.get(0).getName().getOrig());
    PrismReferenceValue r123 = new PrismReferenceValue("r123", RoleType.COMPLEX_TYPE);
    query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_DELEGATED_REF).ref(r123).build();
    users = repositoryService.searchObjects(UserType.class, query, null, result);
    result.recomputeStatus();
    assertTrue(result.isSuccess());
    assertEquals("Should find no users", 0, users.size());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 77 with PrismReferenceValue

use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.

the class SearchTest method orgAssignmentSearchTest.

@Test
public void orgAssignmentSearchTest() throws Exception {
    PrismReferenceValue org = new PrismReferenceValue("00000000-8888-6666-0000-100000000085", OrgType.COMPLEX_TYPE);
    ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(org).build();
    OperationResult result = new OperationResult("search");
    List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, query, null, result);
    result.recomputeStatus();
    assertTrue(result.isSuccess());
    assertEquals("Should find one user", 1, users.size());
    assertEquals("Wrong user name", "atestuserX00002", users.get(0).getName().getOrig());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 78 with PrismReferenceValue

use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.

the class SearchTest method roleAndOrgAssignmentSearchTest.

@Test
public void roleAndOrgAssignmentSearchTest() throws Exception {
    PrismReferenceValue r123 = new PrismReferenceValue("r123", RoleType.COMPLEX_TYPE);
    PrismReferenceValue org = new PrismReferenceValue("00000000-8888-6666-0000-100000000085", OrgType.COMPLEX_TYPE);
    ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(r123).and().item(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(org).build();
    OperationResult result = new OperationResult("search");
    List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, query, null, result);
    result.recomputeStatus();
    assertTrue(result.isSuccess());
    assertEquals("Should find one user", 1, users.size());
    assertEquals("Wrong user name", "atestuserX00002", users.get(0).getName().getOrig());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 79 with PrismReferenceValue

use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.

the class AbstractOrgClosureTest method removeObjectParent.

protected void removeObjectParent(ObjectType object, ObjectReferenceType parentOrgRef, boolean useReplace, OperationResult opResult) throws Exception {
    List<ItemDelta> modifications = new ArrayList<>();
    if (!useReplace) {
        // standard case
        PrismReferenceValue existingValue = parentOrgRef.asReferenceValue();
        ItemDelta removeParent = ReferenceDelta.createModificationDelete(object.getClass(), OrgType.F_PARENT_ORG_REF, prismContext, existingValue.clone());
        modifications.add(removeParent);
    } else {
        // using REPLACE modification
        List<PrismReferenceValue> newValues = new ArrayList<>();
        for (ObjectReferenceType ort : object.getParentOrgRef()) {
            if (!ort.getOid().equals(parentOrgRef.getOid())) {
                newValues.add(ort.asReferenceValue().clone());
            }
        }
        PrismObjectDefinition objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(object.getClass());
        ItemDelta replaceParent = ReferenceDelta.createModificationReplace(new ItemPath(OrgType.F_PARENT_ORG_REF), objectDefinition, newValues);
        modifications.add(replaceParent);
    }
    repositoryService.modifyObject(object.getClass(), object.getOid(), modifications, opResult);
    if (object instanceof OrgType) {
        orgGraph.removeEdge(object.getOid(), parentOrgRef.getOid());
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 80 with PrismReferenceValue

use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.

the class AbstractOrgClosureTest method addUserParent.

protected void addUserParent(UserType user, ObjectReferenceType parentOrgRef, OperationResult opResult) throws Exception {
    List<ItemDelta> modifications = new ArrayList<>();
    PrismReferenceValue existingValue = parentOrgRef.asReferenceValue();
    ItemDelta readdParent = ReferenceDelta.createModificationAdd(UserType.class, UserType.F_PARENT_ORG_REF, prismContext, existingValue.clone());
    modifications.add(readdParent);
    repositoryService.modifyObject(UserType.class, user.getOid(), modifications, opResult);
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Aggregations

PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)126 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)64 Test (org.testng.annotations.Test)47 Task (com.evolveum.midpoint.task.api.Task)45 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)32 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)27 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)26 PrismObject (com.evolveum.midpoint.prism.PrismObject)25 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)24 ArrayList (java.util.ArrayList)22 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)21 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)20 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)16 PrismReference (com.evolveum.midpoint.prism.PrismReference)15 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)12 Collection (java.util.Collection)12 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)11