Search in sources :

Example 11 with Environment

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

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

the class SimpleBackgroundableTask method setupMidpointClient.

private MidPointClient setupMidpointClient() {
    logToConsole("Setting up MidPoint client");
    Environment env = getEnvironment();
    midPointService.printToConsole(env, getClass(), "Initializing '" + getTitle() + "' action");
    MidPointClient client = new MidPointClient(getProject(), env);
    logToConsole("MidPoint client setup done");
    return client;
}
Also used : MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) Environment(com.evolveum.midpoint.studio.impl.Environment)

Example 13 with Environment

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

the class BrowseToolPanel method searchPerformed.

private void searchPerformed(AnActionEvent evt, ProgressIndicator indicator) {
    LOG.debug("Clearing table");
    // clear result table
    updateTableModel(null);
    // load data
    EnvironmentService em = EnvironmentService.getInstance(evt.getProject());
    Environment env = em.getSelected();
    indicator.setText("Searching objects in environment: " + env.getName());
    SearchResultList result = null;
    try {
        LOG.debug("Setting up midpoint client");
        MidPointClient client = new MidPointClient(evt.getProject(), env);
        ObjectTypes type = objectType.getSelected();
        ObjectQuery query = buildQuery(client);
        LOG.debug("Starting search");
        result = client.list(type.getClassDefinition(), query, rawSearch);
    } catch (Exception ex) {
        handleGenericException(env, "Couldn't search objects", ex);
    }
    LOG.debug("Updating table");
    // update result table
    updateTableModel(result);
}
Also used : SearchResultList(com.evolveum.midpoint.schema.SearchResultList) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) Environment(com.evolveum.midpoint.studio.impl.Environment) EnvironmentService(com.evolveum.midpoint.studio.impl.EnvironmentService) ComboObjectTypes(com.evolveum.midpoint.studio.action.browse.ComboObjectTypes) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException)

Example 14 with Environment

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

the class BrowseToolPanel method processPerformed.

private void processPerformed(AnActionEvent evt) {
    String query = this.query.getText();
    ComboQueryType.Type queryType = this.queryType.getSelected();
    ObjectTypes type = this.objectType.getSelected();
    List<ObjectType> selected = getResultsModel().getSelectedObjects(results);
    if (ComboQueryType.Type.QUERY_XML != queryType && StringUtils.isNotEmpty(query)) {
        // translate query
        EnvironmentService em = EnvironmentService.getInstance(evt.getProject());
        Environment env = em.getSelected();
        try {
            LOG.debug("Setting up midpoint client");
            MidPointClient client = new MidPointClient(evt.getProject(), env);
            LOG.debug("Translating object query");
            ObjectQuery objectQuery = buildQuery(client);
            ObjectPaging paging = objectQuery.getPaging();
            if (paging != null) {
                // cleanup ordering, not necessary for bulk processing
                paging.setOrdering(new ObjectOrdering[0]);
            }
            PrismContext ctx = client.getPrismContext();
            QueryConverter converter = ctx.getQueryConverter();
            QueryType q = converter.createQueryType(objectQuery);
            RunnableUtils.PluginClassCallable<String> callable = new RunnableUtils.PluginClassCallable<>() {

                @Override
                public String callWithPluginClassLoader() throws Exception {
                    return ctx.serializerFor(PrismContext.LANG_XML).serializeRealValue(q);
                }
            };
            query = callable.call();
        } catch (Exception ex) {
            handleGenericException(env, "Couldn't serialize query", ex);
        }
    }
    ProcessResultsDialog dialog = new ProcessResultsDialog(processResultsOptions, query, type, selected);
    dialog.show();
    if (dialog.isOK() || dialog.isGenerate()) {
        processResultsOptions = dialog.buildOptions();
        performGenerate(evt, selected, processResultsOptions, !dialog.isGenerate());
    }
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) ComboObjectTypes(com.evolveum.midpoint.studio.action.browse.ComboObjectTypes) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) RunnableUtils(com.evolveum.midpoint.studio.util.RunnableUtils) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) ComboQueryType(com.evolveum.midpoint.studio.action.browse.ComboQueryType) Environment(com.evolveum.midpoint.studio.impl.Environment) EnvironmentService(com.evolveum.midpoint.studio.impl.EnvironmentService) ComboQueryType(com.evolveum.midpoint.studio.action.browse.ComboQueryType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 15 with Environment

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

the class BrowseToolPanel method createFilter.

private ObjectFilter createFilter(PrismContext ctx, boolean oid, boolean name) {
    String text = query.getText();
    if (StringUtils.isEmpty(text)) {
        return null;
    }
    List<String> filtered = new ArrayList<>();
    String[] items = text.split("\n");
    for (String item : items) {
        item = item.trim();
        if (StringUtils.isEmpty(item)) {
            continue;
        }
        filtered.add(item);
    }
    if (filtered.isEmpty()) {
        return null;
    }
    QueryFactory qf = ctx.queryFactory();
    OrFilter or = qf.createOr();
    if (oid) {
        List<String> filteredOids = filtered;
        if (name) {
            // if search by name or oid is used, filter out items that can't be used in oid filter
            filteredOids = filteredOids.stream().filter(s -> MidPointUtils.UUID_PATTERN.matcher(s).matches()).collect(Collectors.toList());
            if (filteredOids.size() != filtered.size()) {
                MidPointService ms = MidPointService.getInstance(project);
                EnvironmentService em = EnvironmentService.getInstance(project);
                Environment env = em.getSelected();
                ms.printToConsole(env, BrowseToolPanel.class, "Items in search filed that are not valid OIDs were filtered out (" + (filtered.size() - filteredOids.size()) + ").");
            }
        }
        if (!filteredOids.isEmpty()) {
            InOidFilter inOid = qf.createInOid(filteredOids);
            or.addCondition(inOid);
        }
    }
    if (name) {
        PrismPropertyDefinition def = ctx.getSchemaRegistry().findPropertyDefinitionByElementName(ObjectType.F_NAME);
        QName matchingRule = PrismConstants.POLY_STRING_NORM_MATCHING_RULE_NAME;
        List<ObjectFilter> filters = new ArrayList<>();
        for (String s : filtered) {
            ObjectFilter filter = Objects.equals(nameFilterType, Constants.Q_EQUAL_Q) ? EqualFilterImpl.createEqual(ctx.path(ObjectType.F_NAME), def, matchingRule, ctx, s) : SubstringFilterImpl.createSubstring(ctx.path(ObjectType.F_NAME), def, ctx, matchingRule, s, false, false);
            filters.add(filter);
        }
        OrFilter nameOr = qf.createOr(filters);
        or.addCondition(nameOr);
    }
    return or;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) MidPointService(com.evolveum.midpoint.studio.impl.MidPointService) Environment(com.evolveum.midpoint.studio.impl.Environment) EnvironmentService(com.evolveum.midpoint.studio.impl.EnvironmentService)

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