use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test315ReplaceAssignmentWithCid.
@Test
public void test315ReplaceAssignmentWithCid() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("object with existing container values");
List<AssignmentType> assignments = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable().getAssignment().stream().map(ass -> // we need to get it out of original parent
ass.clone().lifecycleState(// some change
String.valueOf(ass.getId()))).collect(Collectors.toList());
and("delta replacing the values with the same values again (with CIDs already)");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).replace(assignments.stream().map(ass -> ass.asPrismContainerValue()).collect(Collectors.toList())).asObjectDelta(user1Oid);
when("modifyObject is called");
repositoryService.modifyObject(UserType.class, user1Oid, delta.getModifications(), result);
then("operation is successful");
assertThatOperationResult(result).isSuccess();
and("serialized form (fullObject) is updated");
UserType userObject = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(userObject.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
List<AssignmentType> newAssignments = userObject.getAssignment();
assertThat(newAssignments).hasSize(assignments.size());
and("new assignment rows replace the old ones");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
// no need for change
assertThat(row.containerIdSeq).isEqualTo(originalRow.containerIdSeq);
QAssignment<?> a = QAssignmentMapping.getAssignmentMapping().defaultAlias();
List<MAssignment> aRows = select(a, a.ownerOid.eq(UUID.fromString(user1Oid)));
assertThat(aRows).hasSize(assignments.size()).allMatch(aRow -> String.valueOf(aRow.cid).equals(aRow.lifecycleState));
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class SqaleRepoAddDeleteObjectTest method test821ArchetypeAndInducement.
// This covers mapping of attributes in AbstractRole + Archetype + inducement mapping.
// There is no focus on QFocusMapping that is covered above.
@Test
public void test821ArchetypeAndInducement() throws Exception {
OperationResult result = createOperationResult();
given("archetype object");
String objectName = "arch" + getTestNumber();
ArchetypeType archetype = new ArchetypeType(prismContext).name(objectName).autoassign(new AutoassignSpecificationType().enabled(true)).displayName("display-name").identifier("identifier").requestable(false).riskLevel("extremely-high").inducement(new AssignmentType(prismContext).order(2).targetRef(UUID.randomUUID().toString(), RoleType.COMPLEX_TYPE)).inducement(new AssignmentType(prismContext).order(3).targetRef(UUID.randomUUID().toString(), RoleType.COMPLEX_TYPE));
// this is no additional attribute specific for archetype
when("adding it to the repository");
repositoryService.addObject(archetype.asPrismObject(), null, result);
then("it is stored and relevant attributes are in columns");
assertThatOperationResult(result).isSuccess();
UUID archetypeOid = UUID.fromString(archetype.getOid());
MArchetype row = selectObjectByOid(QArchetype.class, archetypeOid);
// all attributes from MAbstractRole
assertThat(row.autoAssignEnabled).isTrue();
assertThat(row.displayNameOrig).isEqualTo("display-name");
assertThat(row.displayNameNorm).isEqualTo("displayname");
assertThat(row.identifier).isEqualTo("identifier");
assertThat(row.requestable).isFalse();
assertThat(row.riskLevel).isEqualTo("extremely-high");
QAssignment<?> a = QAssignmentMapping.getAssignmentMapping().defaultAlias();
assertThat(select(a, a.ownerOid.eq(archetypeOid))).hasSize(2).anyMatch(ar -> ar.orderValue.equals(2)).anyMatch(ar -> ar.orderValue.equals(3)).allMatch(ar -> ar.targetRefTargetOid != null && ar.targetRefTargetType == MObjectType.ROLE);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test185AddingAssignmentWithPolicySituations.
// this section tests two things: array in container, and integer[] requiring conversion (URIs)
@Test
public void test185AddingAssignmentWithPolicySituations() throws Exception {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
// Container tests are in 3xx category, but let's focus on policy situations.
given("delta adding assignment with policy situations");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(new AssignmentType(prismContext).policySituation("policy-situation-1").policySituation("policy-situation-2")).asObjectDelta(user1Oid);
when("modifyObject is called");
repositoryService.modifyObject(UserType.class, user1Oid, delta.getModifications(), result);
then("operation is successful");
assertThatOperationResult(result).isSuccess();
and("serialized form (fullObject) is updated");
UserType userObject = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(userObject.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
assertThat(userObject.getAssignment().get(0).getPolicySituation()).containsExactlyInAnyOrder("policy-situation-1", "policy-situation-2");
and("policySituation column is set in the assignment row");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
QAssignment<?> a = QAssignmentMapping.getAssignmentMapping().defaultAlias();
MAssignment aRow = selectOne(a, a.ownerOid.eq(UUID.fromString(user1Oid)));
assertThat(aRow.policySituations).extracting(uriId -> cachedUriById(uriId)).containsExactlyInAnyOrder("policy-situation-1", "policy-situation-2");
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class TestConsistencyMechanism 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.
*/
@Test
public void test511AssignAccountMorgan() throws Exception {
// GIVEN
openDJController.assumeRunning();
Task task = getTestTask();
OperationResult result = task.getResult();
dummyAuditService.clear();
// prepare new OU in opendj
openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILE);
PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
display("User Morgan: ", user);
ExpressionType expression = new ExpressionType();
ObjectFactory of = new ObjectFactory();
RawType raw = new RawType(prismContext.xnodeFactory().primitive("uid=morgan,ou=users,dc=example,dc=com").frozen(), 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(ItemPath.create(getOpenDjSecondaryIdentifierQName())));
attrDefType.setOutbound(mapping);
ConstructionType construction = new ConstructionType();
construction.getAttribute().add(attrDefType);
construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo, prismContext));
AssignmentType assignment = new AssignmentType();
assignment.setConstruction(construction);
// noinspection unchecked
ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, assignment.asPrismContainerValue());
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
when();
modelService.executeChanges(deltas, null, task, result);
// THEN
then();
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);
provisioningService.applyDefinition(accountShadow, task, result);
assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=users,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=users,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
ResourceAttribute<?> attributes = ShadowUtil.getAttribute(accountModel, new QName(MidPointConstants.NS_RI, "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 RAbstractRole method copyFromJAXB.
// dynamically called
public static void copyFromJAXB(AbstractRoleType jaxb, RAbstractRole repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
copyFocusInformationFromJAXB(jaxb, repo, repositoryContext, generatorResult);
repo.setRequestable(jaxb.isRequestable());
repo.setDisplayName(RPolyString.copyFromJAXB(jaxb.getDisplayName()));
repo.setIdentifier(jaxb.getIdentifier());
repo.setRiskLevel(jaxb.getRiskLevel());
if (jaxb.getAutoassign() != null) {
RAutoassignSpecification aa = new RAutoassignSpecification();
RAutoassignSpecification.formJaxb(jaxb.getAutoassign(), aa);
repo.setAutoassign(aa);
}
for (AssignmentType inducement : jaxb.getInducement()) {
RAssignment rInducement = new RAssignment(repo, RAssignmentOwner.ABSTRACT_ROLE);
RAssignment.fromJaxb(inducement, rInducement, jaxb, repositoryContext, generatorResult);
repo.getAssignments().add(rInducement);
}
}
Aggregations