Search in sources :

Example 1 with ShowResultNotificationAction

use of com.evolveum.midpoint.studio.impl.ShowResultNotificationAction in project midpoint-studio by Evolveum.

the class GeneratorTask method uploadContent.

private void uploadContent(ProgressIndicator indicator, String content) {
    Project project = getProject();
    Environment env = getEnvironment();
    updateIndicator(indicator, "Content created, uploading to " + env.getName());
    MidPointService mm = MidPointService.getInstance(project);
    MidPointClient client = new MidPointClient(project, env);
    List<MidPointObject> objects = MidPointUtils.parseText(project, content, null, NOTIFICATION_KEY);
    int fail = 0;
    int success = 0;
    for (MidPointObject object : objects) {
        try {
            OperationResult result = UploadExecuteTask.uploadExecute(client, object);
            boolean problem = result != null && !result.isSuccess();
            if (problem) {
                fail++;
                String msg = "Upload status of " + object.getName() + " was " + result.getStatus();
                mm.printToConsole(env, getClass(), msg);
                MidPointUtils.publishNotification(project, NOTIFICATION_KEY, "Warning", msg, NotificationType.WARNING, new ShowResultNotificationAction(result));
            } else {
                success++;
                mm.printToConsole(env, getClass(), "Content uploaded successfuly");
            }
        } catch (Exception ex) {
            fail++;
            mm.printToConsole(env, getClass(), "Couldn't upload generated content. Reason: " + ex.getMessage());
            MidPointUtils.publishExceptionNotification(project, env, GeneratorTask.class, NOTIFICATION_KEY, "Couldn't upload generated content", ex);
        }
    }
    showNotificationAfterFinish(project, success, fail);
    updateIndicator(indicator, "Content uploaded");
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) MidPointService(com.evolveum.midpoint.studio.impl.MidPointService) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) ShowResultNotificationAction(com.evolveum.midpoint.studio.impl.ShowResultNotificationAction) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) Environment(com.evolveum.midpoint.studio.impl.Environment)

Example 2 with ShowResultNotificationAction

use of com.evolveum.midpoint.studio.impl.ShowResultNotificationAction in project midpoint-studio by Evolveum.

the class ObjectsBackgroundableTask method printAndNotifyProblem.

protected void printAndNotifyProblem(String operation, String objectName, OperationResult result, Exception ex) {
    String msg = StringUtils.capitalize(operation) + " status of " + objectName + " was " + result.getStatus();
    midPointService.printToConsole(getEnvironment(), getClass(), msg);
    MidPointUtils.publishNotification(getProject(), notificationKey, "Warning", msg, NotificationType.WARNING, new ShowResultNotificationAction(result));
    if (ex != null) {
        publishException(midPointService, "Exception occurred during '" + operation + "' of " + objectName, ex);
    }
}
Also used : ShowResultNotificationAction(com.evolveum.midpoint.studio.impl.ShowResultNotificationAction)

Example 3 with ShowResultNotificationAction

use of com.evolveum.midpoint.studio.impl.ShowResultNotificationAction in project midpoint-studio by Evolveum.

the class SetLoggerTask method doRun.

