Fix ResourceService.getUsedResources; improve dashboard fields ordering
This commit is contained in:
parent
3124ad360d
commit
e79e5c8f8e
@ -606,7 +606,8 @@ public class DashboardControllerTest extends AbstractControllerTest {
|
|||||||
{"xxx":
|
{"xxx":
|
||||||
{"config":{"actions":{"elementClick":[
|
{"config":{"actions":{"elementClick":[
|
||||||
{"customResources":[{"url":{"entityType":"TB_RESOURCE","id":
|
{"customResources":[{"url":{"entityType":"TB_RESOURCE","id":
|
||||||
"tb-resource;/api/resource/js_module/tenant/gateway-management-extension.js"},"isModule":true}]}]}}}}
|
"tb-resource;/api/resource/js_module/tenant/gateway-management-extension.js"},"isModule":true},
|
||||||
|
{"url":"tb-resource;/api/resource/js_module/tenant/gateway-management-extension.js","isModule":true}]}]}}}}
|
||||||
""")));
|
""")));
|
||||||
dashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
|
dashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
|
||||||
|
|
||||||
|
|||||||
@ -84,9 +84,9 @@ public interface ResourceService extends EntityDaoService {
|
|||||||
|
|
||||||
boolean updateResourcesUsage(WidgetTypeDetails widgetTypeDetails);
|
boolean updateResourcesUsage(WidgetTypeDetails widgetTypeDetails);
|
||||||
|
|
||||||
List<TbResourceInfo> getUsedResources(Dashboard dashboard);
|
Collection<TbResourceInfo> getUsedResources(Dashboard dashboard);
|
||||||
|
|
||||||
List<TbResourceInfo> getUsedResources(WidgetTypeDetails widgetTypeDetails);
|
Collection<TbResourceInfo> getUsedResources(WidgetTypeDetails widgetTypeDetails);
|
||||||
|
|
||||||
TbResource createOrUpdateSystemResource(ResourceType resourceType, String resourceKey, byte[] data);
|
TbResource createOrUpdateSystemResource(ResourceType resourceType, String resourceKey, byte[] data);
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
package org.thingsboard.server.common.data;
|
package org.thingsboard.server.common.data;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.google.common.collect.Streams;
|
import com.google.common.collect.Streams;
|
||||||
@ -32,6 +33,7 @@ import java.util.Optional;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@JsonPropertyOrder({"title", "image", "mobileHide", "mobileOrder", "configuration", "name", "resources"})
|
||||||
public class Dashboard extends DashboardInfo implements ExportableEntity<DashboardId> {
|
public class Dashboard extends DashboardInfo implements ExportableEntity<DashboardId> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 872682138346187503L;
|
private static final long serialVersionUID = 872682138346187503L;
|
||||||
@ -68,7 +70,7 @@ public class Dashboard extends DashboardInfo implements ExportableEntity<Dashboa
|
|||||||
@Schema(description = "JSON object with main configuration of the dashboard: layouts, widgets, aliases, etc. " +
|
@Schema(description = "JSON object with main configuration of the dashboard: layouts, widgets, aliases, etc. " +
|
||||||
"The JSON structure of the dashboard configuration is quite complex. " +
|
"The JSON structure of the dashboard configuration is quite complex. " +
|
||||||
"The easiest way to learn it is to export existing dashboard to JSON."
|
"The easiest way to learn it is to export existing dashboard to JSON."
|
||||||
,implementation = com.fasterxml.jackson.databind.JsonNode.class)
|
, implementation = com.fasterxml.jackson.databind.JsonNode.class)
|
||||||
public JsonNode getConfiguration() {
|
public JsonNode getConfiguration() {
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
@ -111,4 +113,5 @@ public class Dashboard extends DashboardInfo implements ExportableEntity<Dashboa
|
|||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,6 @@ import org.thingsboard.server.dao.service.Validator;
|
|||||||
import org.thingsboard.server.dao.service.validator.ResourceDataValidator;
|
import org.thingsboard.server.dao.service.validator.ResourceDataValidator;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -461,22 +460,22 @@ public class BaseResourceService extends AbstractCachedEntityService<ResourceInf
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TbResourceInfo> getUsedResources(Dashboard dashboard) {
|
public Collection<TbResourceInfo> getUsedResources(Dashboard dashboard) {
|
||||||
return getUsedResources(dashboard.getTenantId(), dashboard.getConfiguration(), DASHBOARD_RESOURCES_MAPPING);
|
return getUsedResources(dashboard.getTenantId(), dashboard.getConfiguration(), DASHBOARD_RESOURCES_MAPPING).values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TbResourceInfo> getUsedResources(WidgetTypeDetails widgetTypeDetails) {
|
public Collection<TbResourceInfo> getUsedResources(WidgetTypeDetails widgetTypeDetails) {
|
||||||
List<TbResourceInfo> resources = getUsedResources(widgetTypeDetails.getTenantId(), widgetTypeDetails.getDescriptor(), WIDGET_RESOURCES_MAPPING);
|
Map<TbResourceId, TbResourceInfo> resources = getUsedResources(widgetTypeDetails.getTenantId(), widgetTypeDetails.getDescriptor(), WIDGET_RESOURCES_MAPPING);
|
||||||
JsonNode defaultConfig = widgetTypeDetails.getDefaultConfig();
|
JsonNode defaultConfig = widgetTypeDetails.getDefaultConfig();
|
||||||
if (defaultConfig != null) {
|
if (defaultConfig != null) {
|
||||||
resources.addAll(getUsedResources(widgetTypeDetails.getTenantId(), defaultConfig, WIDGET_DEFAULT_CONFIG_RESOURCES_MAPPING));
|
resources.putAll(getUsedResources(widgetTypeDetails.getTenantId(), defaultConfig, WIDGET_DEFAULT_CONFIG_RESOURCES_MAPPING));
|
||||||
}
|
}
|
||||||
return resources;
|
return resources.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TbResourceInfo> getUsedResources(TenantId tenantId, JsonNode jsonNode, Map<String, String> mapping) {
|
private Map<TbResourceId, TbResourceInfo> getUsedResources(TenantId tenantId, JsonNode jsonNode, Map<String, String> mapping) {
|
||||||
List<TbResourceInfo> resources = new ArrayList<>();
|
Map<TbResourceId, TbResourceInfo> resources = new HashMap<>();
|
||||||
processResources(jsonNode, mapping, value -> {
|
processResources(jsonNode, mapping, value -> {
|
||||||
String link = getResourceLink(value);
|
String link = getResourceLink(value);
|
||||||
if (link == null) {
|
if (link == null) {
|
||||||
@ -499,7 +498,7 @@ public class BaseResourceService extends AbstractCachedEntityService<ResourceInf
|
|||||||
|
|
||||||
TbResourceInfo resourceInfo = findResourceInfoByTenantIdAndKey(resourceTenantId, resourceType, resourceKey);
|
TbResourceInfo resourceInfo = findResourceInfoByTenantIdAndKey(resourceTenantId, resourceType, resourceKey);
|
||||||
if (resourceInfo != null) {
|
if (resourceInfo != null) {
|
||||||
resources.add(resourceInfo);
|
resources.putIfAbsent(resourceInfo.getId(), resourceInfo);
|
||||||
} else {
|
} else {
|
||||||
log.warn("[{}] Unknown resource referenced with '{}'", tenantId, value);
|
log.warn("[{}] Unknown resource referenced with '{}'", tenantId, value);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user