Search in sources :

Example 6 with MidPointClient

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

the class OperationResultDialog method saveResult.

private void saveResult(final Project project, ProgressIndicator indicator, final VirtualFileWrapper fileWrapper, OperationResult result) {
    MidPointService mm = MidPointService.getInstance(project);
    EnvironmentService em = EnvironmentService.getInstance(project);
    Environment environment = em.getSelected();
    RunnableUtils.runWriteActionAndWait(() -> {
        File file = fileWrapper.getFile();
        try {
            if (file.exists()) {
                file.delete();
            }
            file.createNewFile();
        } catch (IOException ex) {
            mm.printToConsole(environment, OperationResultDialog.class, "Couldn't create file " + file.getPath() + " for operation result", ex);
        }
        VirtualFile vFile = fileWrapper.getVirtualFile();
        try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(vFile.getOutputStream(this), vFile.getCharset()))) {
            MidPointClient client = new MidPointClient(project, environment);
            PrismContext ctx = client.getPrismContext();
            PrismSerializer<String> serializer = ctx.serializerFor(PrismContext.LANG_XML);
            String xml = serializer.serializeAnyData(result.createOperationResultType(), SchemaConstantsGenerated.C_OPERATION_RESULT);
            IOUtils.write(xml, out);
        } catch (IOException | SchemaException ex) {
            mm.printToConsole(environment, OperationResultDialog.class, "Couldn't create file " + file.getPath() + " for operation result", ex);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContext(com.evolveum.midpoint.prism.PrismContext) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) MidPointService(com.evolveum.midpoint.studio.impl.MidPointService) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) Environment(com.evolveum.midpoint.studio.impl.Environment) EnvironmentService(com.evolveum.midpoint.studio.impl.EnvironmentService) OutputStreamWriter(java.io.OutputStreamWriter) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 7 with MidPointClient

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

the class EnvironmentEditorDialog method executeTestConnection.

private void executeTestConnection(Project project, JLabel testConnection) {
    Environment env = new Environment();
    populateEnvironment(env);
    try {
        MidPointClient client = new MidPointClient(project, env, settings);
        TestConnectionResult result = client.testConnection();
        if (result.success()) {
            updateInAwtThread(ConsoleViewContentType.NORMAL_OUTPUT_KEY.getDefaultAttributes().getForegroundColor(), "Version: " + result.version() + ", revision: " + result.revision());
        } else {
            String msg = result.exception() != null ? result.exception().getMessage() : null;
            updateInAwtThread(ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY.getDefaultAttributes().getForegroundColor(), msg);
        }
    } catch (Exception ex) {
        LOG.error("Couldn't test connection", ex);
        updateInAwtThread(ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY.getDefaultAttributes().getForegroundColor(), ex.getMessage());
    }
}
Also used : MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) Environment(com.evolveum.midpoint.studio.impl.Environment) TestConnectionResult(com.evolveum.midpoint.studio.client.TestConnectionResult)

Example 8 with MidPointClient

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

the class ConnectorXmlSchemaCacheService method refresh.

private void refresh(Environment env) {
    LOG.info("Invoking refresh");
    RunnableUtils.submitNonBlockingReadAction(() -> {
        LOG.info("Refreshing");
        cache.clear();
        if (env == null) {
            LOG.info("Refresh skipped, no environment selected");
            return;
        }
        MidPointClient client = new MidPointClient(project, env, true, true);
        SearchResult result = client.search(ConnectorType.class, null, true);
        for (MidPointObject object : result.getObjects()) {
            try {
                PrismObject<?> prismObject = client.parseObject(object.getContent());
                ConnectorType connectorType = (ConnectorType) prismObject.asObjectable();
                cache.put(connectorType, new CacheValue(connectorType, buildIcfSchema(object), buildConnectorSchema(object)));
            } catch (Exception ex) {
                if (ex instanceof ProcessCanceledException) {
                    throw (ProcessCanceledException) ex;
                }
                LOG.error("Couldn't parse connector object", ex);
            }
        }
        LOG.info("Refresh finished, " + cache.size() + " objects in cache");
    }, AppExecutorUtil.getAppExecutorService());
    LOG.info("Invoke done");
}
Also used : ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) SearchResult(com.evolveum.midpoint.studio.client.SearchResult) ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 9 with MidPointClient

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

the class TestAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent evt) {
    if (evt.getProject() == null) {
        return;
    }
    // Project project = evt.getProject();
    // 
    // ResourceWizard wizard = ResourceWizard.createWizard(project);
    // wizard.showAndGet();
    RunnableUtils.executeWithPluginClassloader(() -> {
        EnvironmentService es = EnvironmentService.getInstance(evt.getProject());
        MidPointClient client = new MidPointClient(evt.getProject(), es.getSelected(), true, true);
        Map<SchemaFileType, String> result = client.getExtensionSchemas();
        System.out.println(result);
        return result;
    });
}
Also used : MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) SchemaFileType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType) EnvironmentService(com.evolveum.midpoint.studio.impl.EnvironmentService)

Example 10 with MidPointClient

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

the class TestConnectionAction method testConnection.

private void testConnection(Project project, Environment environment) {
    try {
        MidPointClient client = new MidPointClient(project, environment);
        TestConnectionResult result = client.testConnection();
        String status = result.success() ? "was successful" : "failed";
        NotificationType type = result.success() ? NotificationType.INFORMATION : NotificationType.ERROR;
        String versionInfo = "";
        if (result.success()) {
            versionInfo = " Version: " + result.version() + ", build: " + result.revision() + ".";
        }
        NotificationAction action = null;
        if (result.exception() != null) {
            action = new ShowExceptionNotificationAction("Connection test exception for '" + environment.getName() + "'", result.exception(), TestConnectionAction.class, environment);
        }
        MidPointUtils.publishNotification(project, NOTIFICATION_KEY, "Test connection", "Connection test for '" + environment.getName() + "' " + status + "." + versionInfo, type, action);
    } catch (Exception ex) {
        MidPointUtils.publishExceptionNotification(project, environment, TestConnectionAction.class, NOTIFICATION_KEY, "Connection test for '" + environment.getName() + "' failed with exception", ex);
    }
}
Also used : ShowExceptionNotificationAction(com.evolveum.midpoint.studio.impl.ShowExceptionNotificationAction) ShowExceptionNotificationAction(com.evolveum.midpoint.studio.impl.ShowExceptionNotificationAction) NotificationAction(com.intellij.notification.NotificationAction) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) NotificationType(com.intellij.notification.NotificationType) TestConnectionResult(com.evolveum.midpoint.studio.client.TestConnectionResult)

Aggregations

MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)12 Environment (com.evolveum.midpoint.studio.impl.Environment)7 IOException (java.io.IOException)5 EnvironmentService (com.evolveum.midpoint.studio.impl.EnvironmentService)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 MidPointObject (com.evolveum.midpoint.studio.client.MidPointObject)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)2 ComboObjectTypes (com.evolveum.midpoint.studio.action.browse.ComboObjectTypes)2 TestConnectionResult (com.evolveum.midpoint.studio.client.TestConnectionResult)2 MidPointService (com.evolveum.midpoint.studio.impl.MidPointService)2 SchemaFileType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 SearchResultList (com.evolveum.midpoint.schema.SearchResultList)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ObjectValidator (com.evolveum.midpoint.schema.validator.ObjectValidator)1 ValidationItem (com.evolveum.midpoint.schema.validator.ValidationItem)1 ValidationResult (com.evolveum.midpoint.schema.validator.ValidationResult)1 ComboQueryType (com.evolveum.midpoint.studio.action.browse.ComboQueryType)1