Search in sources :

Example 1 with ControlFlowException

use of com.intellij.openapi.diagnostic.ControlFlowException in project midpoint-studio by Evolveum.

the class ConnectorXmlSchemaCacheService method getSchema.

public XmlFile getSchema(String url, XmlFile file) {
    if (url == null || (!SchemaConstantsGenerated.NS_ICF_CONFIGURATION.equals(url) && !url.startsWith(ICF_NS_PREFIX))) {
        return null;
    }
    XmlTag rootTag = file.getRootTag();
    QName root = MidPointUtils.createQName(rootTag);
    if (DOMUtil.XSD_SCHEMA_ELEMENT.equals(root)) {
        String fileName = file.getVirtualFile().getName();
        String uuid = fileName.replaceFirst("^connector-", "").replaceFirst("-schema.xsd$", "");
        if (MidPointUtils.UUID_PATTERN.matcher(uuid).matches()) {
            return getSchema(url, uuid);
        }
    }
    if (SchemaConstants.C_OBJECTS.equals(root)) {
        XmlTag[] tags = rootTag.getSubTags();
        if (tags.length > 0) {
            rootTag = tags[0];
            root = MidPointUtils.createQName(rootTag);
        }
    }
    if (!SchemaConstantsGenerated.C_RESOURCE.equals(root) && !isResourceUsingXsi(rootTag)) {
        return null;
    }
    XmlTag connectorRef = MidPointUtils.findSubTag(rootTag, ResourceType.F_CONNECTOR_REF);
    if (connectorRef == null) {
        return null;
    }
    String oid = connectorRef.getAttributeValue("oid", SchemaConstantsGenerated.NS_COMMON);
    if (oid != null) {
        List<ConnectorType> keys = cache.keySet().stream().filter(c -> oid.equals(c.getOid())).collect(Collectors.toList());
        if (keys.size() != 1) {
            return null;
        }
        CacheValue value = cache.get(keys.get(0));
        return getSchema(url, value);
    }
    XmlTag filter = MidPointUtils.findSubTag(connectorRef, ObjectReferenceType.F_FILTER);
    RunnableUtils.PluginClassCallable<XmlFile> callable = new RunnableUtils.PluginClassCallable<>() {

        @Override
        public XmlFile callWithPluginClassLoader() throws Exception {
            ObjectFilter of = null;
            try {
                String xml = updateNamespaces(filter);
                PrismContext ctx = MidPointUtils.DEFAULT_PRISM_CONTEXT;
                PrismParser parser = ClientUtils.createParser(ctx, xml);
                SearchFilterType filterType = parser.parseRealValue(SearchFilterType.class);
                of = ctx.getQueryConverter().parseFilter(filterType, ConnectorType.class);
            } catch (Exception ex) {
                LOG.debug("Couldn't parse connectorRef filter defined in resource, reason: " + ex.getMessage() + "(" + ex.getClass().getName() + ")");
            }
            if (of == null) {
                return null;
            }
            // todo check if this for-cycle returns more than one result -> more connector matches filter, throw some error
            for (Map.Entry<ConnectorType, CacheValue> e : cache.entrySet()) {
                try {
                    boolean match = ObjectQuery.match(e.getKey(), of, MATCHING_REGISTRY);
                    if (!match) {
                        continue;
                    }
                } catch (SchemaException ex) {
                    LOG.error("Couldn't match connector with connectorRef filter defined in resource", ex);
                }
                return getSchema(url, e.getValue());
            }
            return null;
        }
    };
    try {
        return callable.call();
    } catch (Exception ex) {
        if (!(ex instanceof ControlFlowException)) {
            LOG.error("Couldn't find connector schema", ex);
        }
    }
    return null;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) XmlFile(com.intellij.psi.xml.XmlFile) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RunnableUtils(com.evolveum.midpoint.studio.util.RunnableUtils) XMLLanguage(com.intellij.lang.xml.XMLLanguage) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) StringUtils(org.apache.commons.lang3.StringUtils) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) Environment(com.evolveum.midpoint.studio.impl.Environment) DOMUtil(com.evolveum.midpoint.util.DOMUtil) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SchemaConstantsGenerated(com.evolveum.midpoint.schema.SchemaConstantsGenerated) PrismContext(com.evolveum.midpoint.prism.PrismContext) Document(org.w3c.dom.Document) Map(java.util.Map) Project(com.intellij.openapi.project.Project) AppExecutorUtil(com.intellij.util.concurrency.AppExecutorUtil) Logger(com.intellij.openapi.diagnostic.Logger) XMLConstants(javax.xml.XMLConstants) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ClientUtils(com.evolveum.midpoint.studio.client.ClientUtils) SearchResult(com.evolveum.midpoint.studio.client.SearchResult) XmlTag(com.intellij.psi.xml.XmlTag) PrismParser(com.evolveum.midpoint.prism.PrismParser) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PrismObject(com.evolveum.midpoint.prism.PrismObject) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) Collectors(java.util.stream.Collectors) MidPointUtils(com.evolveum.midpoint.studio.util.MidPointUtils) MatchingRuleRegistryFactory(com.evolveum.midpoint.prism.impl.match.MatchingRuleRegistryFactory) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) List(java.util.List) Element(org.w3c.dom.Element) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) Optional(java.util.Optional) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) XmlFile(com.intellij.psi.xml.XmlFile) ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException) QName(javax.xml.namespace.QName) PrismContext(com.evolveum.midpoint.prism.PrismContext) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) RunnableUtils(com.evolveum.midpoint.studio.util.RunnableUtils) PrismParser(com.evolveum.midpoint.prism.PrismParser) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) XmlTag(com.intellij.psi.xml.XmlTag)

