Search in sources :

Example 11 with MidPointObject

use of com.evolveum.midpoint.studio.client.MidPointObject 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 12 with MidPointObject

use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.

the class DownloadTask method downloadByQuery.

private void downloadByQuery() {
    List<VirtualFile> files = new ArrayList<>();
    try {
        SearchResult result = client.search(type.getClassDefinition(), query, raw);
        if (result == null || result.getObjects() == null) {
            return;
        }
        LOG.debug("Storing file");
        RunnableUtils.runWriteActionAndWait(() -> {
            for (MidPointObject obj : result.getObjects()) {
                VirtualFile file = saveFile(obj);
                if (file != null) {
                    files.add(file);
                }
            }
        });
        LOG.debug("Files saved");
    } catch (Exception ex) {
        MidPointUtils.publishExceptionNotification(getProject(), getEnvironment(), DownloadTask.class, NOTIFICATION_KEY, "Exception occurred when searching for " + type.getValue(), 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) SearchResult(com.evolveum.midpoint.studio.client.SearchResult) IOException(java.io.IOException)

Example 13 with MidPointObject

use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.

the class ObjectsBackgroundableTask method processObjects.

protected ProcessFileObjectsResult processObjects(ProgressIndicator indicator, List<MidPointObject> objects, VirtualFile file) {
    if (objects.isEmpty()) {
        state.incrementSkippedFile();
        midPointService.printToConsole(null, RefreshAction.class, "Skipped file " + (file != null ? file.getPath() : "<unknown>") + " no objects found (parsed).");
        return new ProcessFileObjectsResult();
    }
    List<String> newObjects = new ArrayList<>();
    boolean stop = false;
    int current = 0;
    for (MidPointObject object : objects) {
        ProgressManager.checkCanceled();
        current++;
        if (indicator != null) {
            indicator.setFraction((double) current / objects.size());
        }
        if (shouldSkipObjectProcessing(object)) {
            newObjects.add(object.getContent());
            state.incrementSkipped();
            continue;
        }
        ProcessObjectResult result = processObject(object, new ExtendedCallable<>() {

            @Override
            public String describe() {
                return object.getName() + "(" + object.getOid() + ")";
            }

            @Override
            public ProcessObjectResult call() throws Exception {
                return processObject(object);
            }
        });
        if (!result.shouldContinue()) {
            state.setStopOnError();
            stop = true;
            break;
        }
        MidPointObject newObject = result.object();
        if (newObject != null) {
            newObjects.add(newObject.getContent());
        }
    }
    return new ProcessFileObjectsResult(newObjects, stop);
}
Also used : MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ProcessObjectResult(com.evolveum.midpoint.studio.action.transfer.ProcessObjectResult)

Example 14 with MidPointObject

use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.

the class ObjectsBackgroundableTask method processFile.

protected boolean processFile(VirtualFile file) {
    try {
        List<MidPointObject> objects = loadObjectsFromFile(file);
        ProcessFileObjectsResult result = processObjects(null, objects, file);
        List<String> newObjects = result.getNewObjects();
        boolean checkChanges = false;
        if (objects.size() == newObjects.size()) {
            for (int i = 0; i < objects.size(); i++) {
                MidPointObject object = objects.get(i);
                if (!Objects.equals(object.getContent(), newObjects.get(i))) {
                    checkChanges = true;
                    break;
                }
            }
        }
        if (checkChanges && isUpdateObjectAfterProcessing()) {
            writeObjectsToFile(file, newObjects);
        }
        if (result.isStop()) {
            state.incrementProcessedFile();
            return false;
        }
    } catch (Exception ex) {
        state.incrementSkippedFile();
        midPointService.printToConsole(null, getClass(), "Couldn't process file " + (file != null ? file.getPath() : "<unknown>") + ", reason: " + ex.getMessage(), ex);
    }
    state.incrementProcessedFile();
    return true;
}
Also used : MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) IOException(java.io.IOException)

Example 15 with MidPointObject

use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.

the class VerifyAction method processFiles.

private void processFiles(AnActionEvent evt, MidPointService mm, Environment env, List<VirtualFile> files) {
    ObjectValidator validator = new ObjectValidator(MidPointUtils.DEFAULT_PRISM_CONTEXT);
    validator.setAllWarnings();
    MidPointClient client = new MidPointClient(evt.getProject(), env);
    for (VirtualFile file : files) {
        RunnableUtils.runReadAction(() -> {
            try {
                List<MidPointObject> objects = MidPointUtils.parseProjectFile(evt.getProject(), file, NOTIFICATION_KEY);
                for (MidPointObject obj : objects) {
                    try {
                        PrismObject object = client.parseObject(obj.getContent());
                        ValidationResult validationResult = validator.validate(object);
                        for (ValidationItem validationItem : validationResult.getItems()) {
                            String msg = buildValidationItem(object, validationItem);
                            mm.printToConsole(env, VerifyAction.class, msg);
                        }
                    } catch (Exception ex) {
                        mm.printToConsole(env, VerifyAction.class, "Couldn't parse object '" + obj.getName() + "'(" + obj.getType() + ") from file '" + file.getPath() + "', reason: " + ex.getMessage());
                    }
                }
            } catch (Exception ex) {
                mm.printToConsole(env, VerifyAction.class, "Couldn't parse objects from file '" + file.getPath() + "', reason: " + ex.getMessage());
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PrismObject(com.evolveum.midpoint.prism.PrismObject) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) ValidationItem(com.evolveum.midpoint.schema.validator.ValidationItem) ObjectValidator(com.evolveum.midpoint.schema.validator.ObjectValidator) ValidationResult(com.evolveum.midpoint.schema.validator.ValidationResult) IOException(java.io.IOException)

Aggregations

MidPointObject (com.evolveum.midpoint.studio.client.MidPointObject)16 IOException (java.io.IOException)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 ArrayList (java.util.ArrayList)6 Environment (com.evolveum.midpoint.studio.impl.Environment)5 MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 SearchResult (com.evolveum.midpoint.studio.client.SearchResult)4 ProcessObjectResult (com.evolveum.midpoint.studio.action.transfer.ProcessObjectResult)3 SearchOptions (com.evolveum.midpoint.studio.impl.SearchOptions)3 MidPointUtils (com.evolveum.midpoint.studio.util.MidPointUtils)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)3 NotificationType (com.intellij.notification.NotificationType)3 ControlFlowException (com.intellij.openapi.diagnostic.ControlFlowException)3 Logger (com.intellij.openapi.diagnostic.Logger)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 Project (com.intellij.openapi.project.Project)3 Writer (java.io.Writer)3 List (java.util.List)3