Search in sources :

Example 1 with SortOrder

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)));
}
Also used : ArrayList(java.util.ArrayList) SortOrder(org.thingsboard.server.common.data.page.SortOrder)

Example 2 with SortOrder

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);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) Dashboard(org.thingsboard.server.common.data.Dashboard) SortOrder(org.thingsboard.server.common.data.page.SortOrder) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) Test(org.junit.Test)

Example 3 with SortOrder

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);
    }
}
Also used : ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) PageLink(org.thingsboard.server.common.data.page.PageLink) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) SortOrder(org.thingsboard.server.common.data.page.SortOrder)

Example 4 with SortOrder

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());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) EdgeId(org.thingsboard.server.common.data.id.EdgeId) SortOrder(org.thingsboard.server.common.data.page.SortOrder) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent) Test(org.junit.Test)

Example 5 with SortOrder

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());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Event(org.thingsboard.server.common.data.Event) SortOrder(org.thingsboard.server.common.data.page.SortOrder) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) Test(org.junit.Test) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest)

Aggregations

SortOrder (org.thingsboard.server.common.data.page.SortOrder)13 Test (org.junit.Test)9 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)9 TenantId (org.thingsboard.server.common.data.id.TenantId)5 Alarm (org.thingsboard.server.common.data.alarm.Alarm)4 AlarmInfo (org.thingsboard.server.common.data.alarm.AlarmInfo)4 EntityDataSortOrder (org.thingsboard.server.common.data.query.EntityDataSortOrder)4 AlarmOperationResult (org.thingsboard.server.dao.alarm.AlarmOperationResult)4 ArrayList (java.util.ArrayList)3 AssetId (org.thingsboard.server.common.data.id.AssetId)3 PageLink (org.thingsboard.server.common.data.page.PageLink)3 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)3 Event (org.thingsboard.server.common.data.Event)2 EdgeEvent (org.thingsboard.server.common.data.edge.EdgeEvent)2 CustomerId (org.thingsboard.server.common.data.id.CustomerId)2 DeviceId (org.thingsboard.server.common.data.id.DeviceId)2 EdgeId (org.thingsboard.server.common.data.id.EdgeId)2 AlarmData (org.thingsboard.server.common.data.query.AlarmData)2 AlarmDataPageLink (org.thingsboard.server.common.data.query.AlarmDataPageLink)2 EntityKey (org.thingsboard.server.common.data.query.EntityKey)2