use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method addTriggers.
protected void addTriggers(String oid, Collection<XMLGregorianCalendar> timestamps, String uri, boolean makeDistinct) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
Task task = createPlainTask("addTriggers");
OperationResult result = task.getResult();
Collection<TriggerType> triggers = timestamps.stream().map(ts -> new TriggerType().timestamp(ts).handlerUri(uri)).map(ts -> makeDistinct ? addRandomValue(ts) : ts).collect(Collectors.toList());
ObjectDelta<ObjectType> delta = prismContext.deltaFor(ObjectType.class).item(ObjectType.F_TRIGGER).addRealValues(triggers).asObjectDeltaCast(oid);
executeChanges(delta, null, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException 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.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test332ModifiedCertificationCaseStoresIt.
@Test
public void test332ModifiedCertificationCaseStoresIt() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
OperationResult result = createOperationResult();
MAccessCertificationCampaign originalRow = selectObjectByOid(QAccessCertificationCampaign.class, accessCertificationCampaign1Oid);
given("delta adding case for campaign 1");
ObjectDelta<AccessCertificationCampaignType> delta = prismContext.deltaFor(AccessCertificationCampaignType.class).item(ItemPath.create(AccessCertificationCampaignType.F_CASE, CAMPAIGN_1_CASE_2_ID, AccessCertificationCaseType.F_OUTCOME)).replace("People are the problem").asObjectDelta(accessCertificationCampaign1Oid);
when("modifyObject is called");
repositoryService.modifyObject(AccessCertificationCampaignType.class, accessCertificationCampaign1Oid, delta.getModifications(), result);
then("operation is successful");
assertThatOperationResult(result).isSuccess();
and("serialized form (fullObject) is updated");
AccessCertificationCampaignType campaignObjectAfter = repositoryService.getObject(AccessCertificationCampaignType.class, accessCertificationCampaign1Oid, retrieveWithCases(), result).asObjectable();
assertThat(campaignObjectAfter.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
List<AccessCertificationCaseType> casesAfter = campaignObjectAfter.getCase();
assertThat(casesAfter).isNotNull();
assertThat(casesAfter.get(1).getId()).isEqualTo(CAMPAIGN_1_CASE_2_ID);
and("campaign row is created");
MAccessCertificationCampaign row = selectObjectByOid(QAccessCertificationCampaign.class, accessCertificationCampaign1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
and("case row is created");
QAccessCertificationCase a = QAccessCertificationCaseMapping.getAccessCertificationCaseMapping().defaultAlias();
List<MAccessCertificationCase> caseRows = select(a, a.ownerOid.eq(UUID.fromString(accessCertificationCampaign1Oid)));
assertThat(caseRows).hasSize(2);
caseRows.sort(comparing(tr -> tr.cid));
MAccessCertificationCase aRow = caseRows.get(1);
assertThat(aRow.cid).isEqualTo(CAMPAIGN_1_CASE_2_ID);
assertThat(aRow.containerType).isEqualTo(MContainerType.ACCESS_CERTIFICATION_CASE);
assertThat(aRow.targetRefTargetOid).isNull();
assertThat(aRow.objectRefTargetOid).isEqualTo(accCertCampaign1Case2ObjectOid);
assertThat(aRow.objectRefTargetType).isEqualTo(MObjectType.USER);
assertCachedUri(aRow.objectRefRelationId, relationRegistry.getDefaultRelation());
assertThat(aRow.outcome).isEqualTo("People are the problem");
assertThat(aRow.stageNumber).isEqualTo(5);
assertThat(aRow.campaignIteration).isEqualTo(7);
// Check that case (container) fullObject was updated, as opposed to campaign (object) fullObject
PrismContainerValue<AccessCertificationCaseType> fullObjectCval = prismContext.parserFor(new String(aRow.fullObject, StandardCharsets.UTF_8)).parseItemValue();
// Unchanged
assertThat(fullObjectCval.asContainerable().getStageNumber()).isEqualTo(5);
assertThat(fullObjectCval.asContainerable().getIteration()).isEqualTo(7);
// Changed
assertThat(fullObjectCval.asContainerable().getOutcome()).isEqualTo("People are the problem");
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class RoleMemberListRepoTest method fillDatabase.
@Test
public void fillDatabase() throws SchemaException, ObjectAlreadyExistsException {
OperationResult operationResult = createOperationResult();
for (int roleIndex = ROLE_MIN; roleIndex <= ROLE_MAX; roleIndex++) {
String name = String.format("role-%05d", roleIndex);
RoleType role = new RoleType(prismContext).name(PolyStringType.fromOrig(name));
try {
repositoryService.addObject(role.asPrismObject(), null, operationResult);
roleOids.add(role.getOid());
System.out.println("Created role " + name);
} catch (ObjectAlreadyExistsException e) {
// never mind, we'll use the existing one
QRole r = aliasFor(QRole.class);
MRole existingRow = selectOne(r, r.nameOrig.eq(name));
roleOids.add(existingRow.oid.toString());
System.out.println("Reused existing role " + name);
}
}
for (int userIndex = USER_MIN; userIndex <= USER_MAX; userIndex++) {
String name = String.format("user-%07d", userIndex);
UserType user = new UserType(prismContext).name(PolyStringType.fromOrig(name));
addRoles(user);
try {
repositoryService.addObject(user.asPrismObject(), null, operationResult);
System.out.println("Created user " + name + " with " + user.getRoleMembershipRef().size() + " roles");
} catch (ObjectAlreadyExistsException e) {
System.out.println("User " + name + " already exists");
}
}
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class OrgClosureConcurrencyTest method _test300AddRemoveNodesMT.
protected void _test300AddRemoveNodesMT(final boolean random) throws Exception {
OperationResult opResult = new OperationResult("===[ test300AddRemoveNodesMT ]===");
info("test300AddRemoveNodes starting with random = " + random);
final Set<ObjectType> nodesToRemove = Collections.synchronizedSet(new HashSet<>());
final Set<ObjectType> nodesToAdd = Collections.synchronizedSet(new HashSet<>());
final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<>());
for (int level = 0; level < getConfiguration().getNodeRoundsForLevel().length; level++) {
int rounds = getConfiguration().getNodeRoundsForLevel()[level];
List<String> levelOids = orgsByLevels.get(level);
generateNodesAtOneLevel(nodesToRemove, nodesToAdd, OrgType.class, rounds, levelOids, opResult);
}
int numberOfRunners = THREADS;
final List<Thread> runners = Collections.synchronizedList(new ArrayList<>());
for (int i = 0; i < numberOfRunners; i++) {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
while (true) {
ObjectType objectType = getNext(nodesToRemove, random);
if (objectType == null) {
break;
}
logger.info("Removing {}", objectType);
int remaining;
try {
removeObject(objectType);
synchronized (OrgClosureConcurrencyTest.this) {
nodesToRemove.remove(objectType);
remaining = nodesToRemove.size();
}
info(Thread.currentThread().getName() + " removed " + objectType + "; remaining: " + remaining);
} catch (ObjectNotFoundException e) {
// this is OK
info(Thread.currentThread().getName() + ": " + objectType + " already deleted");
// give other threads a chance
Thread.sleep(300);
}
}
} catch (Throwable e) {
e.printStackTrace();
exceptions.add(e);
} finally {
runners.remove(Thread.currentThread());
}
}
};
Thread t = new Thread(runnable);
runners.add(t);
t.start();
}
waitForRunnersCompletion(runners);
if (!nodesToRemove.isEmpty()) {
throw new AssertionError("Nodes to remove is not empty, see the console or log: " + nodesToRemove);
}
if (!exceptions.isEmpty()) {
throw new AssertionError("Found exceptions: " + exceptions);
}
rebuildGraph();
checkClosure(orgGraph.vertexSet());
info("Consistency after removing OK");
numberOfRunners = THREADS;
for (int i = 0; i < numberOfRunners; i++) {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
while (true) {
ObjectType objectType = getNext(nodesToAdd, random);
if (objectType == null) {
break;
}
logger.info("Adding {}", objectType);
try {
addObject(objectType.clone());
// rebuildGraph();
// checkClosure(orgGraph.vertexSet());
int remaining;
synchronized (OrgClosureConcurrencyTest.this) {
nodesToAdd.remove(objectType);
remaining = nodesToAdd.size();
}
info(Thread.currentThread().getName() + " re-added " + objectType + "; remaining: " + remaining);
} catch (ObjectAlreadyExistsException e) {
// this is OK
info(Thread.currentThread().getName() + ": " + objectType + " already exists");
// give other threads a chance
Thread.sleep(300);
}
}
} catch (Throwable e) {
e.printStackTrace();
exceptions.add(e);
} finally {
runners.remove(Thread.currentThread());
}
}
};
Thread t = new Thread(runnable);
runners.add(t);
t.start();
}
waitForRunnersCompletion(runners);
if (!nodesToAdd.isEmpty()) {
throw new AssertionError("Nodes to add is not empty, see the console or log: " + nodesToAdd);
}
if (!exceptions.isEmpty()) {
throw new AssertionError("Found exceptions: " + exceptions);
}
rebuildGraph();
checkClosure(orgGraph.vertexSet());
info("Consistency after re-adding OK");
}
Aggregations