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