Search in sources :

Example 1 with ModelService

use of com.evolveum.midpoint.model.api.ModelService in project midpoint by Evolveum.

the class PageProcessInstances method deleteProcessInstancesPerformed.

private void deleteProcessInstancesPerformed(AjaxRequestTarget target) {
    List<ProcessInstanceDto> processInstanceDtoList = WebComponentUtil.getSelectedData(getTable());
    if (!isSomeItemSelected(processInstanceDtoList, false, target)) {
        return;
    }
    Task opTask = createSimpleTask(OPERATION_DELETE_PROCESS_INSTANCES);
    OperationResult result = opTask.getResult();
    ModelService modelService = getModelService();
    for (ProcessInstanceDto processInstanceDto : processInstanceDtoList) {
        String taskOid = processInstanceDto.getTaskOid();
        try {
            ObjectDelta<? extends ObjectType> deleteDelta = ObjectDelta.createDeleteDelta(TaskType.class, taskOid, getPrismContext());
            modelService.executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singletonList(deleteDelta), null, opTask, result);
        } catch (CommonException | RuntimeException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete task (process instance) {}", e, taskOid);
        }
    }
    if (result.isUnknown()) {
        result.recomputeStatus();
    }
    if (result.isSuccess()) {
        result.recordStatus(OperationResultStatus.SUCCESS, "Selected process instance(s) have been successfully deleted.");
    }
    showResult(result);
    ProcessInstanceDtoProvider provider = (ProcessInstanceDtoProvider) getTable().getDataTable().getDataProvider();
    provider.clearCache();
    //refresh feedback and table
    target.add(getFeedbackPanel());
    target.add(getTable());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ProcessInstanceDto(com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) ProcessInstanceDtoProvider(com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDtoProvider) ModelService(com.evolveum.midpoint.model.api.ModelService)

Example 2 with ModelService

use of com.evolveum.midpoint.model.api.ModelService in project midpoint by Evolveum.

the class ProgressReporter method executeChanges.

/**
     * Executes changes on behalf of the parent page. By default, changes are executed asynchronously (in
     * a separate thread). However, when set in the midpoint configuration, changes are executed synchronously.
     *
     * @param deltas Deltas to be executed.
     * @param options Model execution options.
     * @param task Task in context of which the changes have to be executed.
     * @param result Operation result.
     * @param target AjaxRequestTarget into which any synchronous changes are signalized.
     */
public void executeChanges(final Collection<ObjectDelta<? extends ObjectType>> deltas, final boolean previewOnly, final ModelExecuteOptions options, final Task task, final OperationResult result, AjaxRequestTarget target) {
    parentPage.startProcessing(target, result);
    ModelService modelService = parentPage.getModelService();
    ModelInteractionService modelInteractionService = parentPage.getModelInteractionService();
    if (asynchronousExecution) {
        executeChangesAsync(deltas, previewOnly, options, task, result, target, modelService, modelInteractionService);
    } else {
        executeChangesSync(deltas, previewOnly, options, task, result, target, modelService, modelInteractionService);
    }
}
Also used : ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) ModelService(com.evolveum.midpoint.model.api.ModelService)

Example 3 with ModelService

use of com.evolveum.midpoint.model.api.ModelService in project midpoint by Evolveum.

the class ObjectChangesExecutorImpl method executeChangesSync.

private Collection<ObjectDeltaOperation<? extends ObjectType>> executeChangesSync(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, Task task, OperationResult result) {
    try {
        MidPointApplication application = MidPointApplication.get();
        ModelService service = application.getModel();
        Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = service.executeChanges(deltas, options, task, result);
        result.computeStatusIfUnknown();
        return 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);
        }
    }
    return null;
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) CommonException(com.evolveum.midpoint.util.exception.CommonException) ModelService(com.evolveum.midpoint.model.api.ModelService)

Example 4 with ModelService

use of com.evolveum.midpoint.model.api.ModelService in project midpoint by Evolveum.

the class NameStep method discoverConnectors.

private void discoverConnectors(ConnectorHostType host) {
    PageBase page = (PageBase) getPage();
    Task task = page.createSimpleTask(OPERATION_DISCOVER_CONNECTORS);
    OperationResult result = task.getResult();
    try {
        ModelService model = page.getModelService();
        model.discoverConnectors(host, task, result);
    } catch (CommonException | RuntimeException ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't discover connectors", ex);
    } finally {
        result.recomputeStatus();
    }
    if (WebComponentUtil.showResultInPage(result)) {
        page.showResult(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) ModelService(com.evolveum.midpoint.model.api.ModelService)

Example 5 with ModelService

use of com.evolveum.midpoint.model.api.ModelService in project midpoint by Evolveum.

the class ProgressAwareChangesExecutorImpl method executeChangesSync.

private void executeChangesSync(ProgressReporter reporter, Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ModelExecuteOptions options, Task task, OperationResult result) {
    try {
        MidPointApplication application = MidPointApplication.get();
        if (previewOnly) {
            ModelInteractionService service = application.getModelInteractionService();
            ModelContext previewResult = service.previewChanges(deltas, options, task, result);
            reporter.setPreviewResult(previewResult);
        } else {
            ModelService service = application.getModel();
            Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = service.executeChanges(deltas, options, task, result);
            reporter.setObjectDeltaOperation(executedDeltas);
        }
        result.computeStatusIfUnknown();
    } 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);
        }
    }
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) CommonException(com.evolveum.midpoint.util.exception.CommonException) ModelService(com.evolveum.midpoint.model.api.ModelService)

Aggregations

ModelService (com.evolveum.midpoint.model.api.ModelService)14 CommonException (com.evolveum.midpoint.util.exception.CommonException)10 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 Task (com.evolveum.midpoint.task.api.Task)7 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)6 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)5 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)4 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)3 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)3 HttpConnectionInformation (com.evolveum.midpoint.security.api.HttpConnectionInformation)2 SecurityContextManager (com.evolveum.midpoint.security.api.SecurityContextManager)2 AsyncWebProcessManager (com.evolveum.midpoint.web.application.AsyncWebProcessManager)2 SecurityContextAwareCallable (com.evolveum.midpoint.web.component.SecurityContextAwareCallable)2 Collection (java.util.Collection)2 RestartResponseException (org.apache.wicket.RestartResponseException)2 Authentication (org.springframework.security.core.Authentication)2 WebComponentUtil (com.evolveum.midpoint.gui.api.util.WebComponentUtil)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1