use of com.microsoft.azure.toolkit.lib.common.cache.Cacheable 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.lib.common.cache.Cacheable in project azure-tools-for-java by Microsoft.
the class AzureSdkLibraryService method loadAzureSDKWhitelist.
@Cacheable("sdk/packages/whitelist")
@AzureOperation(name = "sdk.load_meta_data.whitelist", type = AzureOperation.Type.TASK)
private static Set<String> loadAzureSDKWhitelist() {
try {
final URL destination = AzureSdkLibraryService.class.getResource(SDK_ALLOW_LIST_CSV);
final ObjectReader reader = CSV_MAPPER.readerFor(AzureSdkAllowListEntity.class).with(CsvSchema.emptySchema().withHeader());
final MappingIterator<AzureSdkAllowListEntity> data = reader.readValues(destination);
return data.readAll().stream().filter(e -> StringUtils.isNoneBlank(e.getArtifactId(), e.getGroupId())).map(AzureSdkAllowListEntity::getPackageName).collect(Collectors.toSet());
} catch (final IOException e) {
log.warn(String.format("failed to load Azure SDK allow list from \"%s\"", SDK_ALLOW_LIST_CSV), e);
}
return Collections.emptySet();
}
Aggregations