Data Update - update only dashboard which configurationthat contains required filters
This commit is contained in:
parent
e45775ce8f
commit
cf3beda316
@ -716,27 +716,30 @@ public class DefaultDataUpdateService implements DataUpdateService {
|
||||
};
|
||||
|
||||
private void updateTenantDashboardsFilters(TenantId tenantId) {
|
||||
PageLink pageLink = new PageLink(100);
|
||||
PageData<DashboardInfo> pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
|
||||
boolean hasNext = true;
|
||||
while (hasNext) {
|
||||
List<ListenableFuture<List<Void>>> updateFutures = new ArrayList<>();
|
||||
for (DashboardInfo dashboardInfo : pageData.getData()) {
|
||||
updateFutures.add(updateDashboardFilters(tenantId, dashboardInfo));
|
||||
for (String filterTypeForUpdate : DataConstants.DASHBOARD_FILTER_TYPES_FOR_UPDATE) {
|
||||
PageLink pageLink = new PageLink(100);
|
||||
PageData<DashboardInfo> pageData = dashboardService.findDashboardsByTenantIdAndConfigurationText(tenantId, filterTypeForUpdate, pageLink);
|
||||
boolean hasNext = true;
|
||||
while (hasNext) {
|
||||
List<ListenableFuture<List<Void>>> updateFutures = new ArrayList<>();
|
||||
for (DashboardInfo dashboardInfo : pageData.getData()) {
|
||||
updateFutures.add(updateDashboardFilters(tenantId, dashboardInfo));
|
||||
}
|
||||
|
||||
try {
|
||||
Futures.allAsList(updateFutures).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
log.error("Failed to update dashboards filters", e);
|
||||
}
|
||||
|
||||
if (pageData.hasNext()) {
|
||||
pageLink = pageLink.nextPageLink();
|
||||
pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
|
||||
} else {
|
||||
hasNext = false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Futures.allAsList(updateFutures).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
log.error("Failed to update dashboards filters", e);
|
||||
}
|
||||
|
||||
if (pageData.hasNext()) {
|
||||
pageLink = pageLink.nextPageLink();
|
||||
pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
|
||||
} else {
|
||||
hasNext = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -70,4 +70,6 @@ public interface DashboardService extends EntityDaoService {
|
||||
|
||||
List<Dashboard> findTenantDashboardsByTitle(TenantId tenantId, String title);
|
||||
|
||||
PageData<DashboardInfo> findDashboardsByTenantIdAndConfigurationText(TenantId tenantId, String searchText, PageLink pageLink);
|
||||
|
||||
}
|
||||
|
||||
@ -15,6 +15,11 @@
|
||||
*/
|
||||
package org.thingsboard.server.common.data;
|
||||
|
||||
import org.thingsboard.server.common.data.query.EntityFilterType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Andrew Shvayka
|
||||
*/
|
||||
@ -126,4 +131,9 @@ public class DataConstants {
|
||||
public static final String SQ_QUEUE_NAME = "SequentialByOriginator";
|
||||
public static final String SQ_QUEUE_TOPIC = "tb_rule_engine.sq";
|
||||
|
||||
public static final List<String> DASHBOARD_FILTER_TYPES_FOR_UPDATE = Arrays.asList(
|
||||
EntityFilterType.ASSET_TYPE.getLabel(),
|
||||
EntityFilterType.DEVICE_TYPE.getLabel(),
|
||||
EntityFilterType.ENTITY_VIEW_TYPE.getLabel(),
|
||||
EntityFilterType.EDGE_TYPE.getLabel());
|
||||
}
|
||||
|
||||
@ -77,4 +77,6 @@ public interface DashboardInfoDao extends Dao<DashboardInfo> {
|
||||
|
||||
DashboardInfo findFirstByTenantIdAndName(UUID tenantId, String name);
|
||||
|
||||
PageData<DashboardInfo> findByTenantIdAndConfigurationText(UUID tenantId, String searchText, PageLink pageLink);
|
||||
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.DashboardInfo;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.edge.Edge;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
@ -38,7 +39,6 @@ import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.query.EntityFilterType;
|
||||
import org.thingsboard.server.common.data.relation.EntityRelation;
|
||||
import org.thingsboard.server.common.data.relation.RelationTypeGroup;
|
||||
import org.thingsboard.server.dao.customer.CustomerDao;
|
||||
@ -123,22 +123,21 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
||||
if (filter == null || filter.get("type") == null) {
|
||||
return;
|
||||
}
|
||||
updateFilterByTypeIfRequired(filter, EntityFilterType.ASSET_TYPE.getLabel());
|
||||
updateFilterByTypeIfRequired(filter, EntityFilterType.DEVICE_TYPE.getLabel());
|
||||
updateFilterByTypeIfRequired(filter, EntityFilterType.ENTITY_VIEW_TYPE.getLabel());
|
||||
updateFilterByTypeIfRequired(filter, EntityFilterType.EDGE_TYPE.getLabel());
|
||||
for (String filterTypeForUpdate : DataConstants.DASHBOARD_FILTER_TYPES_FOR_UPDATE) {
|
||||
updateFilterByTypeIfRequired(filter, filterTypeForUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateFilterByTypeIfRequired(JsonNode filter, String FILTER_TYPE_SINGULAR_LABEL) {
|
||||
if (filter.get(FILTER_TYPE_SINGULAR_LABEL) == null) {
|
||||
private static void updateFilterByTypeIfRequired(JsonNode filter, String filterTypeSingularLabel) {
|
||||
if (filter.get(filterTypeSingularLabel) == null) {
|
||||
return;
|
||||
}
|
||||
if (FILTER_TYPE_SINGULAR_LABEL.equals(filter.get("type").asText())) {
|
||||
if (filterTypeSingularLabel.equals(filter.get("type").asText())) {
|
||||
ArrayNode filterTypes = JacksonUtil.OBJECT_MAPPER.createArrayNode();
|
||||
filterTypes.add(filter.get(FILTER_TYPE_SINGULAR_LABEL).asText());
|
||||
final String FILTER_TYPES_PLURAL_LABEL = String.format("%ss", FILTER_TYPE_SINGULAR_LABEL);
|
||||
((ObjectNode) filter).set(FILTER_TYPES_PLURAL_LABEL, filterTypes);
|
||||
((ObjectNode) filter).remove(FILTER_TYPE_SINGULAR_LABEL);
|
||||
filterTypes.add(filter.get(filterTypeSingularLabel).asText());
|
||||
final String filterTypesPluralLabel = String.format("%ss", filterTypeSingularLabel);
|
||||
((ObjectNode) filter).set(filterTypesPluralLabel, filterTypes);
|
||||
((ObjectNode) filter).remove(filterTypeSingularLabel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,6 +328,11 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
||||
return dashboardDao.findByTenantIdAndTitle(tenantId.getId(), title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<DashboardInfo> findDashboardsByTenantIdAndConfigurationText(TenantId tenantId, String searchText, PageLink pageLink) {
|
||||
return dashboardInfoDao.findByTenantIdAndConfigurationText(tenantId.getId(), searchText, pageLink);
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, DashboardInfo> tenantDashboardsRemover =
|
||||
new PaginatedRemover<TenantId, DashboardInfo>() {
|
||||
|
||||
|
||||
@ -72,4 +72,9 @@ public interface DashboardInfoRepository extends JpaRepository<DashboardInfoEnti
|
||||
@Param("searchText") String searchText,
|
||||
Pageable pageable);
|
||||
|
||||
@Query("SELECT d FROM DashboardEntity d WHERE d.tenantId = :tenantId " +
|
||||
"AND LOWER(d.configuration) LIKE LOWER(CONCAT('%', :searchText, '%'))")
|
||||
Page<DashboardInfoEntity> findByTenantIdAndConfigurationText(@Param("tenantId") UUID tenantId,
|
||||
@Param("searchText") String searchText,
|
||||
Pageable pageable);
|
||||
}
|
||||
|
||||
@ -118,4 +118,14 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE
|
||||
public DashboardInfo findFirstByTenantIdAndName(UUID tenantId, String name) {
|
||||
return DaoUtil.getData(dashboardInfoRepository.findFirstByTenantIdAndTitle(tenantId, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<DashboardInfo> findByTenantIdAndConfigurationText(UUID tenantId, String searchText, PageLink pageLink) {
|
||||
log.debug("Try to find dashboards by tenantId [{}], configuration text [{}] and pageLink [{}]", tenantId, searchText, pageLink);
|
||||
return DaoUtil.toPageData(dashboardInfoRepository
|
||||
.findByTenantIdAndConfigurationText(
|
||||
tenantId,
|
||||
searchText,
|
||||
DaoUtil.toPageable(pageLink)));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user