Skip to content

Commit a6f620b

Browse files
committed
Handling IOException while fetch meta data and migrate to javax annotation
1 parent 8a645f6 commit a6f620b

File tree

1 file changed

+29
-31
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/service

1 file changed

+29
-31
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/service/WorkspaceTaggingService.java

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import com.microsoft.azure.toolkit.lib.common.cache.Preload;
1919
import org.apache.commons.lang3.ObjectUtils;
2020
import org.apache.commons.lang3.StringUtils;
21-
import org.jetbrains.annotations.Nullable;
2221

22+
import javax.annotation.Nonnull;
23+
import javax.annotation.Nullable;
2324
import java.io.IOException;
2425
import java.io.InputStream;
2526
import java.net.URL;
27+
import java.util.Collections;
2628
import java.util.List;
2729

2830
public class WorkspaceTaggingService {
@@ -33,57 +35,53 @@ public class WorkspaceTaggingService {
3335
private static final String WORKSPACE_TAG_JSON = "/workspaceTag.json";
3436

3537
@Nullable
36-
public static String getWorkspaceTag(String groupId, final String artifactId) {
38+
public static String getWorkspaceTag(@Nonnull String groupId, @Nonnull final String artifactId) {
3739
if (StringUtils.isAnyEmpty(groupId, artifactId)) {
3840
return null;
3941
}
4042
return ObjectUtils.firstNonNull(getAzureDependencyTag(groupId, artifactId), getExternalDependencyTag(groupId, artifactId));
4143
}
4244

4345
private static String getAzureDependencyTag(final String groupId, final String artifactId) {
44-
try {
45-
return getAzureSDKEntities()
46-
.stream()
47-
.filter(entity -> StringUtils.isNotEmpty(entity.getType())
48-
&& StringUtils.equalsIgnoreCase(entity.getGroupId(), groupId)
49-
&& StringUtils.equalsIgnoreCase(entity.getPackageName(), artifactId))
50-
.map(AzureJavaSdkEntity::getType)
51-
.findFirst().orElse(null);
52-
} catch (IOException e) {
53-
// swallow exception for workspace tagging
54-
return null;
55-
}
46+
return getAzureSDKEntities()
47+
.stream()
48+
.filter(entity -> StringUtils.isNotEmpty(entity.getType())
49+
&& StringUtils.equalsIgnoreCase(entity.getGroupId(), groupId)
50+
&& StringUtils.equalsIgnoreCase(entity.getPackageName(), artifactId))
51+
.map(AzureJavaSdkEntity::getType)
52+
.findFirst().orElse(null);
5653
}
5754

5855
private static String getExternalDependencyTag(final String groupId, final String artifactId) {
59-
try {
60-
return getWorkspaceTagEntities()
61-
.stream()
62-
.filter(entity -> (StringUtils.isEmpty(entity.getGroupId()) || StringUtils.equalsIgnoreCase(entity.getGroupId(), groupId))
63-
&& (StringUtils.isEmpty(entity.getArtifactId()) || StringUtils.equalsIgnoreCase(entity.getArtifactId(), artifactId)))
64-
.map(WorkspaceTagEntity::getTag)
65-
.findFirst().orElse(null);
66-
} catch (IOException e) {
67-
// swallow exception for workspace tagging
68-
return null;
69-
}
56+
return getWorkspaceTagEntities()
57+
.stream()
58+
.filter(entity -> (StringUtils.isEmpty(entity.getGroupId()) || StringUtils.equalsIgnoreCase(entity.getGroupId(), groupId))
59+
&& (StringUtils.isEmpty(entity.getArtifactId()) || StringUtils.equalsIgnoreCase(entity.getArtifactId(), artifactId)))
60+
.map(WorkspaceTagEntity::getTag)
61+
.findFirst().orElse(null);
7062
}
7163

7264
@Preload
7365
@Cacheable(value = "workspace-tag", condition = "!(force&&force[0])")
74-
public static List<WorkspaceTagEntity> getWorkspaceTagEntities(boolean... force) throws IOException {
66+
public static List<WorkspaceTagEntity> getWorkspaceTagEntities(boolean... force) {
7567
try (final InputStream stream = WorkspaceTaggingService.class.getResourceAsStream(WORKSPACE_TAG_JSON)) {
7668
final MappingIterator<WorkspaceTagEntity> iterator = JSON_MAPPER.readerFor(WorkspaceTagEntity.class).readValues(stream);
7769
return iterator.readAll();
70+
} catch (IOException exception) {
71+
return Collections.emptyList();
7872
}
7973
}
8074

8175
@Preload
8276
@Cacheable(value = "workspace-tag-azure", condition = "!(force&&force[0])")
83-
public static List<AzureJavaSdkEntity> getAzureSDKEntities(boolean... force) throws IOException {
84-
final URL destination = new URL(SDK_METADATA_URL);
85-
final CsvSchema schema = CsvSchema.emptySchema().withHeader();
86-
final MappingIterator<AzureJavaSdkEntity> mappingIterator = CSV_MAPPER.readerFor(AzureJavaSdkEntity.class).with(schema).readValues(destination);
87-
return mappingIterator.readAll();
77+
public static List<AzureJavaSdkEntity> getAzureSDKEntities(boolean... force) {
78+
try {
79+
final URL destination = new URL(SDK_METADATA_URL);
80+
final CsvSchema schema = CsvSchema.emptySchema().withHeader();
81+
final MappingIterator<AzureJavaSdkEntity> mappingIterator = CSV_MAPPER.readerFor(AzureJavaSdkEntity.class).with(schema).readValues(destination);
82+
return mappingIterator.readAll();
83+
} catch (IOException e) {
84+
return Collections.emptyList();
85+
}
8886
}
8987
}

0 commit comments

Comments
 (0)