Search in sources :

Example 1 with AzureSdkServiceEntity

use of com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity in project azure-tools-for-java by Microsoft.

the class AzureSdkTreePanel method loadData.

private void loadData(final Map<String, List<AzureSdkCategoryEntity>> categoryToServiceMap, final List<? extends AzureSdkServiceEntity> services, String... filters) {
    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.model.getRoot();
    root.removeAllChildren();
    final Map<String, AzureSdkServiceEntity> serviceMap = services.stream().collect(Collectors.toMap(e -> getServiceKeyByName(e.getName()), e -> e));
    final List<String> categories = categoryToServiceMap.keySet().stream().filter(StringUtils::isNotBlank).sorted((s1, s2) -> StringUtils.contains(s1, "Others") ? 1 : StringUtils.contains(s2, "Others") ? -1 : s1.compareTo(s2)).collect(Collectors.toList());
    for (final String category : categories) {
        // no feature found for current category
        if (CollectionUtils.isEmpty(categoryToServiceMap.get(category)) || categoryToServiceMap.get(category).stream().allMatch(e -> Objects.isNull(serviceMap.get(getServiceKeyByName(e.getServiceName()))) || CollectionUtils.isEmpty(serviceMap.get(getServiceKeyByName(e.getServiceName())).getContent()))) {
            continue;
        }
        // add features for current category
        final MutableTreeNode categoryNode = new DefaultMutableTreeNode(category);
        final boolean categoryMatched = this.isMatchedFilters(category, filters);
        categoryToServiceMap.get(category).stream().sorted(Comparator.comparing(AzureSdkCategoryEntity::getServiceName)).forEach(categoryService -> {
            final AzureSdkServiceEntity service = serviceMap.get(getServiceKeyByName(categoryService.getServiceName()));
            this.loadServiceData(service, categoryService, categoryNode, filters);
        });
        if (ArrayUtils.isEmpty(filters) || categoryMatched || categoryNode.getChildCount() > 0) {
            this.model.insertNodeInto(categoryNode, root, root.getChildCount());
        }
    }
    this.model.reload();
    if (ArrayUtils.isNotEmpty(filters)) {
        TreeUtil.expandAll(this.tree);
    }
    TreeUtil.promiseSelectFirstLeaf(this.tree);
}
Also used : Arrays(java.util.Arrays) AllIcons(com.intellij.icons.AllIcons) AzureSdkCategoryService(com.microsoft.azure.toolkit.intellij.azuresdk.service.AzureSdkCategoryService) Presentation(com.intellij.openapi.actionSystem.Presentation) StringUtils(org.apache.commons.lang3.StringUtils) Map(java.util.Map) CommonActionsManager(com.intellij.ide.CommonActionsManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreePath(javax.swing.tree.TreePath) TailingDebouncer(com.microsoft.azure.toolkit.lib.common.utils.TailingDebouncer) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Collectors(java.util.stream.Collectors) DefaultTreeExpander(com.intellij.ide.DefaultTreeExpander) MutableTreeNode(javax.swing.tree.MutableTreeNode) JBScrollPane(com.intellij.ui.components.JBScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Objects(java.util.Objects) IdeBundle(com.intellij.ide.IdeBundle) RelativeFont(com.intellij.ui.RelativeFont) List(java.util.List) SimpleTree(com.intellij.ui.treeStructure.SimpleTree) ActionPlaces(com.intellij.openapi.actionSystem.ActionPlaces) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Optional(java.util.Optional) TextDocumentListenerAdapter(com.microsoft.azure.toolkit.intellij.common.TextDocumentListenerAdapter) NotNull(org.jetbrains.annotations.NotNull) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) Setter(lombok.Setter) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Getter(lombok.Getter) ActionToolbarImpl(com.intellij.openapi.actionSystem.impl.ActionToolbarImpl) SearchTextField(com.intellij.ui.SearchTextField) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AzureSdkLibraryService(com.microsoft.azure.toolkit.intellij.azuresdk.service.AzureSdkLibraryService) ActivityTracker(com.intellij.ide.ActivityTracker) Tree(com.intellij.ui.treeStructure.Tree) TreeUtil(com.intellij.util.ui.tree.TreeUtil) AnimatedIcon(com.intellij.ui.AnimatedIcon) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) IOException(java.io.IOException) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) RenderingUtil(com.intellij.ui.render.RenderingUtil) Consumer(java.util.function.Consumer) AzureSdkFeatureEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) Comparator(java.util.Comparator) javax.swing(javax.swing) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StringUtils(org.apache.commons.lang3.StringUtils) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 2 with AzureSdkServiceEntity

