use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ReconciliationLauncher method launch.
/**
* Launch an import. Calling this method will start import in a new
* thread, possibly on a different node.
*/
public void launch(ResourceType resource, QName objectclass, Task task, OperationResult parentResult) {
LOGGER.info("Launching reconciliation for resource {} as asynchronous task", ObjectTypeUtil.toShortString(resource));
OperationResult result = parentResult.createSubresult(ReconciliationLauncher.class.getName() + ".launch");
result.addParam("resource", resource);
result.addParam("objectclass", objectclass);
// Set handler URI so we will be called back
task.setHandlerUri(ModelPublicConstants.RECONCILIATION_TASK_HANDLER_URI);
PolyStringType polyString = new PolyStringType("Reconciling " + resource.getName());
task.setName(polyString);
ObjectReferenceType resourceRef = ObjectTypeUtil.createObjectRef(resource, prismContext);
// Not strictly necessary but nice to do (activity would fill-in these when started)
task.setObjectRef(resourceRef.clone());
task.addArchetypeInformationIfMissing(SystemObjectsType.ARCHETYPE_RECONCILIATION_TASK.value());
try {
// @formatter:off
task.setRootActivityDefinition(new ActivityDefinitionType(PrismContext.get()).beginWork().beginReconciliation().beginResourceObjects().resourceRef(resourceRef.clone()).objectclass(objectclass).<ReconciliationWorkDefinitionType>end().<WorkDefinitionsType>end().end());
// @formatter:on
// just to be sure (if the task was already persistent)
task.flushPendingModifications(result);
} catch (ObjectNotFoundException e) {
LOGGER.error("Task object not found, expecting it to exist (task {})", task, e);
result.recordFatalError("Task object not found", e);
throw new IllegalStateException("Task object not found, expecting it to exist", e);
} catch (ObjectAlreadyExistsException e) {
LOGGER.error("Task object wasn't updated (task {})", task, e);
result.recordFatalError("Task object wasn't updated", e);
throw new IllegalStateException("Task object wasn't updated", e);
} catch (SchemaException e) {
LOGGER.error("Error dealing with schema (task {})", task, e);
result.recordFatalError("Error dealing with schema", e);
throw new IllegalStateException("Error dealing with schema", e);
}
task.addArchetypeInformationIfMissing(SystemObjectsType.ARCHETYPE_RECONCILIATION_TASK.value());
// Switch task to background. This will start new thread and call
// the run(task) method.
// Note: the thread may be actually started on a different node
taskManager.switchToBackground(task, result);
result.setBackgroundTaskOid(task.getOid());
result.computeStatus("Reconciliation launch failed");
LOGGER.trace("Reconciliation for resource {} switched to background, control thread returning with task {}", ObjectTypeUtil.toShortString(resource), task);
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class AbstractInternalModelIntegrationTest method initSystem.
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
logger.trace("initSystem");
super.initSystem(initTask, initResult);
// We want logging config from logback-test.xml and not from system config object (unless suppressed)
InternalsConfig.setAvoidLoggingChange(isAvoidLoggingChange());
mockClockworkHook = new MockClockworkHook();
hookRegistry.registerChangeHook(MOCK_CLOCKWORK_HOOK_URL, mockClockworkHook);
modelService.postInit(initResult);
// System Configuration
try {
repoAddObjectFromFile(SYSTEM_CONFIGURATION_FILE, initResult);
} catch (ObjectAlreadyExistsException e) {
throw new ObjectAlreadyExistsException("System configuration already exists in repository;" + "looks like the previous test haven't cleaned it up", e);
}
repoAddObjectFromFile(SECURITY_POLICY_FILE, initResult);
// Administrator
repoAddObjectFromFile(ROLE_SUPERUSER_FILE, initResult);
userAdministrator = repoAddObjectFromFile(USER_ADMINISTRATOR_FILE, initResult);
login(userAdministrator);
// User Templates
repoAddObjectFromFile(USER_TEMPLATE_FILE, initResult);
// Resources
initDummyResourcePirate(null, RESOURCE_DUMMY_FILE, RESOURCE_DUMMY_OID, initTask, initResult);
// We need to create Barbossa's account in exactly the shape that is given by his existing assignments
// otherwise any substantial change will trigger reconciliation and the recon changes will interfere with
// the tests
DummyAccount account = new DummyAccount(ACCOUNT_HBARBOSSA_DUMMY_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Hector Barbossa");
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Caribbean");
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Pirate Brethren, Inc.");
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "Undead Monkey");
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "rum");
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME, "Arr!");
getDummyResource().addAccount(account);
getDummyResourceController().addAccount(ACCOUNT_HERMAN_DUMMY_USERNAME, "Herman Toothrot", "Monkey Island");
getDummyResourceController().addAccount(ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", "Melee Island");
// Accounts
repoAddObjectFromFile(ACCOUNT_HBARBOSSA_DUMMY_FILE, initResult);
repoAddObjectFromFile(ACCOUNT_SHADOW_GUYBRUSH_DUMMY_FILE, initResult);
repoAddObjectFromFile(ACCOUNT_SHADOW_ELAINE_DUMMY_FILE, initResult);
// Users
userTypeJack = repoAddObjectFromFile(USER_JACK_FILE, UserType.class, initResult).asObjectable();
userTypeBarbossa = repoAddObjectFromFile(USER_BARBOSSA_FILE, UserType.class, initResult).asObjectable();
userTypeGuybrush = repoAddObjectFromFile(USER_GUYBRUSH_FILE, UserType.class, initResult).asObjectable();
userTypeElaine = repoAddObjectFromFile(USER_ELAINE_FILE, UserType.class, initResult).asObjectable();
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class TestAssignmentErrors method test222UserAssignAccountDeletedShadowRecomputeNoSync.
/**
* Assign account to user, delete the account shadow (not the account), recompute the user.
* We expect an error.
* <p>
* This is tried on the red dummy resource where there is no synchronization.
*/
// TODO: after fixing uniqueness check in ProjectionValueProcessor, change the test little bit
// see git commit: 7052f9628a76815d27a119090a97ec57fbdebaec
@Test
public void test222UserAssignAccountDeletedShadowRecomputeNoSync() throws Exception {
// GIVEN
PrismObject<UserType> user = setupUserAssignAccountDeletedShadowRecompute(RESOURCE_DUMMY_RED_OID, RESOURCE_DUMMY_RED_NAME, USER_BFET_NAME, USER_BFET_FULLNAME);
Task task = createPlainTask();
OperationResult result = task.getResult();
try {
// WHEN
recomputeUser(user.getOid(), task, result);
AssertJUnit.fail("Unexpected success");
} catch (ObjectAlreadyExistsException e) {
// this is expected
result.computeStatus();
TestUtil.assertFailure(result);
}
user = getUser(user.getOid());
display("User after", user);
assertNoLinkedAccount(user);
// and again ...
task = createPlainTask();
result = task.getResult();
try {
// WHEN
recomputeUser(user.getOid(), task, result);
AssertJUnit.fail("Unexpected success");
} catch (ObjectAlreadyExistsException e) {
// this is expected
result.computeStatus();
TestUtil.assertFailure(result);
}
user = getUser(user.getOid());
display("User after", user);
assertNoLinkedAccount(user);
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class CertHelper method appendStatistics.
public void appendStatistics(StringBuilder sb, AccessCertificationCampaignType campaign, Task task, OperationResult result) {
AccessCertificationCasesStatisticsType stat;
try {
stat = certificationManager.getCampaignStatistics(campaign.getOid(), false, task, result);
} catch (ObjectNotFoundException | SchemaException | SecurityViolationException | ObjectAlreadyExistsException | ExpressionEvaluationException | RuntimeException | CommunicationException | ConfigurationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get campaign statistics", e);
sb.append("Couldn't get campaign statistics because of ").append(e);
return;
}
int all = stat.getMarkedAsAccept() + stat.getMarkedAsRevoke() + stat.getMarkedAsReduce() + stat.getMarkedAsNotDecide() + stat.getWithoutResponse();
sb.append("Number of cases:\t").append(all);
sb.append("\nMarked as ACCEPT:\t").append(stat.getMarkedAsAccept());
sb.append("\nMarked as REVOKE:\t").append(stat.getMarkedAsRevoke()).append(" (remedied: ").append(stat.getMarkedAsRevokeAndRemedied()).append(")");
sb.append("\nMarked as REDUCE:\t").append(stat.getMarkedAsReduce()).append(" (remedied: ").append(stat.getMarkedAsReduceAndRemedied()).append(")");
sb.append("\nMarked as NOT DECIDED:\t").append(stat.getMarkedAsNotDecide());
sb.append("\nNo response:\t\t").append(stat.getWithoutResponse());
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ShadowIntegrityCheckActivityRun method deleteShadows.
// shadowsToDelete do not contain 'already deleted shadows'
private void deleteShadows(DuplicateShadowsTreatmentInstruction instruction, StringBuilder sb, Task task, OperationResult result) {
ShadowCheckConfiguration cfg = getConfiguration();
LOGGER.trace("Going to delete shadows:\n{}", instruction);
if (instruction == null || instruction.getShadowsToDelete() == null) {
return;
}
Collection<PrismObject<ShadowType>> shadowsToDelete = instruction.getShadowsToDelete();
String shadowOidToReplaceDeleted = instruction.getShadowOidToReplaceDeletedOnes();
for (PrismObject<ShadowType> shadowToDelete : shadowsToDelete) {
LOGGER.info("Deleting redundant shadow{} {}", skippedForDryRun(), ObjectTypeUtil.toShortString(shadowToDelete));
sb.append(" --> deleted redundant shadow").append(skippedForDryRun()).append(" ").append(ObjectTypeUtil.toShortString(shadowToDelete)).append("\n");
String oid = shadowToDelete.getOid();
List<PrismObject<FocusType>> owners;
if (cfg.checkOwners) {
owners = shadowToDelete.getUserData(KEY_OWNERS);
} else {
owners = searchOwners(shadowToDelete, result);
}
if (!cfg.dryRun) {
try {
getRepositoryService().deleteObject(ShadowType.class, oid, result);
task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, null);
workingState.duplicateShadowsDeleted.add(oid);
} catch (ObjectNotFoundException e) {
// suspicious, but not a big deal
task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, e);
LoggingUtils.logExceptionAsWarning(LOGGER, "Shadow {} couldn't be deleted, because it does not exist anymore", e, ObjectTypeUtil.toShortString(shadowToDelete));
continue;
} catch (RuntimeException e) {
task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, e);
LoggingUtils.logUnexpectedException(LOGGER, "Shadow {} couldn't be deleted because of an unexpected exception", e, ObjectTypeUtil.toShortString(shadowToDelete));
continue;
}
}
if (owners == null || owners.isEmpty()) {
continue;
}
for (PrismObject<FocusType> owner : owners) {
List<ItemDelta<?, ?>> modifications = new ArrayList<>(2);
ReferenceDelta deleteDelta = PrismContext.get().deltaFactory().reference().createModificationDelete(FocusType.F_LINK_REF, owner.getDefinition(), PrismContext.get().itemFactory().createReferenceValue(oid, ShadowType.COMPLEX_TYPE));
modifications.add(deleteDelta);
if (shadowOidToReplaceDeleted != null) {
ReferenceDelta addDelta = PrismContext.get().deltaFactory().reference().createModificationAdd(FocusType.F_LINK_REF, owner.getDefinition(), PrismContext.get().itemFactory().createReferenceValue(shadowOidToReplaceDeleted, ShadowType.COMPLEX_TYPE));
modifications.add(addDelta);
}
LOGGER.info("Executing modify delta{} for owner {}:\n{}", skippedForDryRun(), ObjectTypeUtil.toShortString(owner), DebugUtil.debugDump(modifications));
if (!cfg.dryRun) {
try {
getRepositoryService().modifyObject(owner.asObjectable().getClass(), owner.getOid(), modifications, result);
task.recordObjectActionExecuted(owner, ChangeType.MODIFY, null);
} catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException | RuntimeException e) {
task.recordObjectActionExecuted(owner, ChangeType.MODIFY, e);
LoggingUtils.logUnexpectedException(LOGGER, "Focal object {} (owner of {}) couldn't be updated", e, ObjectTypeUtil.toShortString(owner), ObjectTypeUtil.toShortString(shadowToDelete));
}
}
}
}
}
Aggregations