Search in sources :

Example 1 with MidPointService

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

the class ExtractLocalizationPropertiesAction method dumpToConsole.

private void dumpToConsole(Project project, Map<String, String> properties, Map<String, String> existing) {
    MidPointService ms = MidPointService.getInstance(project);
    StringBuilder sb = new StringBuilder();
    sb.append("Generated localization:\n");
    List<String> keys = new ArrayList<>();
    properties.keySet().forEach(k -> {
        if (existing != null && !existing.containsKey(k)) {
            keys.add(k);
        }
    });
    Collections.sort(keys);
    keys.forEach(k -> sb.append(k + "=" + properties.get(k)).append('\n'));
    ms.printToConsole(null, TestAction.class, sb.toString());
}
Also used : MidPointService(com.evolveum.midpoint.studio.impl.MidPointService)

Example 2 with MidPointService

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

the class FileUtils method createFile.

public static <O extends ObjectType> VirtualFile createFile(Project project, Environment env, Class<O> objectType, String oid, String objectName, boolean overwrite) throws IOException {
    Map<String, String> params = new HashMap<>();
    // environment short name
    params.put("s", env.getShortName());
    // environment name
    params.put("e", env.getName());
    MidPointService mm = MidPointService.getInstance(project);
    MidPointSettings settings = mm.getSettings();
    return createFile(project, params, objectType, oid, objectName, settings.getDowloadFilePattern(), null, overwrite);
}
Also used : MidPointService(com.evolveum.midpoint.studio.impl.MidPointService) HashMap(java.util.HashMap) MidPointSettings(com.evolveum.midpoint.studio.impl.MidPointSettings)

Example 3 with MidPointService

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

the class TraceViewEditor method initialize.

private void initialize() {
    OpNode root;
    long start = System.currentTimeMillis();
    LOG.info("Initializing TraceViewEditor");
    try (InputStream is = file.getInputStream()) {
        String extension = file.getExtension();
        boolean isZip = extension != null && extension.equalsIgnoreCase("zip");
        PrismContext prismContext = MidPointUtils.DEFAULT_PRISM_CONTEXT;
        TraceParser parser = new TraceParser(prismContext);
        TracingOutputType tracingOutput = parser.parse(is, isZip, file.getCanonicalPath());
        LOG.info("Initializing TraceViewEditor - parsed tracing output: " + (System.currentTimeMillis() - start) + " ms");
        StudioNameResolver nameResolver = new StudioNameResolver(tracingOutput.getDictionary(), file);
        List<OpNode> data = new OpNodeTreeBuilder(prismContext).build(tracingOutput, nameResolver);
        if (data.size() == 1) {
            root = data.get(0);
        } else {
            throw new IllegalStateException("Unexpected # of OpNode objects: " + data.size());
        }
        LOG.info("Initializing TraceViewEditor - built op node tree: " + (System.currentTimeMillis() - start) + " ms");
    } catch (Exception ex) {
        MidPointService mm = MidPointService.getInstance(project);
        mm.printToConsole(null, TraceViewEditor.class, "Couldn't load file", ex, ConsoleViewContentType.LOG_ERROR_OUTPUT);
        MidPointUtils.publishExceptionNotification(project, null, TraceViewEditor.class, NOTIFICATION_KEY, "Couldn't load file", ex);
        ex.printStackTrace();
        root = null;
    }
    if (root != null) {
        PresentationInitializer.initialize(root);
    }
    opTreePanel = new OpTreePanel(project, root);
    wrapper.setContent(opTreePanel);
}
Also used : TraceParser(com.evolveum.midpoint.schema.traces.TraceParser) OpNodeTreeBuilder(com.evolveum.midpoint.schema.traces.OpNodeTreeBuilder) InputStream(java.io.InputStream) PrismContext(com.evolveum.midpoint.prism.PrismContext) TracingOutputType(com.evolveum.midpoint.xml.ns._public.common.common_3.TracingOutputType) MidPointService(com.evolveum.midpoint.studio.impl.MidPointService) OpTreePanel(com.evolveum.midpoint.studio.ui.trace.mainTree.OpTreePanel) StudioNameResolver(com.evolveum.midpoint.studio.impl.trace.StudioNameResolver) OpNode(com.evolveum.midpoint.schema.traces.OpNode)

Example 4 with MidPointService

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

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

MidPointService (com.evolveum.midpoint.studio.impl.MidPointService)9 Environment (com.evolveum.midpoint.studio.impl.Environment)4 EnvironmentService (com.evolveum.midpoint.studio.impl.EnvironmentService)3 MidPointSettings (com.evolveum.midpoint.studio.impl.MidPointSettings)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 OpNode (com.evolveum.midpoint.schema.traces.OpNode)1 OpNodeTreeBuilder (com.evolveum.midpoint.schema.traces.OpNodeTreeBuilder)1 TraceParser (com.evolveum.midpoint.schema.traces.TraceParser)1 MidPointObject (com.evolveum.midpoint.studio.client.MidPointObject)1 DocGeneratorOptions (com.evolveum.midpoint.studio.impl.DocGeneratorOptions)1 ShowResultNotificationAction (com.evolveum.midpoint.studio.impl.ShowResultNotificationAction)1 StudioNameResolver (com.evolveum.midpoint.studio.impl.trace.StudioNameResolver)1