@Override
protected void doRun(ProgressIndicator indicator) {
    super.doRun(indicator);
    indicator.setIndeterminate(false);
    List<ClassLoggerConfigurationType> newLoggers = buildClassLoggers();
    if (newLoggers == null || newLoggers.isEmpty()) {
        noChangeNeeded();
        return;
    }
    Environment env = getEnvironment();
    LOG.debug("Downloading system configuration");
    PrismObject<SystemConfigurationType> configPrism;
    try {
        MidPointObject object = client.get(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), new SearchOptions());
        if (object == null) {
            return;
        }
        configPrism = (PrismObject) client.parseObject(object.getContent());
        indicator.setFraction(0.5);
    } catch (Exception ex) {
        MidPointUtils.publishException(getProject(), env, getClass(), NOTIFICATION_KEY, "Couldn't download and parse system configuration", ex);
        return;
    }
    LOG.debug("Updating logging configuration");
    SystemConfigurationType config = configPrism.asObjectable();
    LoggingConfigurationType logging = config.getLogging();
    if (logging == null) {
        logging = new LoggingConfigurationType();
        config.setLogging(logging);
    }
    List<ClassLoggerConfigurationType> existing = logging.getClassLogger();
    Map<String, ClassLoggerConfigurationType> existingMap = existing.stream().collect(Collectors.toMap(o -> o.getPackage(), o -> o, (a, b) -> a));
    boolean changed = false;
    for (ClassLoggerConfigurationType cl : newLoggers) {
        ClassLoggerConfigurationType existingLogger = existingMap.get(cl.getPackage());
        if (existingLogger == null) {
            LOG.debug("Adding new class logger ", cl.getPackage(), " with level ", cl.getLevel());
            existing.add(cl);
            changed = true;
        } else {
            if (existingLogger.getLevel() != cl.getLevel()) {
                LOG.debug("Updating class logger ", existingLogger.getPackage(), " with level ", cl.getLevel());
                existingLogger.setLevel(cl.getLevel());
                changed = true;
            }
        }
    }
    if (!changed) {
        noChangeNeeded();
        indicator.setFraction(1);
        return;
    }
    LOG.debug("Uploading system configuration");
    try {
        UploadResponse resp = client.upload(configPrism, Arrays.asList(ModelExecuteOptionsType.F_OVERWRITE.getLocalPart()));
        OperationResult result = resp.getResult();
        if (result != null && !result.isSuccess()) {
            String msg = "Upload status of system configuration was " + result.getStatus();
            midPointService.printToConsole(env, getClass(), msg);
            MidPointUtils.publishNotification(getProject(), NOTIFICATION_KEY, "Warning", msg, NotificationType.WARNING, new ShowResultNotificationAction(result));
        } else {
            midPointService.printToConsole(env, getClass(), "System configuration uploaded");
        }
        indicator.setFraction(1);
    } catch (Exception ex) {
        MidPointUtils.publishException(getProject(), env, getClass(), NOTIFICATION_KEY, "Exception occurred during system configuration upload", ex);
    }
}
Also used : Arrays(java.util.Arrays) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SearchOptions(com.evolveum.midpoint.studio.impl.SearchOptions) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collectors(java.util.stream.Collectors) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) Environment(com.evolveum.midpoint.studio.impl.Environment) NotificationType(com.intellij.notification.NotificationType) MidPointUtils(com.evolveum.midpoint.studio.util.MidPointUtils) ShowResultNotificationAction(com.evolveum.midpoint.studio.impl.ShowResultNotificationAction) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) UploadResponse(com.evolveum.midpoint.studio.impl.UploadResponse) Map(java.util.Map) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SearchOptions(com.evolveum.midpoint.studio.impl.SearchOptions) UploadResponse(com.evolveum.midpoint.studio.impl.UploadResponse) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) ShowResultNotificationAction(com.evolveum.midpoint.studio.impl.ShowResultNotificationAction) Environment(com.evolveum.midpoint.studio.impl.Environment)

Aggregations

ShowResultNotificationAction (com.evolveum.midpoint.studio.impl.ShowResultNotificationAction)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 MidPointObject (com.evolveum.midpoint.studio.client.MidPointObject)2 Environment (com.evolveum.midpoint.studio.impl.Environment)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)1 MidPointService (com.evolveum.midpoint.studio.impl.MidPointService)1 SearchOptions (com.evolveum.midpoint.studio.impl.SearchOptions)1 UploadResponse (com.evolveum.midpoint.studio.impl.UploadResponse)1 MidPointUtils (com.evolveum.midpoint.studio.util.MidPointUtils)1 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)1 NotificationType (com.intellij.notification.NotificationType)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Project (com.intellij.openapi.project.Project)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1