Search in sources :

Example 51 with AssignmentType

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

the class AbstractModelIntegrationTest method getUserAssignment.

protected AssignmentType getUserAssignment(String userOid, String roleOid, QName relation) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    PrismObject<UserType> user = getUser(userOid);
    List<AssignmentType> assignments = user.asObjectable().getAssignment();
    for (AssignmentType assignment : assignments) {
        ObjectReferenceType targetRef = assignment.getTargetRef();
        if (targetRef != null && roleOid.equals(targetRef.getOid()) && prismContext.relationMatches(relation, targetRef.getRelation())) {
            return assignment;
        }
    }
    return null;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)

Example 52 with AssignmentType

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

the class AbstractModelIntegrationTest method unassignAllRoles.

protected void unassignAllRoles(String userOid, boolean useRawPlusRecompute) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException {
    Task task = createPlainTask("unassignAllRoles");
    OperationResult result = task.getResult();
    PrismObject<UserType> user = modelService.getObject(UserType.class, userOid, null, task, result);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    for (AssignmentType assignment : user.asObjectable().getAssignment()) {
        ObjectReferenceType targetRef = assignment.getTargetRef();
        if (targetRef != null) {
            if (targetRef.getType().equals(RoleType.COMPLEX_TYPE)) {
                ContainerDelta<AssignmentType> assignmentDelta = prismContext.deltaFactory().container().createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
                PrismContainerValue<AssignmentType> cval = prismContext.itemFactory().createContainerValue();
                cval.setId(assignment.getId());
                assignmentDelta.addValueToDelete(cval);
                modifications.add(assignmentDelta);
            }
        }
    }
    if (modifications.isEmpty()) {
        return;
    }
    ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createModifyDelta(userOid, modifications, UserType.class);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    modelService.executeChanges(deltas, useRawPlusRecompute ? executeOptions().raw() : null, task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    if (useRawPlusRecompute) {
        recomputeUser(userOid, task, result);
        result.computeStatus();
        TestUtil.assertSuccess(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)

Example 53 with AssignmentType

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

the class ResourceTypeAssignmentPopupTabPanel method getSelectedAssignmentsMap.

@Override
protected Map<String, AssignmentType> getSelectedAssignmentsMap() {
    Map<String, AssignmentType> assignmentList = new HashMap<>();
    List<ResourceType> selectedObjects = getSelectedObjectsList();
    ShadowKindType kind = getKindValue();
    String intent = getIntentValue();
    selectedObjects.forEach(selectedObject -> {
        AssignmentType newConstructionAssignment = ObjectTypeUtil.createAssignmentWithConstruction(selectedObject.asPrismObject(), kind, intent, getPageBase().getPrismContext());
        if (isEntitlementAssignment()) {
            NameItemPathSegment segment = getAssociationValue() != null ? new NameItemPathSegment(getAssociationValue().getName()) : null;
            if (segment != null) {
                ResourceObjectAssociationType association = new ResourceObjectAssociationType();
                association.setRef(new ItemPathType(ItemPath.create(segment)));
                newConstructionAssignment.getConstruction().getAssociation().add(association);
            }
        }
        assignmentList.put(selectedObject.getOid(), newConstructionAssignment);
    });
    return assignmentList;
}
Also used : HashMap(java.util.HashMap) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ResourceObjectAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectAssociationType)

Example 54 with AssignmentType

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

the class AssignmentHolderTypeAssignmentsTabPanel method initLayout.

private void initLayout() {
    WebMarkupContainer assignments = new WebMarkupContainer(ID_ASSIGNMENTS);
    assignments.setOutputMarkupId(true);
    add(assignments);
    PrismContainerWrapperModel<AHT, AssignmentType> model = PrismContainerWrapperModel.fromContainerWrapper(getObjectWrapperModel(), AssignmentHolderType.F_ASSIGNMENT);
    SwitchAssignmentTypePanel panel = createPanel(ID_ASSIGNMENTS_PANEL, model);
    assignments.add(panel);
}
Also used : AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) SwitchAssignmentTypePanel(com.evolveum.midpoint.web.component.assignment.SwitchAssignmentTypePanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 55 with AssignmentType

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

the class TestSoD method test020AssignRolePirate.

/**
 * Assign Pirate to jack. This should trigger an approval.
 */
@Test
public void test020AssignRolePirate() throws Exception {
    given();
    login(userAdministrator);
    OperationResult result = getTestOperationResult();
    PrismObject<UserType> jack = getUser(userJackOid);
    String originalDescription = jack.asObjectable().getDescription();
    ObjectDelta<UserType> addPirateDelta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(rolePirateOid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
    ObjectDelta<UserType> changeDescriptionDelta = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace("Pirate Judge").asObjectDelta(userJackOid);
    ObjectDelta<UserType> primaryDelta = ObjectDeltaCollectionsUtil.summarize(addPirateDelta, changeDescriptionDelta);
    when();
    executeTest2(new TestDetails2<UserType>() {

        @Override
        protected PrismObject<UserType> getFocus(OperationResult result) {
            return jack.clone();
        }

        @Override
        protected ObjectDelta<UserType> getFocusDelta() {
            return primaryDelta.clone();
        }

        @Override
        protected int getNumberOfDeltasToApprove() {
            return 1;
        }

        @Override
        protected List<Boolean> getApprovals() {
            return Collections.singletonList(true);
        }

        @Override
        protected List<ObjectDelta<UserType>> getExpectedDeltasToApprove() {
            return Collections.singletonList(addPirateDelta.clone());
        }

        @Override
        protected ObjectDelta<UserType> getExpectedDelta0() {
            return changeDescriptionDelta.clone();
        }

        @Override
        protected String getObjectOid() {
            return jack.getOid();
        }

        @Override
        protected List<ExpectedTask> getExpectedTasks() {
            return Collections.singletonList(new ExpectedTask(rolePirateOid, "Role \"Pirate\" excludes role \"Judge\""));
        }

        @Override
        protected List<ExpectedWorkItem> getExpectedWorkItems() {
            List<ExpectedTask> etasks = getExpectedTasks();
            return Collections.singletonList(new ExpectedWorkItem(userSodApproverOid, rolePirateOid, etasks.get(0)));
        }

        @Override
        protected void assertDeltaExecuted(int number, boolean yes, Task opTask, OperationResult result) throws Exception {
            switch(number) {
                case 0:
                    if (yes) {
                        assertUserProperty(userJackOid, UserType.F_DESCRIPTION, "Pirate Judge");
                    } else {
                        if (originalDescription != null) {
                            assertUserProperty(userJackOid, UserType.F_DESCRIPTION, originalDescription);
                        } else {
                            assertUserNoProperty(userJackOid, UserType.F_DESCRIPTION);
                        }
                    }
                    break;
                case 1:
                    if (yes) {
                        assertAssignedRole(userJackOid, rolePirateOid, result);
                    } else {
                        assertNotAssignedRole(userJackOid, rolePirateOid, result);
                    }
                    break;
            }
        }

        @Override
        protected Boolean decideOnApproval(CaseWorkItemType caseWorkItem) throws Exception {
            login(getUser(userSodApproverOid));
            return true;
        }
    }, 1, false);
    then();
    display("jack as a Pirate + Judge", getUser(userJackOid));
    AssignmentType judgeAssignment = assertAssignedRole(userJackOid, roleJudgeOid, result);
    assertExclusionViolationSituation(judgeAssignment);
    AssignmentType pirateAssignment = assertAssignedRole(userJackOid, rolePirateOid, result);
    assertExclusionViolationSituation(pirateAssignment);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) CaseWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType) PrismObject(com.evolveum.midpoint.prism.PrismObject) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) List(java.util.List) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Aggregations

AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)121 Test (org.testng.annotations.Test)61 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)55 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)42 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)41 Task (com.evolveum.midpoint.task.api.Task)39 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)33 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)25 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)24 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)21 QName (javax.xml.namespace.QName)20 PrismObject (com.evolveum.midpoint.prism.PrismObject)19 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)17 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)17 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)17 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)17 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)17 ArrayList (java.util.ArrayList)17 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)15 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)14