Search in sources :

Example 1 with SearchOptions

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

the class DiffRemoteTask method processFiles.

private void processFiles(ProgressIndicator indicator, List<VirtualFile> files) {
    Environment env = getEnvironment();
    int skipped = 0;
    int missing = 0;
    AtomicInteger diffed = new AtomicInteger(0);
    AtomicInteger failed = new AtomicInteger(0);
    int current = 0;
    for (VirtualFile file : files) {
        ProgressManager.checkCanceled();
        current++;
        indicator.setFraction((double) current / files.size());
        List<MidPointObject> objects;
        try {
            objects = loadObjectsFromFile(file);
        } catch (Exception ex) {
            failed.incrementAndGet();
            midPointService.printToConsole(env, DiffRemoteTask.class, "Couldn't load objects from file " + file.getPath(), ex);
            continue;
        }
        if (objects.isEmpty()) {
            skipped++;
            midPointService.printToConsole(env, DiffRemoteTask.class, "Skipped file " + file.getPath() + " no objects found (parsed).");
            continue;
        }
        Map<String, MidPointObject> remoteObjects = new HashMap<>();
        for (MidPointObject object : objects) {
            ProgressManager.checkCanceled();
            try {
                MidPointObject newObject = client.get(object.getType().getClassDefinition(), object.getOid(), new SearchOptions().raw(true));
                if (newObject == null) {
                    missing++;
                    midPointService.printToConsole(env, DiffRemoteTask.class, "Couldn't find object " + object.getType().getTypeQName().getLocalPart() + "(" + object.getOid() + ").");
                    continue;
                }
                MidPointObject obj = MidPointObject.copy(object);
                obj.setContent(newObject.getContent());
                remoteObjects.put(obj.getOid(), obj);
                diffed.incrementAndGet();
            } catch (Exception ex) {
                failed.incrementAndGet();
                midPointService.printToConsole(env, DiffRemoteTask.class, "Error getting object" + object.getType().getTypeQName().getLocalPart() + "(" + object.getOid() + ")", ex);
            }
        }
        RunnableUtils.runWriteActionAndWait(() -> {
            Writer writer = null;
            VirtualFile vf = null;
            try {
                List<String> deltas = new ArrayList<>();
                for (MidPointObject local : objects) {
                    MidPointObject remote = remoteObjects.get(local.getOid());
                    if (remote == null) {
                        continue;
                    }
                    deltas.add(createDiffXml(local, file, LocationType.LOCAL, remote, null, LocationType.REMOTE));
                }
                vf = createScratchAndWriteDiff(deltas);
            } catch (Exception ex) {
                failed.incrementAndGet();
                midPointService.printToConsole(env, DiffRemoteTask.class, "Failed to compare file " + file.getPath(), ex);
            } finally {
                IOUtils.closeQuietly(writer);
            }
            MidPointUtils.openFile(getProject(), vf);
        });
    }
    NotificationType type = missing > 0 || failed.get() > 0 || skipped > 0 ? NotificationType.WARNING : NotificationType.INFORMATION;
    StringBuilder msg = new StringBuilder();
    msg.append("Compared ").append(diffed.get()).append(" objects<br/>");
    msg.append("Missing ").append(missing).append(" objects<br/>");
    msg.append("Failed to compare ").append(failed.get()).append(" objects<br/>");
    msg.append("Skipped ").append(skipped).append(" files");
    MidPointUtils.publishNotification(getProject(), NOTIFICATION_KEY, TITLE, msg.toString(), type);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SearchOptions(com.evolveum.midpoint.studio.impl.SearchOptions) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NotificationType(com.intellij.notification.NotificationType) Environment(com.evolveum.midpoint.studio.impl.Environment) Writer(java.io.Writer)

Example 2 with SearchOptions

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

the class DownloadTask method downloadByOid.

private void downloadByOid() {
    List<VirtualFile> files = new ArrayList<>();
    for (Pair<String, ObjectTypes> pair : oids) {
        try {
            LOG.debug("Downloading " + pair);
            MidPointObject obj = client.get(pair.getSecond().getClassDefinition(), pair.getFirst(), new SearchOptions().raw(raw));
            if (obj == null) {
                continue;
            }
            LOG.debug("Storing file");
            RunnableUtils.runWriteActionAndWait(() -> {
                VirtualFile file = saveFile(obj);
                if (file != null) {
                    files.add(file);
                }
            });
            LOG.debug("File saved");
        } catch (Exception ex) {
            MidPointUtils.publishExceptionNotification(getProject(), getEnvironment(), DownloadTask.class, NOTIFICATION_KEY, "Exception occurred when getting object " + pair.getFirst() + " (" + pair.getSecond().getTypeQName().getLocalPart() + ")", ex);
        }
    }
    if (!files.isEmpty() && openAfterDownload) {
        ApplicationManager.getApplication().invokeAndWait(() -> MidPointUtils.openFile(getProject(), files.get(0)));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) ArrayList(java.util.ArrayList) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) SearchOptions(com.evolveum.midpoint.studio.impl.SearchOptions) IOException(java.io.IOException)

Example 3 with SearchOptions

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

the class DownloadTask method showByOid.

private void showByOid(Writer out) {
    for (Pair<String, ObjectTypes> oid : oids) {
        try {
            MidPointObject object = client.get(oid.getSecond().getClassDefinition(), oid.getFirst(), new SearchOptions().raw(raw));
            if (object == null) {
                continue;
            }
            String content = oids.size() > 1 ? MidPointUtils.updateObjectRootElementToObject(object.getContent()) : object.getContent();
            IOUtils.write(content, out);
        } catch (Exception ex) {
            MidPointUtils.publishExceptionNotification(getProject(), getEnvironment(), DownloadTask.class, NOTIFICATION_KEY, "Exception occurred when getting object " + oid.getFirst() + " (" + oid.getSecond().getTypeQName().getLocalPart() + ")", ex);
        }
    }
}
Also used : MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) SearchOptions(com.evolveum.midpoint.studio.impl.SearchOptions) IOException(java.io.IOException)

Example 4 with SearchOptions

use of com.evolveum.midpoint.studio.impl.SearchOptions 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

MidPointObject (com.evolveum.midpoint.studio.client.MidPointObject)4 SearchOptions (com.evolveum.midpoint.studio.impl.SearchOptions)4 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)2 Environment (com.evolveum.midpoint.studio.impl.Environment)2 NotificationType (com.intellij.notification.NotificationType)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ShowResultNotificationAction (com.evolveum.midpoint.studio.impl.ShowResultNotificationAction)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 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Writer (java.io.Writer)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1