Search in sources :

Example 11 with TimePageLink

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

the class AuditLogController method getAuditLogs.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/audit/logs", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TimePageData<AuditLog> getAuditLogs(@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 {
        TenantId tenantId = getCurrentUser().getTenantId();
        TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
        return checkNotNull(auditLogService.findAuditLogsByTenantId(tenantId, pageLink));
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 12 with TimePageLink

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

the class EventController method getEvents.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/events/{entityType}/{entityId}", method = RequestMethod.GET)
@ResponseBody
public TimePageData<Event> getEvents(@PathVariable("entityType") String strEntityType, @PathVariable("entityId") String strEntityId, @RequestParam("tenantId") String strTenantId, @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 {
    checkParameter("EntityId", strEntityId);
    checkParameter("EntityType", strEntityType);
    try {
        TenantId tenantId = new TenantId(toUUID(strTenantId));
        if (!tenantId.getId().equals(ModelConstants.NULL_UUID) && !tenantId.equals(getCurrentUser().getTenantId())) {
            throw new ThingsboardException("You don't have permission to perform this operation!", ThingsboardErrorCode.PERMISSION_DENIED);
        }
        TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
        return checkNotNull(eventService.findEvents(tenantId, EntityIdFactory.getByTypeAndId(strEntityType, strEntityId), pageLink));
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : ThingsboardException(org.thingsboard.server.exception.ThingsboardException) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 13 with TimePageLink

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

the class DashboardController method getCustomerDashboards.

@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/dashboards", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TimePageData<DashboardInfo> getCustomerDashboards(@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 {
    checkParameter("customerId", strCustomerId);
    try {
        TenantId tenantId = getCurrentUser().getTenantId();
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        checkCustomerId(customerId);
        TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
        return checkNotNull(dashboardService.findDashboardsByTenantIdAndCustomerId(tenantId, customerId, pageLink).get());
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 14 with TimePageLink

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

the class TimePaginatedRemover method removeEntities.

public void removeEntities(I id) {
    TimePageLink pageLink = new TimePageLink(DEFAULT_LIMIT);
    boolean hasNext = true;
    while (hasNext) {
        List<D> entities = findEntities(id, pageLink);
        for (D entity : entities) {
            removeEntity(entity);
        }
        hasNext = entities.size() == pageLink.getLimit();
        if (hasNext) {
            int index = entities.size() - 1;
            UUID idOffset = entities.get(index).getUuidId();
            pageLink.setIdOffset(idOffset);
        }
    }
}
Also used : UUID(java.util.UUID) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) UUID(java.util.UUID)

Example 15 with TimePageLink

use of org.thingsboard.server.common.data.page.TimePageLink 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);
    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, true));
    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());
    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(savedEvent3.getUuidId()));
    Assert.assertFalse(events.hasNext());
    Assert.assertNull(events.getNextPageLink());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) RuleId(org.thingsboard.server.common.data.id.RuleId) Event(org.thingsboard.server.common.data.Event) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) Test(org.junit.Test) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest)

Aggregations

TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)20 Test (org.junit.Test)9 TenantId (org.thingsboard.server.common.data.id.TenantId)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)7 ArrayList (java.util.ArrayList)6 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 UUID (java.util.UUID)5 Event (org.thingsboard.server.common.data.Event)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 DashboardInfo (org.thingsboard.server.common.data.DashboardInfo)3 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)3 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 List (java.util.List)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 Device (org.thingsboard.server.common.data.Device)2