Resource controller description
This commit is contained in:
parent
3103f596d5
commit
36bb7f36a5
@ -182,6 +182,7 @@ public abstract class BaseController {
|
||||
public static final String RULE_CHAIN_ID_PARAM_DESCRIPTION = "A string value representing the rule chain id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
|
||||
public static final String WIDGET_BUNDLE_ID_PARAM_DESCRIPTION = "A string value representing the widget bundle id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
|
||||
public static final String WIDGET_TYPE_ID_PARAM_DESCRIPTION = "A string value representing the widget type id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
|
||||
public static final String RESOURCE_ID_PARAM_DESCRIPTION = "A string value representing the resource id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
|
||||
|
||||
|
||||
protected static final String SYSTEM_AUTHORITY_PARAGRAPH = "\n\nAvailable for users with 'SYS_ADMIN' authority.";
|
||||
@ -248,6 +249,12 @@ public abstract class BaseController {
|
||||
protected static final String OTA_PACKAGE_CHECKSUM_ALGORITHM_ALLOWABLE_VALUES = "MD5, SHA256, SHA384, SHA512, CRC32, MURMUR3_32, MURMUR3_128";
|
||||
protected static final String OTA_PACKAGE_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on the ota package title.";
|
||||
protected static final String OTA_PACKAGE_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, type, title, version, tag, url, fileName, dataSize, checksum";
|
||||
protected static final String RESOURCE_INFO_DESCRIPTION = "Resource Info is a lightweight object that includes main information about the Resource excluding the heavyweight data. ";
|
||||
protected static final String RESOURCE_DESCRIPTION = "Resource is a heavyweight object that includes main information about the Resource and also data. ";
|
||||
protected static final String RESOURCE_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on the resource title.";
|
||||
protected static final String RESOURCE_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, title, resourceType, tenantId";
|
||||
protected static final String LWM2M_OBJECT_DESCRIPTION = "LwM2M Object is a object that includes information about the LwM2M model which can be used in transport configuration for the LwM2M device profile. ";
|
||||
protected static final String LWM2M_OBJECT_SORT_PROPERTY_ALLOWABLE_VALUES = "id, name";
|
||||
|
||||
protected static final String DEVICE_NAME_DESCRIPTION = "A string value representing the Device name.";
|
||||
protected static final String ASSET_NAME_DESCRIPTION = "A string value representing the Asset name.";
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.thingsboard.server.controller;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@ -53,10 +55,12 @@ public class TbResourceController extends BaseController {
|
||||
|
||||
public static final String RESOURCE_ID = "resourceId";
|
||||
|
||||
@ApiOperation(value = "Download Resource (downloadResource)", notes = "Download Resource based on the provided Resource Id." + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/resource/{resourceId}/download", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<org.springframework.core.io.Resource> downloadResource(@PathVariable(RESOURCE_ID) String strResourceId) throws ThingsboardException {
|
||||
public ResponseEntity<org.springframework.core.io.Resource> downloadResource(@ApiParam(value = RESOURCE_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable(RESOURCE_ID) String strResourceId) throws ThingsboardException {
|
||||
checkParameter(RESOURCE_ID, strResourceId);
|
||||
try {
|
||||
TbResourceId resourceId = new TbResourceId(toUUID(strResourceId));
|
||||
@ -74,10 +78,15 @@ public class TbResourceController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get Resource Info (getResourceInfoById)",
|
||||
notes = "Fetch the Resource Info object based on the provided Resource Id. " +
|
||||
RESOURCE_INFO_DESCRIPTION + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/resource/info/{resourceId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public TbResourceInfo getResourceInfoById(@PathVariable(RESOURCE_ID) String strResourceId) throws ThingsboardException {
|
||||
public TbResourceInfo getResourceInfoById(@ApiParam(value = RESOURCE_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable(RESOURCE_ID) String strResourceId) throws ThingsboardException {
|
||||
checkParameter(RESOURCE_ID, strResourceId);
|
||||
try {
|
||||
TbResourceId resourceId = new TbResourceId(toUUID(strResourceId));
|
||||
@ -87,10 +96,15 @@ public class TbResourceController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get Resource (getResourceById)",
|
||||
notes = "Fetch the Resource object based on the provided Resource Id. " +
|
||||
RESOURCE_DESCRIPTION + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/resource/{resourceId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public TbResource getResourceById(@PathVariable(RESOURCE_ID) String strResourceId) throws ThingsboardException {
|
||||
public TbResource getResourceById(@ApiParam(value = RESOURCE_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable(RESOURCE_ID) String strResourceId) throws ThingsboardException {
|
||||
checkParameter(RESOURCE_ID, strResourceId);
|
||||
try {
|
||||
TbResourceId resourceId = new TbResourceId(toUUID(strResourceId));
|
||||
@ -100,10 +114,19 @@ public class TbResourceController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Create Or Update Resource (saveResource)",
|
||||
notes = "Create or update the Resource. When creating the Resource, platform generates Resource id as [time-based UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_(date-time_and_MAC_address). " +
|
||||
"The newly created Resource id will be present in the response. " +
|
||||
"Specify existing Resource id to update the Resource. " +
|
||||
"Referencing non-existing Resource Id will cause 'Not Found' error. " +
|
||||
"\n\nResource combination of the title with the key is unique in the scope of tenant. " + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json",
|
||||
consumes = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/resource", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public TbResource saveResource(@RequestBody TbResource resource) throws ThingsboardException {
|
||||
public TbResource saveResource(@ApiParam(value = "A JSON value representing the Resource.")
|
||||
@RequestBody TbResource resource) throws ThingsboardException {
|
||||
boolean created = resource.getId() == null;
|
||||
try {
|
||||
resource.setTenantId(getTenantId());
|
||||
@ -120,13 +143,22 @@ public class TbResourceController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get Resource Infos (getResources)",
|
||||
notes = "Returns a page of Resource Info objects owned by tenant or sysadmin. " +
|
||||
PAGE_DATA_PARAMETERS + RESOURCE_INFO_DESCRIPTION + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/resource", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public PageData<TbResourceInfo> getResources(@RequestParam int pageSize,
|
||||
public PageData<TbResourceInfo> getResources(@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
|
||||
@RequestParam int pageSize,
|
||||
@ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
|
||||
@RequestParam int page,
|
||||
@ApiParam(value = RESOURCE_TEXT_SEARCH_DESCRIPTION)
|
||||
@RequestParam(required = false) String textSearch,
|
||||
@ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = RESOURCE_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);
|
||||
@ -140,13 +172,22 @@ public class TbResourceController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get LwM2M Objects (getLwm2mListObjectsPage)",
|
||||
notes = "Returns a page of LwM2M objects parsed from Resources with type 'LWM2M_MODEL' owned by tenant or sysadmin. " +
|
||||
PAGE_DATA_PARAMETERS + LWM2M_OBJECT_DESCRIPTION + TENANT_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/resource/lwm2m/page", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public List<LwM2mObject> getLwm2mListObjectsPage(@RequestParam int pageSize,
|
||||
public List<LwM2mObject> getLwm2mListObjectsPage(@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
|
||||
@RequestParam int pageSize,
|
||||
@ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
|
||||
@RequestParam int page,
|
||||
@ApiParam(value = RESOURCE_TEXT_SEARCH_DESCRIPTION)
|
||||
@RequestParam(required = false) String textSearch,
|
||||
@ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = LWM2M_OBJECT_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 = new PageLink(pageSize, page, textSearch);
|
||||
@ -156,11 +197,18 @@ public class TbResourceController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get LwM2M Objects (getLwm2mListObjects)",
|
||||
notes = "Returns a page of LwM2M objects parsed from Resources with type 'LWM2M_MODEL' owned by tenant or sysadmin. " +
|
||||
"You can specify parameters to filter the results. " + LWM2M_OBJECT_DESCRIPTION + TENANT_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/resource/lwm2m", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public List<LwM2mObject> getLwm2mListObjects(@RequestParam String sortOrder,
|
||||
public List<LwM2mObject> getLwm2mListObjects(@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES, required = true)
|
||||
@RequestParam String sortOrder,
|
||||
@ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = LWM2M_OBJECT_SORT_PROPERTY_ALLOWABLE_VALUES, required = true)
|
||||
@RequestParam String sortProperty,
|
||||
@ApiParam(value = "LwM2M Object ids.", required = true)
|
||||
@RequestParam(required = false) String[] objectIds) throws ThingsboardException {
|
||||
try {
|
||||
return checkNotNull(resourceService.findLwM2mObject(getTenantId(), sortOrder, sortProperty, objectIds));
|
||||
@ -169,10 +217,13 @@ public class TbResourceController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Delete Resource (deleteResource)",
|
||||
notes = "Deletes the Resource. Referencing non-existing Resource Id will cause an error." + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/resource/{resourceId}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public void deleteResource(@PathVariable("resourceId") String strResourceId) throws ThingsboardException {
|
||||
public void deleteResource(@ApiParam(value = RESOURCE_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable("resourceId") String strResourceId) throws ThingsboardException {
|
||||
checkParameter(RESOURCE_ID, strResourceId);
|
||||
try {
|
||||
TbResourceId resourceId = new TbResourceId(toUUID(strResourceId));
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -16,6 +16,8 @@
|
||||
package org.thingsboard.server.common.data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -23,6 +25,7 @@ import org.thingsboard.server.common.data.id.TbResourceId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.validation.NoXss;
|
||||
|
||||
@ApiModel
|
||||
@Slf4j
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ -30,11 +33,16 @@ public class TbResourceInfo extends SearchTextBased<TbResourceId> implements Has
|
||||
|
||||
private static final long serialVersionUID = 7282664529021651736L;
|
||||
|
||||
@ApiModelProperty(position = 3, value = "JSON object with Tenant Id. Tenant Id of the resource can't be changed.", readOnly = true)
|
||||
private TenantId tenantId;
|
||||
@NoXss
|
||||
@ApiModelProperty(position = 4, value = "Resource title.", example = "BinaryAppDataContainer id=19 v1.0")
|
||||
private String title;
|
||||
@ApiModelProperty(position = 5, value = "Resource type.", example = "LWM2M_MODEL", readOnly = true)
|
||||
private ResourceType resourceType;
|
||||
@ApiModelProperty(position = 6, value = "Resource key.", example = "19_1.0", readOnly = true)
|
||||
private String resourceKey;
|
||||
@ApiModelProperty(position = 7, value = "Resource search text.", example = "19_1.0:binaryappdatacontainer", readOnly = true)
|
||||
private String searchText;
|
||||
|
||||
public TbResourceInfo() {
|
||||
@ -54,6 +62,21 @@ public class TbResourceInfo extends SearchTextBased<TbResourceId> implements Has
|
||||
this.searchText = resourceInfo.getSearchText();
|
||||
}
|
||||
|
||||
@ApiModelProperty(position = 1, value = "JSON object with the Resource Id. " +
|
||||
"Specify this field to update the Resource. " +
|
||||
"Referencing non-existing Resource Id will cause error. " +
|
||||
"Omit this field to create new Resource." )
|
||||
@Override
|
||||
public TbResourceId getId() {
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
@ApiModelProperty(position = 2, value = "Timestamp of the resource creation, in milliseconds", example = "1609459200000", readOnly = true)
|
||||
@Override
|
||||
public long getCreatedTime() {
|
||||
return super.getCreatedTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public String getName() {
|
||||
|
||||
@ -15,11 +15,16 @@
|
||||
*/
|
||||
package org.thingsboard.server.common.data.lwm2m;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel
|
||||
@Data
|
||||
public class LwM2mInstance {
|
||||
@ApiModelProperty(position = 1, value = "LwM2M Instance id.", example = "0")
|
||||
int id;
|
||||
@ApiModelProperty(position = 2, value = "LwM2M Resource observe.")
|
||||
LwM2mResourceObserve[] resources;
|
||||
|
||||
}
|
||||
|
||||
@ -15,14 +15,23 @@
|
||||
*/
|
||||
package org.thingsboard.server.common.data.lwm2m;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel
|
||||
@Data
|
||||
public class LwM2mObject {
|
||||
@ApiModelProperty(position = 1, value = "LwM2M Object id.", example = "19")
|
||||
int id;
|
||||
@ApiModelProperty(position = 2, value = "LwM2M Object key id.", example = "19_1.0")
|
||||
String keyId;
|
||||
@ApiModelProperty(position = 3, value = "LwM2M Object name.", example = "BinaryAppDataContainer")
|
||||
String name;
|
||||
@ApiModelProperty(position = 4, value = "LwM2M Object multiple.", example = "true")
|
||||
boolean multiple;
|
||||
@ApiModelProperty(position = 5, value = "LwM2M Object mandatory.", example = "false")
|
||||
boolean mandatory;
|
||||
@ApiModelProperty(position = 6, value = "LwM2M Object instances.")
|
||||
LwM2mInstance [] instances;
|
||||
}
|
||||
|
||||
@ -15,19 +15,28 @@
|
||||
*/
|
||||
package org.thingsboard.server.common.data.lwm2m;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ApiModel
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class LwM2mResourceObserve {
|
||||
@ApiModelProperty(position = 1, value = "LwM2M Resource Observe id.", example = "0")
|
||||
int id;
|
||||
@ApiModelProperty(position = 2, value = "LwM2M Resource Observe name.", example = "Data")
|
||||
String name;
|
||||
@ApiModelProperty(position = 3, value = "LwM2M Resource Observe observe.", example = "false")
|
||||
boolean observe;
|
||||
@ApiModelProperty(position = 4, value = "LwM2M Resource Observe attribute.", example = "false")
|
||||
boolean attribute;
|
||||
@ApiModelProperty(position = 5, value = "LwM2M Resource Observe telemetry.", example = "false")
|
||||
boolean telemetry;
|
||||
@ApiModelProperty(position = 6, value = "LwM2M Resource Observe key name.", example = "data")
|
||||
String keyName;
|
||||
|
||||
public LwM2mResourceObserve(int id, String name, boolean observe, boolean attribute, boolean telemetry) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user