use of org.thingsboard.server.common.data.page.SortOrder in project thingsboard by thingsboard.
the class JpaDashboardInfoDao method findMobileDashboardsByTenantIdAndCustomerId.
@Override
public PageData<DashboardInfo> findMobileDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) {
List<SortOrder> sortOrders = new ArrayList<>();
sortOrders.add(new SortOrder("mobileOrder", SortOrder.Direction.ASC));
if (pageLink.getSortOrder() != null) {
sortOrders.add(pageLink.getSortOrder());
}
return DaoUtil.toPageData(dashboardInfoRepository.findMobileByTenantIdAndCustomerId(tenantId, customerId, Objects.toString(pageLink.getTextSearch(), ""), DaoUtil.toPageable(pageLink, sortOrders)));
}
use of org.thingsboard.server.common.data.page.SortOrder in project thingsboard by thingsboard.
the class BaseDashboardServiceTest method testFindMobileDashboardsByTenantId.
@Test
public void testFindMobileDashboardsByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<DashboardInfo> mobileDashboards = new ArrayList<>();
for (int i = 0; i < 165; i++) {
Dashboard dashboard = new Dashboard();
dashboard.setTenantId(tenantId);
dashboard.setTitle("Dashboard" + i);
dashboard.setMobileHide(i % 2 == 0);
if (!dashboard.isMobileHide()) {
dashboard.setMobileOrder(i % 4 == 0 ? (int) (Math.random() * 100) : null);
}
Dashboard savedDashboard = dashboardService.saveDashboard(dashboard);
if (!dashboard.isMobileHide()) {
mobileDashboards.add(new DashboardInfo(savedDashboard));
}
}
List<DashboardInfo> loadedMobileDashboards = new ArrayList<>();
PageLink pageLink = new PageLink(16, 0, null, new SortOrder("title", SortOrder.Direction.ASC));
PageData<DashboardInfo> pageData = null;
do {
pageData = dashboardService.findMobileDashboardsByTenantId(tenantId, pageLink);
loadedMobileDashboards.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(mobileDashboards, (o1, o2) -> {
Integer order1 = o1.getMobileOrder();
Integer order2 = o2.getMobileOrder();
if (order1 == null && order2 == null) {
return o1.getTitle().compareTo(o2.getTitle());
} else if (order1 == null && order2 != null) {
return 1;
} else if (order2 == null) {
return -1;
} else {
return order1 - order2;
}
});
Assert.assertEquals(mobileDashboards, loadedMobileDashboards);
dashboardService.deleteDashboardsByTenantId(tenantId);
pageLink = new PageLink(31);
pageData = dashboardService.findMobileDashboardsByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
}
use of org.thingsboard.server.common.data.page.SortOrder in project thingsboard by thingsboard.
the class BaseController method createPageLink.
PageLink createPageLink(int pageSize, int page, String textSearch, String sortProperty, String sortOrder) throws ThingsboardException {
if (!StringUtils.isEmpty(sortProperty)) {
SortOrder.Direction direction = SortOrder.Direction.ASC;
if (!StringUtils.isEmpty(sortOrder)) {
try {
direction = SortOrder.Direction.valueOf(sortOrder.toUpperCase());
} catch (IllegalArgumentException e) {
throw new ThingsboardException("Unsupported sort order '" + sortOrder + "'! Only 'ASC' or 'DESC' types are allowed.", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
}
}
SortOrder sort = new SortOrder(sortProperty, direction);
return new PageLink(pageSize, page, textSearch, sort);
} else {
return new PageLink(pageSize, page, textSearch);
}
}
use of org.thingsboard.server.common.data.page.SortOrder in project thingsboard by thingsboard.
the class BaseEdgeEventServiceTest method findEdgeEventsWithTsUpdateAndWithout.
@Test
public void findEdgeEventsWithTsUpdateAndWithout() throws Exception {
EdgeId edgeId = new EdgeId(Uuids.timeBased());
DeviceId deviceId = new DeviceId(Uuids.timeBased());
TenantId tenantId = TenantId.fromUUID(Uuids.timeBased());
TimePageLink pageLink = new TimePageLink(1, 0, null, new SortOrder("createdTime", SortOrder.Direction.ASC));
EdgeEvent edgeEventWithTsUpdate = generateEdgeEvent(tenantId, edgeId, deviceId, EdgeEventActionType.TIMESERIES_UPDATED);
edgeEventService.save(edgeEventWithTsUpdate);
PageData<EdgeEvent> allEdgeEvents = edgeEventService.findEdgeEvents(tenantId, edgeId, pageLink, true);
PageData<EdgeEvent> edgeEventsWithoutTsUpdate = edgeEventService.findEdgeEvents(tenantId, edgeId, pageLink, false);
Assert.assertNotNull(allEdgeEvents.getData());
Assert.assertNotNull(edgeEventsWithoutTsUpdate.getData());
Assert.assertEquals(1, allEdgeEvents.getData().size());
Assert.assertEquals(allEdgeEvents.getData().get(0).getUuidId(), edgeEventWithTsUpdate.getUuidId());
Assert.assertTrue(edgeEventsWithoutTsUpdate.getData().isEmpty());
}
use of org.thingsboard.server.common.data.page.SortOrder in project thingsboard by thingsboard.
the class BaseEventServiceTest method findEventsByTypeAndTimeDescOrder.
@Test
public void findEventsByTypeAndTimeDescOrder() throws Exception {
long timeBeforeStartTime = LocalDateTime.of(2017, Month.NOVEMBER, 1, 11, 30).toEpochSecond(ZoneOffset.UTC);
long startTime = LocalDateTime.of(2017, Month.NOVEMBER, 1, 12, 0).toEpochSecond(ZoneOffset.UTC);
long eventTime = LocalDateTime.of(2017, Month.NOVEMBER, 1, 12, 30).toEpochSecond(ZoneOffset.UTC);
long endTime = LocalDateTime.of(2017, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
long timeAfterEndTime = LocalDateTime.of(2017, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC);
CustomerId customerId = new CustomerId(Uuids.timeBased());
TenantId tenantId = TenantId.fromUUID(Uuids.timeBased());
saveEventWithProvidedTime(timeBeforeStartTime, customerId, tenantId);
Event savedEvent = saveEventWithProvidedTime(eventTime, customerId, tenantId);
Event savedEvent2 = saveEventWithProvidedTime(eventTime + 1, customerId, tenantId);
Event savedEvent3 = saveEventWithProvidedTime(eventTime + 2, customerId, tenantId);
saveEventWithProvidedTime(timeAfterEndTime, customerId, tenantId);
TimePageLink timePageLink = new TimePageLink(2, 0, "", new SortOrder("createdTime", SortOrder.Direction.DESC), startTime, endTime);
PageData<Event> events = eventService.findEvents(tenantId, customerId, DataConstants.STATS, timePageLink);
Assert.assertNotNull(events.getData());
Assert.assertTrue(events.getData().size() == 2);
Assert.assertTrue(events.getData().get(0).getUuidId().equals(savedEvent3.getUuidId()));
Assert.assertTrue(events.getData().get(1).getUuidId().equals(savedEvent2.getUuidId()));
Assert.assertTrue(events.hasNext());
events = eventService.findEvents(tenantId, customerId, DataConstants.STATS, timePageLink.nextPageLink());
Assert.assertNotNull(events.getData());
Assert.assertTrue(events.getData().size() == 1);
Assert.assertTrue(events.getData().get(0).getUuidId().equals(savedEvent.getUuidId()));
Assert.assertFalse(events.hasNext());
}
Aggregations