Search in sources :

Example 1 with AsyncWebProcessManager

use of com.evolveum.midpoint.web.application.AsyncWebProcessManager in project midpoint by Evolveum.

the class ProgressAwareChangesExecutorImpl method executeChangesAsync.

private void executeChangesAsync(ProgressPanel progressPanel, Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ModelExecuteOptions options, Task task, OperationResult result) {
    MidPointApplication application = MidPointApplication.get();
    final ModelInteractionService modelInteraction = application.getModelInteractionService();
    final ModelService model = application.getModel();
    final SecurityContextManager secManager = application.getSecurityContextManager();
    final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    final HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
    AsyncWebProcessModel<ProgressReporter> reporterModel = progressPanel.getReporterModel();
    Callable<Void> execution = new SecurityContextAwareCallable<>(secManager, auth, connInfo) {

        @Override
        public Void callWithContextPrepared() {
            ProgressReporter reporter = reporterModel.getProcessData();
            try {
                LOGGER.debug("Execution start");
                reporter.recordExecutionStart();
                if (previewOnly) {
                    ModelContext previewResult = modelInteraction.previewChanges(deltas, options, task, Collections.singleton(reporter), result);
                    reporter.setPreviewResult(previewResult);
                } else if (deltas != null && deltas.size() > 0) {
                    Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = model.executeChanges(deltas, options, task, Collections.singleton(reporter), result);
                    reporter.setObjectDeltaOperation(executedDeltas);
                }
            } catch (CommonException | RuntimeException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Error executing changes", e);
                if (!result.isFatalError()) {
                    // just to be sure the exception is recorded into the result
                    result.recordFatalError(e.getMessage(), e);
                }
            } finally {
                LOGGER.debug("Execution finish {}", result);
            }
            reporter.recordExecutionStop();
            // signals that the operation has finished
            reporter.setAsyncOperationResult(result);
            return null;
        }
    };
    // to disable showing not-final results (why does it work? and why is the result shown otherwise?)
    result.setInProgress();
    AsyncWebProcessManager manager = application.getAsyncWebProcessManager();
    manager.submit(reporterModel.getId(), execution);
}
Also used : ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) ProgressReporter(com.evolveum.midpoint.web.component.progress.ProgressReporter) ModelService(com.evolveum.midpoint.model.api.ModelService) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) HttpConnectionInformation(com.evolveum.midpoint.security.api.HttpConnectionInformation) Authentication(org.springframework.security.core.Authentication) Collection(java.util.Collection) AsyncWebProcessManager(com.evolveum.midpoint.web.application.AsyncWebProcessManager) CommonException(com.evolveum.midpoint.util.exception.CommonException) SecurityContextManager(com.evolveum.midpoint.security.api.SecurityContextManager)

Example 2 with AsyncWebProcessManager

use of com.evolveum.midpoint.web.application.AsyncWebProcessManager in project midpoint by Evolveum.

the class ProgressPanel method executeChangesAsync.

private void executeChangesAsync(ProgressReporter reporter, Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ModelExecuteOptions options, Task task, OperationResult result) {
    MidPointApplication application = MidPointApplication.get();
    final ModelInteractionService modelInteraction = application.getModelInteractionService();
    final ModelService model = application.getModel();
    final SecurityContextManager secManager = application.getSecurityContextManager();
    final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    final HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
    Callable<Void> execution = new SecurityContextAwareCallable<Void>(secManager, auth, connInfo) {

        @Override
        public Void callWithContextPrepared() throws Exception {
            try {
                LOGGER.debug("Execution start");
                reporter.recordExecutionStart();
                if (previewOnly) {
                    ModelContext previewResult = modelInteraction.previewChanges(deltas, options, task, Collections.singleton(reporter), result);
                    reporter.setPreviewResult(previewResult);
                } else if (deltas != null && deltas.size() > 0) {
                    Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = model.executeChanges(deltas, options, task, Collections.singleton(reporter), result);
                    reporter.setObjectDeltaOperation(executedDeltas);
                }
            } catch (CommonException | RuntimeException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Error executing changes", e);
                if (!result.isFatalError()) {
                    // just to be sure the exception is recorded into the result
                    result.recordFatalError(e.getMessage(), e);
                }
            } finally {
                LOGGER.debug("Execution finish {}", result);
            }
            reporter.recordExecutionStop();
            // signals that the operation has finished
            reporter.setAsyncOperationResult(result);
            return null;
        }
    };
    // to disable showing not-final results (why does it work? and why is the result shown otherwise?)
    result.setInProgress();
    AsyncWebProcessManager manager = application.getAsyncWebProcessManager();
    manager.submit(reporterModel.getId(), execution);
}
Also used : ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) ModelService(com.evolveum.midpoint.model.api.ModelService) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) HttpConnectionInformation(com.evolveum.midpoint.security.api.HttpConnectionInformation) Authentication(org.springframework.security.core.Authentication) Collection(java.util.Collection) AsyncWebProcessManager(com.evolveum.midpoint.web.application.AsyncWebProcessManager) CommonException(com.evolveum.midpoint.util.exception.CommonException) SecurityContextManager(com.evolveum.midpoint.security.api.SecurityContextManager)

Example 3 with AsyncWebProcessManager

use of com.evolveum.midpoint.web.application.AsyncWebProcessManager in project midpoint by Evolveum.

the class AsyncUpdatePanel method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    PageBase page = getPageBase();
    AsyncWebProcessManager manager = page.getAsyncWebProcessManager();
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    manager.submit(processModel.getId(), createCallable(auth, callableParameterModel));
}
Also used : Authentication(org.springframework.security.core.Authentication) AsyncWebProcessManager(com.evolveum.midpoint.web.application.AsyncWebProcessManager) PageBase(com.evolveum.midpoint.gui.api.page.PageBase)

Aggregations

AsyncWebProcessManager (com.evolveum.midpoint.web.application.AsyncWebProcessManager)3 Authentication (org.springframework.security.core.Authentication)3 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)2 ModelService (com.evolveum.midpoint.model.api.ModelService)2 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)2 HttpConnectionInformation (com.evolveum.midpoint.security.api.HttpConnectionInformation)2 SecurityContextManager (com.evolveum.midpoint.security.api.SecurityContextManager)2 CommonException (com.evolveum.midpoint.util.exception.CommonException)2 SecurityContextAwareCallable (com.evolveum.midpoint.web.component.SecurityContextAwareCallable)2 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)2 Collection (java.util.Collection)2 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)1 ProgressReporter (com.evolveum.midpoint.web.component.progress.ProgressReporter)1