Search in sources :

Example 6 with Environment

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

the class EncryptedPropertiesSerializer method serialize.

public void serialize(List<EncryptedProperty> properties, File file) throws IOException {
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    Properties props = new Properties() {

        /**
         * not very nice way to make properties sorted when stored to file
         */
        @Override
        public Set<Map.Entry<Object, Object>> entrySet() {
            Set<Map.Entry<Object, Object>> set = new TreeSet<>((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare((String) o1.getKey(), (String) o2.getKey()));
            set.addAll(super.entrySet());
            return set;
        }
    };
    int i = 0;
    for (EncryptedProperty property : properties) {
        String prefix = "property." + i + ".";
        putProperty(props, prefix + "key", property.getKey());
        putProperty(props, prefix + "value", property.getValue());
        putProperty(props, prefix + "description", property.getDescription());
        if (property.getEnvironment() != null) {
            Environment env = environmentService.get(property.getEnvironment());
            if (env != null) {
                putProperty(props, prefix + "environment", env.getName());
            }
        }
        i++;
    }
    try (Writer w = new FileWriter(file, StandardCharsets.UTF_8)) {
        props.store(w, null);
    }
}
Also used : EncryptedProperty(com.evolveum.midpoint.studio.impl.EncryptedProperty) FileWriter(java.io.FileWriter) Environment(com.evolveum.midpoint.studio.impl.Environment) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 7 with Environment

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

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

the class DownloadSelectedTypesTask method doRun.

@Override
protected void doRun(ProgressIndicator indicator) {
    super.doRun(indicator);
    MidPointSettings settings = midPointService.getSettings();
    if (settings.getTypesToDownloadLimit() == 0 && settings.getDownloadTypesInclude().isEmpty() && settings.getDownloadTypesExclude().isEmpty()) {
        // probably
        MidPointSettings defaults = MidPointSettings.createDefaultSettings();
        settings.setDownloadTypesInclude(defaults.getDownloadTypesInclude());
        settings.setDownloadTypesExclude(defaults.getDownloadTypesExclude());
        settings.setTypesToDownloadLimit(defaults.getTypesToDownloadLimit());
        midPointService.settingsUpdated();
    }
    if (settings.getTypesToDownloadLimit() <= 0) {
        MidPointUtils.publishNotification(getProject(), NOTIFICATION_KEY, "Download Selected Types", "Download limit set to zero. Done.", NotificationType.WARNING);
        return;
    }
    Environment environment = getEnvironment();
    PrismContext ctx = ServiceFactory.DEFAULT_PRISM_CONTEXT;
    QueryFactory qf = ctx.queryFactory();
    ObjectPaging paging = qf.createPaging(0, settings.getTypesToDownloadLimit(), ctx.path(ObjectType.F_NAME), OrderDirection.ASCENDING);
    ObjectQuery query = qf.createQuery(null, paging);
    List<ObjectTypes> typesToDownload = determineTypesToDownload(settings);
    for (ObjectTypes type : typesToDownload) {
        try {
            DownloadTask dt = new DownloadTask(event, null, type, query, false, false, true);
            dt.setEnvironment(environment);
            dt.setOpenAfterDownload(false);
            dt.download(indicator);
        } catch (Exception ex) {
            midPointService.printToConsole(environment, getClass(), "Couldn't download objects of type '" + type.getValue() + "'. Reason: " + ex.getMessage());
        }
    }
}
Also used : QueryFactory(com.evolveum.midpoint.prism.query.QueryFactory) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) PrismContext(com.evolveum.midpoint.prism.PrismContext) Environment(com.evolveum.midpoint.studio.impl.Environment) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) MidPointSettings(com.evolveum.midpoint.studio.impl.MidPointSettings)

Example 9 with Environment

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

the class GeneratorTask method writeContent.

private void writeContent(ProgressIndicator indicator, String content) {
    updateIndicator(indicator, "Content created, writing to file");
    Project project = getProject();
    Environment env = getEnvironment();
    RunnableUtils.runWriteActionAndWait(() -> {
        VirtualFile file = null;
        Writer out = null;
        try {
            file = FileUtils.createScratchFile(project, env);
            out = new BufferedWriter(new OutputStreamWriter(file.getOutputStream(GeneratorTask.this), file.getCharset()));
            IOUtils.write(content, out);
            FileEditorManager fem = FileEditorManager.getInstance(project);
            fem.openFile(file, true, true);
        } catch (IOException ex) {
            MidPointUtils.publishExceptionNotification(project, env, GeneratorTask.class, NOTIFICATION_KEY, "Couldn't store generated content to file " + (file != null ? file.getName() : "[null]"), ex);
        } finally {
            IOUtils.closeQuietly(out);
        }
    });
    updateIndicator(indicator, "File saved");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Environment(com.evolveum.midpoint.studio.impl.Environment) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 10 with Environment

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

the class GeneratorTask method doRun.

@Override
protected void doRun(ProgressIndicator indicator) {
    super.doRun(indicator);
    updateIndicator(indicator, "Starting generator");
    Project project = getProject();
    Environment env = getEnvironment();
    String content = generator.generate(project, objects, options);
    if (options.isUseActivities()) {
        try {
            content = MidPointUtils.upgradeTaskToUseActivities(content);
        } catch (Exception ex) {
            midPointService.printToConsole(env, getClass(), "Couldn't update generate task to use activities. Reason: " + ex.getMessage());
            MidPointUtils.publishExceptionNotification(project, env, GeneratorTask.class, NOTIFICATION_KEY, "Couldn't update generate task to use activities", ex);
        }
    }
    if (!execute) {
        writeContent(indicator, content);
    } else {
        uploadContent(indicator, content);
    }
}
Also used : Project(com.intellij.openapi.project.Project) Environment(com.evolveum.midpoint.studio.impl.Environment) IOException(java.io.IOException)

Aggregations

Environment (com.evolveum.midpoint.studio.impl.Environment)32 EnvironmentService (com.evolveum.midpoint.studio.impl.EnvironmentService)13 Project (com.intellij.openapi.project.Project)10 MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 MidPointService (com.evolveum.midpoint.studio.impl.MidPointService)5 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 NotNull (org.jetbrains.annotations.NotNull)4 ComboObjectTypes (com.evolveum.midpoint.studio.action.browse.ComboObjectTypes)3 MidPointObject (com.evolveum.midpoint.studio.client.MidPointObject)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 BufferedWriter (java.io.BufferedWriter)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Writer (java.io.Writer)3 List (java.util.List)3 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2