|
|
|
@ -50,6 +50,8 @@ import org.thingsboard.server.common.data.sync.vc.request.create.VersionCreateRe |
|
|
|
import org.thingsboard.server.common.data.sync.vc.request.load.VersionLoadRequest; |
|
|
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
|
|
import org.thingsboard.server.service.security.model.SecurityUser; |
|
|
|
import org.thingsboard.server.service.security.permission.Operation; |
|
|
|
import org.thingsboard.server.service.security.permission.Resource; |
|
|
|
import org.thingsboard.server.service.sync.vc.EntitiesVersionControlService; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
@ -118,6 +120,7 @@ public class EntitiesVersionControlController extends BaseController { |
|
|
|
public DeferredResult<VersionCreationResult> saveEntitiesVersion(@RequestBody VersionCreateRequest request) throws ThingsboardException { |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
try { |
|
|
|
accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.WRITE); |
|
|
|
return wrapFuture(versionControlService.saveEntitiesVersion(user, request)); |
|
|
|
} catch (Exception e) { |
|
|
|
throw handleException(e); |
|
|
|
@ -146,6 +149,7 @@ public class EntitiesVersionControlController extends BaseController { |
|
|
|
@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES) |
|
|
|
@RequestParam(required = false) String sortOrder) throws ThingsboardException { |
|
|
|
try { |
|
|
|
accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ); |
|
|
|
EntityId externalEntityId = EntityIdFactory.getByTypeAndUuid(entityType, externalEntityUuid); |
|
|
|
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); |
|
|
|
return wrapFuture(versionControlService.listEntityVersions(getTenantId(), branch, externalEntityId, pageLink)); |
|
|
|
@ -175,6 +179,7 @@ public class EntitiesVersionControlController extends BaseController { |
|
|
|
@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES) |
|
|
|
@RequestParam(required = false) String sortOrder) throws ThingsboardException { |
|
|
|
try { |
|
|
|
accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ); |
|
|
|
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); |
|
|
|
return wrapFuture(versionControlService.listEntityTypeVersions(getTenantId(), branch, entityType, pageLink)); |
|
|
|
} catch (Exception e) { |
|
|
|
@ -210,6 +215,7 @@ public class EntitiesVersionControlController extends BaseController { |
|
|
|
@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES) |
|
|
|
@RequestParam(required = false) String sortOrder) throws ThingsboardException { |
|
|
|
try { |
|
|
|
accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ); |
|
|
|
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); |
|
|
|
return wrapFuture(versionControlService.listVersions(getTenantId(), branch, pageLink)); |
|
|
|
} catch (Exception e) { |
|
|
|
@ -223,6 +229,7 @@ public class EntitiesVersionControlController extends BaseController { |
|
|
|
@PathVariable EntityType entityType, |
|
|
|
@PathVariable String versionId) throws ThingsboardException { |
|
|
|
try { |
|
|
|
accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ); |
|
|
|
return wrapFuture(versionControlService.listEntitiesAtVersion(getTenantId(), branch, versionId, entityType)); |
|
|
|
} catch (Exception e) { |
|
|
|
throw handleException(e); |
|
|
|
@ -233,6 +240,7 @@ public class EntitiesVersionControlController extends BaseController { |
|
|
|
public DeferredResult<List<VersionedEntityInfo>> listAllEntitiesAtVersion(@PathVariable String branch, |
|
|
|
@PathVariable String versionId) throws ThingsboardException { |
|
|
|
try { |
|
|
|
accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ); |
|
|
|
return wrapFuture(versionControlService.listAllEntitiesAtVersion(getTenantId(), branch, versionId)); |
|
|
|
} catch (Exception e) { |
|
|
|
throw handleException(e); |
|
|
|
@ -244,6 +252,7 @@ public class EntitiesVersionControlController extends BaseController { |
|
|
|
@PathVariable EntityType entityType, |
|
|
|
@PathVariable UUID externalEntityUuid) throws ThingsboardException { |
|
|
|
try { |
|
|
|
accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ); |
|
|
|
EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, externalEntityUuid); |
|
|
|
return wrapFuture(versionControlService.getEntityDataInfo(getCurrentUser(), entityId, versionId)); |
|
|
|
} catch (Exception e) { |
|
|
|
@ -257,6 +266,7 @@ public class EntitiesVersionControlController extends BaseController { |
|
|
|
@PathVariable UUID internalEntityUuid, |
|
|
|
@RequestParam String versionId) throws ThingsboardException { |
|
|
|
try { |
|
|
|
accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ); |
|
|
|
EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, internalEntityUuid); |
|
|
|
return wrapFuture(versionControlService.compareEntityDataToVersion(getCurrentUser(), branch, entityId, versionId)); |
|
|
|
} catch (Exception e) { |
|
|
|
@ -300,6 +310,7 @@ public class EntitiesVersionControlController extends BaseController { |
|
|
|
public DeferredResult<VersionLoadResult> loadEntitiesVersion(@RequestBody VersionLoadRequest request) throws ThingsboardException { |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
try { |
|
|
|
accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ); |
|
|
|
return wrapFuture(versionControlService.loadEntitiesVersion(user, request)); |
|
|
|
} catch (Exception e) { |
|
|
|
throw handleException(e); |
|
|
|
@ -325,6 +336,7 @@ public class EntitiesVersionControlController extends BaseController { |
|
|
|
@GetMapping("/branches") |
|
|
|
public DeferredResult<List<BranchInfo>> listBranches() throws ThingsboardException { |
|
|
|
try { |
|
|
|
accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ); |
|
|
|
final TenantId tenantId = getTenantId(); |
|
|
|
ListenableFuture<List<String>> branches = versionControlService.listBranches(tenantId); |
|
|
|
return wrapFuture(Futures.transform(branches, remoteBranches -> { |
|
|
|
|