use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class DummyItsm method tryToFail.
private void tryToFail() throws CommonException {
if (failureClass == null) {
return;
}
CommonException exception;
try {
Constructor<? extends CommonException> constructor = failureClass.getConstructor(String.class);
exception = constructor.newInstance("Simulated error: " + failureClass.getSimpleName());
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new RuntimeException("Failed to fail: " + e.getMessage(), e);
}
throw exception;
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PolicyRuleScriptExecutor method executeScriptsFromCollectedRules.
private <O extends ObjectType> void executeScriptsFromCollectedRules(List<EvaluatedPolicyRuleImpl> rules, LensContext<O> context, Task task, OperationResult parentResult) {
// Must not be minor because of background OID information.
OperationResult result = parentResult.createSubresult(OP_EXECUTE_SCRIPTS_FROM_RULES);
try (RunAsRunner runAsRunner = runAsRunnerFactory.runner()) {
for (EvaluatedPolicyRuleImpl rule : rules) {
List<ScriptExecutionPolicyActionType> enabledActions = rule.getEnabledActions(ScriptExecutionPolicyActionType.class);
LOGGER.trace("Rule {} has {} enabled script execution actions", rule, enabledActions.size());
for (ScriptExecutionPolicyActionType action : enabledActions) {
ActionContext actx = new ActionContext(action, rule, context, task, this);
try {
// We should consider ordering actions to be executed by runAsRef to avoid unnecessary context switches.
runAsRunner.runAs(() -> executeScriptingAction(actx, result), actx.action.getRunAsRef(), result);
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute scripting action - continuing with others (if present)", e);
}
}
}
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
// as we are used to. So this hack is definitely the lesser evil for now.
if (result.getStatus() == OperationResultStatus.FATAL_ERROR) {
result.setStatus(OperationResultStatus.PARTIAL_ERROR);
}
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class ActivityBasedTaskRun method setupTaskArchetypeIfNeeded.
private void setupTaskArchetypeIfNeeded(OperationResult result) throws ActivityRunException {
if (activityBasedTaskHandler.isAvoidAutoAssigningArchetypes()) {
return;
}
try {
RunningTask task = getRunningTask();
String defaultArchetypeOid = activityTree.getRootActivity().getHandler().getDefaultArchetypeOid();
if (defaultArchetypeOid != null) {
task.addArchetypeInformationIfMissing(defaultArchetypeOid);
task.flushPendingModifications(result);
}
} catch (CommonException e) {
throw new ActivityRunException("Couldn't setup the task archetype", FATAL_ERROR, PERMANENT_ERROR, e);
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class InitializableMixin method initialize.
/**
* Initializes given object.
*
* - Precondition: lifecycle state is CREATED.
* - Postcondition (unless exception is thrown): lifecycle state is INITIALIZED or INITIALIZATION_FAILED.
*/
default void initialize(Task task, OperationResult result) {
InitializationState state = getInitializationState();
getLogger().trace("Item before initialization (state: {}):\n{}", state, debugDumpLazily());
try {
state.moveFromCreatedToInitializing();
try {
initializeInternal(task, result);
} catch (NotApplicableException e) {
state.recordNotApplicable();
result.recordNotApplicable();
}
state.moveFromInitializingToInitialized();
checkConsistence();
} catch (CommonException | EncryptionException | RuntimeException e) {
// TODO change to debug
getLogger().warn("Got an exception during initialization of {}", this, e);
getInitializationState().recordInitializationFailed(e);
result.recordFatalError(e);
}
state.checkAfterInitialization();
getLogger().trace("Item after initialization (state: {}):\n{}", state, debugDumpLazily());
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class ClassicDashboardReportExportActivityRun method iterateOverItemsInBucket.
@Override
public void iterateOverItemsInBucket(OperationResult result) throws CommonException {
// Issue the search to audit or model/repository
// And use the following handler to handle the results
List<DashboardWidgetType> widgets = support.getDashboard().getWidget();
AtomicInteger widgetSequence = new AtomicInteger(1);
for (DashboardWidgetType widget : widgets) {
ExportDashboardReportLine<Containerable> widgetLine = new ExportDashboardReportLine<>(widgetSequence.getAndIncrement(), widget);
ItemProcessingRequest<ExportDashboardReportLine<Containerable>> widgetRequest = new ExportDashboardReportLineProcessingRequest(widgetLine, this);
coordinator.submit(widgetRequest, result);
if (support.isWidgetTableVisible()) {
AtomicInteger sequence = new AtomicInteger(1);
Handler<Containerable> handler = record -> {
ExportDashboardReportLine<Containerable> line = new ExportDashboardReportLine<>(sequence.getAndIncrement(), record, widget.getIdentifier());
ItemProcessingRequest<ExportDashboardReportLine<Containerable>> request = new ExportDashboardReportLineProcessingRequest(line, this);
coordinator.submit(request, result);
return true;
};
DashboardWidgetHolder holder = mapOfWidgetsController.get(widget.getIdentifier());
ContainerableReportDataSource searchSpecificationHolder = holder.getSearchSpecificationHolder();
searchSpecificationHolder.run(handler, result);
}
}
}
Aggregations