Merge remote-tracking branch 'origin/develop/3.4' into develop/3.4
This commit is contained in:
		
						commit
						3e7086cc6f
					
				@ -138,6 +138,7 @@ public class ControllerConstants {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected static final String ENTITY_VERSION_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'substring' filter based on the entity version name.";
 | 
					    protected static final String ENTITY_VERSION_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'substring' filter based on the entity version name.";
 | 
				
			||||||
    protected static final String VERSION_ID_PARAM_DESCRIPTION = "Version id, for example fd82625bdd7d6131cf8027b44ee967012ecaf990. Represents commit hash.";
 | 
					    protected static final String VERSION_ID_PARAM_DESCRIPTION = "Version id, for example fd82625bdd7d6131cf8027b44ee967012ecaf990. Represents commit hash.";
 | 
				
			||||||
 | 
					    protected static final String BRANCH_PARAM_DESCRIPTION = "The name of the working branch, for example 'master'";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected static final String MARKDOWN_CODE_BLOCK_START = "```json\n";
 | 
					    protected static final String MARKDOWN_CODE_BLOCK_START = "```json\n";
 | 
				
			||||||
    protected static final String MARKDOWN_CODE_BLOCK_END = "\n```";
 | 
					    protected static final String MARKDOWN_CODE_BLOCK_END = "\n```";
 | 
				
			||||||
 | 
				
			|||||||
@ -58,6 +58,9 @@ import java.util.List;
 | 
				
			|||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
import java.util.stream.Collectors;
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import static org.thingsboard.server.controller.ControllerConstants.BRANCH_PARAM_DESCRIPTION;
 | 
				
			||||||
 | 
					import static org.thingsboard.server.controller.ControllerConstants.ENTITY_ID_PARAM_DESCRIPTION;
 | 
				
			||||||
 | 
					import static org.thingsboard.server.controller.ControllerConstants.ENTITY_TYPE_PARAM_DESCRIPTION;
 | 
				
			||||||
import static org.thingsboard.server.controller.ControllerConstants.MARKDOWN_CODE_BLOCK_END;
 | 
					import static org.thingsboard.server.controller.ControllerConstants.MARKDOWN_CODE_BLOCK_END;
 | 
				
			||||||
import static org.thingsboard.server.controller.ControllerConstants.MARKDOWN_CODE_BLOCK_START;
 | 
					import static org.thingsboard.server.controller.ControllerConstants.MARKDOWN_CODE_BLOCK_START;
 | 
				
			||||||
import static org.thingsboard.server.controller.ControllerConstants.NEW_LINE;
 | 
					import static org.thingsboard.server.controller.ControllerConstants.NEW_LINE;
 | 
				
			||||||
@ -230,8 +233,11 @@ public class EntitiesVersionControlController extends BaseController {
 | 
				
			|||||||
            MARKDOWN_CODE_BLOCK_END +
 | 
					            MARKDOWN_CODE_BLOCK_END +
 | 
				
			||||||
            TENANT_AUTHORITY_PARAGRAPH)
 | 
					            TENANT_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @GetMapping(value = "/version/{entityType}/{externalEntityUuid}", params = {"branch", "pageSize", "page"})
 | 
					    @GetMapping(value = "/version/{entityType}/{externalEntityUuid}", params = {"branch", "pageSize", "page"})
 | 
				
			||||||
    public DeferredResult<PageData<EntityVersion>> listEntityVersions(@PathVariable EntityType entityType,
 | 
					    public DeferredResult<PageData<EntityVersion>> listEntityVersions(@ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
 | 
					                                                                      @PathVariable EntityType entityType,
 | 
				
			||||||
 | 
					                                                                      @ApiParam(value = "A string value representing external entity id. This is `externalId` property of an entity, or otherwise if not set - simply id of this entity.")
 | 
				
			||||||
                                                                      @PathVariable UUID externalEntityUuid,
 | 
					                                                                      @PathVariable UUID externalEntityUuid,
 | 
				
			||||||
 | 
					                                                                      @ApiParam(value = BRANCH_PARAM_DESCRIPTION)
 | 
				
			||||||
                                                                      @RequestParam String branch,
 | 
					                                                                      @RequestParam String branch,
 | 
				
			||||||
                                                                      @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
 | 
					                                                                      @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
 | 
				
			||||||
                                                                      @RequestParam int pageSize,
 | 
					                                                                      @RequestParam int pageSize,
 | 
				
			||||||
@ -256,7 +262,9 @@ public class EntitiesVersionControlController extends BaseController {
 | 
				
			|||||||
            "The response structure is the same as for `listEntityVersions` API method." +
 | 
					            "The response structure is the same as for `listEntityVersions` API method." +
 | 
				
			||||||
            TENANT_AUTHORITY_PARAGRAPH)
 | 
					            TENANT_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @GetMapping(value = "/version/{entityType}", params = {"branch", "pageSize", "page"})
 | 
					    @GetMapping(value = "/version/{entityType}", params = {"branch", "pageSize", "page"})
 | 
				
			||||||
    public DeferredResult<PageData<EntityVersion>> listEntityTypeVersions(@PathVariable EntityType entityType,
 | 
					    public DeferredResult<PageData<EntityVersion>> listEntityTypeVersions(@ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
 | 
					                                                                          @PathVariable EntityType entityType,
 | 
				
			||||||
 | 
					                                                                          @ApiParam(value = BRANCH_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
                                                                          @RequestParam String branch,
 | 
					                                                                          @RequestParam String branch,
 | 
				
			||||||
                                                                          @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
 | 
					                                                                          @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
 | 
				
			||||||
                                                                          @RequestParam int pageSize,
 | 
					                                                                          @RequestParam int pageSize,
 | 
				
			||||||
@ -279,7 +287,8 @@ public class EntitiesVersionControlController extends BaseController {
 | 
				
			|||||||
            "The response format is the same as for `listEntityVersions` API method." +
 | 
					            "The response format is the same as for `listEntityVersions` API method." +
 | 
				
			||||||
            TENANT_AUTHORITY_PARAGRAPH)
 | 
					            TENANT_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @GetMapping(value = "/version", params = {"branch", "pageSize", "page"})
 | 
					    @GetMapping(value = "/version", params = {"branch", "pageSize", "page"})
 | 
				
			||||||
    public DeferredResult<PageData<EntityVersion>> listVersions(@RequestParam String branch,
 | 
					    public DeferredResult<PageData<EntityVersion>> listVersions(@ApiParam(value = BRANCH_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
 | 
					                                                                @RequestParam String branch,
 | 
				
			||||||
                                                                @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
 | 
					                                                                @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
 | 
				
			||||||
                                                                @RequestParam int pageSize,
 | 
					                                                                @RequestParam int pageSize,
 | 
				
			||||||
                                                                @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
 | 
					                                                                @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
 | 
				
			||||||
@ -302,9 +311,11 @@ public class EntitiesVersionControlController extends BaseController {
 | 
				
			|||||||
            "Entities order will be the same as in the repository." +
 | 
					            "Entities order will be the same as in the repository." +
 | 
				
			||||||
            TENANT_AUTHORITY_PARAGRAPH)
 | 
					            TENANT_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @GetMapping(value = "/entity/{entityType}/{versionId}", params = {"branch"})
 | 
					    @GetMapping(value = "/entity/{entityType}/{versionId}", params = {"branch"})
 | 
				
			||||||
    public DeferredResult<List<VersionedEntityInfo>> listEntitiesAtVersion(@PathVariable EntityType entityType,
 | 
					    public DeferredResult<List<VersionedEntityInfo>> listEntitiesAtVersion(@ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
 | 
					                                                                           @PathVariable EntityType entityType,
 | 
				
			||||||
                                                                           @ApiParam(value = VERSION_ID_PARAM_DESCRIPTION, required = true)
 | 
					                                                                           @ApiParam(value = VERSION_ID_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
                                                                           @PathVariable String versionId,
 | 
					                                                                           @PathVariable String versionId,
 | 
				
			||||||
 | 
					                                                                           @ApiParam(value = BRANCH_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
                                                                           @RequestParam String branch) throws Exception {
 | 
					                                                                           @RequestParam String branch) throws Exception {
 | 
				
			||||||
        accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ);
 | 
					        accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ);
 | 
				
			||||||
        return wrapFuture(versionControlService.listEntitiesAtVersion(getTenantId(), branch, versionId, entityType));
 | 
					        return wrapFuture(versionControlService.listEntitiesAtVersion(getTenantId(), branch, versionId, entityType));
 | 
				
			||||||
@ -318,6 +329,7 @@ public class EntitiesVersionControlController extends BaseController {
 | 
				
			|||||||
    @GetMapping(value = "/entity/{versionId}", params = {"branch"})
 | 
					    @GetMapping(value = "/entity/{versionId}", params = {"branch"})
 | 
				
			||||||
    public DeferredResult<List<VersionedEntityInfo>> listAllEntitiesAtVersion(@ApiParam(value = VERSION_ID_PARAM_DESCRIPTION, required = true)
 | 
					    public DeferredResult<List<VersionedEntityInfo>> listAllEntitiesAtVersion(@ApiParam(value = VERSION_ID_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
                                                                              @PathVariable String versionId,
 | 
					                                                                              @PathVariable String versionId,
 | 
				
			||||||
 | 
					                                                                              @ApiParam(value = BRANCH_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
                                                                              @RequestParam String branch) throws Exception {
 | 
					                                                                              @RequestParam String branch) throws Exception {
 | 
				
			||||||
        accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ);
 | 
					        accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ);
 | 
				
			||||||
        return wrapFuture(versionControlService.listAllEntitiesAtVersion(getTenantId(), branch, versionId));
 | 
					        return wrapFuture(versionControlService.listAllEntitiesAtVersion(getTenantId(), branch, versionId));
 | 
				
			||||||
@ -332,7 +344,9 @@ public class EntitiesVersionControlController extends BaseController {
 | 
				
			|||||||
    @GetMapping("/info/{versionId}/{entityType}/{externalEntityUuid}")
 | 
					    @GetMapping("/info/{versionId}/{entityType}/{externalEntityUuid}")
 | 
				
			||||||
    public DeferredResult<EntityDataInfo> getEntityDataInfo(@ApiParam(value = VERSION_ID_PARAM_DESCRIPTION, required = true)
 | 
					    public DeferredResult<EntityDataInfo> getEntityDataInfo(@ApiParam(value = VERSION_ID_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
                                                            @PathVariable String versionId,
 | 
					                                                            @PathVariable String versionId,
 | 
				
			||||||
 | 
					                                                            @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
                                                            @PathVariable EntityType entityType,
 | 
					                                                            @PathVariable EntityType entityType,
 | 
				
			||||||
 | 
					                                                            @ApiParam(value = "A string value representing external entity id", required = true)
 | 
				
			||||||
                                                            @PathVariable UUID externalEntityUuid) throws Exception {
 | 
					                                                            @PathVariable UUID externalEntityUuid) throws Exception {
 | 
				
			||||||
        accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ);
 | 
					        accessControlService.checkPermission(getCurrentUser(), Resource.VERSION_CONTROL, Operation.READ);
 | 
				
			||||||
        EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, externalEntityUuid);
 | 
					        EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, externalEntityUuid);
 | 
				
			||||||
@ -344,8 +358,11 @@ public class EntitiesVersionControlController extends BaseController {
 | 
				
			|||||||
            "Entity data structure is the same as stored in a repository. " +
 | 
					            "Entity data structure is the same as stored in a repository. " +
 | 
				
			||||||
            TENANT_AUTHORITY_PARAGRAPH)
 | 
					            TENANT_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @GetMapping(value = "/diff/{entityType}/{internalEntityUuid}", params = {"branch", "versionId"})
 | 
					    @GetMapping(value = "/diff/{entityType}/{internalEntityUuid}", params = {"branch", "versionId"})
 | 
				
			||||||
    public DeferredResult<EntityDataDiff> compareEntityDataToVersion(@PathVariable EntityType entityType,
 | 
					    public DeferredResult<EntityDataDiff> compareEntityDataToVersion(@ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
 | 
					                                                                     @PathVariable EntityType entityType,
 | 
				
			||||||
 | 
					                                                                     @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
                                                                     @PathVariable UUID internalEntityUuid,
 | 
					                                                                     @PathVariable UUID internalEntityUuid,
 | 
				
			||||||
 | 
					                                                                     @ApiParam(value = BRANCH_PARAM_DESCRIPTION)
 | 
				
			||||||
                                                                     @RequestParam String branch,
 | 
					                                                                     @RequestParam String branch,
 | 
				
			||||||
                                                                     @ApiParam(value = VERSION_ID_PARAM_DESCRIPTION, required = true)
 | 
					                                                                     @ApiParam(value = VERSION_ID_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
                                                                     @RequestParam String versionId) throws Exception {
 | 
					                                                                     @RequestParam String versionId) throws Exception {
 | 
				
			||||||
 | 
				
			|||||||
@ -128,7 +128,7 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void notifyCreateOruUpdateTenant(Tenant tenant, ComponentLifecycleEvent event) {
 | 
					    public void notifyCreateOrUpdateTenant(Tenant tenant, ComponentLifecycleEvent event) {
 | 
				
			||||||
        tbClusterService.onTenantChange(tenant, null);
 | 
					        tbClusterService.onTenantChange(tenant, null);
 | 
				
			||||||
        tbClusterService.broadcastEntityStateChangeEvent(tenant.getId(), tenant.getId(), event);
 | 
					        tbClusterService.broadcastEntityStateChangeEvent(tenant.getId(), tenant.getId(), event);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -71,7 +71,7 @@ public interface TbNotificationEntityService {
 | 
				
			|||||||
                                                                                    E entity, ActionType actionType,
 | 
					                                                                                    E entity, ActionType actionType,
 | 
				
			||||||
                                                                                    SecurityUser user, Object... additionalInfo);
 | 
					                                                                                    SecurityUser user, Object... additionalInfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void notifyCreateOruUpdateTenant(Tenant tenant, ComponentLifecycleEvent event);
 | 
					    void notifyCreateOrUpdateTenant(Tenant tenant, ComponentLifecycleEvent event);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void notifyDeleteTenant(Tenant tenant);
 | 
					    void notifyDeleteTenant(Tenant tenant);
 | 
				
			||||||
 | 
				
			|||||||
@ -54,7 +54,7 @@ public class DefaultTbTenantService extends AbstractTbEntityService implements T
 | 
				
			|||||||
                installScripts.createDefaultEdgeRuleChains(savedTenant.getId());
 | 
					                installScripts.createDefaultEdgeRuleChains(savedTenant.getId());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            tenantProfileCache.evict(savedTenant.getId());
 | 
					            tenantProfileCache.evict(savedTenant.getId());
 | 
				
			||||||
            notificationEntityService.notifyCreateOruUpdateTenant(savedTenant, created ?
 | 
					            notificationEntityService.notifyCreateOrUpdateTenant(savedTenant, created ?
 | 
				
			||||||
                    ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
 | 
					                    ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            TenantProfile oldTenantProfile = oldTenant != null ? tenantProfileService.findTenantProfileById(TenantId.SYS_TENANT_ID, oldTenant.getTenantProfileId()) : null;
 | 
					            TenantProfile oldTenantProfile = oldTenant != null ? tenantProfileService.findTenantProfileById(TenantId.SYS_TENANT_ID, oldTenant.getTenantProfileId()) : null;
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,7 @@ import org.thingsboard.server.dao.relation.RelationService;
 | 
				
			|||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
					import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
				
			||||||
import org.thingsboard.server.service.action.EntityActionService;
 | 
					import org.thingsboard.server.service.action.EntityActionService;
 | 
				
			||||||
import org.thingsboard.server.service.apiusage.RateLimitService;
 | 
					import org.thingsboard.server.service.apiusage.RateLimitService;
 | 
				
			||||||
 | 
					import org.thingsboard.server.service.entitiy.TbNotificationEntityService;
 | 
				
			||||||
import org.thingsboard.server.service.sync.ie.exporting.EntityExportService;
 | 
					import org.thingsboard.server.service.sync.ie.exporting.EntityExportService;
 | 
				
			||||||
import org.thingsboard.server.service.sync.ie.exporting.impl.BaseEntityExportService;
 | 
					import org.thingsboard.server.service.sync.ie.exporting.impl.BaseEntityExportService;
 | 
				
			||||||
import org.thingsboard.server.service.sync.ie.exporting.impl.DefaultEntityExportService;
 | 
					import org.thingsboard.server.service.sync.ie.exporting.impl.DefaultEntityExportService;
 | 
				
			||||||
@ -57,9 +58,9 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
 | 
				
			|||||||
    private final Map<EntityType, EntityExportService<?, ?, ?>> exportServices = new HashMap<>();
 | 
					    private final Map<EntityType, EntityExportService<?, ?, ?>> exportServices = new HashMap<>();
 | 
				
			||||||
    private final Map<EntityType, EntityImportService<?, ?, ?>> importServices = new HashMap<>();
 | 
					    private final Map<EntityType, EntityImportService<?, ?, ?>> importServices = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final EntityActionService entityActionService;
 | 
					 | 
				
			||||||
    private final RelationService relationService;
 | 
					    private final RelationService relationService;
 | 
				
			||||||
    private final RateLimitService rateLimitService;
 | 
					    private final RateLimitService rateLimitService;
 | 
				
			||||||
 | 
					    private final TbNotificationEntityService entityNotificationService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected static final List<EntityType> SUPPORTED_ENTITY_TYPES = List.of(
 | 
					    protected static final List<EntityType> SUPPORTED_ENTITY_TYPES = List.of(
 | 
				
			||||||
            EntityType.CUSTOMER, EntityType.ASSET, EntityType.RULE_CHAIN,
 | 
					            EntityType.CUSTOMER, EntityType.ASSET, EntityType.RULE_CHAIN,
 | 
				
			||||||
@ -109,10 +110,8 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
 | 
				
			|||||||
        relationService.saveRelations(ctx.getTenantId(), new ArrayList<>(ctx.getRelations()));
 | 
					        relationService.saveRelations(ctx.getTenantId(), new ArrayList<>(ctx.getRelations()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (EntityRelation relation : ctx.getRelations()) {
 | 
					        for (EntityRelation relation : ctx.getRelations()) {
 | 
				
			||||||
            entityActionService.logEntityAction(ctx.getUser(), relation.getFrom(), null, null,
 | 
					            entityNotificationService.notifyCreateOrUpdateOrDeleteRelation(ctx.getTenantId(), null,
 | 
				
			||||||
                    ActionType.RELATION_ADD_OR_UPDATE, null, relation);
 | 
					                    relation, ctx.getUser(), ActionType.RELATION_ADD_OR_UPDATE, null, relation);
 | 
				
			||||||
            entityActionService.logEntityAction(ctx.getUser(), relation.getTo(), null, null,
 | 
					 | 
				
			||||||
                    ActionType.RELATION_ADD_OR_UPDATE, null, relation);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -41,8 +41,6 @@ public abstract class BaseEntityExportService<I extends EntityId, E extends Expo
 | 
				
			|||||||
        return (D) new EntityExportData<E>();
 | 
					        return (D) new EntityExportData<E>();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public abstract Set<EntityType> getSupportedEntityTypes();
 | 
					    public abstract Set<EntityType> getSupportedEntityTypes();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected void replaceUuidsRecursively(EntitiesExportCtx<?> ctx, JsonNode node, Set<String> skipFieldsSet) {
 | 
					    protected void replaceUuidsRecursively(EntitiesExportCtx<?> ctx, JsonNode node, Set<String> skipFieldsSet) {
 | 
				
			||||||
 | 
				
			|||||||
@ -30,7 +30,7 @@ import org.thingsboard.server.common.data.relation.RelationTypeGroup;
 | 
				
			|||||||
import org.thingsboard.server.common.data.sync.ie.AttributeExportData;
 | 
					import org.thingsboard.server.common.data.sync.ie.AttributeExportData;
 | 
				
			||||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
 | 
					import org.thingsboard.server.common.data.sync.ie.EntityExportData;
 | 
				
			||||||
import org.thingsboard.server.dao.attributes.AttributesService;
 | 
					import org.thingsboard.server.dao.attributes.AttributesService;
 | 
				
			||||||
import org.thingsboard.server.dao.relation.RelationService;
 | 
					import org.thingsboard.server.dao.relation.RelationDao;
 | 
				
			||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
					import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
				
			||||||
import org.thingsboard.server.service.sync.ie.exporting.EntityExportService;
 | 
					import org.thingsboard.server.service.sync.ie.exporting.EntityExportService;
 | 
				
			||||||
import org.thingsboard.server.service.sync.ie.exporting.ExportableEntitiesService;
 | 
					import org.thingsboard.server.service.sync.ie.exporting.ExportableEntitiesService;
 | 
				
			||||||
@ -55,7 +55,7 @@ public class DefaultEntityExportService<I extends EntityId, E extends Exportable
 | 
				
			|||||||
    @Lazy
 | 
					    @Lazy
 | 
				
			||||||
    protected ExportableEntitiesService exportableEntitiesService;
 | 
					    protected ExportableEntitiesService exportableEntitiesService;
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private RelationService relationService;
 | 
					    private RelationDao relationDao;
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private AttributesService attributesService;
 | 
					    private AttributesService attributesService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -99,10 +99,10 @@ public class DefaultEntityExportService<I extends EntityId, E extends Exportable
 | 
				
			|||||||
    private List<EntityRelation> exportRelations(EntitiesExportCtx<?> ctx, E entity) throws ThingsboardException {
 | 
					    private List<EntityRelation> exportRelations(EntitiesExportCtx<?> ctx, E entity) throws ThingsboardException {
 | 
				
			||||||
        List<EntityRelation> relations = new ArrayList<>();
 | 
					        List<EntityRelation> relations = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List<EntityRelation> inboundRelations = relationService.findByTo(ctx.getTenantId(), entity.getId(), RelationTypeGroup.COMMON);
 | 
					        List<EntityRelation> inboundRelations = relationDao.findAllByTo(ctx.getTenantId(), entity.getId(), RelationTypeGroup.COMMON);
 | 
				
			||||||
        relations.addAll(inboundRelations);
 | 
					        relations.addAll(inboundRelations);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List<EntityRelation> outboundRelations = relationService.findByFrom(ctx.getTenantId(), entity.getId(), RelationTypeGroup.COMMON);
 | 
					        List<EntityRelation> outboundRelations = relationDao.findAllByFrom(ctx.getTenantId(), entity.getId(), RelationTypeGroup.COMMON);
 | 
				
			||||||
        relations.addAll(outboundRelations);
 | 
					        relations.addAll(outboundRelations);
 | 
				
			||||||
        return relations;
 | 
					        return relations;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -19,14 +19,11 @@ import lombok.RequiredArgsConstructor;
 | 
				
			|||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
import org.thingsboard.server.common.data.EntityType;
 | 
					import org.thingsboard.server.common.data.EntityType;
 | 
				
			||||||
import org.thingsboard.server.common.data.asset.Asset;
 | 
					import org.thingsboard.server.common.data.asset.Asset;
 | 
				
			||||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
 | 
					 | 
				
			||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
					 | 
				
			||||||
import org.thingsboard.server.common.data.id.AssetId;
 | 
					import org.thingsboard.server.common.data.id.AssetId;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
					import org.thingsboard.server.common.data.id.TenantId;
 | 
				
			||||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
 | 
					import org.thingsboard.server.common.data.sync.ie.EntityExportData;
 | 
				
			||||||
import org.thingsboard.server.dao.asset.AssetService;
 | 
					import org.thingsboard.server.dao.asset.AssetService;
 | 
				
			||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
					import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
				
			||||||
import org.thingsboard.server.service.security.model.SecurityUser;
 | 
					 | 
				
			||||||
import org.thingsboard.server.service.sync.vc.data.EntitiesImportCtx;
 | 
					import org.thingsboard.server.service.sync.vc.data.EntitiesImportCtx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Service
 | 
					@Service
 | 
				
			||||||
@ -52,14 +49,6 @@ public class AssetImportService extends BaseEntityImportService<AssetId, Asset,
 | 
				
			|||||||
        return assetService.saveAsset(asset);
 | 
					        return assetService.saveAsset(asset);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    protected void onEntitySaved(SecurityUser user, Asset savedAsset, Asset oldAsset) throws ThingsboardException {
 | 
					 | 
				
			||||||
        super.onEntitySaved(user, savedAsset, oldAsset);
 | 
					 | 
				
			||||||
        if (oldAsset != null) {
 | 
					 | 
				
			||||||
            entityActionService.sendEntityNotificationMsgToEdge(user.getTenantId(), savedAsset.getId(), EdgeEventActionType.UPDATED);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected Asset deepCopy(Asset asset) {
 | 
					    protected Asset deepCopy(Asset asset) {
 | 
				
			||||||
        return new Asset(asset);
 | 
					        return new Asset(asset);
 | 
				
			||||||
 | 
				
			|||||||
@ -26,10 +26,8 @@ import org.springframework.context.annotation.Lazy;
 | 
				
			|||||||
import org.springframework.transaction.annotation.Transactional;
 | 
					import org.springframework.transaction.annotation.Transactional;
 | 
				
			||||||
import org.thingsboard.common.util.JacksonUtil;
 | 
					import org.thingsboard.common.util.JacksonUtil;
 | 
				
			||||||
import org.thingsboard.server.cluster.TbClusterService;
 | 
					import org.thingsboard.server.cluster.TbClusterService;
 | 
				
			||||||
import org.thingsboard.server.common.data.Device;
 | 
					 | 
				
			||||||
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.HasCustomerId;
 | 
					 | 
				
			||||||
import org.thingsboard.server.common.data.audit.ActionType;
 | 
					import org.thingsboard.server.common.data.audit.ActionType;
 | 
				
			||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
					import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.EntityId;
 | 
					import org.thingsboard.server.common.data.id.EntityId;
 | 
				
			||||||
@ -49,13 +47,13 @@ import org.thingsboard.server.common.data.relation.RelationTypeGroup;
 | 
				
			|||||||
import org.thingsboard.server.common.data.sync.ie.AttributeExportData;
 | 
					import org.thingsboard.server.common.data.sync.ie.AttributeExportData;
 | 
				
			||||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
 | 
					import org.thingsboard.server.common.data.sync.ie.EntityExportData;
 | 
				
			||||||
import org.thingsboard.server.common.data.sync.ie.EntityImportResult;
 | 
					import org.thingsboard.server.common.data.sync.ie.EntityImportResult;
 | 
				
			||||||
 | 
					import org.thingsboard.server.dao.relation.RelationDao;
 | 
				
			||||||
import org.thingsboard.server.dao.relation.RelationService;
 | 
					import org.thingsboard.server.dao.relation.RelationService;
 | 
				
			||||||
import org.thingsboard.server.service.action.EntityActionService;
 | 
					import org.thingsboard.server.service.action.EntityActionService;
 | 
				
			||||||
import org.thingsboard.server.service.entitiy.TbNotificationEntityService;
 | 
					import org.thingsboard.server.service.entitiy.TbNotificationEntityService;
 | 
				
			||||||
import org.thingsboard.server.service.security.model.SecurityUser;
 | 
					import org.thingsboard.server.service.security.model.SecurityUser;
 | 
				
			||||||
import org.thingsboard.server.service.sync.ie.exporting.ExportableEntitiesService;
 | 
					import org.thingsboard.server.service.sync.ie.exporting.ExportableEntitiesService;
 | 
				
			||||||
import org.thingsboard.server.service.sync.ie.importing.EntityImportService;
 | 
					import org.thingsboard.server.service.sync.ie.importing.EntityImportService;
 | 
				
			||||||
import org.thingsboard.server.service.sync.vc.data.EntitiesExportCtx;
 | 
					 | 
				
			||||||
import org.thingsboard.server.service.sync.vc.data.EntitiesImportCtx;
 | 
					import org.thingsboard.server.service.sync.vc.data.EntitiesImportCtx;
 | 
				
			||||||
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService;
 | 
					import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -79,6 +77,8 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
 | 
				
			|||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private RelationService relationService;
 | 
					    private RelationService relationService;
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    private RelationDao relationDao;
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
    private TelemetrySubscriptionService tsSubService;
 | 
					    private TelemetrySubscriptionService tsSubService;
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    protected EntityActionService entityActionService;
 | 
					    protected EntityActionService entityActionService;
 | 
				
			||||||
@ -203,19 +203,18 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if (importResult.getOldEntity() != null) {
 | 
					            if (importResult.getOldEntity() != null) {
 | 
				
			||||||
                List<EntityRelation> existingRelations = new ArrayList<>();
 | 
					                List<EntityRelation> existingRelations = new ArrayList<>();
 | 
				
			||||||
                existingRelations.addAll(relationService.findByTo(tenantId, entity.getId(), RelationTypeGroup.COMMON));
 | 
					                existingRelations.addAll(relationDao.findAllByTo(tenantId, entity.getId(), RelationTypeGroup.COMMON));
 | 
				
			||||||
                existingRelations.addAll(relationService.findByFrom(tenantId, entity.getId(), RelationTypeGroup.COMMON));
 | 
					                existingRelations.addAll(relationDao.findAllByFrom(tenantId, entity.getId(), RelationTypeGroup.COMMON));
 | 
				
			||||||
 | 
					                // dao is used here instead of service to avoid getting cached values, because relationService.deleteRelation will evict value from cache only after transaction is committed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                for (EntityRelation existingRelation : existingRelations) {
 | 
					                for (EntityRelation existingRelation : existingRelations) {
 | 
				
			||||||
                    EntityRelation relation = relationsMap.get(existingRelation);
 | 
					                    EntityRelation relation = relationsMap.get(existingRelation);
 | 
				
			||||||
                    if (relation == null) {
 | 
					                    if (relation == null) {
 | 
				
			||||||
                        importResult.setUpdatedRelatedEntities(true);
 | 
					                        importResult.setUpdatedRelatedEntities(true);
 | 
				
			||||||
                        relationService.deleteRelation(tenantId, existingRelation);
 | 
					                        relationService.deleteRelation(ctx.getTenantId(), existingRelation.getFrom(), existingRelation.getTo(), existingRelation.getType(), existingRelation.getTypeGroup());
 | 
				
			||||||
                        importResult.addSendEventsCallback(() -> {
 | 
					                        importResult.addSendEventsCallback(() -> {
 | 
				
			||||||
                            entityActionService.logEntityAction(ctx.getUser(), existingRelation.getFrom(), null, null,
 | 
					                            entityNotificationService.notifyCreateOrUpdateOrDeleteRelation(tenantId, null,
 | 
				
			||||||
                                    ActionType.RELATION_DELETED, null, existingRelation);
 | 
					                                    existingRelation, ctx.getUser(), ActionType.RELATION_DELETED, null, existingRelation);
 | 
				
			||||||
                            entityActionService.logEntityAction(ctx.getUser(), existingRelation.getTo(), null, null,
 | 
					 | 
				
			||||||
                                    ActionType.RELATION_DELETED, null, existingRelation);
 | 
					 | 
				
			||||||
                        });
 | 
					                        });
 | 
				
			||||||
                    } else if (Objects.equal(relation.getAdditionalInfo(), existingRelation.getAdditionalInfo())) {
 | 
					                    } else if (Objects.equal(relation.getAdditionalInfo(), existingRelation.getAdditionalInfo())) {
 | 
				
			||||||
                        relationsMap.remove(relation);
 | 
					                        relationsMap.remove(relation);
 | 
				
			||||||
@ -269,9 +268,8 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected void onEntitySaved(SecurityUser user, E savedEntity, E oldEntity) throws ThingsboardException {
 | 
					    protected void onEntitySaved(SecurityUser user, E savedEntity, E oldEntity) throws ThingsboardException {
 | 
				
			||||||
        entityActionService.logEntityAction(user, savedEntity.getId(), savedEntity,
 | 
					        entityNotificationService.notifyCreateOrUpdateEntity(user.getTenantId(), savedEntity.getId(), savedEntity,
 | 
				
			||||||
                savedEntity instanceof HasCustomerId ? ((HasCustomerId) savedEntity).getCustomerId() : user.getCustomerId(),
 | 
					                null, oldEntity == null ? ActionType.ADDED : ActionType.UPDATED, user);
 | 
				
			||||||
                oldEntity == null ? ActionType.ADDED : ActionType.UPDATED, null);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -68,14 +68,6 @@ public class CustomerImportService extends BaseEntityImportService<CustomerId, C
 | 
				
			|||||||
        return new Customer(customer);
 | 
					        return new Customer(customer);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    protected void onEntitySaved(SecurityUser user, Customer savedCustomer, Customer oldCustomer) throws ThingsboardException {
 | 
					 | 
				
			||||||
        super.onEntitySaved(user, savedCustomer, oldCustomer);
 | 
					 | 
				
			||||||
        if (oldCustomer != null) {
 | 
					 | 
				
			||||||
            entityActionService.sendEntityNotificationMsgToEdge(user.getTenantId(), savedCustomer.getId(), EdgeEventActionType.UPDATED);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public EntityType getEntityType() {
 | 
					    public EntityType getEntityType() {
 | 
				
			||||||
        return EntityType.CUSTOMER;
 | 
					        return EntityType.CUSTOMER;
 | 
				
			||||||
 | 
				
			|||||||
@ -118,11 +118,8 @@ public class DashboardImportService extends BaseEntityImportService<DashboardId,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected void onEntitySaved(SecurityUser user, Dashboard savedDashboard, Dashboard oldDashboard) throws ThingsboardException {
 | 
					    protected boolean compare(EntitiesImportCtx ctx, EntityExportData<Dashboard> exportData, Dashboard prepared, Dashboard existing) {
 | 
				
			||||||
        super.onEntitySaved(user, savedDashboard, oldDashboard);
 | 
					        return super.compare(ctx, exportData, prepared, existing) || !prepared.getConfiguration().equals(existing.getConfiguration());
 | 
				
			||||||
        if (oldDashboard != null) {
 | 
					 | 
				
			||||||
            entityActionService.sendEntityNotificationMsgToEdge(user.getTenantId(), savedDashboard.getId(), EdgeEventActionType.UPDATED);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
 | 
				
			|||||||
@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor;
 | 
				
			|||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
import org.thingsboard.server.common.data.Device;
 | 
					import org.thingsboard.server.common.data.Device;
 | 
				
			||||||
import org.thingsboard.server.common.data.EntityType;
 | 
					import org.thingsboard.server.common.data.EntityType;
 | 
				
			||||||
 | 
					import org.thingsboard.server.common.data.audit.ActionType;
 | 
				
			||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
					import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.DeviceId;
 | 
					import org.thingsboard.server.common.data.id.DeviceId;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
					import org.thingsboard.server.common.data.id.TenantId;
 | 
				
			||||||
@ -93,8 +94,8 @@ public class DeviceImportService extends BaseEntityImportService<DeviceId, Devic
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected void onEntitySaved(SecurityUser user, Device savedDevice, Device oldDevice) throws ThingsboardException {
 | 
					    protected void onEntitySaved(SecurityUser user, Device savedDevice, Device oldDevice) throws ThingsboardException {
 | 
				
			||||||
        super.onEntitySaved(user, savedDevice, oldDevice);
 | 
					        entityNotificationService.notifyCreateOrUpdateDevice(user.getTenantId(), savedDevice.getId(), savedDevice.getCustomerId(),
 | 
				
			||||||
        clusterService.onDeviceUpdated(savedDevice, oldDevice);
 | 
					                savedDevice, oldDevice, oldDevice == null ? ActionType.ADDED : ActionType.UPDATED, user);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
 | 
				
			|||||||
@ -52,6 +52,7 @@ public class DeviceProfileImportService extends BaseEntityImportService<DevicePr
 | 
				
			|||||||
        deviceProfile.setDefaultDashboardId(idProvider.getInternalId(deviceProfile.getDefaultDashboardId()));
 | 
					        deviceProfile.setDefaultDashboardId(idProvider.getInternalId(deviceProfile.getDefaultDashboardId()));
 | 
				
			||||||
        deviceProfile.setFirmwareId(getOldEntityField(old, DeviceProfile::getFirmwareId));
 | 
					        deviceProfile.setFirmwareId(getOldEntityField(old, DeviceProfile::getFirmwareId));
 | 
				
			||||||
        deviceProfile.setSoftwareId(getOldEntityField(old, DeviceProfile::getSoftwareId));
 | 
					        deviceProfile.setSoftwareId(getOldEntityField(old, DeviceProfile::getSoftwareId));
 | 
				
			||||||
 | 
					        deviceProfile.setDefaultQueueId(getOldEntityField(old, DeviceProfile::getDefaultQueueId));
 | 
				
			||||||
        return deviceProfile;
 | 
					        return deviceProfile;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -62,15 +63,13 @@ public class DeviceProfileImportService extends BaseEntityImportService<DevicePr
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected void onEntitySaved(SecurityUser user, DeviceProfile savedDeviceProfile, DeviceProfile oldDeviceProfile) throws ThingsboardException {
 | 
					    protected void onEntitySaved(SecurityUser user, DeviceProfile savedDeviceProfile, DeviceProfile oldDeviceProfile) throws ThingsboardException {
 | 
				
			||||||
        super.onEntitySaved(user, savedDeviceProfile, oldDeviceProfile);
 | 
					 | 
				
			||||||
        clusterService.onDeviceProfileChange(savedDeviceProfile, null);
 | 
					        clusterService.onDeviceProfileChange(savedDeviceProfile, null);
 | 
				
			||||||
        clusterService.broadcastEntityStateChangeEvent(user.getTenantId(), savedDeviceProfile.getId(),
 | 
					        clusterService.broadcastEntityStateChangeEvent(user.getTenantId(), savedDeviceProfile.getId(),
 | 
				
			||||||
                oldDeviceProfile == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
 | 
					                oldDeviceProfile == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
 | 
				
			||||||
        entityActionService.sendEntityNotificationMsgToEdge(user.getTenantId(), savedDeviceProfile.getId(),
 | 
					 | 
				
			||||||
                oldDeviceProfile == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
 | 
					 | 
				
			||||||
        otaPackageStateService.update(savedDeviceProfile,
 | 
					        otaPackageStateService.update(savedDeviceProfile,
 | 
				
			||||||
                oldDeviceProfile != null && !Objects.equals(oldDeviceProfile.getFirmwareId(), savedDeviceProfile.getFirmwareId()),
 | 
					                oldDeviceProfile != null && !Objects.equals(oldDeviceProfile.getFirmwareId(), savedDeviceProfile.getFirmwareId()),
 | 
				
			||||||
                oldDeviceProfile != null && !Objects.equals(oldDeviceProfile.getSoftwareId(), savedDeviceProfile.getSoftwareId()));
 | 
					                oldDeviceProfile != null && !Objects.equals(oldDeviceProfile.getSoftwareId(), savedDeviceProfile.getSoftwareId()));
 | 
				
			||||||
 | 
					        super.onEntitySaved(user, savedDeviceProfile, oldDeviceProfile);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
 | 
				
			|||||||
@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.edge.EdgeEventActionType;
 | 
				
			|||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
					import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.EntityViewId;
 | 
					import org.thingsboard.server.common.data.id.EntityViewId;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
					import org.thingsboard.server.common.data.id.TenantId;
 | 
				
			||||||
 | 
					import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
 | 
				
			||||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
 | 
					import org.thingsboard.server.common.data.sync.ie.EntityExportData;
 | 
				
			||||||
import org.thingsboard.server.dao.entityview.EntityViewService;
 | 
					import org.thingsboard.server.dao.entityview.EntityViewService;
 | 
				
			||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
					import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
				
			||||||
@ -64,9 +65,8 @@ public class EntityViewImportService extends BaseEntityImportService<EntityViewI
 | 
				
			|||||||
    protected void onEntitySaved(SecurityUser user, EntityView savedEntityView, EntityView oldEntityView) throws ThingsboardException {
 | 
					    protected void onEntitySaved(SecurityUser user, EntityView savedEntityView, EntityView oldEntityView) throws ThingsboardException {
 | 
				
			||||||
        tbEntityViewService.updateEntityViewAttributes(user, savedEntityView, oldEntityView);
 | 
					        tbEntityViewService.updateEntityViewAttributes(user, savedEntityView, oldEntityView);
 | 
				
			||||||
        super.onEntitySaved(user, savedEntityView, oldEntityView);
 | 
					        super.onEntitySaved(user, savedEntityView, oldEntityView);
 | 
				
			||||||
        if (oldEntityView != null) {
 | 
					        clusterService.broadcastEntityStateChangeEvent(savedEntityView.getTenantId(), savedEntityView.getId(),
 | 
				
			||||||
            entityActionService.sendEntityNotificationMsgToEdge(user.getTenantId(), savedEntityView.getId(), EdgeEventActionType.UPDATED);
 | 
					                oldEntityView == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
 | 
				
			|||||||
@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor;
 | 
				
			|||||||
import lombok.extern.slf4j.Slf4j;
 | 
					import lombok.extern.slf4j.Slf4j;
 | 
				
			||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
import org.thingsboard.server.common.data.EntityType;
 | 
					import org.thingsboard.server.common.data.EntityType;
 | 
				
			||||||
 | 
					import org.thingsboard.server.common.data.audit.ActionType;
 | 
				
			||||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
 | 
					import org.thingsboard.server.common.data.edge.EdgeEventActionType;
 | 
				
			||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
					import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
				
			||||||
import org.thingsboard.server.common.data.id.RuleChainId;
 | 
					import org.thingsboard.server.common.data.id.RuleChainId;
 | 
				
			||||||
@ -119,14 +120,15 @@ public class RuleChainImportService extends BaseEntityImportService<RuleChainId,
 | 
				
			|||||||
            RuleChainMetaData newMD = exportData.getMetaData();
 | 
					            RuleChainMetaData newMD = exportData.getMetaData();
 | 
				
			||||||
            RuleChainMetaData existingMD = ruleChainService.loadRuleChainMetaData(ctx.getTenantId(), prepared.getId());
 | 
					            RuleChainMetaData existingMD = ruleChainService.loadRuleChainMetaData(ctx.getTenantId(), prepared.getId());
 | 
				
			||||||
            existingMD.setRuleChainId(null);
 | 
					            existingMD.setRuleChainId(null);
 | 
				
			||||||
            different = newMD.equals(existingMD);
 | 
					            different = !newMD.equals(existingMD);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return different;
 | 
					        return different;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected void onEntitySaved(SecurityUser user, RuleChain savedRuleChain, RuleChain oldRuleChain) throws ThingsboardException {
 | 
					    protected void onEntitySaved(SecurityUser user, RuleChain savedRuleChain, RuleChain oldRuleChain) throws ThingsboardException {
 | 
				
			||||||
        super.onEntitySaved(user, savedRuleChain, oldRuleChain);
 | 
					        entityActionService.logEntityAction(user, savedRuleChain.getId(), savedRuleChain, null,
 | 
				
			||||||
 | 
					                oldRuleChain == null ? ActionType.ADDED : ActionType.UPDATED, null);
 | 
				
			||||||
        if (savedRuleChain.getType() == RuleChainType.CORE) {
 | 
					        if (savedRuleChain.getType() == RuleChainType.CORE) {
 | 
				
			||||||
            clusterService.broadcastEntityStateChangeEvent(user.getTenantId(), savedRuleChain.getId(),
 | 
					            clusterService.broadcastEntityStateChangeEvent(user.getTenantId(), savedRuleChain.getId(),
 | 
				
			||||||
                    oldRuleChain == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
 | 
					                    oldRuleChain == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
 | 
				
			||||||
 | 
				
			|||||||
@ -86,9 +86,13 @@ public class WidgetsBundleImportService extends BaseEntityImportService<WidgetsB
 | 
				
			|||||||
        return savedWidgetsBundle;
 | 
					        return savedWidgetsBundle;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    protected boolean compare(EntitiesImportCtx ctx, WidgetsBundleExportData exportData, WidgetsBundle prepared, WidgetsBundle existing) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected void onEntitySaved(SecurityUser user, WidgetsBundle savedWidgetsBundle, WidgetsBundle oldWidgetsBundle) throws ThingsboardException {
 | 
					    protected void onEntitySaved(SecurityUser user, WidgetsBundle savedWidgetsBundle, WidgetsBundle oldWidgetsBundle) throws ThingsboardException {
 | 
				
			||||||
        super.onEntitySaved(user, savedWidgetsBundle, oldWidgetsBundle);
 | 
					 | 
				
			||||||
        entityNotificationService.notifySendMsgToEdgeService(user.getTenantId(), savedWidgetsBundle.getId(),
 | 
					        entityNotificationService.notifySendMsgToEdgeService(user.getTenantId(), savedWidgetsBundle.getId(),
 | 
				
			||||||
                oldWidgetsBundle == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
 | 
					                oldWidgetsBundle == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -23,7 +23,6 @@ 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 com.google.common.util.concurrent.MoreExecutors;
 | 
				
			||||||
import com.google.gson.JsonParseException;
 | 
					import com.google.gson.JsonParseException;
 | 
				
			||||||
import lombok.extern.slf4j.Slf4j;
 | 
					 | 
				
			||||||
import org.apache.commons.collections.CollectionUtils;
 | 
					import org.apache.commons.collections.CollectionUtils;
 | 
				
			||||||
import org.apache.commons.lang3.BooleanUtils;
 | 
					import org.apache.commons.lang3.BooleanUtils;
 | 
				
			||||||
import org.thingsboard.rule.engine.api.TbContext;
 | 
					import org.thingsboard.rule.engine.api.TbContext;
 | 
				
			||||||
@ -50,7 +49,6 @@ import static org.thingsboard.server.common.data.DataConstants.LATEST_TS;
 | 
				
			|||||||
import static org.thingsboard.server.common.data.DataConstants.SERVER_SCOPE;
 | 
					import static org.thingsboard.server.common.data.DataConstants.SERVER_SCOPE;
 | 
				
			||||||
import static org.thingsboard.server.common.data.DataConstants.SHARED_SCOPE;
 | 
					import static org.thingsboard.server.common.data.DataConstants.SHARED_SCOPE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Slf4j
 | 
					 | 
				
			||||||
public abstract class TbAbstractGetAttributesNode<C extends TbGetAttributesNodeConfiguration, T extends EntityId> implements TbNode {
 | 
					public abstract class TbAbstractGetAttributesNode<C extends TbGetAttributesNodeConfiguration, T extends EntityId> implements TbNode {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static ObjectMapper mapper = new ObjectMapper();
 | 
					    private static ObjectMapper mapper = new ObjectMapper();
 | 
				
			||||||
@ -113,7 +111,6 @@ public abstract class TbAbstractGetAttributesNode<C extends TbGetAttributesNodeC
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        ListenableFuture<List<AttributeKvEntry>> attributeKvEntryListFuture = ctx.getAttributesService().find(ctx.getTenantId(), entityId, scope, keys);
 | 
					        ListenableFuture<List<AttributeKvEntry>> attributeKvEntryListFuture = ctx.getAttributesService().find(ctx.getTenantId(), entityId, scope, keys);
 | 
				
			||||||
        return Futures.transform(attributeKvEntryListFuture, attributeKvEntryList -> {
 | 
					        return Futures.transform(attributeKvEntryListFuture, attributeKvEntryList -> {
 | 
				
			||||||
            log.warn("[{}][{}][{}][{}] Lookup attribute result: {}", ctx.getTenantId(), entityId, scope, keys, attributeKvEntryList);
 | 
					 | 
				
			||||||
            if (!CollectionUtils.isEmpty(attributeKvEntryList)) {
 | 
					            if (!CollectionUtils.isEmpty(attributeKvEntryList)) {
 | 
				
			||||||
                List<AttributeKvEntry> existingAttributesKvEntry = attributeKvEntryList.stream().filter(attributeKvEntry -> keys.contains(attributeKvEntry.getKey())).collect(Collectors.toList());
 | 
					                List<AttributeKvEntry> existingAttributesKvEntry = attributeKvEntryList.stream().filter(attributeKvEntry -> keys.contains(attributeKvEntry.getKey())).collect(Collectors.toList());
 | 
				
			||||||
                existingAttributesKvEntry.forEach(kvEntry -> msg.getMetaData().putValue(prefix + kvEntry.getKey(), kvEntry.getValueAsString()));
 | 
					                existingAttributesKvEntry.forEach(kvEntry -> msg.getMetaData().putValue(prefix + kvEntry.getKey(), kvEntry.getValueAsString()));
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user