use of com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity 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);
}
use of com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity in project azure-tools-for-java by Microsoft.
the class AzureSdkCategoryService method loadAzureSDKCategories.
@Cacheable(value = "azure-sdk-category-entities")
@AzureOperation(name = "sdk.load_category_data", type = AzureOperation.Type.TASK)
public static Map<String, List<AzureSdkCategoryEntity>> loadAzureSDKCategories() {
try (final InputStream stream = AzureSdkCategoryService.class.getResourceAsStream(SERVICE_CATEGORY_CSV)) {
// read
final ObjectReader reader = CSV_MAPPER.readerFor(AzureSdkCategoryEntity.class).with(CsvSchema.emptySchema().withHeader());
final MappingIterator<AzureSdkCategoryEntity> data = reader.readValues(stream);
final List<AzureSdkCategoryEntity> categories = data.readAll();
// default category & description suffix.
categories.stream().filter(c -> StringUtils.isNotBlank(c.getServiceName())).forEach(c -> {
if (StringUtils.isBlank(c.getCategory())) {
c.setCategory("Others");
}
final String trimDescription = StringUtils.trim(c.getDescription());
if (StringUtils.isNotBlank(trimDescription) && !StringUtils.endsWith(trimDescription, ".")) {
c.setDescription(trimDescription + ".");
}
});
// unique
final List<AzureSdkCategoryEntity> uniqueCategories = categories.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getCategory() + "," + o.getServiceName()))), ArrayList::new));
// group
return uniqueCategories.stream().collect(Collectors.groupingBy(AzureSdkCategoryEntity::getCategory));
} catch (final IOException e) {
final String message = String.format("failed to load Azure SDK categories from \"%s\"", SERVICE_CATEGORY_CSV);
throw new AzureToolkitRuntimeException(message, e);
}
}
use of com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity 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());
}
}
})));
}
Aggregations