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 = taskManager.createTaskInstance(AbstractModelIntegrationTest.class + ".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 = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
PrismContainerValue<AssignmentType> cval = new PrismContainerValue<>(prismContext);
cval.setId(assignment.getId());
assignmentDelta.addValueToDelete(cval);
modifications.add(assignmentDelta);
}
}
}
if (modifications.isEmpty()) {
return;
}
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
modelService.executeChanges(deltas, useRawPlusRecompute ? ModelExecuteOptions.createRaw() : null, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
if (useRawPlusRecompute) {
recomputeUser(userOid, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method createAssignmentModification.
protected ContainerDelta<AssignmentType> createAssignmentModification(String roleOid, QName refType, QName relation, Consumer<AssignmentType> modificationBlock, boolean add) throws SchemaException {
ContainerDelta<AssignmentType> assignmentDelta = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
PrismContainerValue<AssignmentType> cval = new PrismContainerValue<AssignmentType>(prismContext);
if (add) {
assignmentDelta.addValueToAdd(cval);
} else {
assignmentDelta.addValueToDelete(cval);
}
PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF);
targetRef.getValue().setOid(roleOid);
targetRef.getValue().setTargetType(refType);
targetRef.getValue().setRelation(relation);
if (modificationBlock != null) {
modificationBlock.accept(cval.asContainerable());
}
return assignmentDelta;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType 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;
}
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()) && ObjectTypeUtil.relationMatches(relation, targetRef.getRelation())) {
return assignment;
}
}
return null;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method modifyRoleDeleteInducement.
protected void modifyRoleDeleteInducement(String roleOid, long inducementId, boolean reconcileAffected, Task task) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
if (task == null) {
task = createTask(AbstractModelIntegrationTest.class.getName() + ".modifyRoleDeleteInducement");
}
OperationResult result = task.getResult();
AssignmentType inducement = new AssignmentType();
inducement.setId(inducementId);
ObjectDelta<RoleType> roleDelta = ObjectDelta.createModificationDeleteContainer(RoleType.class, roleOid, RoleType.F_INDUCEMENT, prismContext, inducement);
ModelExecuteOptions options = new ModelExecuteOptions();
options.setReconcileAffected(reconcileAffected);
modelService.executeChanges(MiscSchemaUtil.createCollection(roleDelta), options, task, result);
result.computeStatus();
if (reconcileAffected) {
TestUtil.assertInProgressOrSuccess(result);
} else {
TestUtil.assertSuccess(result);
}
}
Aggregations