@ -15,6 +15,8 @@
* /
package org.thingsboard.server.controller ;
import io.swagger.annotations.ApiOperation ;
import io.swagger.annotations.ApiParam ;
import org.apache.commons.lang3.StringUtils ;
import org.springframework.security.access.prepost.PreAuthorize ;
import org.springframework.web.bind.annotation.PathVariable ;
@ -38,10 +40,20 @@ import java.util.Set;
@RequestMapping ( "/api" )
public class ComponentDescriptorController extends BaseController {
private static final String COMPONENT_DESCRIPTOR_DEFINITION = "Each Component Descriptor represents configuration of specific rule node (e.g. 'Save Timeseries' or 'Send Email'.). " +
"The Component Descriptors are used by the rule chain Web UI to build the configuration forms for the rule nodes. " +
"The Component Descriptors are discovered at runtime by scanning the class path and searching for @RuleNode annotation. " +
"Once discovered, the up to date list of descriptors is persisted to the database." ;
@ApiOperation ( value = "Get Component Descriptor (getComponentDescriptorByClazz)" ,
notes = "Gets the Component Descriptor object using class name from the path parameters. " +
COMPONENT_DESCRIPTOR_DEFINITION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')" )
@RequestMapping ( value = "/component/{componentDescriptorClazz:.+}" , method = RequestMethod . GET )
@ResponseBody
public ComponentDescriptor getComponentDescriptorByClazz ( @PathVariable ( "componentDescriptorClazz" ) String strComponentDescriptorClazz ) throws ThingsboardException {
public ComponentDescriptor getComponentDescriptorByClazz (
@ApiParam ( value = "Component Descriptor class name" , required = true )
@PathVariable ( "componentDescriptorClazz" ) String strComponentDescriptorClazz ) throws ThingsboardException {
checkParameter ( "strComponentDescriptorClazz" , strComponentDescriptorClazz ) ;
try {
return checkComponentDescriptorByClazz ( strComponentDescriptorClazz ) ;
@ -50,11 +62,17 @@ public class ComponentDescriptorController extends BaseController {
}
}
@ApiOperation ( value = "Get Component Descriptors (getComponentDescriptorsByType)" ,
notes = "Gets the Component Descriptors using rule node type and optional rule chain type request parameters. " +
COMPONENT_DESCRIPTOR_DEFINITION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')" )
@RequestMapping ( value = "/components/{componentType}" , method = RequestMethod . GET )
@ResponseBody
public List < ComponentDescriptor > getComponentDescriptorsByType ( @PathVariable ( "componentType" ) String strComponentType ,
@RequestParam ( value = "ruleChainType" , required = false ) String strRuleChainType ) throws ThingsboardException {
public List < ComponentDescriptor > getComponentDescriptorsByType (
@ApiParam ( value = "Type of the Rule Node" , allowableValues = "ENRICHMENT,FILTER,TRANSFORMATION,ACTION,EXTERNAL" , required = true )
@PathVariable ( "componentType" ) String strComponentType ,
@ApiParam ( value = "Type of the Rule Chain" , allowableValues = "CORE,EDGE" )
@RequestParam ( value = "ruleChainType" , required = false ) String strRuleChainType ) throws ThingsboardException {
checkParameter ( "componentType" , strComponentType ) ;
try {
return checkComponentDescriptorsByType ( ComponentType . valueOf ( strComponentType ) , getRuleChainType ( strRuleChainType ) ) ;
@ -63,11 +81,17 @@ public class ComponentDescriptorController extends BaseController {
}
}
@ApiOperation ( value = "Get Component Descriptors (getComponentDescriptorsByTypes)" ,
notes = "Gets the Component Descriptors using coma separated list of rule node types and optional rule chain type request parameters. " +
COMPONENT_DESCRIPTOR_DEFINITION )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')" )
@RequestMapping ( value = "/components" , params = { "componentTypes" } , method = RequestMethod . GET )
@ResponseBody
public List < ComponentDescriptor > getComponentDescriptorsByTypes ( @RequestParam ( "componentTypes" ) String [ ] strComponentTypes ,
@RequestParam ( value = "ruleChainType" , required = false ) String strRuleChainType ) throws ThingsboardException {
public List < ComponentDescriptor > getComponentDescriptorsByTypes (
@ApiParam ( value = "List of types of the Rule Nodes, (ENRICHMENT, FILTER, TRANSFORMATION, ACTION or EXTERNAL)" , required = true )
@RequestParam ( "componentTypes" ) String [ ] strComponentTypes ,
@ApiParam ( value = "Type of the Rule Chain" , allowableValues = "CORE,EDGE" )
@RequestParam ( value = "ruleChainType" , required = false ) String strRuleChainType ) throws ThingsboardException {
checkArrayParameter ( "componentTypes" , strComponentTypes ) ;
try {
Set < ComponentType > componentTypes = new HashSet < > ( ) ;