Non-null check for updateResourcesUsage

This commit is contained in:
ViacheslavKlimov 2024-12-05 12:44:50 +02:00
parent f50789ebf3
commit a2ae5b06c0
2 changed files with 9 additions and 3 deletions

View File

@ -50,7 +50,8 @@ public class WidgetType extends BaseWidgetType {
@JsonIgnore
public JsonNode getDefaultConfig() {
return Optional.ofNullable(descriptor.get("defaultConfig"))
return Optional.ofNullable(descriptor)
.map(descriptor -> descriptor.get("defaultConfig"))
.filter(JsonNode::isTextual).map(JsonNode::asText)
.map(json -> {
try {

View File

@ -403,6 +403,9 @@ public class BaseResourceService extends AbstractCachedEntityService<ResourceInf
@Override
public boolean updateResourcesUsage(TenantId tenantId, Dashboard dashboard) {
if (dashboard.getConfiguration() == null) {
return false;
}
Map<String, String> links = getResourcesLinks(dashboard.getResources());
return updateResourcesUsage(tenantId, List.of(dashboard.getConfiguration()), List.of(DASHBOARD_RESOURCES_MAPPING), links);
}
@ -413,8 +416,10 @@ public class BaseResourceService extends AbstractCachedEntityService<ResourceInf
List<JsonNode> jsonNodes = new ArrayList<>(2);
List<Map<String, String>> mappings = new ArrayList<>(2);
jsonNodes.add(widgetTypeDetails.getDescriptor());
mappings.add(WIDGET_RESOURCES_MAPPING);
if (widgetTypeDetails.getDescriptor() != null) {
jsonNodes.add(widgetTypeDetails.getDescriptor());
mappings.add(WIDGET_RESOURCES_MAPPING);
}
JsonNode defaultConfig = widgetTypeDetails.getDefaultConfig();
if (defaultConfig != null) {