|
|
|
@ -17,6 +17,8 @@ package org.thingsboard.server.service.sync.vc.data; |
|
|
|
|
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import lombok.Data; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.sync.ie.EntityExportSettings; |
|
|
|
import org.thingsboard.server.common.data.sync.vc.request.create.VersionCreateConfig; |
|
|
|
@ -24,8 +26,11 @@ import org.thingsboard.server.common.data.sync.vc.request.create.VersionCreateRe |
|
|
|
import org.thingsboard.server.service.security.model.SecurityUser; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Data |
|
|
|
public abstract class EntitiesExportCtx<R extends VersionCreateRequest> { |
|
|
|
|
|
|
|
@ -33,12 +38,14 @@ public abstract class EntitiesExportCtx<R extends VersionCreateRequest> { |
|
|
|
protected final CommitGitRequest commit; |
|
|
|
protected final R request; |
|
|
|
private final List<ListenableFuture<Void>> futures; |
|
|
|
private final Map<EntityId, EntityId> externalIdMap; |
|
|
|
|
|
|
|
public EntitiesExportCtx(SecurityUser user, CommitGitRequest commit, R request) { |
|
|
|
this.user = user; |
|
|
|
this.commit = commit; |
|
|
|
this.request = request; |
|
|
|
this.futures = new ArrayList<>(); |
|
|
|
this.externalIdMap = new HashMap<>(); |
|
|
|
} |
|
|
|
|
|
|
|
protected <T extends R> EntitiesExportCtx(EntitiesExportCtx<T> other) { |
|
|
|
@ -46,6 +53,7 @@ public abstract class EntitiesExportCtx<R extends VersionCreateRequest> { |
|
|
|
this.commit = other.getCommit(); |
|
|
|
this.request = other.getRequest(); |
|
|
|
this.futures = other.getFutures(); |
|
|
|
this.externalIdMap = other.getExternalIdMap(); |
|
|
|
} |
|
|
|
|
|
|
|
public void add(ListenableFuture<Void> future) { |
|
|
|
@ -65,4 +73,16 @@ public abstract class EntitiesExportCtx<R extends VersionCreateRequest> { |
|
|
|
} |
|
|
|
|
|
|
|
public abstract EntityExportSettings getSettings(); |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public <ID extends EntityId> ID getExternalId(ID internalId) { |
|
|
|
var result = externalIdMap.get(internalId); |
|
|
|
log.debug("[{}][{}] Local cache {} for id", internalId.getEntityType(), internalId.getId(), result != null ? "hit" : "miss"); |
|
|
|
return (ID) result; |
|
|
|
} |
|
|
|
|
|
|
|
public void putExternalId(EntityId internalId, EntityId externalId) { |
|
|
|
log.debug("[{}][{}] Local cache put: {}", internalId.getEntityType(), internalId.getId(), externalId); |
|
|
|
externalIdMap.put(internalId, externalId); |
|
|
|
} |
|
|
|
} |
|
|
|
|