Example 2 with ControlFlowException

use of com.intellij.openapi.diagnostic.ControlFlowException in project tabnine-intellij by codota.

the class LimitExceededLookupElement method handleInlayCreation.

private void handleInlayCreation(AtomicReference<Inlay> inlayHolder, AtomicBoolean documentChanged, Editor editor, int inlayOffset) {
    // get the inlay and hover popup data
    HoverBinaryResponse hoverBinaryResponse = this.binaryRequestFacade.executeRequest(new HoverBinaryRequest());
    if (hoverBinaryResponse == null || hoverBinaryResponse.getTitle() == null || documentChanged.get()) {
        return;
    }
    // inlay must be added from UI thread
    ApplicationManager.getApplication().invokeLater(() -> {
        try {
            addInlay(editor, inlayOffset, inlayHolder, documentChanged, hoverBinaryResponse);
        } catch (Exception e) {
            if (e instanceof ControlFlowException) {
                throw e;
            }
            Logger.getInstance(getClass()).warn("Error adding locked item inlay.", e);
        }
    });
}
Also used : ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException) HoverBinaryRequest(com.tabnine.binary.requests.notifications.HoverBinaryRequest) ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException) HoverBinaryResponse(com.tabnine.binary.requests.notifications.HoverBinaryResponse)

Example 3 with ControlFlowException

use of com.intellij.openapi.diagnostic.ControlFlowException in project tabnine-intellij by codota.

the class LimitExceededLookupElement method tryAddLimitExceededInlay.

private void tryAddLimitExceededInlay(Editor editor, int caretOffset, AtomicReference<Inlay> inlayHolder, AtomicBoolean documentChanged) {
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        try {
            final Document document = editor.getDocument();
            // add the inlay at the end of the line. Ideally we would use
            // 'addAfterLineEndElement' but that's
            // only available from IJ > 191.
            final int currentLineNumber = document.getLineNumber(caretOffset);
            final int inlayOffset = document.getLineEndOffset(currentLineNumber);
            if (isInlayAlreadyDisplayed(editor, inlayOffset, currentLineNumber)) {
                // inlay already displayed at the end of this line - don't add another one.
                return;
            }
            handleInlayCreation(inlayHolder, documentChanged, editor, inlayOffset);
        } catch (Exception e) {
            if (e instanceof ControlFlowException) {
                throw e;
            }
            Logger.getInstance(getClass()).warn("Error on locked item selection.", e);
        }
    });
}
Also used : ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException) Document(com.intellij.openapi.editor.Document) ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException)

Aggregations

ControlFlowException (com.intellij.openapi.diagnostic.ControlFlowException)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismParser (com.evolveum.midpoint.prism.PrismParser)1 MatchingRuleRegistryFactory (com.evolveum.midpoint.prism.impl.match.MatchingRuleRegistryFactory)1 MatchingRuleRegistry (com.evolveum.midpoint.prism.match.MatchingRuleRegistry)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 SchemaConstantsGenerated (com.evolveum.midpoint.schema.SchemaConstantsGenerated)1 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)1 ClientUtils (com.evolveum.midpoint.studio.client.ClientUtils)1 MidPointObject (com.evolveum.midpoint.studio.client.MidPointObject)1 SearchResult (com.evolveum.midpoint.studio.client.SearchResult)1 Environment (com.evolveum.midpoint.studio.impl.Environment)1 MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)1 MidPointUtils (com.evolveum.midpoint.studio.util.MidPointUtils)1 RunnableUtils (com.evolveum.midpoint.studio.util.RunnableUtils)1 DOMUtil (com.evolveum.midpoint.util.DOMUtil)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)1