Search in sources :

Example 11 with SortOrder

use of org.thingsboard.server.common.data.page.SortOrder in project thingsboard by thingsboard.

the class BaseAlarmServiceTest method testFindCustomerAlarm.

@Test
public void testFindCustomerAlarm() throws ExecutionException, InterruptedException {
    Customer customer = new Customer();
    customer.setTitle("TestCustomer");
    customer.setTenantId(tenantId);
    customer = customerService.saveCustomer(customer);
    Device tenantDevice = new Device();
    tenantDevice.setName("TestTenantDevice");
    tenantDevice.setType("default");
    tenantDevice.setTenantId(tenantId);
    tenantDevice = deviceService.saveDevice(tenantDevice);
    Device customerDevice = new Device();
    customerDevice.setName("TestCustomerDevice");
    customerDevice.setType("default");
    customerDevice.setTenantId(tenantId);
    customerDevice.setCustomerId(customer.getId());
    customerDevice = deviceService.saveDevice(customerDevice);
    long ts = System.currentTimeMillis();
    Alarm tenantAlarm = Alarm.builder().tenantId(tenantId).originator(tenantDevice.getId()).type(TEST_ALARM).propagate(true).severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK).startTs(ts).build();
    AlarmOperationResult result = alarmService.createOrUpdateAlarm(tenantAlarm);
    tenantAlarm = result.getAlarm();
    Alarm deviceAlarm = Alarm.builder().tenantId(tenantId).originator(customerDevice.getId()).type(TEST_ALARM).propagate(true).severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK).startTs(ts).build();
    result = alarmService.createOrUpdateAlarm(deviceAlarm);
    deviceAlarm = result.getAlarm();
    AlarmDataPageLink pageLink = new AlarmDataPageLink();
    pageLink.setPage(0);
    pageLink.setPageSize(10);
    pageLink.setSortOrder(new EntityDataSortOrder(new EntityKey(EntityKeyType.ALARM_FIELD, "createdTime")));
    pageLink.setStartTs(0L);
    pageLink.setEndTs(System.currentTimeMillis());
    pageLink.setSearchPropagatedAlarms(true);
    pageLink.setSeverityList(Arrays.asList(AlarmSeverity.CRITICAL, AlarmSeverity.WARNING));
    pageLink.setStatusList(Arrays.asList(AlarmSearchStatus.ACTIVE));
    PageData<AlarmData> tenantAlarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Arrays.asList(tenantDevice.getId(), customerDevice.getId()));
    Assert.assertEquals(2, tenantAlarms.getData().size());
    PageData<AlarmData> customerAlarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(customerDevice.getId()));
    Assert.assertEquals(1, customerAlarms.getData().size());
    Assert.assertEquals(deviceAlarm, customerAlarms.getData().get(0));
    PageData<AlarmInfo> alarms = alarmService.findAlarms(tenantId, AlarmQuery.builder().affectedEntityId(tenantDevice.getId()).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(10, 0, "", new SortOrder("createdTime", SortOrder.Direction.DESC), 0L, System.currentTimeMillis())).build()).get();
    Assert.assertNotNull(alarms.getData());
    Assert.assertEquals(1, alarms.getData().size());
    Assert.assertEquals(tenantAlarm, alarms.getData().get(0));
}
Also used : Customer(org.thingsboard.server.common.data.Customer) Device(org.thingsboard.server.common.data.Device) SortOrder(org.thingsboard.server.common.data.page.SortOrder) EntityDataSortOrder(org.thingsboard.server.common.data.query.EntityDataSortOrder) EntityKey(org.thingsboard.server.common.data.query.EntityKey) Alarm(org.thingsboard.server.common.data.alarm.Alarm) EntityDataSortOrder(org.thingsboard.server.common.data.query.EntityDataSortOrder) AlarmInfo(org.thingsboard.server.common.data.alarm.AlarmInfo) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) AlarmOperationResult(org.thingsboard.server.dao.alarm.AlarmOperationResult) AlarmDataPageLink(org.thingsboard.server.common.data.query.AlarmDataPageLink) AlarmData(org.thingsboard.server.common.data.query.AlarmData) Test(org.junit.Test)

Example 12 with SortOrder

use of org.thingsboard.server.common.data.page.SortOrder in project thingsboard by thingsboard.

the class JpaDashboardInfoDao method findMobileDashboardsByTenantId.

@Override
public PageData<DashboardInfo> findMobileDashboardsByTenantId(UUID tenantId, 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.findMobileByTenantId(tenantId, Objects.toString(pageLink.getTextSearch(), ""), DaoUtil.toPageable(pageLink, sortOrders)));
}
Also used : ArrayList(java.util.ArrayList) SortOrder(org.thingsboard.server.common.data.page.SortOrder)

Example 13 with SortOrder

use of org.thingsboard.server.common.data.page.SortOrder in project thingsboard by thingsboard.

the class BaseEventServiceTest method findEventsByTypeAndTimeAscOrder.

@Test
public void findEventsByTypeAndTimeAscOrder() throws Exception {
    long timeBeforeStartTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 11, 30).toEpochSecond(ZoneOffset.UTC);
    long startTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 12, 0).toEpochSecond(ZoneOffset.UTC);
    long eventTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 12, 30).toEpochSecond(ZoneOffset.UTC);
    long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
    long timeAfterEndTime = LocalDateTime.of(2016, 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"), 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(savedEvent.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(savedEvent3.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