@ -15,16 +15,19 @@
* /
* /
package org.thingsboard.server.controller ;
package org.thingsboard.server.controller ;
import io.swagger.v3.oas.annotations.Hidden ;
import io.swagger.v3.oas.annotations.Parameter ;
import io.swagger.v3.oas.annotations.Parameter ;
import lombok.RequiredArgsConstructor ;
import lombok.RequiredArgsConstructor ;
import org.springframework.http.HttpStatus ;
import org.springframework.security.access.prepost.PreAuthorize ;
import org.springframework.security.access.prepost.PreAuthorize ;
import org.springframework.web.bind.annotation.DeleteMapping ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.PathVariable ;
import org.springframework.web.bind.annotation.PostMapping ;
import org.springframework.web.bind.annotation.RequestBody ;
import org.springframework.web.bind.annotation.RequestBody ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestMethod ;
import org.springframework.web.bind.annotation.RequestMethod ;
import org.springframework.web.bind.annotation.RequestParam ;
import org.springframework.web.bind.annotation.RequestParam ;
import org.springframework.web.bind.annotation.ResponseBody ;
import org.springframework.web.bind.annotation.ResponseBody ;
import org.springframework.web.bind.annotation.ResponseStatus ;
import org.springframework.web.bind.annotation.RestController ;
import org.springframework.web.bind.annotation.RestController ;
import org.thingsboard.server.common.data.exception.ThingsboardException ;
import org.thingsboard.server.common.data.exception.ThingsboardException ;
import org.thingsboard.server.common.data.id.EntityId ;
import org.thingsboard.server.common.data.id.EntityId ;
@ -76,8 +79,7 @@ public class EntityRelationController extends BaseController {
"Relations unique key is a combination of from/to entity id and relation type group and relation type. " +
"Relations unique key is a combination of from/to entity id and relation type group and relation type. " +
SECURITY_CHECKS_ENTITIES_DESCRIPTION )
SECURITY_CHECKS_ENTITIES_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relation" , method = RequestMethod . POST )
@PostMapping ( value = "/relation" )
@ResponseStatus ( value = HttpStatus . OK )
public void saveRelation ( @Parameter ( description = "A JSON value representing the relation." , required = true )
public void saveRelation ( @Parameter ( description = "A JSON value representing the relation." , required = true )
@RequestBody EntityRelation relation ) throws ThingsboardException {
@RequestBody EntityRelation relation ) throws ThingsboardException {
doSave ( relation ) ;
doSave ( relation ) ;
@ -88,8 +90,7 @@ public class EntityRelationController extends BaseController {
"Relations unique key is a combination of from/to entity id and relation type group and relation type. " +
"Relations unique key is a combination of from/to entity id and relation type group and relation type. " +
SECURITY_CHECKS_ENTITIES_DESCRIPTION )
SECURITY_CHECKS_ENTITIES_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/v2/relation" , method = RequestMethod . POST )
@PostMapping ( value = "/v2/relation" )
@ResponseStatus ( value = HttpStatus . OK )
public EntityRelation saveRelationV2 ( @Parameter ( description = "A JSON value representing the relation." , required = true )
public EntityRelation saveRelationV2 ( @Parameter ( description = "A JSON value representing the relation." , required = true )
@RequestBody EntityRelation relation ) throws ThingsboardException {
@RequestBody EntityRelation relation ) throws ThingsboardException {
return doSave ( relation ) ;
return doSave ( relation ) ;
@ -109,8 +110,7 @@ public class EntityRelationController extends BaseController {
@ApiOperation ( value = "Delete Relation (deleteRelation)" ,
@ApiOperation ( value = "Delete Relation (deleteRelation)" ,
notes = "Deletes a relation between two entities in the platform. " + SECURITY_CHECKS_ENTITIES_DESCRIPTION )
notes = "Deletes a relation between two entities in the platform. " + SECURITY_CHECKS_ENTITIES_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relation" , method = RequestMethod . DELETE , params = { FROM_ID , FROM_TYPE , RELATION_TYPE , TO_ID , TO_TYPE } )
@DeleteMapping ( value = "/relation" )
@ResponseStatus ( value = HttpStatus . OK )
public void deleteRelation ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_ID ) String strFromId ,
public void deleteRelation ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_ID ) String strFromId ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( RELATION_TYPE ) String strRelationType ,
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( RELATION_TYPE ) String strRelationType ,
@ -123,8 +123,7 @@ public class EntityRelationController extends BaseController {
@ApiOperation ( value = "Delete Relation (deleteRelationV2)" ,
@ApiOperation ( value = "Delete Relation (deleteRelationV2)" ,
notes = "Deletes a relation between two entities in the platform. " + SECURITY_CHECKS_ENTITIES_DESCRIPTION )
notes = "Deletes a relation between two entities in the platform. " + SECURITY_CHECKS_ENTITIES_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/v2/relation" , method = RequestMethod . DELETE , params = { FROM_ID , FROM_TYPE , RELATION_TYPE , TO_ID , TO_TYPE } )
@DeleteMapping ( value = "/v2/relation" )
@ResponseStatus ( value = HttpStatus . OK )
public EntityRelation deleteRelationV2 ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_ID ) String strFromId ,
public EntityRelation deleteRelationV2 ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_ID ) String strFromId ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( RELATION_TYPE ) String strRelationType ,
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( RELATION_TYPE ) String strRelationType ,
@ -154,8 +153,7 @@ public class EntityRelationController extends BaseController {
notes = "Deletes all the relations ('from' and 'to' direction) for the specified entity and relation type group: 'COMMON'. " +
notes = "Deletes all the relations ('from' and 'to' direction) for the specified entity and relation type group: 'COMMON'. " +
SECURITY_CHECKS_ENTITY_DESCRIPTION )
SECURITY_CHECKS_ENTITY_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relations" , method = RequestMethod . DELETE , params = { "entityId" , "entityType" } )
@DeleteMapping ( value = "/relations" )
@ResponseStatus ( value = HttpStatus . OK )
public void deleteRelations ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( "entityId" ) String strId ,
public void deleteRelations ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( "entityId" ) String strId ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( "entityType" ) String strType ) throws ThingsboardException {
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( "entityType" ) String strType ) throws ThingsboardException {
checkParameter ( "entityId" , strId ) ;
checkParameter ( "entityId" , strId ) ;
@ -168,8 +166,7 @@ public class EntityRelationController extends BaseController {
@ApiOperation ( value = "Get Relation (getRelation)" ,
@ApiOperation ( value = "Get Relation (getRelation)" ,
notes = "Returns relation object between two specified entities if present. Otherwise throws exception. " + SECURITY_CHECKS_ENTITIES_DESCRIPTION )
notes = "Returns relation object between two specified entities if present. Otherwise throws exception. " + SECURITY_CHECKS_ENTITIES_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relation" , method = RequestMethod . GET , params = { FROM_ID , FROM_TYPE , RELATION_TYPE , TO_ID , TO_TYPE } )
@GetMapping ( value = "/relation" )
@ResponseBody
public EntityRelation getRelation ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_ID ) String strFromId ,
public EntityRelation getRelation ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_ID ) String strFromId ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( RELATION_TYPE ) String strRelationType ,
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( RELATION_TYPE ) String strRelationType ,
@ -189,15 +186,11 @@ public class EntityRelationController extends BaseController {
return checkNotNull ( relationService . getRelation ( getTenantId ( ) , fromId , toId , strRelationType , typeGroup ) ) ;
return checkNotNull ( relationService . getRelation ( getTenantId ( ) , fromId , toId , strRelationType , typeGroup ) ) ;
}
}
@ApiOperation ( value = "Get List of Relations (findByFrom)" ,
@Hidden
notes = "Returns list of relation objects for the specified entity by the 'from' direction. " +
SECURITY_CHECKS_ENTITY_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relations" , method = RequestMethod . GET , params = { FROM_ID , FROM_TYPE } )
@GetMapping ( value = "/relations" , params = { FROM_ID , FROM_TYPE } )
@ResponseBody
public List < EntityRelation > findByFrom ( @RequestParam ( FROM_ID ) String strFromId ,
public List < EntityRelation > findByFrom ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_ID ) String strFromId ,
@RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@RequestParam ( value = "relationTypeGroup" , required = false ) String strRelationTypeGroup ) throws ThingsboardException {
@RequestParam ( value = "relationTypeGroup" , required = false ) String strRelationTypeGroup ) throws ThingsboardException {
checkParameter ( FROM_ID , strFromId ) ;
checkParameter ( FROM_ID , strFromId ) ;
checkParameter ( FROM_TYPE , strFromType ) ;
checkParameter ( FROM_TYPE , strFromType ) ;
@ -207,12 +200,21 @@ public class EntityRelationController extends BaseController {
return checkNotNull ( filterRelationsByReadPermission ( relationService . findByFrom ( getTenantId ( ) , entityId , typeGroup ) ) ) ;
return checkNotNull ( filterRelationsByReadPermission ( relationService . findByFrom ( getTenantId ( ) , entityId , typeGroup ) ) ) ;
}
}
@ApiOperation ( value = "Get List of Relation Info s (findInfo ByFrom)" ,
@ApiOperation ( value = "Get List of Relations (findByFromV2 )" ,
notes = "Returns list of relation info objects for the specified entity by the 'from' direction. " +
notes = "Returns list of relation objects for the specified entity by the 'from' direction. " +
SECURITY_CHECKS_ENTITY_DESCRIPTION + " " + RELATION_INFO_DESCRIPTION )
SECURITY_CHECKS_ENTITY_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relations/info" , method = RequestMethod . GET , params = { FROM_ID , FROM_TYPE } )
@GetMapping ( value = "/relations/from/{fromType}/{fromId}" )
@ResponseBody
public List < EntityRelation > findByFromV2 ( @Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @PathVariable ( FROM_TYPE ) String strFromType ,
@Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @PathVariable ( FROM_ID ) String strFromId ,
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@RequestParam ( value = "relationTypeGroup" , required = false ) String strRelationTypeGroup ) throws ThingsboardException {
return findByFrom ( strFromId , strFromType , strRelationTypeGroup ) ;
}
@Hidden
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@GetMapping ( value = "/relations/info" , params = { FROM_ID , FROM_TYPE } )
public List < EntityRelationInfo > findInfoByFrom ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_ID ) String strFromId ,
public List < EntityRelationInfo > findInfoByFrom ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_ID ) String strFromId ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@ -225,16 +227,24 @@ public class EntityRelationController extends BaseController {
return checkNotNull ( filterRelationsByReadPermission ( relationService . findInfoByFrom ( getTenantId ( ) , entityId , typeGroup ) . get ( ) ) ) ;
return checkNotNull ( filterRelationsByReadPermission ( relationService . findInfoByFrom ( getTenantId ( ) , entityId , typeGroup ) . get ( ) ) ) ;
}
}
@ApiOperation ( value = "Get List of Relations (findByFrom)" ,
@ApiOperation ( value = "Get List of Relation Info s (findInfo ByFromV2 )" ,
notes = "Returns list of relation objects for the specified entity by the 'from' direction and relation type . " +
notes = "Returns list of relation info objects for the specified entity by the 'from' direction. " +
SECURITY_CHECKS_ENTITY_DESCRIPTION )
SECURITY_CHECKS_ENTITY_DESCRIPTION + " " + RELATION_INFO_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relations" , method = RequestMethod . GET , params = { FROM_ID , FROM_TYPE , RELATION_TYPE } )
@GetMapping ( value = "/relations/info/from/{fromType}/{fromId}" )
@ResponseBody
public List < EntityRelationInfo > findInfoByFromV2 ( @Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @PathVariable ( FROM_TYPE ) String strFromType ,
public List < EntityRelation > findByFrom ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_ID ) String strFromId ,
@Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @PathVariable ( FROM_ID ) String strFromId ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( FROM_TYPE ) String strFromType ,
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( RELATION_TYPE ) String strRelationType ,
@RequestParam ( value = "relationTypeGroup" , required = false ) String strRelationTypeGroup ) throws ThingsboardException , ExecutionException , InterruptedException {
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
return findInfoByFrom ( strFromId , strFromType , strRelationTypeGroup ) ;
}
@Hidden
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@GetMapping ( value = "/relations" , params = { FROM_ID , FROM_TYPE , RELATION_TYPE } )
public List < EntityRelation > findByFrom ( @RequestParam ( FROM_ID ) String strFromId ,
@RequestParam ( FROM_TYPE ) String strFromType ,
@RequestParam ( RELATION_TYPE ) String strRelationType ,
@RequestParam ( value = "relationTypeGroup" , required = false ) String strRelationTypeGroup ) throws ThingsboardException {
@RequestParam ( value = "relationTypeGroup" , required = false ) String strRelationTypeGroup ) throws ThingsboardException {
checkParameter ( FROM_ID , strFromId ) ;
checkParameter ( FROM_ID , strFromId ) ;
checkParameter ( FROM_TYPE , strFromType ) ;
checkParameter ( FROM_TYPE , strFromType ) ;
@ -245,12 +255,22 @@ public class EntityRelationController extends BaseController {
return checkNotNull ( filterRelationsByReadPermission ( relationService . findByFromAndType ( getTenantId ( ) , entityId , strRelationType , typeGroup ) ) ) ;
return checkNotNull ( filterRelationsByReadPermission ( relationService . findByFromAndType ( getTenantId ( ) , entityId , strRelationType , typeGroup ) ) ) ;
}
}
@ApiOperation ( value = "Get List of Relations (findByTo )" ,
@ApiOperation ( value = "Get List of Relations (findByFromV2 )" ,
notes = "Returns list of relation objects for the specified entity by the 'to' direction . " +
notes = "Returns list of relation objects for the specified entity by the 'from' direction and relation type . " +
SECURITY_CHECKS_ENTITY_DESCRIPTION )
SECURITY_CHECKS_ENTITY_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relations" , method = RequestMethod . GET , params = { TO_ID , TO_TYPE } )
@GetMapping ( value = "/relations/from/{fromType}/{fromId}/{relationType}" )
@ResponseBody
public List < EntityRelation > findByFromV2 ( @Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @PathVariable ( FROM_TYPE ) String strFromType ,
@Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @PathVariable ( FROM_ID ) String strFromId ,
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @PathVariable ( RELATION_TYPE ) String strRelationType ,
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@RequestParam ( value = "relationTypeGroup" , required = false ) String strRelationTypeGroup ) throws ThingsboardException {
return findByFrom ( strFromId , strFromType , strRelationType , strRelationTypeGroup ) ;
}
@Hidden
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@GetMapping ( value = "/relations" , params = { TO_ID , TO_TYPE } )
public List < EntityRelation > findByTo ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_ID ) String strToId ,
public List < EntityRelation > findByTo ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_ID ) String strToId ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_TYPE ) String strToType ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_TYPE ) String strToType ,
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@ -263,12 +283,21 @@ public class EntityRelationController extends BaseController {
return checkNotNull ( filterRelationsByReadPermission ( relationService . findByTo ( getTenantId ( ) , entityId , typeGroup ) ) ) ;
return checkNotNull ( filterRelationsByReadPermission ( relationService . findByTo ( getTenantId ( ) , entityId , typeGroup ) ) ) ;
}
}
@ApiOperation ( value = "Get List of Relation Info s (findInfo ByTo)" ,
@ApiOperation ( value = "Get List of Relations (findByToV2 )" ,
notes = "Returns list of relation info objects for the specified entity by the 'to' direction. " +
notes = "Returns list of relation objects for the specified entity by the 'to' direction. " +
SECURITY_CHECKS_ENTITY_DESCRIPTION + " " + RELATION_INFO_DESCRIPTION )
SECURITY_CHECKS_ENTITY_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relations/info" , method = RequestMethod . GET , params = { TO_ID , TO_TYPE } )
@GetMapping ( value = "/relations/to/{toType}/{toId}" )
@ResponseBody
public List < EntityRelation > findByToV2 ( @Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @PathVariable ( TO_TYPE ) String strToType ,
@Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @PathVariable ( TO_ID ) String strToId ,
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@RequestParam ( value = "relationTypeGroup" , required = false ) String strRelationTypeGroup ) throws ThingsboardException {
return findByTo ( strToId , strToType , strRelationTypeGroup ) ;
}
@Hidden
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@GetMapping ( value = "/relations/info" , params = { TO_ID , TO_TYPE } )
public List < EntityRelationInfo > findInfoByTo ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_ID ) String strToId ,
public List < EntityRelationInfo > findInfoByTo ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_ID ) String strToId ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_TYPE ) String strToType ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_TYPE ) String strToType ,
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@ -281,12 +310,21 @@ public class EntityRelationController extends BaseController {
return checkNotNull ( filterRelationsByReadPermission ( relationService . findInfoByTo ( getTenantId ( ) , entityId , typeGroup ) . get ( ) ) ) ;
return checkNotNull ( filterRelationsByReadPermission ( relationService . findInfoByTo ( getTenantId ( ) , entityId , typeGroup ) . get ( ) ) ) ;
}
}
@ApiOperation ( value = "Get List of Relations (findByTo)" ,
@ApiOperation ( value = "Get List of Relation Info s (findInfo ByToV2 )" ,
notes = "Returns list of relation objects for the specified entity by the 'to' direction and relation type . " +
notes = "Returns list of relation info objects for the specified entity by the 'to' direction. " +
SECURITY_CHECKS_ENTITY_DESCRIPTION )
SECURITY_CHECKS_ENTITY_DESCRIPTION + " " + RELATION_INFO_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relations" , method = RequestMethod . GET , params = { TO_ID , TO_TYPE , RELATION_TYPE } )
@GetMapping ( value = "/relations/info/to/{toType}/{toId}" )
@ResponseBody
public List < EntityRelationInfo > findInfoByToV2 ( @Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @PathVariable ( TO_TYPE ) String strToType ,
@Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @PathVariable ( TO_ID ) String strToId ,
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@RequestParam ( value = "relationTypeGroup" , required = false ) String strRelationTypeGroup ) throws ThingsboardException , ExecutionException , InterruptedException {
return findInfoByTo ( strToId , strToType , strRelationTypeGroup ) ;
}
@Hidden
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@GetMapping ( value = "/relations" , params = { TO_ID , TO_TYPE , RELATION_TYPE } )
public List < EntityRelation > findByTo ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_ID ) String strToId ,
public List < EntityRelation > findByTo ( @Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_ID ) String strToId ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_TYPE ) String strToType ,
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( TO_TYPE ) String strToType ,
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( RELATION_TYPE ) String strRelationType ,
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @RequestParam ( RELATION_TYPE ) String strRelationType ,
@ -301,13 +339,25 @@ public class EntityRelationController extends BaseController {
return checkNotNull ( filterRelationsByReadPermission ( relationService . findByToAndType ( getTenantId ( ) , entityId , strRelationType , typeGroup ) ) ) ;
return checkNotNull ( filterRelationsByReadPermission ( relationService . findByToAndType ( getTenantId ( ) , entityId , strRelationType , typeGroup ) ) ) ;
}
}
@ApiOperation ( value = "Get List of Relations (findByToV2)" ,
notes = "Returns list of relation objects for the specified entity by the 'to' direction and relation type. " +
SECURITY_CHECKS_ENTITY_DESCRIPTION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@GetMapping ( value = "/relations/to/{toType}/{toId}/{relationType}" )
public List < EntityRelation > findByToV2 ( @Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true ) @PathVariable ( TO_TYPE ) String strToType ,
@Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @PathVariable ( TO_ID ) String strToId ,
@Parameter ( description = RELATION_TYPE_PARAM_DESCRIPTION , required = true ) @PathVariable ( RELATION_TYPE ) String strRelationType ,
@Parameter ( description = RELATION_TYPE_GROUP_PARAM_DESCRIPTION )
@RequestParam ( value = "relationTypeGroup" , required = false ) String strRelationTypeGroup ) throws ThingsboardException {
return findByTo ( strToId , strToType , strRelationType , strRelationTypeGroup ) ;
}
@ApiOperation ( value = "Find related entities (findByQuery)" ,
@ApiOperation ( value = "Find related entities (findByQuery)" ,
notes = "Returns all entities that are related to the specific entity. " +
notes = "Returns all entities that are related to the specific entity. " +
"The entity id, relation type, entity types, depth of the search, and other query parameters defined using complex 'EntityRelationsQuery' object. " +
"The entity id, relation type, entity types, depth of the search, and other query parameters defined using complex 'EntityRelationsQuery' object. " +
"See 'Model' tab of the Parameters for more info." )
"See 'Model' tab of the Parameters for more info." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/relations" , method = RequestMethod . POST )
@PostMapping ( value = "/relations" )
@ResponseBody
public List < EntityRelation > findByQuery ( @Parameter ( description = "A JSON value representing the entity relations query object." , required = true )
public List < EntityRelation > findByQuery ( @Parameter ( description = "A JSON value representing the entity relations query object." , required = true )
@RequestBody EntityRelationsQuery query ) throws ThingsboardException , ExecutionException , InterruptedException {
@RequestBody EntityRelationsQuery query ) throws ThingsboardException , ExecutionException , InterruptedException {
checkNotNull ( query ) ;
checkNotNull ( query ) ;