Ota package controller description
This commit is contained in:
parent
1236e89bca
commit
3103f596d5
@ -177,6 +177,7 @@ public abstract class BaseController {
|
||||
public static final String ASSET_ID_PARAM_DESCRIPTION = "A string value representing the asset id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
|
||||
public static final String ALARM_ID_PARAM_DESCRIPTION = "A string value representing the alarm id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
|
||||
public static final String ENTITY_ID_PARAM_DESCRIPTION = "A string value representing the entity id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
|
||||
public static final String OTA_PACKAGE_ID_PARAM_DESCRIPTION = "A string value representing the ota package id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
|
||||
public static final String ENTITY_TYPE_PARAM_DESCRIPTION = "A string value representing the entity type. For example, 'DEVICE'";
|
||||
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'";
|
||||
@ -242,6 +243,11 @@ public abstract class BaseController {
|
||||
protected static final String DEVICE_PROFILE_INFO_DESCRIPTION = "Device Profile Info is a lightweight object that includes main information about Device Profile excluding the heavyweight configuration object. ";
|
||||
protected static final String QUEUE_SERVICE_TYPE_DESCRIPTION = "Service type (implemented only for the TB-RULE-ENGINE)";
|
||||
protected static final String QUEUE_SERVICE_TYPE_ALLOWABLE_VALUES = "TB-RULE-ENGINE, TB-CORE, TB-TRANSPORT, JS-EXECUTOR";
|
||||
protected static final String OTA_PACKAGE_INFO_DESCRIPTION = "OTA Package Info is a lightweight object that includes main information about the OTA Package excluding the heavyweight data. ";
|
||||
protected static final String OTA_PACKAGE_DESCRIPTION = "OTA Package is a heavyweight object that includes main information about the OTA Package and also data. ";
|
||||
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 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.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
@ -56,10 +58,12 @@ public class OtaPackageController extends BaseController {
|
||||
public static final String OTA_PACKAGE_ID = "otaPackageId";
|
||||
public static final String CHECKSUM_ALGORITHM = "checksumAlgorithm";
|
||||
|
||||
@ApiOperation(value = "Download OTA Package (downloadOtaPackage)", notes = "Download OTA Package based on the provided OTA Package Id." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority( 'TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/otaPackage/{otaPackageId}/download", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<org.springframework.core.io.Resource> downloadOtaPackage(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
||||
public ResponseEntity<org.springframework.core.io.Resource> downloadOtaPackage(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
||||
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
|
||||
try {
|
||||
OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId));
|
||||
@ -81,10 +85,15 @@ public class OtaPackageController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get OTA Package Info (getOtaPackageInfoById)",
|
||||
notes = "Fetch the OTA Package Info object based on the provided OTA Package Id. " +
|
||||
OTA_PACKAGE_INFO_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/otaPackage/info/{otaPackageId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public OtaPackageInfo getOtaPackageInfoById(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
||||
public OtaPackageInfo getOtaPackageInfoById(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
||||
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
|
||||
try {
|
||||
OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId));
|
||||
@ -94,10 +103,15 @@ public class OtaPackageController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get OTA Package (getOtaPackageById)",
|
||||
notes = "Fetch the OTA Package object based on the provided OTA Package Id. " +
|
||||
"The server checks that the OTA Package is owned by the same tenant. " + OTA_PACKAGE_DESCRIPTION + TENANT_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public OtaPackage getOtaPackageById(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
||||
public OtaPackage getOtaPackageById(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
||||
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
|
||||
try {
|
||||
OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId));
|
||||
@ -107,10 +121,19 @@ public class OtaPackageController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Create Or Update OTA Package Info (saveOtaPackageInfo)",
|
||||
notes = "Create or update the OTA Package Info. When creating OTA Package Info, platform generates OTA Package id as [time-based UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_(date-time_and_MAC_address). " +
|
||||
"The newly created OTA Package id will be present in the response. " +
|
||||
"Specify existing OTA Package id to update the OTA Package Info. " +
|
||||
"Referencing non-existing OTA Package Id will cause 'Not Found' error. " +
|
||||
"\n\nOTA Package combination of the title with the version is unique in the scope of tenant. " + TENANT_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json",
|
||||
consumes = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/otaPackage", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public OtaPackageInfo saveOtaPackageInfo(@RequestBody SaveOtaPackageInfoRequest otaPackageInfo) throws ThingsboardException {
|
||||
public OtaPackageInfo saveOtaPackageInfo(@ApiParam(value = "A JSON value representing the OTA Package.")
|
||||
@RequestBody SaveOtaPackageInfoRequest otaPackageInfo) throws ThingsboardException {
|
||||
boolean created = otaPackageInfo.getId() == null;
|
||||
try {
|
||||
otaPackageInfo.setTenantId(getTenantId());
|
||||
@ -126,12 +149,19 @@ public class OtaPackageController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Save OTA Package data (saveOtaPackageData)",
|
||||
notes = "Update the OTA Package. Adds the date to the existing OTA Package Info" + TENANT_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public OtaPackageInfo saveOtaPackageData(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId,
|
||||
public OtaPackageInfo saveOtaPackageData(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId,
|
||||
@ApiParam(value = "OTA Package checksum. For example, '0xd87f7e0c'")
|
||||
@RequestParam(required = false) String checksum,
|
||||
@ApiParam(value = "OTA Package checksum algorithm.", allowableValues = OTA_PACKAGE_CHECKSUM_ALGORITHM_ALLOWABLE_VALUES)
|
||||
@RequestParam(CHECKSUM_ALGORITHM) String checksumAlgorithmStr,
|
||||
@ApiParam(value = "OTA Package data.")
|
||||
@RequestBody MultipartFile file) throws ThingsboardException {
|
||||
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
|
||||
checkParameter(CHECKSUM_ALGORITHM, checksumAlgorithmStr);
|
||||
@ -171,13 +201,22 @@ public class OtaPackageController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get OTA Package Infos (getOtaPackages)",
|
||||
notes = "Returns a page of OTA Package Info objects owned by tenant. " +
|
||||
PAGE_DATA_PARAMETERS + OTA_PACKAGE_INFO_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/otaPackages", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public PageData<OtaPackageInfo> getOtaPackages(@RequestParam int pageSize,
|
||||
public PageData<OtaPackageInfo> getOtaPackages(@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
|
||||
@RequestParam int pageSize,
|
||||
@ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
|
||||
@RequestParam int page,
|
||||
@ApiParam(value = OTA_PACKAGE_TEXT_SEARCH_DESCRIPTION)
|
||||
@RequestParam(required = false) String textSearch,
|
||||
@ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = OTA_PACKAGE_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);
|
||||
@ -187,15 +226,26 @@ public class OtaPackageController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get OTA Package Infos (getOtaPackages)",
|
||||
notes = "Returns a page of OTA Package Info objects owned by tenant. " +
|
||||
PAGE_DATA_PARAMETERS + OTA_PACKAGE_INFO_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/otaPackages/{deviceProfileId}/{type}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public PageData<OtaPackageInfo> getOtaPackages(@PathVariable("deviceProfileId") String strDeviceProfileId,
|
||||
public PageData<OtaPackageInfo> getOtaPackages(@ApiParam(value = DEVICE_PROFILE_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable("deviceProfileId") String strDeviceProfileId,
|
||||
@ApiParam(value = "OTA Package type.", allowableValues = "FIRMWARE, SOFTWARE")
|
||||
@PathVariable("type") String strType,
|
||||
@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
|
||||
@RequestParam int pageSize,
|
||||
@ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
|
||||
@RequestParam int page,
|
||||
@ApiParam(value = OTA_PACKAGE_TEXT_SEARCH_DESCRIPTION)
|
||||
@RequestParam(required = false) String textSearch,
|
||||
@ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = OTA_PACKAGE_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("deviceProfileId", strDeviceProfileId);
|
||||
checkParameter("type", strType);
|
||||
@ -208,10 +258,15 @@ public class OtaPackageController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Delete OTA Package (deleteOtaPackage)",
|
||||
notes = "Deletes the OTA Package. Referencing non-existing OTA Package Id will cause an error. " +
|
||||
"Can't delete the OTA Package if it is referenced by existing devices or device profile." + TENANT_AUTHORITY_PARAGRAPH,
|
||||
produces = "application/json")
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public void deleteOtaPackage(@PathVariable("otaPackageId") String strOtaPackageId) throws ThingsboardException {
|
||||
public void deleteOtaPackage(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable("otaPackageId") String strOtaPackageId) throws ThingsboardException {
|
||||
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
|
||||
try {
|
||||
OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId));
|
||||
|
||||
@ -15,18 +15,22 @@
|
||||
*/
|
||||
package org.thingsboard.server.common.data;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.thingsboard.server.common.data.id.OtaPackageId;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@ApiModel
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class OtaPackage extends OtaPackageInfo {
|
||||
|
||||
private static final long serialVersionUID = 3091601761339422546L;
|
||||
|
||||
@ApiModelProperty(position = 16, value = "OTA Package data.", readOnly = true)
|
||||
private transient ByteBuffer data;
|
||||
|
||||
public OtaPackage() {
|
||||
|
||||
@ -16,15 +16,19 @@
|
||||
package org.thingsboard.server.common.data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.server.common.data.ota.ChecksumAlgorithm;
|
||||
import org.thingsboard.server.common.data.ota.OtaPackageType;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.OtaPackageId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.ota.ChecksumAlgorithm;
|
||||
import org.thingsboard.server.common.data.ota.OtaPackageType;
|
||||
|
||||
@ApiModel
|
||||
@Slf4j
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ -32,21 +36,33 @@ public class OtaPackageInfo extends SearchTextBasedWithAdditionalInfo<OtaPackage
|
||||
|
||||
private static final long serialVersionUID = 3168391583570815419L;
|
||||
|
||||
@ApiModelProperty(position = 3, value = "JSON object with Tenant Id. Tenant Id of the ota package can't be changed.", readOnly = true)
|
||||
private TenantId tenantId;
|
||||
@ApiModelProperty(position = 4, value = "JSON object with Device Profile Id. Device Profile Id of the ota package can't be changed.", readOnly = true)
|
||||
private DeviceProfileId deviceProfileId;
|
||||
@ApiModelProperty(position = 5, value = "OTA Package type.", example = "FIRMWARE", readOnly = true)
|
||||
private OtaPackageType type;
|
||||
@ApiModelProperty(position = 6, value = "OTA Package title.", example = "fw", readOnly = true)
|
||||
private String title;
|
||||
@ApiModelProperty(position = 7, value = "OTA Package version.", example = "1.0", readOnly = true)
|
||||
private String version;
|
||||
@ApiModelProperty(position = 8, value = "OTA Package tag.", example = "fw_1.0", readOnly = true)
|
||||
private String tag;
|
||||
@ApiModelProperty(position = 9, value = "OTA Package url.", example = "http://thingsboard.org/fw/1", readOnly = true)
|
||||
private String url;
|
||||
@ApiModelProperty(position = 10, value = "Indicates OTA Package 'has data'. Field is returned from DB ('true' if data exists or url is set). If OTA Package 'has data' is 'false' we can not assign the OTA Package to the Device or Device Profile.", example = "true", readOnly = true)
|
||||
private boolean hasData;
|
||||
@ApiModelProperty(position = 11, value = "OTA Package file name.", example = "fw_1.0", readOnly = true)
|
||||
private String fileName;
|
||||
@ApiModelProperty(position = 12, value = "OTA Package content type.", example = "APPLICATION_OCTET_STREAM", readOnly = true)
|
||||
private String contentType;
|
||||
@ApiModelProperty(position = 13, value = "OTA Package checksum algorithm.", example = "CRC32", readOnly = true)
|
||||
private ChecksumAlgorithm checksumAlgorithm;
|
||||
@ApiModelProperty(position = 14, value = "OTA Package checksum.", example = "0xd87f7e0c", readOnly = true)
|
||||
private String checksum;
|
||||
@ApiModelProperty(position = 15, value = "OTA Package data size.", example = "8", readOnly = true)
|
||||
private Long dataSize;
|
||||
|
||||
|
||||
public OtaPackageInfo() {
|
||||
super();
|
||||
}
|
||||
@ -72,6 +88,21 @@ public class OtaPackageInfo extends SearchTextBasedWithAdditionalInfo<OtaPackage
|
||||
this.dataSize = otaPackageInfo.getDataSize();
|
||||
}
|
||||
|
||||
@ApiModelProperty(position = 1, value = "JSON object with the ota package Id. " +
|
||||
"Specify existing ota package Id to update the ota package. " +
|
||||
"Referencing non-existing ota package id will cause error. " +
|
||||
"Omit this field to create new ota package.")
|
||||
@Override
|
||||
public OtaPackageId getId() {
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
@ApiModelProperty(position = 2, value = "Timestamp of the ota package creation, in milliseconds", example = "1609459200000", readOnly = true)
|
||||
@Override
|
||||
public long getCreatedTime() {
|
||||
return super.getCreatedTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSearchText() {
|
||||
return title;
|
||||
@ -87,4 +118,10 @@ public class OtaPackageInfo extends SearchTextBasedWithAdditionalInfo<OtaPackage
|
||||
public boolean hasUrl() {
|
||||
return StringUtils.isNotEmpty(url);
|
||||
}
|
||||
|
||||
@ApiModelProperty(position = 17, value = "OTA Package description.", example = "Description for the OTA Package fw_1.0")
|
||||
@Override
|
||||
public JsonNode getAdditionalInfo() {
|
||||
return super.getAdditionalInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,14 +15,18 @@
|
||||
*/
|
||||
package org.thingsboard.server.common.data;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@ApiModel
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
public class SaveOtaPackageInfoRequest extends OtaPackageInfo {
|
||||
@ApiModelProperty(position = 16, value = "Indicates OTA Package uses url. Should be 'true' if uses url or 'false' if will be used data.", example = "true", readOnly = true)
|
||||
boolean usesUrl;
|
||||
|
||||
public SaveOtaPackageInfoRequest(OtaPackageInfo otaPackageInfo, boolean usesUrl) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user