use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class TestPlentyOfAssignments method addAssignments.
private void addAssignments(PrismObject<UserType> user, QName relation, int offset, int num) {
UserType userType = user.asObjectable();
for (int i = 0; i < num; i++) {
AssignmentType assignmentType = new AssignmentType();
String oid = generateRoleOid(offset + i);
assignmentType.targetRef(oid, RoleType.COMPLEX_TYPE, relation);
userType.getAssignment().add(assignmentType);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class ModifyAssignmentTest method test30DeleteAssignment.
@Test
public void test30DeleteAssignment() throws Exception {
//given
//when
// ObjectModificationType modification = prismContext.getPrismJaxbProcessor().unmarshalObject(
// new File(TEST_DIR, "modify-delete-assignment.xml"), ObjectModificationType.class);
//
// ObjectDelta delta = DeltaConvertor.createObjectDelta(modification, RoleType.class, prismContext);
AssignmentType a = new AssignmentType();
a.setId(4L);
ObjectDelta<RoleType> delta = ObjectDelta.createModificationDeleteContainer(RoleType.class, "00000000-8888-6666-0000-100000000005", RoleType.F_ASSIGNMENT, prismContext, a);
OperationResult result = new OperationResult("delete assignment");
repositoryService.modifyObject(RoleType.class, delta.getOid(), delta.getModifications(), result);
result.recomputeStatus();
result.recordSuccessIfUnknown();
//then
AssertJUnit.assertTrue(result.isSuccess());
result = new OperationResult("get role");
PrismObject repoRole = repositoryService.getObject(RoleType.class, ROLE_OID, null, result);
result.recomputeStatus();
result.recordSuccessIfUnknown();
AssertJUnit.assertTrue(result.isSuccess());
PrismContainer inducement = repoRole.findContainer(new ItemPath(RoleType.F_INDUCEMENT));
AssertJUnit.assertNotNull(inducement);
AssertJUnit.assertEquals(3, inducement.getValues().size());
PrismContainer assignment = repoRole.findContainer(new ItemPath(AbstractRoleType.F_ASSIGNMENT));
AssertJUnit.assertNotNull(assignment);
AssertJUnit.assertEquals(1, assignment.getValues().size());
AssertJUnit.assertNotNull(assignment.getValue(1L));
Session session = open();
try {
Query query = session.createSQLQuery("select count(*) from m_assignment where owner_oid=:oid and id=:id");
query.setParameter("oid", delta.getOid());
query.setParameter("id", 4);
Number number = (Number) query.uniqueResult();
AssertJUnit.assertEquals(0, number.intValue());
} finally {
close(session);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class AbstractTestForExchangeConnector method createRoleAssignment.
protected AssignmentType createRoleAssignment(String roleOid) {
AssignmentType roleAssignment = new AssignmentType();
ObjectReferenceType roleRef = new ObjectReferenceType();
roleRef.setOid(roleOid);
roleRef.setType(ModelClientUtil.getTypeQName(RoleType.class));
roleAssignment.setTargetRef(roleRef);
return roleAssignment;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class ConsistencyTest method test511AssignAccountMorgan.
/**
* assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
* account should be linked to the user.
* @throws Exception
*/
@Test
public void test511AssignAccountMorgan() throws Exception {
final String TEST_NAME = "test511AssignAccountMorgan";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
openDJController.assumeRunning();
Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
//prepare new OU in opendj
Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
display("User Morgan: ", user);
PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
ExpressionType expression = new ExpressionType();
ObjectFactory of = new ObjectFactory();
RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), prismContext);
JAXBElement val = of.createValue(raw);
expression.getExpressionEvaluator().add(val);
MappingType mapping = new MappingType();
mapping.setExpression(expression);
ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
attrDefType.setRef(new ItemPathType(new ItemPath(getOpenDjSecondaryIdentifierQName())));
attrDefType.setOutbound(mapping);
ConstructionType construction = new ConstructionType();
construction.getAttribute().add(attrDefType);
construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
AssignmentType assignment = new AssignmentType();
assignment.setConstruction(construction);
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
// assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
display("User morgan after", userMorgan);
UserType userMorganType = userMorgan.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class AbstractLdapHierarchyTest method createUser.
private PrismObject<UserType> createUser(String username, String givenName, String familyName, String parentOrgOid) throws SchemaException {
PrismObject<UserType> user = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).instantiate();
UserType userType = user.asObjectable();
userType.setName(new PolyStringType(username));
userType.setGivenName(new PolyStringType(givenName));
userType.setFamilyName(new PolyStringType(familyName));
userType.setFullName(new PolyStringType(givenName + " " + familyName));
if (parentOrgOid != null) {
AssignmentType parentAssignment = new AssignmentType();
ObjectReferenceType parentAssignmentTargetRef = new ObjectReferenceType();
parentAssignmentTargetRef.setOid(parentOrgOid);
parentAssignmentTargetRef.setType(OrgType.COMPLEX_TYPE);
parentAssignment.setTargetRef(parentAssignmentTargetRef);
userType.getAssignment().add(parentAssignment);
}
return user;
}
Aggregations