Search in sources :

Example 41 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class PageResourceVisualization method loadVisualizationDto.

@NotNull
private ResourceVisualizationDto loadVisualizationDto() {
    Task task = createSimpleTask(OPERATION_EXPORT_DATA_MODEL);
    OperationResult result = task.getResult();
    String dot;
    try {
        resourceObject.revive(getPrismContext());
        dot = getModelDiagnosticService().exportDataModel(resourceObject.asObjectable(), DataModelVisualizer.Target.DOT, task, result);
    } catch (CommonException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't export the data model for {}", e, ObjectTypeUtil.toShortString(resourceObject));
        showResult(result);
        throw redirectBackViaRestartResponseException();
    }
    String renderer = DEFAULT_RENDERER;
    Configuration dotConfig = getMidpointConfiguration().getConfiguration(MidpointConfiguration.DOT_CONFIGURATION);
    if (dotConfig != null) {
        renderer = dotConfig.getString(RENDERER, renderer);
    }
    renderer += " -Tsvg";
    StringBuilder output = new StringBuilder();
    try {
        SystemUtil.executeCommand(renderer, dot, output, -1);
        return new ResourceVisualizationDto(dot, output.toString(), null);
    } catch (IOException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute SVG renderer command: {}", e, renderer);
        return new ResourceVisualizationDto(dot, null, e);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) Configuration(org.apache.commons.configuration2.Configuration) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) IOException(java.io.IOException) ResourceVisualizationDto(com.evolveum.midpoint.web.page.admin.resources.dto.ResourceVisualizationDto) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException 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)

Example 43 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException 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 44 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class PageEvaluateMapping method executeMappingPerformed.

private void executeMappingPerformed(AjaxRequestTarget target) {
    Task task = createSimpleTask(OPERATION_EXECUTE_MAPPING);
    OperationResult result = new OperationResult(OPERATION_EXECUTE_MAPPING);
    ExecuteMappingDto dto = model.getObject();
    if (StringUtils.isBlank(dto.getMapping())) {
        warn(getString("PageEvaluateMapping.message.emptyString"));
        target.add(getFeedbackPanel());
        return;
    }
    try {
        MappingEvaluationRequestType request;
        if (StringUtils.isNotBlank(dto.getRequest())) {
            request = getPrismContext().parserFor(dto.getRequest()).xml().parseRealValue(MappingEvaluationRequestType.class);
        } else {
            request = new MappingEvaluationRequestType();
        }
        if (StringUtils.isNotBlank(dto.getMapping())) {
            request.setMapping(getPrismContext().parserFor(dto.getMapping()).xml().parseRealValue(MappingType.class));
        }
        MappingEvaluationResponseType response = getModelDiagnosticService().evaluateMapping(request, task, result);
        dto.setResultText(response.getResponse());
    } catch (CommonException | RuntimeException e) {
        result.recordFatalError(getString("PageEvaluateMapping.message.executeMappingPerformed.fatalError"), e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute mapping", e);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        pw.close();
        dto.setResultText(sw.toString());
    } finally {
        result.computeStatus();
    }
    showResult(result);
    target.add(this);
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) ExecuteMappingDto(com.evolveum.midpoint.web.page.admin.configuration.dto.ExecuteMappingDto) Task(com.evolveum.midpoint.task.api.Task) StringWriter(java.io.StringWriter) MappingEvaluationResponseType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingEvaluationResponseType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) MappingEvaluationRequestType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingEvaluationRequestType) PrintWriter(java.io.PrintWriter)

Example 45 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class PageRegistrationFinish method init.

private void init() {
    OperationResult result = new OperationResult(OPERATION_FINISH_REGISTRATION);
    try {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (!authentication.isAuthenticated()) {
            LOGGER.error("Unauthenticated request");
            String msg = createStringResource("PageSelfRegistration.unauthenticated").getString();
            getSession().error(createStringResource(msg));
            result.recordFatalError(msg);
            initLayout(result);
            throw new RestartResponseException(PageSelfRegistration.class);
        }
        FocusType user = ((MidPointPrincipal) authentication.getPrincipal()).getFocus();
        PrismObject<UserType> administrator = getAdministratorPrivileged(result);
        assignDefaultRoles(user.getOid(), administrator, result);
        result.computeStatus();
        if (result.getStatus() == OperationResultStatus.FATAL_ERROR) {
            LOGGER.error("Failed to assign default roles, {}", result.getMessage());
        } else {
            NonceType nonceClone = user.getCredentials().getNonce().clone();
            removeNonceAndSetLifecycleState(user.getOid(), nonceClone, administrator, result);
            assignAdditionalRoleIfPresent(user.getOid(), nonceClone, administrator, result);
            result.computeStatus();
        }
        initLayout(result);
    } catch (CommonException | AuthenticationException e) {
        result.computeStatus();
        initLayout(result);
    }
}
Also used : RestartResponseException(org.apache.wicket.RestartResponseException) AuthenticationException(org.springframework.security.core.AuthenticationException) Authentication(org.springframework.security.core.Authentication) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Aggregations

CommonException (com.evolveum.midpoint.util.exception.CommonException)71 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)44 Task (com.evolveum.midpoint.task.api.Task)33 PrismObject (com.evolveum.midpoint.prism.PrismObject)14 SystemException (com.evolveum.midpoint.util.exception.SystemException)14 ArrayList (java.util.ArrayList)12 ModelService (com.evolveum.midpoint.model.api.ModelService)11 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 NotNull (org.jetbrains.annotations.NotNull)7 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ActivityRunException (com.evolveum.midpoint.repo.common.activity.run.ActivityRunException)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 RestartResponseException (org.apache.wicket.RestartResponseException)5 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)4 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)4 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)4