Merge branch 'master' of github.com:thingsboard/thingsboard
This commit is contained in:
commit
c83d600bdd
@ -20,7 +20,6 @@ import com.google.common.cache.CacheLoader;
|
|||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -78,7 +77,8 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMsg(TbContext ctx, TbMsg msg) {
|
public void onMsg(TbContext ctx, TbMsg msg) {
|
||||||
withCallback(processEntityRelationAction(ctx, msg),
|
String relationType = processPattern(msg, config.getRelationType());
|
||||||
|
withCallback(processEntityRelationAction(ctx, msg, relationType),
|
||||||
filterResult -> ctx.tellNext(filterResult.getMsg(), filterResult.isResult() ? SUCCESS : FAILURE), t -> ctx.tellFailure(msg, t), ctx.getDbCallbackExecutor());
|
filterResult -> ctx.tellNext(filterResult.getMsg(), filterResult.isResult() ? SUCCESS : FAILURE), t -> ctx.tellFailure(msg, t), ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,13 +86,13 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA
|
|||||||
public void destroy() {
|
public void destroy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ListenableFuture<RelationContainer> processEntityRelationAction(TbContext ctx, TbMsg msg) {
|
protected ListenableFuture<RelationContainer> processEntityRelationAction(TbContext ctx, TbMsg msg, String relationType) {
|
||||||
return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer), MoreExecutors.directExecutor());
|
return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer, relationType), ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean createEntityIfNotExists();
|
protected abstract boolean createEntityIfNotExists();
|
||||||
|
|
||||||
protected abstract ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entityContainer);
|
protected abstract ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entityContainer, String relationType);
|
||||||
|
|
||||||
protected abstract C loadEntityNodeActionConfig(TbNodeConfiguration configuration) throws TbNodeException;
|
protected abstract C loadEntityNodeActionConfig(TbNodeConfiguration configuration) throws TbNodeException;
|
||||||
|
|
||||||
@ -120,11 +120,11 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA
|
|||||||
if (EntitySearchDirection.FROM.name().equals(this.config.getDirection())) {
|
if (EntitySearchDirection.FROM.name().equals(this.config.getDirection())) {
|
||||||
searchDirectionIds.setFromId(EntityIdFactory.getByTypeAndId(entityContainer.getEntityType().name(), entityContainer.getEntityId().toString()));
|
searchDirectionIds.setFromId(EntityIdFactory.getByTypeAndId(entityContainer.getEntityType().name(), entityContainer.getEntityId().toString()));
|
||||||
searchDirectionIds.setToId(msg.getOriginator());
|
searchDirectionIds.setToId(msg.getOriginator());
|
||||||
searchDirectionIds.setOrignatorDirectionFrom(false);
|
searchDirectionIds.setOriginatorDirectionFrom(false);
|
||||||
} else {
|
} else {
|
||||||
searchDirectionIds.setToId(EntityIdFactory.getByTypeAndId(entityContainer.getEntityType().name(), entityContainer.getEntityId().toString()));
|
searchDirectionIds.setToId(EntityIdFactory.getByTypeAndId(entityContainer.getEntityType().name(), entityContainer.getEntityId().toString()));
|
||||||
searchDirectionIds.setFromId(msg.getOriginator());
|
searchDirectionIds.setFromId(msg.getOriginator());
|
||||||
searchDirectionIds.setOrignatorDirectionFrom(true);
|
searchDirectionIds.setOriginatorDirectionFrom(true);
|
||||||
}
|
}
|
||||||
return searchDirectionIds;
|
return searchDirectionIds;
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA
|
|||||||
protected static class SearchDirectionIds {
|
protected static class SearchDirectionIds {
|
||||||
private EntityId fromId;
|
private EntityId fromId;
|
||||||
private EntityId toId;
|
private EntityId toId;
|
||||||
private boolean orignatorDirectionFrom;
|
private boolean originatorDirectionFrom;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class EntityCacheLoader extends CacheLoader<EntityKey, EntityContainer> {
|
private static class EntityCacheLoader extends CacheLoader<EntityKey, EntityContainer> {
|
||||||
|
|||||||
@ -17,7 +17,6 @@ package org.thingsboard.rule.engine.action;
|
|||||||
|
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.thingsboard.rule.engine.api.RuleNode;
|
import org.thingsboard.rule.engine.api.RuleNode;
|
||||||
import org.thingsboard.rule.engine.api.TbContext;
|
import org.thingsboard.rule.engine.api.TbContext;
|
||||||
@ -57,8 +56,6 @@ import java.util.List;
|
|||||||
)
|
)
|
||||||
public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateRelationNodeConfiguration> {
|
public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateRelationNodeConfiguration> {
|
||||||
|
|
||||||
private String relationType;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TbCreateRelationNodeConfiguration loadEntityNodeActionConfig(TbNodeConfiguration configuration) throws TbNodeException {
|
protected TbCreateRelationNodeConfiguration loadEntityNodeActionConfig(TbNodeConfiguration configuration) throws TbNodeException {
|
||||||
return TbNodeUtils.convert(configuration, TbCreateRelationNodeConfiguration.class);
|
return TbNodeUtils.convert(configuration, TbCreateRelationNodeConfiguration.class);
|
||||||
@ -70,8 +67,8 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entity) {
|
protected ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entity, String relationType) {
|
||||||
ListenableFuture<Boolean> future = createIfAbsent(ctx, msg, entity);
|
ListenableFuture<Boolean> future = createIfAbsent(ctx, msg, entity, relationType);
|
||||||
return Futures.transform(future, result -> {
|
return Futures.transform(future, result -> {
|
||||||
RelationContainer container = new RelationContainer();
|
RelationContainer container = new RelationContainer();
|
||||||
if (result && config.isChangeOriginatorToRelatedEntity()) {
|
if (result && config.isChangeOriginatorToRelatedEntity()) {
|
||||||
@ -82,16 +79,15 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
|
|||||||
}
|
}
|
||||||
container.setResult(result);
|
container.setResult(result);
|
||||||
return container;
|
return container;
|
||||||
}, MoreExecutors.directExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> createIfAbsent(TbContext ctx, TbMsg msg, EntityContainer entityContainer) {
|
private ListenableFuture<Boolean> createIfAbsent(TbContext ctx, TbMsg msg, EntityContainer entityContainer, String relationType) {
|
||||||
relationType = processPattern(msg, config.getRelationType());
|
|
||||||
SearchDirectionIds sdId = processSingleSearchDirection(msg, entityContainer);
|
SearchDirectionIds sdId = processSingleSearchDirection(msg, entityContainer);
|
||||||
ListenableFuture<Boolean> checkRelationFuture = Futures.transformAsync(ctx.getRelationService().checkRelation(ctx.getTenantId(), sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON), result -> {
|
ListenableFuture<Boolean> checkRelationFuture = Futures.transformAsync(ctx.getRelationService().checkRelation(ctx.getTenantId(), sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON), result -> {
|
||||||
if (!result) {
|
if (!result) {
|
||||||
if (config.isRemoveCurrentRelations()) {
|
if (config.isRemoveCurrentRelations()) {
|
||||||
return processDeleteRelations(ctx, processFindRelations(ctx, msg, sdId));
|
return processDeleteRelations(ctx, processFindRelations(ctx, msg, sdId, relationType));
|
||||||
}
|
}
|
||||||
return Futures.immediateFuture(false);
|
return Futures.immediateFuture(false);
|
||||||
}
|
}
|
||||||
@ -100,14 +96,14 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
|
|||||||
|
|
||||||
return Futures.transformAsync(checkRelationFuture, result -> {
|
return Futures.transformAsync(checkRelationFuture, result -> {
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return processCreateRelation(ctx, entityContainer, sdId);
|
return processCreateRelation(ctx, entityContainer, sdId, relationType);
|
||||||
}
|
}
|
||||||
return Futures.immediateFuture(true);
|
return Futures.immediateFuture(true);
|
||||||
}, ctx.getDbCallbackExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<List<EntityRelation>> processFindRelations(TbContext ctx, TbMsg msg, SearchDirectionIds sdId) {
|
private ListenableFuture<List<EntityRelation>> processFindRelations(TbContext ctx, TbMsg msg, SearchDirectionIds sdId, String relationType) {
|
||||||
if (sdId.isOrignatorDirectionFrom()) {
|
if (sdId.isOriginatorDirectionFrom()) {
|
||||||
return ctx.getRelationService().findByFromAndTypeAsync(ctx.getTenantId(), msg.getOriginator(), relationType, RelationTypeGroup.COMMON);
|
return ctx.getRelationService().findByFromAndTypeAsync(ctx.getTenantId(), msg.getOriginator(), relationType, RelationTypeGroup.COMMON);
|
||||||
} else {
|
} else {
|
||||||
return ctx.getRelationService().findByToAndTypeAsync(ctx.getTenantId(), msg.getOriginator(), relationType, RelationTypeGroup.COMMON);
|
return ctx.getRelationService().findByToAndTypeAsync(ctx.getTenantId(), msg.getOriginator(), relationType, RelationTypeGroup.COMMON);
|
||||||
@ -121,91 +117,91 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
|
|||||||
for (EntityRelation relation : entityRelations) {
|
for (EntityRelation relation : entityRelations) {
|
||||||
list.add(ctx.getRelationService().deleteRelationAsync(ctx.getTenantId(), relation));
|
list.add(ctx.getRelationService().deleteRelationAsync(ctx.getTenantId(), relation));
|
||||||
}
|
}
|
||||||
return Futures.transform(Futures.allAsList(list), result -> false, MoreExecutors.directExecutor());
|
return Futures.transform(Futures.allAsList(list), result -> false, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
return Futures.immediateFuture(false);
|
return Futures.immediateFuture(false);
|
||||||
}, ctx.getDbCallbackExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> processCreateRelation(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
|
private ListenableFuture<Boolean> processCreateRelation(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
|
||||||
switch (entityContainer.getEntityType()) {
|
switch (entityContainer.getEntityType()) {
|
||||||
case ASSET:
|
case ASSET:
|
||||||
return processAsset(ctx, entityContainer, sdId);
|
return processAsset(ctx, entityContainer, sdId, relationType);
|
||||||
case DEVICE:
|
case DEVICE:
|
||||||
return processDevice(ctx, entityContainer, sdId);
|
return processDevice(ctx, entityContainer, sdId, relationType);
|
||||||
case CUSTOMER:
|
case CUSTOMER:
|
||||||
return processCustomer(ctx, entityContainer, sdId);
|
return processCustomer(ctx, entityContainer, sdId, relationType);
|
||||||
case DASHBOARD:
|
case DASHBOARD:
|
||||||
return processDashboard(ctx, entityContainer, sdId);
|
return processDashboard(ctx, entityContainer, sdId, relationType);
|
||||||
case ENTITY_VIEW:
|
case ENTITY_VIEW:
|
||||||
return processView(ctx, entityContainer, sdId);
|
return processView(ctx, entityContainer, sdId, relationType);
|
||||||
case TENANT:
|
case TENANT:
|
||||||
return processTenant(ctx, entityContainer, sdId);
|
return processTenant(ctx, entityContainer, sdId, relationType);
|
||||||
}
|
}
|
||||||
return Futures.immediateFuture(true);
|
return Futures.immediateFuture(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> processView(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
|
private ListenableFuture<Boolean> processView(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
|
||||||
return Futures.transformAsync(ctx.getEntityViewService().findEntityViewByIdAsync(ctx.getTenantId(), new EntityViewId(entityContainer.getEntityId().getId())), entityView -> {
|
return Futures.transformAsync(ctx.getEntityViewService().findEntityViewByIdAsync(ctx.getTenantId(), new EntityViewId(entityContainer.getEntityId().getId())), entityView -> {
|
||||||
if (entityView != null) {
|
if (entityView != null) {
|
||||||
return processSave(ctx, sdId);
|
return processSave(ctx, sdId, relationType);
|
||||||
} else {
|
} else {
|
||||||
return Futures.immediateFuture(true);
|
return Futures.immediateFuture(true);
|
||||||
}
|
}
|
||||||
}, ctx.getDbCallbackExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> processDevice(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
|
private ListenableFuture<Boolean> processDevice(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
|
||||||
return Futures.transformAsync(ctx.getDeviceService().findDeviceByIdAsync(ctx.getTenantId(), new DeviceId(entityContainer.getEntityId().getId())), device -> {
|
return Futures.transformAsync(ctx.getDeviceService().findDeviceByIdAsync(ctx.getTenantId(), new DeviceId(entityContainer.getEntityId().getId())), device -> {
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
return processSave(ctx, sdId);
|
return processSave(ctx, sdId, relationType);
|
||||||
} else {
|
} else {
|
||||||
return Futures.immediateFuture(true);
|
return Futures.immediateFuture(true);
|
||||||
}
|
}
|
||||||
}, MoreExecutors.directExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> processAsset(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
|
private ListenableFuture<Boolean> processAsset(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
|
||||||
return Futures.transformAsync(ctx.getAssetService().findAssetByIdAsync(ctx.getTenantId(), new AssetId(entityContainer.getEntityId().getId())), asset -> {
|
return Futures.transformAsync(ctx.getAssetService().findAssetByIdAsync(ctx.getTenantId(), new AssetId(entityContainer.getEntityId().getId())), asset -> {
|
||||||
if (asset != null) {
|
if (asset != null) {
|
||||||
return processSave(ctx, sdId);
|
return processSave(ctx, sdId, relationType);
|
||||||
} else {
|
} else {
|
||||||
return Futures.immediateFuture(true);
|
return Futures.immediateFuture(true);
|
||||||
}
|
}
|
||||||
}, ctx.getDbCallbackExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> processCustomer(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
|
private ListenableFuture<Boolean> processCustomer(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
|
||||||
return Futures.transformAsync(ctx.getCustomerService().findCustomerByIdAsync(ctx.getTenantId(), new CustomerId(entityContainer.getEntityId().getId())), customer -> {
|
return Futures.transformAsync(ctx.getCustomerService().findCustomerByIdAsync(ctx.getTenantId(), new CustomerId(entityContainer.getEntityId().getId())), customer -> {
|
||||||
if (customer != null) {
|
if (customer != null) {
|
||||||
return processSave(ctx, sdId);
|
return processSave(ctx, sdId, relationType);
|
||||||
} else {
|
} else {
|
||||||
return Futures.immediateFuture(true);
|
return Futures.immediateFuture(true);
|
||||||
}
|
}
|
||||||
}, ctx.getDbCallbackExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> processDashboard(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
|
private ListenableFuture<Boolean> processDashboard(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
|
||||||
return Futures.transformAsync(ctx.getDashboardService().findDashboardByIdAsync(ctx.getTenantId(), new DashboardId(entityContainer.getEntityId().getId())), dashboard -> {
|
return Futures.transformAsync(ctx.getDashboardService().findDashboardByIdAsync(ctx.getTenantId(), new DashboardId(entityContainer.getEntityId().getId())), dashboard -> {
|
||||||
if (dashboard != null) {
|
if (dashboard != null) {
|
||||||
return processSave(ctx, sdId);
|
return processSave(ctx, sdId, relationType);
|
||||||
} else {
|
} else {
|
||||||
return Futures.immediateFuture(true);
|
return Futures.immediateFuture(true);
|
||||||
}
|
}
|
||||||
}, ctx.getDbCallbackExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> processTenant(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
|
private ListenableFuture<Boolean> processTenant(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
|
||||||
return Futures.transformAsync(ctx.getTenantService().findTenantByIdAsync(ctx.getTenantId(), new TenantId(entityContainer.getEntityId().getId())), tenant -> {
|
return Futures.transformAsync(ctx.getTenantService().findTenantByIdAsync(ctx.getTenantId(), new TenantId(entityContainer.getEntityId().getId())), tenant -> {
|
||||||
if (tenant != null) {
|
if (tenant != null) {
|
||||||
return processSave(ctx, sdId);
|
return processSave(ctx, sdId, relationType);
|
||||||
} else {
|
} else {
|
||||||
return Futures.immediateFuture(true);
|
return Futures.immediateFuture(true);
|
||||||
}
|
}
|
||||||
}, ctx.getDbCallbackExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> processSave(TbContext ctx, SearchDirectionIds sdId) {
|
private ListenableFuture<Boolean> processSave(TbContext ctx, SearchDirectionIds sdId, String relationType) {
|
||||||
return ctx.getRelationService().saveRelationAsync(ctx.getTenantId(), new EntityRelation(sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON));
|
return ctx.getRelationService().saveRelationAsync(ctx.getTenantId(), new EntityRelation(sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,6 @@ package org.thingsboard.rule.engine.action;
|
|||||||
|
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.thingsboard.rule.engine.api.RuleNode;
|
import org.thingsboard.rule.engine.api.RuleNode;
|
||||||
import org.thingsboard.rule.engine.api.TbContext;
|
import org.thingsboard.rule.engine.api.TbContext;
|
||||||
@ -48,8 +47,6 @@ import java.util.List;
|
|||||||
)
|
)
|
||||||
public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteRelationNodeConfiguration> {
|
public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteRelationNodeConfiguration> {
|
||||||
|
|
||||||
private String relationType;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TbDeleteRelationNodeConfiguration loadEntityNodeActionConfig(TbNodeConfiguration configuration) throws TbNodeException {
|
protected TbDeleteRelationNodeConfiguration loadEntityNodeActionConfig(TbNodeConfiguration configuration) throws TbNodeException {
|
||||||
return TbNodeUtils.convert(configuration, TbDeleteRelationNodeConfiguration.class);
|
return TbNodeUtils.convert(configuration, TbDeleteRelationNodeConfiguration.class);
|
||||||
@ -61,21 +58,20 @@ public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteR
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ListenableFuture<RelationContainer> processEntityRelationAction(TbContext ctx, TbMsg msg) {
|
protected ListenableFuture<RelationContainer> processEntityRelationAction(TbContext ctx, TbMsg msg, String relationType) {
|
||||||
return getRelationContainerListenableFuture(ctx, msg);
|
return getRelationContainerListenableFuture(ctx, msg, relationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entityContainer) {
|
protected ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entityContainer, String relationType) {
|
||||||
return Futures.transform(processSingle(ctx, msg, entityContainer), result -> new RelationContainer(msg, result), MoreExecutors.directExecutor());
|
return Futures.transform(processSingle(ctx, msg, entityContainer, relationType), result -> new RelationContainer(msg, result), ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<RelationContainer> getRelationContainerListenableFuture(TbContext ctx, TbMsg msg) {
|
private ListenableFuture<RelationContainer> getRelationContainerListenableFuture(TbContext ctx, TbMsg msg, String relationType) {
|
||||||
relationType = processPattern(msg, config.getRelationType());
|
|
||||||
if (config.isDeleteForSingleEntity()) {
|
if (config.isDeleteForSingleEntity()) {
|
||||||
return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer), MoreExecutors.directExecutor());
|
return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer, relationType), ctx.getDbCallbackExecutor());
|
||||||
} else {
|
} else {
|
||||||
return Futures.transform(processList(ctx, msg), result -> new RelationContainer(msg, result), MoreExecutors.directExecutor());
|
return Futures.transform(processList(ctx, msg), result -> new RelationContainer(msg, result), ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,23 +91,23 @@ public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Futures.immediateFuture(true);
|
return Futures.immediateFuture(true);
|
||||||
}, MoreExecutors.directExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
}, MoreExecutors.directExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> processSingle(TbContext ctx, TbMsg msg, EntityContainer entityContainer) {
|
private ListenableFuture<Boolean> processSingle(TbContext ctx, TbMsg msg, EntityContainer entityContainer, String relationType) {
|
||||||
SearchDirectionIds sdId = processSingleSearchDirection(msg, entityContainer);
|
SearchDirectionIds sdId = processSingleSearchDirection(msg, entityContainer);
|
||||||
return Futures.transformAsync(ctx.getRelationService().checkRelation(ctx.getTenantId(), sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON),
|
return Futures.transformAsync(ctx.getRelationService().checkRelation(ctx.getTenantId(), sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON),
|
||||||
result -> {
|
result -> {
|
||||||
if (result) {
|
if (result) {
|
||||||
return processSingleDeleteRelation(ctx, sdId);
|
return processSingleDeleteRelation(ctx, sdId, relationType);
|
||||||
}
|
}
|
||||||
return Futures.immediateFuture(true);
|
return Futures.immediateFuture(true);
|
||||||
}, MoreExecutors.directExecutor());
|
}, ctx.getDbCallbackExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> processSingleDeleteRelation(TbContext ctx, SearchDirectionIds sdId) {
|
private ListenableFuture<Boolean> processSingleDeleteRelation(TbContext ctx, SearchDirectionIds sdId, String relationType) {
|
||||||
return ctx.getRelationService().deleteRelationAsync(ctx.getTenantId(), sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON);
|
return ctx.getRelationService().deleteRelationAsync(ctx.getTenantId(), sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user