@ -18,6 +18,7 @@ package org.thingsboard.server.controller;
import com.fasterxml.jackson.databind.JsonNode ;
import com.google.common.util.concurrent.ListenableFuture ;
import io.swagger.annotations.ApiOperation ;
import io.swagger.annotations.ApiParam ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.http.HttpStatus ;
@ -93,7 +94,8 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/edge/{edgeId}" , method = RequestMethod . GET )
@ResponseBody
public Edge getEdgeById ( @PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
public Edge getEdgeById ( @ApiParam ( value = EDGE_ID_PARAM_DESCRIPTION )
@PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
checkParameter ( EDGE_ID , strEdgeId ) ;
try {
EdgeId edgeId = new EdgeId ( toUUID ( strEdgeId ) ) ;
@ -112,7 +114,8 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/edge/info/{edgeId}" , method = RequestMethod . GET )
@ResponseBody
public EdgeInfo getEdgeInfoById ( @PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
public EdgeInfo getEdgeInfoById ( @ApiParam ( value = EDGE_ID_PARAM_DESCRIPTION )
@PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
checkParameter ( EDGE_ID , strEdgeId ) ;
try {
EdgeId edgeId = new EdgeId ( toUUID ( strEdgeId ) ) ;
@ -133,7 +136,8 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/edge" , method = RequestMethod . POST )
@ResponseBody
public Edge saveEdge ( @RequestBody Edge edge ) throws ThingsboardException {
public Edge saveEdge ( @ApiParam ( value = "A JSON value representing the ed." )
@RequestBody Edge edge ) throws ThingsboardException {
try {
TenantId tenantId = getCurrentUser ( ) . getTenantId ( ) ;
edge . setTenantId ( tenantId ) ;
@ -181,7 +185,8 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/edge/{edgeId}" , method = RequestMethod . DELETE )
@ResponseStatus ( value = HttpStatus . OK )
public void deleteEdge ( @PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
public void deleteEdge ( @ApiParam ( value = EDGE_ID_PARAM_DESCRIPTION )
@PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
checkParameter ( EDGE_ID , strEdgeId ) ;
try {
EdgeId edgeId = new EdgeId ( toUUID ( strEdgeId ) ) ;
@ -212,10 +217,15 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/edges" , params = { "pageSize" , "page" } , method = RequestMethod . GET )
@ResponseBody
public PageData < Edge > getEdges ( @RequestParam int pageSize ,
public PageData < Edge > getEdges ( @ApiParam ( value = PAGE_SIZE_DESCRIPTION )
@RequestParam int pageSize ,
@ApiParam ( value = PAGE_NUMBER_DESCRIPTION )
@RequestParam int page ,
@ApiParam ( value = EDGE_TEXT_SEARCH_DESCRIPTION )
@RequestParam ( required = false ) String textSearch ,
@ApiParam ( value = SORT_PROPERTY_DESCRIPTION , allowableValues = SORT_PROPERTY_ALLOWABLE_VALUES )
@RequestParam ( required = false ) String sortProperty ,
@ApiParam ( value = SORT_ORDER_DESCRIPTION , allowableValues = SORT_ORDER_ALLOWABLE_VALUES )
@RequestParam ( required = false ) String sortOrder ) throws ThingsboardException {
try {
PageLink pageLink = createPageLink ( pageSize , page , textSearch , sortProperty , sortOrder ) ;
@ -231,7 +241,9 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/customer/{customerId}/edge/{edgeId}" , method = RequestMethod . POST )
@ResponseBody
public Edge assignEdgeToCustomer ( @PathVariable ( "customerId" ) String strCustomerId ,
public Edge assignEdgeToCustomer ( @ApiParam ( value = CUSTOMER_ID_PARAM_DESCRIPTION )
@PathVariable ( "customerId" ) String strCustomerId ,
@ApiParam ( value = EDGE_ID_PARAM_DESCRIPTION )
@PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
checkParameter ( "customerId" , strCustomerId ) ;
checkParameter ( EDGE_ID , strEdgeId ) ;
@ -268,7 +280,8 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/customer/edge/{edgeId}" , method = RequestMethod . DELETE )
@ResponseBody
public Edge unassignEdgeFromCustomer ( @PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
public Edge unassignEdgeFromCustomer ( @ApiParam ( value = EDGE_ID_PARAM_DESCRIPTION )
@PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
checkParameter ( EDGE_ID , strEdgeId ) ;
try {
EdgeId edgeId = new EdgeId ( toUUID ( strEdgeId ) ) ;
@ -306,7 +319,8 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/customer/public/edge/{edgeId}" , method = RequestMethod . POST )
@ResponseBody
public Edge assignEdgeToPublicCustomer ( @PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
public Edge assignEdgeToPublicCustomer ( @ApiParam ( value = EDGE_ID_PARAM_DESCRIPTION )
@PathVariable ( EDGE_ID ) String strEdgeId ) throws ThingsboardException {
checkParameter ( EDGE_ID , strEdgeId ) ;
try {
EdgeId edgeId = new EdgeId ( toUUID ( strEdgeId ) ) ;
@ -337,11 +351,17 @@ public class EdgeController extends BaseController {
@RequestMapping ( value = "/tenant/edges" , params = { "pageSize" , "page" } , method = RequestMethod . GET )
@ResponseBody
public PageData < Edge > getTenantEdges (
@ApiParam ( value = PAGE_SIZE_DESCRIPTION )
@RequestParam int pageSize ,
@ApiParam ( value = PAGE_NUMBER_DESCRIPTION )
@RequestParam int page ,
@ApiParam ( value = EDGE_TYPE_DESCRIPTION )
@RequestParam ( required = false ) String type ,
@ApiParam ( value = EDGE_TEXT_SEARCH_DESCRIPTION )
@RequestParam ( required = false ) String textSearch ,
@ApiParam ( value = SORT_PROPERTY_DESCRIPTION , allowableValues = SORT_PROPERTY_ALLOWABLE_VALUES )
@RequestParam ( required = false ) String sortProperty ,
@ApiParam ( value = SORT_ORDER_DESCRIPTION , allowableValues = SORT_ORDER_ALLOWABLE_VALUES )
@RequestParam ( required = false ) String sortOrder ) throws ThingsboardException {
try {
TenantId tenantId = getCurrentUser ( ) . getTenantId ( ) ;
@ -363,11 +383,17 @@ public class EdgeController extends BaseController {
@RequestMapping ( value = "/tenant/edgeInfos" , params = { "pageSize" , "page" } , method = RequestMethod . GET )
@ResponseBody
public PageData < EdgeInfo > getTenantEdgeInfos (
@ApiParam ( value = PAGE_SIZE_DESCRIPTION )
@RequestParam int pageSize ,
@ApiParam ( value = PAGE_NUMBER_DESCRIPTION )
@RequestParam int page ,
@ApiParam ( value = EDGE_TYPE_DESCRIPTION )
@RequestParam ( required = false ) String type ,
@ApiParam ( value = EDGE_TEXT_SEARCH_DESCRIPTION )
@RequestParam ( required = false ) String textSearch ,
@ApiParam ( value = SORT_PROPERTY_DESCRIPTION , allowableValues = SORT_PROPERTY_ALLOWABLE_VALUES )
@RequestParam ( required = false ) String sortProperty ,
@ApiParam ( value = SORT_ORDER_DESCRIPTION , allowableValues = SORT_ORDER_ALLOWABLE_VALUES )
@RequestParam ( required = false ) String sortOrder ) throws ThingsboardException {
try {
TenantId tenantId = getCurrentUser ( ) . getTenantId ( ) ;
@ -388,7 +414,8 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/tenant/edges" , params = { "edgeName" } , method = RequestMethod . GET )
@ResponseBody
public Edge getTenantEdge ( @RequestParam String edgeName ) throws ThingsboardException {
public Edge getTenantEdge ( @ApiParam ( value = "Unique name of the edge" )
@RequestParam String edgeName ) throws ThingsboardException {
try {
TenantId tenantId = getCurrentUser ( ) . getTenantId ( ) ;
return checkNotNull ( edgeService . findEdgeByTenantIdAndName ( tenantId , edgeName ) ) ;
@ -403,7 +430,9 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAnyAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/edge/{edgeId}/{ruleChainId}/root" , method = RequestMethod . POST )
@ResponseBody
public Edge setRootRuleChain ( @PathVariable ( EDGE_ID ) String strEdgeId ,
public Edge setRootRuleChain ( @ApiParam ( value = EDGE_ID_PARAM_DESCRIPTION )
@PathVariable ( EDGE_ID ) String strEdgeId ,
@ApiParam ( value = RULE_CHAIN_ID_PARAM_DESCRIPTION )
@PathVariable ( "ruleChainId" ) String strRuleChainId ) throws ThingsboardException {
checkParameter ( EDGE_ID , strEdgeId ) ;
checkParameter ( "ruleChainId" , strRuleChainId ) ;
@ -439,12 +468,19 @@ public class EdgeController extends BaseController {
@RequestMapping ( value = "/customer/{customerId}/edges" , params = { "pageSize" , "page" } , method = RequestMethod . GET )
@ResponseBody
public PageData < Edge > getCustomerEdges (
@ApiParam ( value = CUSTOMER_ID_PARAM_DESCRIPTION )
@PathVariable ( "customerId" ) String strCustomerId ,
@ApiParam ( value = PAGE_SIZE_DESCRIPTION )
@RequestParam int pageSize ,
@ApiParam ( value = PAGE_NUMBER_DESCRIPTION )
@RequestParam int page ,
@ApiParam ( value = EDGE_TYPE_DESCRIPTION )
@RequestParam ( required = false ) String type ,
@ApiParam ( value = EDGE_TEXT_SEARCH_DESCRIPTION )
@RequestParam ( required = false ) String textSearch ,
@ApiParam ( value = SORT_PROPERTY_DESCRIPTION , allowableValues = SORT_PROPERTY_ALLOWABLE_VALUES )
@RequestParam ( required = false ) String sortProperty ,
@ApiParam ( value = SORT_ORDER_DESCRIPTION , allowableValues = SORT_ORDER_ALLOWABLE_VALUES )
@RequestParam ( required = false ) String sortOrder ) throws ThingsboardException {
checkParameter ( "customerId" , strCustomerId ) ;
try {
@ -477,12 +513,19 @@ public class EdgeController extends BaseController {
@RequestMapping ( value = "/customer/{customerId}/edgeInfos" , params = { "pageSize" , "page" } , method = RequestMethod . GET )
@ResponseBody
public PageData < EdgeInfo > getCustomerEdgeInfos (
@ApiParam ( value = CUSTOMER_ID_PARAM_DESCRIPTION )
@PathVariable ( "customerId" ) String strCustomerId ,
@ApiParam ( value = PAGE_SIZE_DESCRIPTION )
@RequestParam int pageSize ,
@ApiParam ( value = PAGE_NUMBER_DESCRIPTION )
@RequestParam int page ,
@ApiParam ( value = EDGE_TYPE_DESCRIPTION )
@RequestParam ( required = false ) String type ,
@ApiParam ( value = EDGE_TEXT_SEARCH_DESCRIPTION )
@RequestParam ( required = false ) String textSearch ,
@ApiParam ( value = SORT_PROPERTY_DESCRIPTION , allowableValues = SORT_PROPERTY_ALLOWABLE_VALUES )
@RequestParam ( required = false ) String sortProperty ,
@ApiParam ( value = SORT_ORDER_DESCRIPTION , allowableValues = SORT_ORDER_ALLOWABLE_VALUES )
@RequestParam ( required = false ) String sortOrder ) throws ThingsboardException {
checkParameter ( "customerId" , strCustomerId ) ;
try {
@ -514,6 +557,7 @@ public class EdgeController extends BaseController {
@RequestMapping ( value = "/edges" , params = { "edgeIds" } , method = RequestMethod . GET )
@ResponseBody
public List < Edge > getEdgesByIds (
@ApiParam ( value = "A list of edges ids, separated by comma ','" )
@RequestParam ( "edgeIds" ) String [ ] strEdgeIds ) throws ThingsboardException {
checkArrayParameter ( "edgeIds" , strEdgeIds ) ;
try {
@ -598,7 +642,8 @@ public class EdgeController extends BaseController {
"All entities that are assigned to particular edge are going to be send to remote edge service." )
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/edge/sync/{edgeId}" , method = RequestMethod . POST )
public void syncEdge ( @PathVariable ( "edgeId" ) String strEdgeId ) throws ThingsboardException {
public void syncEdge ( @ApiParam ( value = EDGE_ID_PARAM_DESCRIPTION )
@PathVariable ( "edgeId" ) String strEdgeId ) throws ThingsboardException {
checkParameter ( "edgeId" , strEdgeId ) ;
try {
if ( isEdgesEnabled ( ) ) {
@ -620,7 +665,8 @@ public class EdgeController extends BaseController {
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/edge/missingToRelatedRuleChains/{edgeId}" , method = RequestMethod . GET )
@ResponseBody
public String findMissingToRelatedRuleChains ( @PathVariable ( "edgeId" ) String strEdgeId ) throws ThingsboardException {
public String findMissingToRelatedRuleChains ( @ApiParam ( value = EDGE_ID_PARAM_DESCRIPTION )
@PathVariable ( "edgeId" ) String strEdgeId ) throws ThingsboardException {
try {
EdgeId edgeId = new EdgeId ( toUUID ( strEdgeId ) ) ;
edgeId = checkNotNull ( edgeId ) ;