|
|
|
@ -21,6 +21,8 @@ import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.cache.Cache; |
|
|
|
import org.springframework.cache.CacheManager; |
|
|
|
import org.springframework.cache.annotation.CacheEvict; |
|
|
|
import org.springframework.cache.annotation.Cacheable; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.EntityView; |
|
|
|
@ -41,6 +43,8 @@ import org.thingsboard.server.dao.tenant.TenantDao; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import static org.thingsboard.server.common.data.CacheConstants.DEVICE_CACHE; |
|
|
|
import static org.thingsboard.server.common.data.CacheConstants.ENTITY_VIEW_CACHE; |
|
|
|
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
|
|
|
import static org.thingsboard.server.dao.service.Validator.validateId; |
|
|
|
import static org.thingsboard.server.dao.service.Validator.validatePageLink; |
|
|
|
@ -68,6 +72,10 @@ public class EntityViewServiceImpl extends AbstractEntityService |
|
|
|
@Autowired |
|
|
|
private CustomerDao customerDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CacheManager cacheManager; |
|
|
|
|
|
|
|
@Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityViewId}") |
|
|
|
@Override |
|
|
|
public EntityView findEntityViewById(EntityViewId entityViewId) { |
|
|
|
log.trace("Executing findEntityViewById [{}]", entityViewId); |
|
|
|
@ -83,6 +91,7 @@ public class EntityViewServiceImpl extends AbstractEntityService |
|
|
|
.orElse(null); |
|
|
|
} |
|
|
|
|
|
|
|
@CacheEvict(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityView.id}") |
|
|
|
@Override |
|
|
|
public EntityView saveEntityView(EntityView entityView) { |
|
|
|
log.trace("Executing save entity view [{}]", entityView); |
|
|
|
@ -107,12 +116,14 @@ public class EntityViewServiceImpl extends AbstractEntityService |
|
|
|
@Override |
|
|
|
public void deleteEntityView(EntityViewId entityViewId) { |
|
|
|
log.trace("Executing deleteEntityView [{}]", entityViewId); |
|
|
|
Cache cache = cacheManager.getCache(ENTITY_VIEW_CACHE); |
|
|
|
validateId(entityViewId, INCORRECT_ENTITY_VIEW_ID + entityViewId); |
|
|
|
deleteEntityRelations(entityViewId); |
|
|
|
EntityView entityView = entityViewDao.findById(entityViewId.getId()); |
|
|
|
List<Object> list = new ArrayList<>(); |
|
|
|
list.add(entityView.getTenantId()); |
|
|
|
list.add(entityView.getName()); |
|
|
|
cache.evict(list); |
|
|
|
entityViewDao.removeById(entityViewId.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -125,6 +136,7 @@ public class EntityViewServiceImpl extends AbstractEntityService |
|
|
|
return new TextPageData<>(entityViews, pageLink); |
|
|
|
} |
|
|
|
|
|
|
|
@Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#tenantId, #entityId, #pageLink}") |
|
|
|
@Override |
|
|
|
public TextPageData<EntityView> findEntityViewByTenantIdAndEntityId(TenantId tenantId, EntityId entityId, |
|
|
|
TextPageLink pageLink) { |
|
|
|
@ -164,6 +176,7 @@ public class EntityViewServiceImpl extends AbstractEntityService |
|
|
|
return new TextPageData<>(entityViews, pageLink); |
|
|
|
} |
|
|
|
|
|
|
|
@Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#tenantId, #customerId, #entityId, #pageLink}") |
|
|
|
@Override |
|
|
|
public TextPageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndEntityId(TenantId tenantId, |
|
|
|
CustomerId customerId, |
|
|
|
|