use of com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity in project azure-tools-for-java by Microsoft.

the class AzureSdkLibraryService method addClientLibs.

private static void addClientLibs(Map<String, AzureSdkServiceEntity> services) {
    getClientLibs().stream().sorted(Comparator.comparing(AzureJavaSdkEntity::getServiceName)).forEachOrdered(raw -> {
        final AzureSdkServiceEntity service = getOrCreateService(services, raw);
        for (final AzureSdkFeatureEntity feature : service.getContent()) {
            final boolean specified = Optional.ofNullable(feature.getClientSource()).filter(s -> s.getGroupId().equals(raw.getGroupId()) && s.getArtifactId().equals(raw.getArtifactId())).isPresent();
            final boolean sameFeatureName = trim(feature.getName()).equals(trim(raw.getDisplayName()));
            if (specified || sameFeatureName) {
                feature.getArtifacts().add(toSdkArtifactEntity(raw));
                return;
            }
        }
        // if no mapping feature found.
        final AzureSdkFeatureEntity feature = AzureSdkFeatureEntity.builder().name(raw.getDisplayName()).msdocs(raw.getMsdocsUrl()).artifacts(new ArrayList<>(Collections.singletonList(toSdkArtifactEntity(raw)))).build();
        service.getContent().add(feature);
    });
}
Also used : java.util(java.util) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) SneakyThrows(lombok.SneakyThrows) URL(java.net.URL) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) AzureSdkAllowListEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkAllowListEntity) CacheEvict(com.microsoft.azure.toolkit.lib.common.cache.CacheEvict) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) CacheManager(com.microsoft.azure.toolkit.lib.common.cache.CacheManager) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable) Preload(com.microsoft.azure.toolkit.lib.common.cache.Preload) Nonnull(javax.annotation.Nonnull) AzureSdkArtifactEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) ImmutableMap(com.google.common.collect.ImmutableMap) MalformedURLException(java.net.MalformedURLException) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) AzureJavaSdkEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureJavaSdkEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Slf4j(lombok.extern.slf4j.Slf4j) AzureSdkFeatureEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) AzureJavaSdkEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureJavaSdkEntity) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) AzureSdkFeatureEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity)

Example 3 with AzureSdkServiceEntity

use of com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity in project azure-tools-for-java by Microsoft.

the class AzureSdkLibraryService method addManagementLibs.

private static void addManagementLibs(Map<String, AzureSdkServiceEntity> services) {
    getManagementLibs().stream().sorted(Comparator.comparing(AzureJavaSdkEntity::getServiceName)).forEachOrdered(raw -> {
        final AzureSdkServiceEntity service = getOrCreateService(services, raw);
        for (final AzureSdkFeatureEntity feature : service.getContent()) {
            feature.setName(feature.getName().replace("Resource Management - ", "").trim());
            feature.getArtifacts().add(toSdkArtifactEntity(raw));
        }
    });
}
Also used : AzureJavaSdkEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureJavaSdkEntity) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) AzureSdkFeatureEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity)

Example 4 with AzureSdkServiceEntity

use of com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity in project azure-tools-for-java by Microsoft.

the class AzureSdkTreePanel method fillDescriptionFromCategoryIfMissing.

