|
|
|
@ -23,6 +23,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.thingsboard.server.common.data.ResourceType; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.msg.queue.ServiceType; |
|
|
|
import org.thingsboard.server.dao.resource.ImageService; |
|
|
|
import org.thingsboard.server.dao.resource.ResourceService; |
|
|
|
import org.thingsboard.server.dao.widget.WidgetsBundleService; |
|
|
|
import org.thingsboard.server.queue.discovery.PartitionService; |
|
|
|
@ -32,6 +33,7 @@ import org.thingsboard.server.service.sync.GitSyncService; |
|
|
|
import org.thingsboard.server.service.sync.vc.GitRepository.FileType; |
|
|
|
import org.thingsboard.server.service.sync.vc.GitRepository.RepoFile; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.stream.Stream; |
|
|
|
@ -45,6 +47,7 @@ public class DashboardSyncService { |
|
|
|
|
|
|
|
private final GitSyncService gitSyncService; |
|
|
|
private final ResourceService resourceService; |
|
|
|
private final ImageService imageService; |
|
|
|
private final WidgetsBundleService widgetsBundleService; |
|
|
|
private final PartitionService partitionService; |
|
|
|
|
|
|
|
@ -70,9 +73,14 @@ public class DashboardSyncService { |
|
|
|
|
|
|
|
List<RepoFile> resources = listFiles("resources"); |
|
|
|
for (RepoFile resourceFile : resources) { |
|
|
|
String data = getFileContent(resourceFile.path()); |
|
|
|
byte[] data = getFileContent(resourceFile.path()).getBytes(StandardCharsets.UTF_8); |
|
|
|
resourceService.createOrUpdateSystemResource(ResourceType.JS_MODULE, resourceFile.name(), data); |
|
|
|
} |
|
|
|
List<RepoFile> images = listFiles("images"); |
|
|
|
for (RepoFile imageFile : images) { |
|
|
|
byte[] data = getFileContent(imageFile.path()).getBytes(StandardCharsets.UTF_8); |
|
|
|
imageService.createOrUpdateSystemImage(imageFile.name(), data); |
|
|
|
} |
|
|
|
|
|
|
|
Stream<String> widgetsBundles = listFiles("widget_bundles").stream() |
|
|
|
.map(widgetsBundleFile -> getFileContent(widgetsBundleFile.path())); |
|
|
|
@ -80,11 +88,8 @@ public class DashboardSyncService { |
|
|
|
.map(widgetTypeFile -> getFileContent(widgetTypeFile.path())); |
|
|
|
widgetsBundleService.updateSystemWidgets(widgetsBundles, widgetTypes); |
|
|
|
|
|
|
|
// TODO: read images folder and save images
|
|
|
|
|
|
|
|
RepoFile dashboardFile = listFiles("dashboards").get(0); |
|
|
|
String dashboardJson = getFileContent(dashboardFile.path()); |
|
|
|
resourceService.createOrUpdateSystemResource(ResourceType.DASHBOARD, GATEWAYS_DASHBOARD_KEY, dashboardJson); |
|
|
|
resourceService.createOrUpdateSystemResource(ResourceType.DASHBOARD, GATEWAYS_DASHBOARD_KEY, getFileContent(dashboardFile.path()).getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
|
|
log.info("Gateways dashboard sync completed"); |
|
|
|
} |
|
|
|
|