Commit ca89a4fc0e2c4c20b9c60bf27ee4f1749aa5744a

Authored by Andrii Shvaika
1 parent e755f3f6

Component Descriptor documentation

@@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
15 */ 15 */
16 package org.thingsboard.server.controller; 16 package org.thingsboard.server.controller;
17 17
  18 +import io.swagger.annotations.ApiOperation;
  19 +import io.swagger.annotations.ApiParam;
18 import org.apache.commons.lang3.StringUtils; 20 import org.apache.commons.lang3.StringUtils;
19 import org.springframework.security.access.prepost.PreAuthorize; 21 import org.springframework.security.access.prepost.PreAuthorize;
20 import org.springframework.web.bind.annotation.PathVariable; 22 import org.springframework.web.bind.annotation.PathVariable;
@@ -38,10 +40,20 @@ import java.util.Set; @@ -38,10 +40,20 @@ import java.util.Set;
38 @RequestMapping("/api") 40 @RequestMapping("/api")
39 public class ComponentDescriptorController extends BaseController { 41 public class ComponentDescriptorController extends BaseController {
40 42
  43 + private static final String COMPONENT_DESCRIPTOR_DEFINITION = "Each Component Descriptor represents configuration of specific rule node (e.g. 'Save Timeseries' or 'Send Email'.). " +
  44 + "The Component Descriptors are used by the rule chain Web UI to build the configuration forms for the rule nodes. " +
  45 + "The Component Descriptors are discovered at runtime by scanning the class path and searching for @RuleNode annotation. " +
  46 + "Once discovered, the up to date list of descriptors is persisted to the database.";
  47 +
  48 + @ApiOperation(value = "Get Component Descriptor (getComponentDescriptorByClazz)",
  49 + notes = "Gets the Component Descriptor object using class name from the path parameters. " +
  50 + COMPONENT_DESCRIPTOR_DEFINITION)
41 @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')") 51 @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')")
42 @RequestMapping(value = "/component/{componentDescriptorClazz:.+}", method = RequestMethod.GET) 52 @RequestMapping(value = "/component/{componentDescriptorClazz:.+}", method = RequestMethod.GET)
43 @ResponseBody 53 @ResponseBody
44 - public ComponentDescriptor getComponentDescriptorByClazz(@PathVariable("componentDescriptorClazz") String strComponentDescriptorClazz) throws ThingsboardException { 54 + public ComponentDescriptor getComponentDescriptorByClazz(
  55 + @ApiParam(value = "Component Descriptor class name", required = true)
  56 + @PathVariable("componentDescriptorClazz") String strComponentDescriptorClazz) throws ThingsboardException {
45 checkParameter("strComponentDescriptorClazz", strComponentDescriptorClazz); 57 checkParameter("strComponentDescriptorClazz", strComponentDescriptorClazz);
46 try { 58 try {
47 return checkComponentDescriptorByClazz(strComponentDescriptorClazz); 59 return checkComponentDescriptorByClazz(strComponentDescriptorClazz);
@@ -50,11 +62,17 @@ public class ComponentDescriptorController extends BaseController { @@ -50,11 +62,17 @@ public class ComponentDescriptorController extends BaseController {
50 } 62 }
51 } 63 }
52 64
  65 + @ApiOperation(value = "Get Component Descriptors (getComponentDescriptorsByType)",
  66 + notes = "Gets the Component Descriptors using rule node type and optional rule chain type request parameters. " +
  67 + COMPONENT_DESCRIPTOR_DEFINITION)
53 @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')") 68 @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')")
54 @RequestMapping(value = "/components/{componentType}", method = RequestMethod.GET) 69 @RequestMapping(value = "/components/{componentType}", method = RequestMethod.GET)
55 @ResponseBody 70 @ResponseBody
56 - public List<ComponentDescriptor> getComponentDescriptorsByType(@PathVariable("componentType") String strComponentType,  
57 - @RequestParam(value = "ruleChainType", required = false) String strRuleChainType) throws ThingsboardException { 71 + public List<ComponentDescriptor> getComponentDescriptorsByType(
  72 + @ApiParam(value = "Type of the Rule Node", allowableValues = "ENRICHMENT,FILTER,TRANSFORMATION,ACTION,EXTERNAL", required = true)
  73 + @PathVariable("componentType") String strComponentType,
  74 + @ApiParam(value = "Type of the Rule Chain", allowableValues = "CORE,EDGE")
  75 + @RequestParam(value = "ruleChainType", required = false) String strRuleChainType) throws ThingsboardException {
58 checkParameter("componentType", strComponentType); 76 checkParameter("componentType", strComponentType);
59 try { 77 try {
60 return checkComponentDescriptorsByType(ComponentType.valueOf(strComponentType), getRuleChainType(strRuleChainType)); 78 return checkComponentDescriptorsByType(ComponentType.valueOf(strComponentType), getRuleChainType(strRuleChainType));
@@ -63,11 +81,17 @@ public class ComponentDescriptorController extends BaseController { @@ -63,11 +81,17 @@ public class ComponentDescriptorController extends BaseController {
63 } 81 }
64 } 82 }
65 83
  84 + @ApiOperation(value = "Get Component Descriptors (getComponentDescriptorsByTypes)",
  85 + notes = "Gets the Component Descriptors using coma separated list of rule node types and optional rule chain type request parameters. " +
  86 + COMPONENT_DESCRIPTOR_DEFINITION)
66 @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')") 87 @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')")
67 @RequestMapping(value = "/components", params = {"componentTypes"}, method = RequestMethod.GET) 88 @RequestMapping(value = "/components", params = {"componentTypes"}, method = RequestMethod.GET)
68 @ResponseBody 89 @ResponseBody
69 - public List<ComponentDescriptor> getComponentDescriptorsByTypes(@RequestParam("componentTypes") String[] strComponentTypes,  
70 - @RequestParam(value = "ruleChainType", required = false) String strRuleChainType) throws ThingsboardException { 90 + public List<ComponentDescriptor> getComponentDescriptorsByTypes(
  91 + @ApiParam(value = "List of types of the Rule Nodes, (ENRICHMENT, FILTER, TRANSFORMATION, ACTION or EXTERNAL)", required = true)
  92 + @RequestParam("componentTypes") String[] strComponentTypes,
  93 + @ApiParam(value = "Type of the Rule Chain", allowableValues = "CORE,EDGE")
  94 + @RequestParam(value = "ruleChainType", required = false) String strRuleChainType) throws ThingsboardException {
71 checkArrayParameter("componentTypes", strComponentTypes); 95 checkArrayParameter("componentTypes", strComponentTypes);
72 try { 96 try {
73 Set<ComponentType> componentTypes = new HashSet<>(); 97 Set<ComponentType> componentTypes = new HashSet<>();
@@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
16 package org.thingsboard.server.common.data.plugin; 16 package org.thingsboard.server.common.data.plugin;
17 17
18 import com.fasterxml.jackson.databind.JsonNode; 18 import com.fasterxml.jackson.databind.JsonNode;
  19 +import io.swagger.annotations.ApiModel;
  20 +import io.swagger.annotations.ApiModelProperty;
19 import lombok.*; 21 import lombok.*;
20 import org.thingsboard.server.common.data.SearchTextBased; 22 import org.thingsboard.server.common.data.SearchTextBased;
21 import org.thingsboard.server.common.data.id.ComponentDescriptorId; 23 import org.thingsboard.server.common.data.id.ComponentDescriptorId;
@@ -23,16 +25,23 @@ import org.thingsboard.server.common.data.id.ComponentDescriptorId; @@ -23,16 +25,23 @@ import org.thingsboard.server.common.data.id.ComponentDescriptorId;
23 /** 25 /**
24 * @author Andrew Shvayka 26 * @author Andrew Shvayka
25 */ 27 */
  28 +@ApiModel
26 @ToString 29 @ToString
27 public class ComponentDescriptor extends SearchTextBased<ComponentDescriptorId> { 30 public class ComponentDescriptor extends SearchTextBased<ComponentDescriptorId> {
28 31
29 private static final long serialVersionUID = 1L; 32 private static final long serialVersionUID = 1L;
30 33
  34 + @ApiModelProperty(position = 3, value = "Type of the Rule Node", readOnly = true)
31 @Getter @Setter private ComponentType type; 35 @Getter @Setter private ComponentType type;
  36 + @ApiModelProperty(position = 4, value = "Scope of the Rule Node. Always set to 'TENANT', since no rule chains on the 'SYSTEM' level yet.", readOnly = true, allowableValues = "TENANT", example = "TENANT")
32 @Getter @Setter private ComponentScope scope; 37 @Getter @Setter private ComponentScope scope;
  38 + @ApiModelProperty(position = 5, value = "Name of the Rule Node. Taken from the @RuleNode annotation.", readOnly = true, example = "Custom Rule Node")
33 @Getter @Setter private String name; 39 @Getter @Setter private String name;
  40 + @ApiModelProperty(position = 6, value = "Full name of the Java class that implements the Rule Engine Node interface.", readOnly = true, example = "com.mycompany.CustomRuleNode")
34 @Getter @Setter private String clazz; 41 @Getter @Setter private String clazz;
  42 + @ApiModelProperty(position = 7, value = "Complex JSON object that represents the Rule Node configuration.", readOnly = true)
35 @Getter @Setter private transient JsonNode configurationDescriptor; 43 @Getter @Setter private transient JsonNode configurationDescriptor;
  44 + @ApiModelProperty(position = 8, value = "Rule Node Actions. Deprecated. Always null.", readOnly = true)
36 @Getter @Setter private String actions; 45 @Getter @Setter private String actions;
37 46
38 public ComponentDescriptor() { 47 public ComponentDescriptor() {
@@ -53,12 +62,26 @@ public class ComponentDescriptor extends SearchTextBased<ComponentDescriptorId> @@ -53,12 +62,26 @@ public class ComponentDescriptor extends SearchTextBased<ComponentDescriptorId>
53 this.actions = plugin.getActions(); 62 this.actions = plugin.getActions();
54 } 63 }
55 64
  65 + @ApiModelProperty(position = 1, value = "JSON object with the descriptor Id. " +
  66 + "Specify existing descriptor id to update the descriptor. " +
  67 + "Referencing non-existing descriptor Id will cause error. " +
  68 + "Omit this field to create new descriptor." )
  69 + @Override
  70 + public ComponentDescriptorId getId() {
  71 + return super.getId();
  72 + }
  73 +
  74 + @ApiModelProperty(position = 2, value = "Timestamp of the descriptor creation, in milliseconds", example = "1609459200000", readOnly = true)
  75 + @Override
  76 + public long getCreatedTime() {
  77 + return super.getCreatedTime();
  78 + }
  79 +
56 @Override 80 @Override
57 public String getSearchText() { 81 public String getSearchText() {
58 return name; 82 return name;
59 } 83 }
60 84
61 -  
62 @Override 85 @Override
63 public boolean equals(Object o) { 86 public boolean equals(Object o) {
64 if (this == o) return true; 87 if (this == o) return true;
@@ -84,4 +107,5 @@ public class ComponentDescriptor extends SearchTextBased<ComponentDescriptorId> @@ -84,4 +107,5 @@ public class ComponentDescriptor extends SearchTextBased<ComponentDescriptorId>
84 result = 31 * result + (actions != null ? actions.hashCode() : 0); 107 result = 31 * result + (actions != null ? actions.hashCode() : 0);
85 return result; 108 return result;
86 } 109 }
  110 +
87 } 111 }