Search in sources :

Example 11 with EnvironmentService

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

Example 12 with EnvironmentService

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

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

the class EnvironmentListDialog method doOKAction.

@Override
protected void doOKAction() {
    super.doOKAction();
    EnvironmentService manager = EnvironmentService.getInstance(project);
    manager.setSettings(panel.getFullSettings());
}
Also used : EnvironmentService(com.evolveum.midpoint.studio.impl.EnvironmentService)

Example 14 with EnvironmentService

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

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

the class TestConnectionAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    super.update(e);
    Project project = e.getProject();
    if (project == null) {
        e.getPresentation().setEnabled(false);
        return;
    }
    boolean hasFacet = MidPointUtils.hasMidPointFacet(e.getProject());
    if (!hasFacet) {
        e.getPresentation().setEnabled(false);
        return;
    }
    EnvironmentService em = EnvironmentService.getInstance(project);
    Environment selected = em.getSelected();
    e.getPresentation().setEnabled(selected != null);
}
Also used : Project(com.intellij.openapi.project.Project) Environment(com.evolveum.midpoint.studio.impl.Environment) EnvironmentService(com.evolveum.midpoint.studio.impl.EnvironmentService)

Aggregations

EnvironmentService (com.evolveum.midpoint.studio.impl.EnvironmentService)19 Environment (com.evolveum.midpoint.studio.impl.Environment)12 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)4 MidPointService (com.evolveum.midpoint.studio.impl.MidPointService)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 File (java.io.File)3 IOException (java.io.IOException)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 Expander (com.evolveum.midpoint.studio.impl.Expander)2 RunnableUtils (com.evolveum.midpoint.studio.util.RunnableUtils)2 PsiFile (com.intellij.psi.PsiFile)2 NotNull (org.jetbrains.annotations.NotNull)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)1 SearchResultList (com.evolveum.midpoint.schema.SearchResultList)1 ComboQueryType (com.evolveum.midpoint.studio.action.browse.ComboQueryType)1 EncryptionService (com.evolveum.midpoint.studio.impl.EncryptionService)1