Browse Source

Refactoring for CustomerData

pull/13023/head
ViacheslavKlimov 2 years ago
parent
commit
92466630b1
  1. 6
      common/edqs/src/main/java/org/thingsboard/server/edqs/data/CustomerData.java
  2. 9
      common/edqs/src/main/java/org/thingsboard/server/edqs/repo/TenantRepo.java

6
common/edqs/src/main/java/org/thingsboard/server/edqs/data/CustomerData.java

@ -50,10 +50,10 @@ public class CustomerData extends BaseEntityData<CustomerFields> {
entitiesById.computeIfAbsent(ed.getEntityType(), et -> new ConcurrentHashMap<>()).put(ed.getId(), ed);
}
public boolean remove(EntityData<?> ed) {
var map = entitiesById.get(ed.getEntityType());
public boolean remove(EntityType entityType, UUID entityId) {
var map = entitiesById.get(entityType);
if (map != null) {
return map.remove(ed.getId()) != null;
return map.remove(entityId) != null;
} else {
return false;
}

9
common/edqs/src/main/java/org/thingsboard/server/edqs/repo/TenantRepo.java

@ -173,10 +173,7 @@ public class TenantRepo {
if (EntityRelation.CONTAINS_TYPE.equals(entityRelation.getType()) && entityRelation.getFrom().getEntityType() == EntityType.CUSTOMER) {
CustomerData customerData = (CustomerData) get(entityRelation.getFrom());
if (customerData != null) {
EntityData<?> dashboardData = get(entityRelation.getTo());
if (dashboardData != null) {
customerData.remove(dashboardData);
}
customerData.remove(EntityType.DASHBOARD, entityRelation.getTo().getId());
}
}
}
@ -205,7 +202,7 @@ public class TenantRepo {
if (oldCustomerId != null) {
CustomerData old = (CustomerData) get(EntityType.CUSTOMER, oldCustomerId);
if (old != null) {
old.remove(entityData);
old.remove(entityType, entityId);
}
}
if (newCustomerId != null) {
@ -233,7 +230,7 @@ public class TenantRepo {
if (customerId != null) {
CustomerData customerData = (CustomerData) get(EntityType.CUSTOMER, customerId);
if (customerData != null) {
customerData.remove(removed);
customerData.remove(entityType, entityId);
}
}
}

Loading…
Cancel
Save