Fix EntityView and Rule Chain auto-commit
This commit is contained in:
		
							parent
							
								
									343b14833a
								
							
						
					
					
						commit
						f0dd3db39e
					
				@ -139,7 +139,7 @@ public class EntityViewController extends BaseController {
 | 
			
		||||
    @ResponseBody
 | 
			
		||||
    public EntityView saveEntityView(
 | 
			
		||||
            @ApiParam(value = "A JSON object representing the entity view.")
 | 
			
		||||
            @RequestBody EntityView entityView) throws ThingsboardException {
 | 
			
		||||
            @RequestBody EntityView entityView) throws Exception {
 | 
			
		||||
        entityView.setTenantId(getCurrentUser().getTenantId());
 | 
			
		||||
        EntityView existingEntityView = null;
 | 
			
		||||
        if (entityView.getId() == null) {
 | 
			
		||||
 | 
			
		||||
@ -141,4 +141,13 @@ public abstract class AbstractTbEntityService {
 | 
			
		||||
            return Futures.immediateFailedFuture(new RuntimeException("Operation not supported!"));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected ListenableFuture<UUID> autoCommit(User user, EntityType entityType, List<UUID> entityIds) throws Exception {
 | 
			
		||||
        if (vcService != null) {
 | 
			
		||||
            return vcService.autoCommit(user, entityType, entityIds);
 | 
			
		||||
        } else {
 | 
			
		||||
            // We do not support auto-commit for rule engine
 | 
			
		||||
            return Futures.immediateFailedFuture(new RuntimeException("Operation not supported!"));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -74,12 +74,13 @@ public class DefaultTbEntityViewService extends AbstractTbEntityService implemen
 | 
			
		||||
    final Map<TenantId, Map<EntityId, List<EntityView>>> localCache = new ConcurrentHashMap<>();
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public EntityView save(EntityView entityView, EntityView existingEntityView, User user) throws ThingsboardException {
 | 
			
		||||
    public EntityView save(EntityView entityView, EntityView existingEntityView, User user) throws Exception {
 | 
			
		||||
        ActionType actionType = entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
 | 
			
		||||
        TenantId tenantId = entityView.getTenantId();
 | 
			
		||||
        try {
 | 
			
		||||
            EntityView savedEntityView = checkNotNull(entityViewService.saveEntityView(entityView));
 | 
			
		||||
            this.updateEntityViewAttributes(tenantId, savedEntityView, existingEntityView, user);
 | 
			
		||||
            autoCommit(user, savedEntityView.getId());
 | 
			
		||||
            notificationEntityService.notifyCreateOrUpdateEntity(savedEntityView.getTenantId(), savedEntityView.getId(), savedEntityView,
 | 
			
		||||
                    null, actionType, user);
 | 
			
		||||
            localCache.computeIfAbsent(savedEntityView.getTenantId(), (k) -> new ConcurrentReferenceHashMap<>()).clear();
 | 
			
		||||
 | 
			
		||||
@ -31,7 +31,7 @@ import java.util.List;
 | 
			
		||||
 | 
			
		||||
public interface TbEntityViewService extends ComponentLifecycleListener {
 | 
			
		||||
 | 
			
		||||
    EntityView save(EntityView entityView, EntityView existingEntityView, User user) throws ThingsboardException;
 | 
			
		||||
    EntityView save(EntityView entityView, EntityView existingEntityView, User user) throws Exception;
 | 
			
		||||
 | 
			
		||||
    void updateEntityViewAttributes(TenantId tenantId, EntityView savedEntityView, EntityView oldEntityView, User user) throws ThingsboardException;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -176,7 +176,7 @@ public class DefaultTbRuleChainService extends AbstractTbEntityService implement
 | 
			
		||||
        ActionType actionType = ruleChain.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
 | 
			
		||||
        try {
 | 
			
		||||
            RuleChain savedRuleChain = checkNotNull(ruleChainService.saveRuleChain(ruleChain));
 | 
			
		||||
            vcService.autoCommit(user, savedRuleChain.getId());
 | 
			
		||||
            autoCommit(user, savedRuleChain.getId());
 | 
			
		||||
 | 
			
		||||
            if (RuleChainType.CORE.equals(savedRuleChain.getType())) {
 | 
			
		||||
                tbClusterService.broadcastEntityStateChangeEvent(tenantId, savedRuleChain.getId(),
 | 
			
		||||
@ -229,7 +229,7 @@ public class DefaultTbRuleChainService extends AbstractTbEntityService implement
 | 
			
		||||
    public RuleChain saveDefaultByName(TenantId tenantId, DefaultRuleChainCreateRequest request, User user) throws Exception {
 | 
			
		||||
        try {
 | 
			
		||||
            RuleChain savedRuleChain = installScripts.createDefaultRuleChain(tenantId, request.getName());
 | 
			
		||||
            vcService.autoCommit(user, savedRuleChain.getId());
 | 
			
		||||
            autoCommit(user, savedRuleChain.getId());
 | 
			
		||||
            tbClusterService.broadcastEntityStateChangeEvent(tenantId, savedRuleChain.getId(), ComponentLifecycleEvent.CREATED);
 | 
			
		||||
            notificationEntityService.logEntityAction(tenantId, savedRuleChain.getId(), savedRuleChain, ActionType.ADDED, user);
 | 
			
		||||
            return savedRuleChain;
 | 
			
		||||
@ -288,12 +288,12 @@ public class DefaultTbRuleChainService extends AbstractTbEntityService implement
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (updatedRuleChains.isEmpty()) {
 | 
			
		||||
                vcService.autoCommit(user, ruleChainMetaData.getRuleChainId());
 | 
			
		||||
                autoCommit(user, ruleChainMetaData.getRuleChainId());
 | 
			
		||||
            } else {
 | 
			
		||||
                List<UUID> uuids = new ArrayList<>(updatedRuleChains.size() + 1);
 | 
			
		||||
                uuids.add(ruleChainMetaData.getRuleChainId().getId());
 | 
			
		||||
                updatedRuleChains.forEach(rc -> uuids.add(rc.getId().getId()));
 | 
			
		||||
                vcService.autoCommit(user, EntityType.RULE_CHAIN, uuids);
 | 
			
		||||
                autoCommit(user, EntityType.RULE_CHAIN, uuids);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            RuleChainMetaData savedRuleChainMetaData = checkNotNull(ruleChainService.loadRuleChainMetaData(tenantId, ruleChainMetaDataId));
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user