Merge pull request #12091 from thingsboard/fix/git-sync-gateway
Fix gateways dashboard sync
This commit is contained in:
		
						commit
						392d2290cd
					
				| 
		 Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB  | 
@ -73,23 +73,23 @@ public class DashboardSyncService {
 | 
			
		||||
 | 
			
		||||
        List<RepoFile> resources = listFiles("resources");
 | 
			
		||||
        for (RepoFile resourceFile : resources) {
 | 
			
		||||
            byte[] data = getFileContent(resourceFile.path()).getBytes(StandardCharsets.UTF_8);
 | 
			
		||||
            byte[] data = getFileContent(resourceFile.path());
 | 
			
		||||
            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);
 | 
			
		||||
            byte[] data = getFileContent(imageFile.path());
 | 
			
		||||
            imageService.createOrUpdateSystemImage(imageFile.name(), data);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Stream<String> widgetsBundles = listFiles("widget_bundles").stream()
 | 
			
		||||
                .map(widgetsBundleFile -> getFileContent(widgetsBundleFile.path()));
 | 
			
		||||
                .map(widgetsBundleFile -> new String(getFileContent(widgetsBundleFile.path()), StandardCharsets.UTF_8));
 | 
			
		||||
        Stream<String> widgetTypes = listFiles("widget_types").stream()
 | 
			
		||||
                .map(widgetTypeFile -> getFileContent(widgetTypeFile.path()));
 | 
			
		||||
                .map(widgetTypeFile -> new String(getFileContent(widgetTypeFile.path()), StandardCharsets.UTF_8));
 | 
			
		||||
        widgetsBundleService.updateSystemWidgets(widgetsBundles, widgetTypes);
 | 
			
		||||
 | 
			
		||||
        RepoFile dashboardFile = listFiles("dashboards").get(0);
 | 
			
		||||
        resourceService.createOrUpdateSystemResource(ResourceType.DASHBOARD, GATEWAYS_DASHBOARD_KEY, getFileContent(dashboardFile.path()).getBytes(StandardCharsets.UTF_8));
 | 
			
		||||
        resourceService.createOrUpdateSystemResource(ResourceType.DASHBOARD, GATEWAYS_DASHBOARD_KEY, getFileContent(dashboardFile.path()));
 | 
			
		||||
 | 
			
		||||
        log.info("Gateways dashboard sync completed");
 | 
			
		||||
    }
 | 
			
		||||
@ -98,7 +98,7 @@ public class DashboardSyncService {
 | 
			
		||||
        return gitSyncService.listFiles(REPO_KEY, path, 1, FileType.FILE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String getFileContent(String path) {
 | 
			
		||||
    private byte[] getFileContent(String path) {
 | 
			
		||||
        return gitSyncService.getFileContent(REPO_KEY, path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -92,14 +92,9 @@ public class DefaultGitSyncService implements GitSyncService {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getFileContent(String key, String path) {
 | 
			
		||||
    public byte[] getFileContent(String key, String path) {
 | 
			
		||||
        GitRepository repository = getRepository(key);
 | 
			
		||||
        try {
 | 
			
		||||
            return repository.getFileContentAtCommit(path, getBranchRef(repository));
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            log.warn("[{}] Failed to get file content for path {}: {}", key, path, e.getMessage());
 | 
			
		||||
            return "{}";
 | 
			
		||||
        }
 | 
			
		||||
        return repository.getFileContentAtCommit(path, getBranchRef(repository));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,7 @@ public interface GitSyncService {
 | 
			
		||||
 | 
			
		||||
    List<RepoFile> listFiles(String key, String path, int depth, FileType type);
 | 
			
		||||
 | 
			
		||||
    String getFileContent(String key, String path);
 | 
			
		||||
    byte[] getFileContent(String key, String path);
 | 
			
		||||
 | 
			
		||||
    String getGithubRawContentUrl(String key, String path);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -172,7 +172,7 @@ public class DefaultGitRepositoryService implements GitRepositoryService {
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getFileContentAtCommit(TenantId tenantId, String relativePath, String versionId) throws IOException {
 | 
			
		||||
        GitRepository repository = checkRepository(tenantId);
 | 
			
		||||
        return repository.getFileContentAtCommit(relativePath, versionId);
 | 
			
		||||
        return new String(repository.getFileContentAtCommit(relativePath, versionId), StandardCharsets.UTF_8);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 | 
			
		||||
@ -284,8 +284,8 @@ public class GitRepository {
 | 
			
		||||
        return files;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public String getFileContentAtCommit(String file, String commitId) throws IOException {
 | 
			
		||||
    @SneakyThrows
 | 
			
		||||
    public byte[] getFileContentAtCommit(String file, String commitId) {
 | 
			
		||||
        log.debug("Executing getFileContentAtCommit [{}][{}][{}]", settings.getRepositoryUri(), commitId, file);
 | 
			
		||||
        RevCommit revCommit = resolveCommit(commitId);
 | 
			
		||||
        try (TreeWalk treeWalk = TreeWalk.forPath(git.getRepository(), file, revCommit.getTree())) {
 | 
			
		||||
@ -296,8 +296,7 @@ public class GitRepository {
 | 
			
		||||
            try (ObjectReader objectReader = git.getRepository().newObjectReader()) {
 | 
			
		||||
                ObjectLoader objectLoader = objectReader.open(blobId);
 | 
			
		||||
                try {
 | 
			
		||||
                    byte[] bytes = objectLoader.getBytes();
 | 
			
		||||
                    return new String(bytes, StandardCharsets.UTF_8);
 | 
			
		||||
                    return objectLoader.getBytes();
 | 
			
		||||
                } catch (LargeObjectException e) {
 | 
			
		||||
                    throw new RuntimeException("File " + file + " is too big to load");
 | 
			
		||||
                }
 | 
			
		||||
@ -397,11 +396,11 @@ public class GitRepository {
 | 
			
		||||
                        diff.setFilePath(diffEntry.getChangeType() != DiffEntry.ChangeType.DELETE ? diffEntry.getNewPath() : diffEntry.getOldPath());
 | 
			
		||||
                        diff.setChangeType(diffEntry.getChangeType());
 | 
			
		||||
                        try {
 | 
			
		||||
                            diff.setFileContentAtCommit1(getFileContentAtCommit(diff.getFilePath(), commit1));
 | 
			
		||||
                            diff.setFileContentAtCommit1(new String(getFileContentAtCommit(diff.getFilePath(), commit1), StandardCharsets.UTF_8));
 | 
			
		||||
                        } catch (IllegalArgumentException ignored) {
 | 
			
		||||
                        }
 | 
			
		||||
                        try {
 | 
			
		||||
                            diff.setFileContentAtCommit2(getFileContentAtCommit(diff.getFilePath(), commit2));
 | 
			
		||||
                            diff.setFileContentAtCommit2(new String(getFileContentAtCommit(diff.getFilePath(), commit2), StandardCharsets.UTF_8));
 | 
			
		||||
                        } catch (IllegalArgumentException ignored) {
 | 
			
		||||
                        }
 | 
			
		||||
                        return diff;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user