Commit 978efe60fc94b540a2965dba03e5c3720d16403d

Authored by deaflynx
1 parent 1545a8cd

Added EdgeEventController.java

  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.controller;
  17 +
  18 +import lombok.extern.slf4j.Slf4j;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.security.access.prepost.PreAuthorize;
  21 +import org.springframework.web.bind.annotation.PathVariable;
  22 +import org.springframework.web.bind.annotation.RequestMapping;
  23 +import org.springframework.web.bind.annotation.RequestMethod;
  24 +import org.springframework.web.bind.annotation.RequestParam;
  25 +import org.springframework.web.bind.annotation.ResponseBody;
  26 +import org.springframework.web.bind.annotation.RestController;
  27 +import org.thingsboard.server.common.data.edge.EdgeEvent;
  28 +import org.thingsboard.server.common.data.exception.ThingsboardException;
  29 +import org.thingsboard.server.common.data.id.EdgeId;
  30 +import org.thingsboard.server.common.data.id.TenantId;
  31 +import org.thingsboard.server.common.data.page.TimePageData;
  32 +import org.thingsboard.server.common.data.page.TimePageLink;
  33 +import org.thingsboard.server.dao.edge.EdgeEventService;
  34 +import org.thingsboard.server.queue.util.TbCoreComponent;
  35 +
  36 +@Slf4j
  37 +@RestController
  38 +@TbCoreComponent
  39 +@RequestMapping("/api")
  40 +public class EdgeEventController extends BaseController {
  41 +
  42 + @Autowired
  43 + private EdgeEventService edgeEventService;
  44 +
  45 + public static final String EDGE_ID = "edgeId";
  46 +
  47 + @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
  48 + @RequestMapping(value = "/edge/{edgeId}/events", method = RequestMethod.GET)
  49 + @ResponseBody
  50 + public TimePageData<EdgeEvent> getEdgeEvents(
  51 + @PathVariable(EDGE_ID) String strEdgeId,
  52 + @RequestParam int limit,
  53 + @RequestParam(required = false) Long startTime,
  54 + @RequestParam(required = false) Long endTime,
  55 + @RequestParam(required = false, defaultValue = "false") boolean ascOrder,
  56 + @RequestParam(required = false) String offset) throws ThingsboardException {
  57 + checkParameter(EDGE_ID, strEdgeId);
  58 + try {
  59 + TenantId tenantId = getCurrentUser().getTenantId();
  60 + EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
  61 + TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
  62 + return checkNotNull(edgeEventService.findEdgeEvents(tenantId, edgeId, pageLink));
  63 + } catch (Exception e) {
  64 + throw handleException(e);
  65 + }
  66 + }
  67 +}
... ...