Search in sources :

Example 1 with ConstructionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.

the class AssignExecutor method createDelta.

private ObjectDelta createDelta(ObjectType objectType, Collection<ObjectReferenceType> resources, Collection<ObjectReferenceType> roles) throws ScriptExecutionException {
    List<AssignmentType> assignments = new ArrayList<>();
    if (roles != null) {
        for (ObjectReferenceType roleRef : roles) {
            AssignmentType assignmentType = new AssignmentType();
            assignmentType.setTargetRef(roleRef);
            assignments.add(assignmentType);
        }
    }
    if (resources != null) {
        for (ObjectReferenceType resourceRef : resources) {
            AssignmentType assignmentType = new AssignmentType();
            ConstructionType constructionType = new ConstructionType();
            constructionType.setResourceRef(resourceRef);
            assignmentType.setConstruction(constructionType);
            assignments.add(assignmentType);
        }
    }
    ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(objectType.getClass(), objectType.getOid(), prismContext);
    try {
        delta.addModificationAddContainer(FocusType.F_ASSIGNMENT, assignments.toArray(new AssignmentType[0]));
    } catch (SchemaException e) {
        throw new ScriptExecutionException("Couldn't prepare modification to add resource/role assignments", e);
    }
    return delta;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ArrayList(java.util.ArrayList) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 2 with ConstructionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.

the class AssignmentTablePanel method removeResourceFromAccConstruction.

/**
	 * remove this method after model is updated - it has to remove resource
	 * from accountConstruction
	 */
@Deprecated
private void removeResourceFromAccConstruction(AssignmentType assignment) {
    ConstructionType accConstruction = assignment.getConstruction();
    if (accConstruction == null || accConstruction.getResource() == null) {
        return;
    }
    ObjectReferenceType ref = new ObjectReferenceType();
    ref.setOid(assignment.getConstruction().getResource().getOid());
    ref.setType(ResourceType.COMPLEX_TYPE);
    assignment.getConstruction().setResourceRef(ref);
    assignment.getConstruction().setResource(null);
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType)

Example 3 with ConstructionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.

the class TestSchemaDelta method testDeleteInducementConstructionSameNullIdApplyToObject.

@Test
public void testDeleteInducementConstructionSameNullIdApplyToObject() throws Exception {
    final String TEST_NAME = "testDeleteInducementConstructionSameNullIdApplyToObject";
    displayTestTile(TEST_NAME);
    // GIVEN
    PrismObject<RoleType> role = PrismTestUtil.parseObject(ROLE_CONSTRUCTION_FILE);
    //Delta
    ConstructionType construction = new ConstructionType();
    ObjectReferenceType resourceRef = new ObjectReferenceType();
    resourceRef.setOid(ROLE_CONSTRUCTION_RESOURCE_OID);
    resourceRef.setType(ObjectTypes.RESOURCE.getTypeQName());
    construction.setResourceRef(resourceRef);
    // No container ID
    ObjectDelta<RoleType> roleDelta = ObjectDelta.createModificationDeleteContainer(RoleType.class, ROLE_CONSTRUCTION_OID, new ItemPath(new NameItemPathSegment(RoleType.F_INDUCEMENT), new IdItemPathSegment(ROLE_CONSTRUCTION_INDUCEMENT_ID), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)), getPrismContext(), construction);
    // WHEN
    roleDelta.applyTo(role);
    // THEN
    System.out.println("Role after delta application:");
    System.out.println(role.debugDump());
    assertEquals("Wrong OID", ROLE_CONSTRUCTION_OID, role.getOid());
    PrismAsserts.assertPropertyValue(role, UserType.F_NAME, PrismTestUtil.createPolyString("Construction"));
    PrismContainer<AssignmentType> inducementContainer = role.findContainer(RoleType.F_INDUCEMENT);
    assertNotNull("No inducement", inducementContainer);
    assertEquals("Unexpected number of inducement values", 1, inducementContainer.size());
    PrismContainerValue<AssignmentType> inducementValue = inducementContainer.getValues().iterator().next();
    AssignmentType inducement = inducementValue.asContainerable();
    ConstructionType constructionAfter = inducement.getConstruction();
    // construction should be gone (the error is that it is empty and not gone)
    assertNull("Construction is not gone", constructionAfter);
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 4 with ConstructionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method assertAssignedAccount.

protected AssignmentType assertAssignedAccount(PrismObject<UserType> user, String resourceOid) throws ObjectNotFoundException, SchemaException {
    UserType userType = user.asObjectable();
    for (AssignmentType assignmentType : userType.getAssignment()) {
        ConstructionType construction = assignmentType.getConstruction();
        if (construction != null) {
            if (construction.getKind() != null && construction.getKind() != ShadowKindType.ACCOUNT) {
                continue;
            }
            if (resourceOid.equals(construction.getResourceRef().getOid())) {
                return assignmentType;
            }
        }
    }
    AssertJUnit.fail(user.toString() + " does not have account assignment for resource " + resourceOid);
    // not reached
    return null;
}
Also used : ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 5 with ConstructionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType 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)

Aggregations

ConstructionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType)17 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)11 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 Test (org.testng.annotations.Test)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 Task (com.evolveum.midpoint.task.api.Task)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 QName (javax.xml.namespace.QName)5 ActivationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)4 MetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)3 ArrayList (java.util.ArrayList)3 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)2