private void fillDescriptionFromCategoryIfMissing(final Map<String, List<AzureSdkCategoryEntity>> categoryToServiceMap, final List<? extends AzureSdkServiceEntity> services) {
    final Map<String, AzureSdkServiceEntity> serviceMap = services.stream().collect(Collectors.toMap(e -> getServiceKeyByName(e.getName()), e -> e));
    categoryToServiceMap.forEach((category, categoryServices) -> categoryServices.forEach(categoryService -> Optional.ofNullable(serviceMap.get(getServiceKeyByName(categoryService.getServiceName()))).ifPresent(service -> {
        for (final AzureSdkFeatureEntity feature : service.getContent()) {
            if (StringUtils.isBlank(feature.getDescription()) && StringUtils.isNotBlank(categoryService.getDescription())) {
                feature.setDescription(categoryService.getDescription());
            }
        }
    })));
}
Also used : Arrays(java.util.Arrays) AllIcons(com.intellij.icons.AllIcons) AzureSdkCategoryService(com.microsoft.azure.toolkit.intellij.azuresdk.service.AzureSdkCategoryService) Presentation(com.intellij.openapi.actionSystem.Presentation) StringUtils(org.apache.commons.lang3.StringUtils) Map(java.util.Map) CommonActionsManager(com.intellij.ide.CommonActionsManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreePath(javax.swing.tree.TreePath) TailingDebouncer(com.microsoft.azure.toolkit.lib.common.utils.TailingDebouncer) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Collectors(java.util.stream.Collectors) DefaultTreeExpander(com.intellij.ide.DefaultTreeExpander) MutableTreeNode(javax.swing.tree.MutableTreeNode) JBScrollPane(com.intellij.ui.components.JBScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Objects(java.util.Objects) IdeBundle(com.intellij.ide.IdeBundle) RelativeFont(com.intellij.ui.RelativeFont) List(java.util.List) SimpleTree(com.intellij.ui.treeStructure.SimpleTree) ActionPlaces(com.intellij.openapi.actionSystem.ActionPlaces) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Optional(java.util.Optional) TextDocumentListenerAdapter(com.microsoft.azure.toolkit.intellij.common.TextDocumentListenerAdapter) NotNull(org.jetbrains.annotations.NotNull) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) Setter(lombok.Setter) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Getter(lombok.Getter) ActionToolbarImpl(com.intellij.openapi.actionSystem.impl.ActionToolbarImpl) SearchTextField(com.intellij.ui.SearchTextField) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AzureSdkLibraryService(com.microsoft.azure.toolkit.intellij.azuresdk.service.AzureSdkLibraryService) ActivityTracker(com.intellij.ide.ActivityTracker) Tree(com.intellij.ui.treeStructure.Tree) TreeUtil(com.intellij.util.ui.tree.TreeUtil) AnimatedIcon(com.intellij.ui.AnimatedIcon) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) IOException(java.io.IOException) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) RenderingUtil(com.intellij.ui.render.RenderingUtil) Consumer(java.util.function.Consumer) AzureSdkFeatureEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) Comparator(java.util.Comparator) javax.swing(javax.swing) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) AzureSdkFeatureEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity)

Example 5 with AzureSdkServiceEntity

use of com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity in project azure-tools-for-java by Microsoft.

the class AzureSdkLibraryService method loadSpringSDKEntities.

public static List<AzureSdkServiceEntity> loadSpringSDKEntities(final URL destination) {
    try {
        final ObjectReader reader = YML_MAPPER.readerFor(AzureSdkServiceEntity.class);
        final MappingIterator<AzureSdkServiceEntity> data = reader.readValues(destination);
        return data.readAll();
    } catch (final IOException e) {
        log.warn(String.format("failed to load Azure SDK list from \"%s\"", destination.toString()), e);
    }
    return Collections.emptyList();
}
Also used : AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException)

Aggregations

AzureSdkServiceEntity (com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity)5 AzureSdkFeatureEntity (com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity)4 IOException (java.io.IOException)4 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)3 Collectors (java.util.stream.Collectors)3 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)2 AllIcons (com.intellij.icons.AllIcons)2 ActivityTracker (com.intellij.ide.ActivityTracker)2 CommonActionsManager (com.intellij.ide.CommonActionsManager)2 DefaultTreeExpander (com.intellij.ide.DefaultTreeExpander)2 IdeBundle (com.intellij.ide.IdeBundle)2 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)2 ActionPlaces (com.intellij.openapi.actionSystem.ActionPlaces)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2 Presentation (com.intellij.openapi.actionSystem.Presentation)2 ActionToolbarImpl (com.intellij.openapi.actionSystem.impl.ActionToolbarImpl)2 AnimatedIcon (com.intellij.ui.AnimatedIcon)2 RelativeFont (com.intellij.ui.RelativeFont)2 SearchTextField (com.intellij.ui.SearchTextField)2