Merge pull request #6588 from ViacheslavKlimov/entities-vc-refactoring
Fixes for vc api
This commit is contained in:
commit
26d766e9dc
@ -243,7 +243,7 @@ public class EntitiesVersionControlController extends BaseController {
|
|||||||
if (versionId == null) {
|
if (versionId == null) {
|
||||||
PageData<EntityVersion> versions = versionControlService.listVersions(user.getTenantId(), request.getBranch(), new PageLink(1));
|
PageData<EntityVersion> versions = versionControlService.listVersions(user.getTenantId(), request.getBranch(), new PageLink(1));
|
||||||
if (versions.getData().size() > 0) {
|
if (versions.getData().size() > 0) {
|
||||||
versionId = versions.getData().get(0).getId();
|
request.setVersionId(versions.getData().get(0).getId());
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("No versions available in branch");
|
throw new IllegalArgumentException("No versions available in branch");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,16 +16,13 @@
|
|||||||
package org.thingsboard.server.service.sync.vc;
|
package org.thingsboard.server.service.sync.vc;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thingsboard.common.util.JacksonUtil;
|
import org.thingsboard.common.util.JacksonUtil;
|
||||||
import org.thingsboard.server.common.data.AdminSettings;
|
import org.thingsboard.server.common.data.AdminSettings;
|
||||||
import org.thingsboard.server.common.data.DataConstants;
|
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.ExportableEntity;
|
import org.thingsboard.server.common.data.ExportableEntity;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
@ -40,7 +37,6 @@ import org.thingsboard.server.common.data.sync.vc.VersionCreationResult;
|
|||||||
import org.thingsboard.server.common.data.sync.vc.VersionedEntityInfo;
|
import org.thingsboard.server.common.data.sync.vc.VersionedEntityInfo;
|
||||||
import org.thingsboard.server.common.data.sync.vc.request.create.VersionCreateRequest;
|
import org.thingsboard.server.common.data.sync.vc.request.create.VersionCreateRequest;
|
||||||
import org.thingsboard.server.dao.DaoUtil;
|
import org.thingsboard.server.dao.DaoUtil;
|
||||||
import org.thingsboard.server.dao.attributes.AttributesService;
|
|
||||||
import org.thingsboard.server.dao.settings.AdminSettingsService;
|
import org.thingsboard.server.dao.settings.AdminSettingsService;
|
||||||
import org.thingsboard.server.dao.tenant.TenantDao;
|
import org.thingsboard.server.dao.tenant.TenantDao;
|
||||||
import org.thingsboard.server.queue.util.AfterStartUp;
|
import org.thingsboard.server.queue.util.AfterStartUp;
|
||||||
@ -64,13 +60,16 @@ import java.util.stream.Collectors;
|
|||||||
@ConditionalOnProperty(prefix = "vc", value = "git.service", havingValue = "local", matchIfMissing = true)
|
@ConditionalOnProperty(prefix = "vc", value = "git.service", havingValue = "local", matchIfMissing = true)
|
||||||
public class LocalGitVersionControlService implements GitVersionControlService {
|
public class LocalGitVersionControlService implements GitVersionControlService {
|
||||||
|
|
||||||
private final ObjectWriter jsonWriter = new ObjectMapper().writer(SerializationFeature.INDENT_OUTPUT);
|
|
||||||
private final GitRepositoryService gitRepositoryService;
|
private final GitRepositoryService gitRepositoryService;
|
||||||
private final TenantDao tenantDao;
|
private final TenantDao tenantDao;
|
||||||
private final AdminSettingsService adminSettingsService;
|
private final AdminSettingsService adminSettingsService;
|
||||||
|
|
||||||
private final ConcurrentMap<TenantId, Lock> tenantRepoLocks = new ConcurrentHashMap<>();
|
private final ConcurrentMap<TenantId, Lock> tenantRepoLocks = new ConcurrentHashMap<>();
|
||||||
private final Map<TenantId, PendingCommit> pendingCommitMap = new HashMap<>();
|
private final Map<TenantId, PendingCommit> pendingCommitMap = new HashMap<>();
|
||||||
|
|
||||||
|
private final ObjectMapper jsonMapper = new ObjectMapper()
|
||||||
|
.enable(SerializationFeature.INDENT_OUTPUT);
|
||||||
|
|
||||||
@AfterStartUp
|
@AfterStartUp
|
||||||
public void init() {
|
public void init() {
|
||||||
DaoUtil.processInBatches(tenantDao::findTenantsIds, 100, tenantId -> {
|
DaoUtil.processInBatches(tenantDao::findTenantsIds, 100, tenantId -> {
|
||||||
@ -167,7 +166,7 @@ public class LocalGitVersionControlService implements GitVersionControlService {
|
|||||||
doInsideLock(commit, c -> {
|
doInsideLock(commit, c -> {
|
||||||
String entityDataJson;
|
String entityDataJson;
|
||||||
try {
|
try {
|
||||||
entityDataJson = jsonWriter.writeValueAsString(entityData);
|
entityDataJson = jsonMapper.writeValueAsString(entityData);
|
||||||
gitRepositoryService.add(c, getRelativePath(entityData.getEntityType(),
|
gitRepositoryService.add(c, getRelativePath(entityData.getEntityType(),
|
||||||
entityData.getEntity().getId().toString()), entityDataJson);
|
entityData.getEntity().getId().toString()), entityDataJson);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -232,7 +231,7 @@ public class LocalGitVersionControlService implements GitVersionControlService {
|
|||||||
try {
|
try {
|
||||||
String entityDataJson = gitRepositoryService.getFileContentAtCommit(tenantId,
|
String entityDataJson = gitRepositoryService.getFileContentAtCommit(tenantId,
|
||||||
getRelativePath(entityId.getEntityType(), entityId.getId().toString()), versionId);
|
getRelativePath(entityId.getEntityType(), entityId.getId().toString()), versionId);
|
||||||
return JacksonUtil.fromString(entityDataJson, EntityExportData.class);
|
return jsonMapper.readValue(entityDataJson, EntityExportData.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//TODO: analyze and return meaningful exceptions that we can show to the client;
|
//TODO: analyze and return meaningful exceptions that we can show to the client;
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
|
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.ExportableEntity;
|
import org.thingsboard.server.common.data.ExportableEntity;
|
||||||
@ -30,7 +31,7 @@ import org.thingsboard.server.common.data.sync.JsonTbEntity;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "entityType", defaultImpl = EntityExportData.class)
|
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "entityType", include = As.EXISTING_PROPERTY, visible = true, defaultImpl = EntityExportData.class)
|
||||||
@JsonSubTypes({
|
@JsonSubTypes({
|
||||||
@Type(name = "DEVICE", value = DeviceExportData.class),
|
@Type(name = "DEVICE", value = DeviceExportData.class),
|
||||||
@Type(name = "RULE_CHAIN", value = RuleChainExportData.class)
|
@Type(name = "RULE_CHAIN", value = RuleChainExportData.class)
|
||||||
|
|||||||
@ -15,26 +15,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.common.data.sync.ie;
|
package org.thingsboard.server.common.data.sync.ie;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.ExportableEntity;
|
import org.thingsboard.server.common.data.ExportableEntity;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
import org.thingsboard.server.common.data.sync.JsonTbEntity;
|
|
||||||
import org.thingsboard.server.common.data.sync.ThrowingRunnable;
|
import org.thingsboard.server.common.data.sync.ThrowingRunnable;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class EntityImportResult<E extends ExportableEntity<? extends EntityId>> {
|
public class EntityImportResult<E extends ExportableEntity<? extends EntityId>> {
|
||||||
|
|
||||||
@JsonTbEntity
|
|
||||||
private E savedEntity;
|
private E savedEntity;
|
||||||
@JsonTbEntity
|
|
||||||
private E oldEntity;
|
private E oldEntity;
|
||||||
private EntityType entityType;
|
private EntityType entityType;
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
private ThrowingRunnable saveReferencesCallback = () -> {};
|
private ThrowingRunnable saveReferencesCallback = () -> {};
|
||||||
@JsonIgnore
|
|
||||||
private ThrowingRunnable sendEventsCallback = () -> {};
|
private ThrowingRunnable sendEventsCallback = () -> {};
|
||||||
|
|
||||||
public void addSaveReferencesCallback(ThrowingRunnable callback) {
|
public void addSaveReferencesCallback(ThrowingRunnable callback) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user