Fix beans cycle dependency
This commit is contained in:
parent
cd30e9a4b1
commit
2eb94fd95e
@ -79,8 +79,6 @@ public class DefaultEntitiesVersionControlService implements EntitiesVersionCont
|
|||||||
private final EntityService entityService;
|
private final EntityService entityService;
|
||||||
private final TransactionTemplate transactionTemplate;
|
private final TransactionTemplate transactionTemplate;
|
||||||
|
|
||||||
public static final String SETTINGS_KEY = "entitiesVersionControl";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VersionCreationResult saveEntitiesVersion(SecurityUser user, VersionCreateRequest request) throws Exception {
|
public VersionCreationResult saveEntitiesVersion(SecurityUser user, VersionCreateRequest request) throws Exception {
|
||||||
var commit = gitService.prepareCommit(user.getTenantId(), request);
|
var commit = gitService.prepareCommit(user.getTenantId(), request);
|
||||||
|
|||||||
@ -32,6 +32,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface EntitiesVersionControlService {
|
public interface EntitiesVersionControlService {
|
||||||
|
|
||||||
|
String SETTINGS_KEY = "entitiesVersionControl";
|
||||||
|
|
||||||
VersionCreationResult saveEntitiesVersion(SecurityUser user, VersionCreateRequest request) throws Exception;
|
VersionCreationResult saveEntitiesVersion(SecurityUser user, VersionCreateRequest request) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,7 @@ 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.DataConstants;
|
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;
|
||||||
@ -38,6 +39,7 @@ 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.attributes.AttributesService;
|
||||||
|
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;
|
||||||
|
|
||||||
@ -63,14 +65,14 @@ public class LocalGitVersionControlService implements GitVersionControlService {
|
|||||||
private final ObjectWriter jsonWriter = new ObjectMapper().writer(SerializationFeature.INDENT_OUTPUT);
|
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 EntitiesVersionControlService entitiesVersionControlService;
|
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<>();
|
||||||
|
|
||||||
@AfterStartUp
|
@AfterStartUp
|
||||||
public void init() {
|
public void init() {
|
||||||
DaoUtil.processInBatches(tenantDao::findTenantsIds, 100, tenantId -> {
|
DaoUtil.processInBatches(tenantDao::findTenantsIds, 100, tenantId -> {
|
||||||
EntitiesVersionControlSettings settings = entitiesVersionControlService.getVersionControlSettings(tenantId);
|
EntitiesVersionControlSettings settings = getVersionControlSettings(tenantId);
|
||||||
if (settings != null) {
|
if (settings != null) {
|
||||||
try {
|
try {
|
||||||
gitRepositoryService.initRepository(tenantId, settings);
|
gitRepositoryService.initRepository(tenantId, settings);
|
||||||
@ -213,6 +215,18 @@ public class LocalGitVersionControlService implements GitVersionControlService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private EntitiesVersionControlSettings getVersionControlSettings(TenantId tenantId) {
|
||||||
|
AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(tenantId, EntitiesVersionControlService.SETTINGS_KEY);
|
||||||
|
if (adminSettings != null) {
|
||||||
|
try {
|
||||||
|
return JacksonUtil.convertValue(adminSettings.getJsonValue(), EntitiesVersionControlSettings.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to load version control settings!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private List<EntityVersion> listVersions(TenantId tenantId, String branch, String path) {
|
private List<EntityVersion> listVersions(TenantId tenantId, String branch, String path) {
|
||||||
try {
|
try {
|
||||||
return gitRepositoryService.listVersions(tenantId, branch, path);
|
return gitRepositoryService.listVersions(tenantId, branch, path);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user