use of org.thingsboard.server.common.data.page.TimePageLink in project thingsboard by thingsboard.
the class BaseEventServiceTest method findEventsByTypeAndTimeDescOrder.
@Test
public void findEventsByTypeAndTimeDescOrder() 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);
RuleId ruleId = new RuleId(UUIDs.timeBased());
TenantId tenantId = new TenantId(UUIDs.timeBased());
saveEventWithProvidedTime(timeBeforeStartTime, ruleId, tenantId);
Event savedEvent = saveEventWithProvidedTime(eventTime, ruleId, tenantId);
Event savedEvent2 = saveEventWithProvidedTime(eventTime + 1, ruleId, tenantId);
Event savedEvent3 = saveEventWithProvidedTime(eventTime + 2, ruleId, tenantId);
saveEventWithProvidedTime(timeAfterEndTime, ruleId, tenantId);
TimePageData<Event> events = eventService.findEvents(tenantId, ruleId, DataConstants.STATS, new TimePageLink(2, startTime, endTime, false));
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());
Assert.assertNotNull(events.getNextPageLink());
events = eventService.findEvents(tenantId, ruleId, DataConstants.STATS, events.getNextPageLink());
Assert.assertNotNull(events.getData());
Assert.assertTrue(events.getData().size() == 1);
Assert.assertTrue(events.getData().get(0).getUuidId().equals(savedEvent.getUuidId()));
Assert.assertFalse(events.hasNext());
Assert.assertNull(events.getNextPageLink());
}
use of org.thingsboard.server.common.data.page.TimePageLink in project thingsboard by thingsboard.
the class AlarmController method getAlarms.
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/alarm/{entityType}/{entityId}", method = RequestMethod.GET)
@ResponseBody
public TimePageData<AlarmInfo> getAlarms(@PathVariable("entityType") String strEntityType, @PathVariable("entityId") String strEntityId, @RequestParam(required = false) String searchStatus, @RequestParam(required = false) String status, @RequestParam int limit, @RequestParam(required = false) Long startTime, @RequestParam(required = false) Long endTime, @RequestParam(required = false, defaultValue = "false") boolean ascOrder, @RequestParam(required = false) String offset, @RequestParam(required = false) Boolean fetchOriginator) throws ThingsboardException {
checkParameter("EntityId", strEntityId);
checkParameter("EntityType", strEntityType);
EntityId entityId = EntityIdFactory.getByTypeAndId(strEntityType, strEntityId);
AlarmSearchStatus alarmSearchStatus = StringUtils.isEmpty(searchStatus) ? null : AlarmSearchStatus.valueOf(searchStatus);
AlarmStatus alarmStatus = StringUtils.isEmpty(status) ? null : AlarmStatus.valueOf(status);
if (alarmSearchStatus != null && alarmStatus != null) {
throw new ThingsboardException("Invalid alarms search query: Both parameters 'searchStatus' " + "and 'status' can't be specified at the same time!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
}
checkEntityId(entityId);
try {
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
return checkNotNull(alarmService.findAlarms(new AlarmQuery(entityId, pageLink, alarmSearchStatus, alarmStatus, fetchOriginator)).get());
} catch (Exception e) {
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.page.TimePageLink in project thingsboard by thingsboard.
the class AuditLogController method getAuditLogsByEntityId.
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/audit/logs/entity/{entityType}/{entityId}", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TimePageData<AuditLog> getAuditLogsByEntityId(@PathVariable("entityType") String strEntityType, @PathVariable("entityId") String strEntityId, @RequestParam int limit, @RequestParam(required = false) Long startTime, @RequestParam(required = false) Long endTime, @RequestParam(required = false, defaultValue = "false") boolean ascOrder, @RequestParam(required = false) String offset) throws ThingsboardException {
try {
checkParameter("EntityId", strEntityId);
checkParameter("EntityType", strEntityType);
TenantId tenantId = getCurrentUser().getTenantId();
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
return checkNotNull(auditLogService.findAuditLogsByTenantIdAndEntityId(tenantId, EntityIdFactory.getByTypeAndId(strEntityType, strEntityId), pageLink));
} catch (Exception e) {
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.page.TimePageLink in project thingsboard by thingsboard.
the class AuditLogController method getAuditLogsByCustomerId.
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/audit/logs/customer/{customerId}", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TimePageData<AuditLog> getAuditLogsByCustomerId(@PathVariable("customerId") String strCustomerId, @RequestParam int limit, @RequestParam(required = false) Long startTime, @RequestParam(required = false) Long endTime, @RequestParam(required = false, defaultValue = "false") boolean ascOrder, @RequestParam(required = false) String offset) throws ThingsboardException {
try {
checkParameter("CustomerId", strCustomerId);
TenantId tenantId = getCurrentUser().getTenantId();
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
return checkNotNull(auditLogService.findAuditLogsByTenantIdAndCustomerId(tenantId, new CustomerId(UUID.fromString(strCustomerId)), pageLink));
} catch (Exception e) {
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.page.TimePageLink in project thingsboard by thingsboard.
the class AuditLogController method getAuditLogsByUserId.
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/audit/logs/user/{userId}", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TimePageData<AuditLog> getAuditLogsByUserId(@PathVariable("userId") String strUserId, @RequestParam int limit, @RequestParam(required = false) Long startTime, @RequestParam(required = false) Long endTime, @RequestParam(required = false, defaultValue = "false") boolean ascOrder, @RequestParam(required = false) String offset) throws ThingsboardException {
try {
checkParameter("UserId", strUserId);
TenantId tenantId = getCurrentUser().getTenantId();
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
return checkNotNull(auditLogService.findAuditLogsByTenantIdAndUserId(tenantId, new UserId(UUID.fromString(strUserId)), pageLink));
} catch (Exception e) {
throw handleException(e);
}
}
Aggregations