Merge PR #6785
This commit is contained in:
parent
7bad2782ea
commit
7c69b7c080
@ -72,6 +72,7 @@ import org.thingsboard.server.gen.edge.v1.RelationRequestMsg;
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataRequestMsg;
|
||||
import org.thingsboard.server.gen.edge.v1.UserCredentialsRequestMsg;
|
||||
import org.thingsboard.server.gen.edge.v1.WidgetBundleTypesRequestMsg;
|
||||
import org.thingsboard.server.service.entitiy.entityView.TbEntityViewService;
|
||||
import org.thingsboard.server.service.executors.DbCallbackExecutorService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -101,7 +102,7 @@ public class DefaultEdgeRequestsService implements EdgeRequestsService {
|
||||
private DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private EntityViewService entityViewService;
|
||||
private TbEntityViewService entityViewService;
|
||||
|
||||
@Autowired
|
||||
private DeviceProfileService deviceProfileService;
|
||||
|
||||
@ -244,16 +244,32 @@ public class DefaultTbEntityViewService extends AbstractTbEntityService implemen
|
||||
@Override
|
||||
public void onComponentLifecycleMsg(ComponentLifecycleMsg componentLifecycleMsg) {
|
||||
Map<EntityId, List<EntityView>> localCacheByTenant = localCache.computeIfAbsent(componentLifecycleMsg.getTenantId(), (k) -> new ConcurrentReferenceHashMap<>());
|
||||
if (componentLifecycleMsg.getEvent() == ComponentLifecycleEvent.DELETED) {
|
||||
localCacheByTenant.clear(); //we don't know which entity was mapped before deletion
|
||||
} else {
|
||||
EntityView entityView = entityViewService.findEntityViewById(componentLifecycleMsg.getTenantId(), new EntityViewId(componentLifecycleMsg.getEntityId().getId()));
|
||||
EntityViewId entityViewId = new EntityViewId(componentLifecycleMsg.getEntityId().getId());
|
||||
deleteOldCacheValue(localCacheByTenant, entityViewId);
|
||||
if (componentLifecycleMsg.getEvent() != ComponentLifecycleEvent.DELETED) {
|
||||
EntityView entityView = entityViewService.findEntityViewById(componentLifecycleMsg.getTenantId(), entityViewId);
|
||||
if (entityView != null) {
|
||||
localCacheByTenant.remove(entityView.getEntityId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteOldCacheValue(Map<EntityId, List<EntityView>> localCacheByTenant, EntityViewId entityViewId) {
|
||||
for (var entry : localCacheByTenant.entrySet()) {
|
||||
EntityView toDelete = null;
|
||||
for (EntityView view : entry.getValue()) {
|
||||
if (entityViewId.equals(view.getId())) {
|
||||
toDelete = view;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (toDelete != null) {
|
||||
entry.getValue().remove(toDelete);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ListenableFuture<List<Void>> copyAttributesFromEntityToEntityView(EntityView entityView, String scope, Collection<String> keys, SecurityUser user) throws ThingsboardException {
|
||||
EntityViewId entityId = entityView.getId();
|
||||
if (keys != null && !keys.isEmpty()) {
|
||||
@ -269,8 +285,8 @@ public class DefaultTbEntityViewService extends AbstractTbEntityService implemen
|
||||
long lastUpdateTs = attributeKvEntry.getLastUpdateTs();
|
||||
return startTime == 0 && endTime == 0 ||
|
||||
(endTime == 0 && startTime < lastUpdateTs) ||
|
||||
(startTime == 0 && endTime > lastUpdateTs)
|
||||
? true : startTime < lastUpdateTs && endTime > lastUpdateTs;
|
||||
(startTime == 0 && endTime > lastUpdateTs) ||
|
||||
(startTime < lastUpdateTs && endTime > lastUpdateTs);
|
||||
}).collect(Collectors.toList());
|
||||
tsSubService.saveAndNotify(entityView.getTenantId(), entityId, scope, attributes, new FutureCallback<Void>() {
|
||||
@Override
|
||||
|
||||
@ -35,7 +35,7 @@ public interface TbEntityViewService extends ComponentLifecycleListener {
|
||||
|
||||
void updateEntityViewAttributes(SecurityUser user, EntityView savedEntityView, EntityView oldEntityView) throws ThingsboardException;
|
||||
|
||||
void delete (EntityView entity, SecurityUser user) throws ThingsboardException;
|
||||
void delete (EntityView entity, SecurityUser user) throws ThingsboardException;
|
||||
|
||||
EntityView assignEntityViewToCustomer(TenantId tenantId, EntityViewId entityViewId, Customer customer,
|
||||
SecurityUser user) throws ThingsboardException;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user