...
|
...
|
@@ -15,6 +15,8 @@ |
15
|
15
|
*/
|
16
|
16
|
package org.thingsboard.server.controller;
|
17
|
17
|
|
|
18
|
+import io.swagger.annotations.ApiOperation;
|
|
19
|
+import io.swagger.annotations.ApiParam;
|
18
|
20
|
import lombok.extern.slf4j.Slf4j;
|
19
|
21
|
import org.apache.commons.lang3.StringUtils;
|
20
|
22
|
import org.springframework.core.io.ByteArrayResource;
|
...
|
...
|
@@ -56,10 +58,12 @@ public class OtaPackageController extends BaseController { |
56
|
58
|
public static final String OTA_PACKAGE_ID = "otaPackageId";
|
57
|
59
|
public static final String CHECKSUM_ALGORITHM = "checksumAlgorithm";
|
58
|
60
|
|
|
61
|
+ @ApiOperation(value = "Download OTA Package (downloadOtaPackage)", notes = "Download OTA Package based on the provided OTA Package Id." + TENANT_AUTHORITY_PARAGRAPH)
|
59
|
62
|
@PreAuthorize("hasAnyAuthority( 'TENANT_ADMIN')")
|
60
|
63
|
@RequestMapping(value = "/otaPackage/{otaPackageId}/download", method = RequestMethod.GET)
|
61
|
64
|
@ResponseBody
|
62
|
|
- public ResponseEntity<org.springframework.core.io.Resource> downloadOtaPackage(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
|
65
|
+ public ResponseEntity<org.springframework.core.io.Resource> downloadOtaPackage(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION)
|
|
66
|
+ @PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
63
|
67
|
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
|
64
|
68
|
try {
|
65
|
69
|
OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId));
|
...
|
...
|
@@ -81,10 +85,15 @@ public class OtaPackageController extends BaseController { |
81
|
85
|
}
|
82
|
86
|
}
|
83
|
87
|
|
|
88
|
+ @ApiOperation(value = "Get OTA Package Info (getOtaPackageInfoById)",
|
|
89
|
+ notes = "Fetch the OTA Package Info object based on the provided OTA Package Id. " +
|
|
90
|
+ OTA_PACKAGE_INFO_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH,
|
|
91
|
+ produces = "application/json")
|
84
|
92
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
85
|
93
|
@RequestMapping(value = "/otaPackage/info/{otaPackageId}", method = RequestMethod.GET)
|
86
|
94
|
@ResponseBody
|
87
|
|
- public OtaPackageInfo getOtaPackageInfoById(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
|
95
|
+ public OtaPackageInfo getOtaPackageInfoById(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION)
|
|
96
|
+ @PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
88
|
97
|
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
|
89
|
98
|
try {
|
90
|
99
|
OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId));
|
...
|
...
|
@@ -94,10 +103,15 @@ public class OtaPackageController extends BaseController { |
94
|
103
|
}
|
95
|
104
|
}
|
96
|
105
|
|
|
106
|
+ @ApiOperation(value = "Get OTA Package (getOtaPackageById)",
|
|
107
|
+ notes = "Fetch the OTA Package object based on the provided OTA Package Id. " +
|
|
108
|
+ "The server checks that the OTA Package is owned by the same tenant. " + OTA_PACKAGE_DESCRIPTION + TENANT_AUTHORITY_PARAGRAPH,
|
|
109
|
+ produces = "application/json")
|
97
|
110
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
98
|
111
|
@RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.GET)
|
99
|
112
|
@ResponseBody
|
100
|
|
- public OtaPackage getOtaPackageById(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
|
113
|
+ public OtaPackage getOtaPackageById(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION)
|
|
114
|
+ @PathVariable(OTA_PACKAGE_ID) String strOtaPackageId) throws ThingsboardException {
|
101
|
115
|
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
|
102
|
116
|
try {
|
103
|
117
|
OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId));
|
...
|
...
|
@@ -107,10 +121,19 @@ public class OtaPackageController extends BaseController { |
107
|
121
|
}
|
108
|
122
|
}
|
109
|
123
|
|
|
124
|
+ @ApiOperation(value = "Create Or Update OTA Package Info (saveOtaPackageInfo)",
|
|
125
|
+ 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). " +
|
|
126
|
+ "The newly created OTA Package id will be present in the response. " +
|
|
127
|
+ "Specify existing OTA Package id to update the OTA Package Info. " +
|
|
128
|
+ "Referencing non-existing OTA Package Id will cause 'Not Found' error. " +
|
|
129
|
+ "\n\nOTA Package combination of the title with the version is unique in the scope of tenant. " + TENANT_AUTHORITY_PARAGRAPH,
|
|
130
|
+ produces = "application/json",
|
|
131
|
+ consumes = "application/json")
|
110
|
132
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
111
|
133
|
@RequestMapping(value = "/otaPackage", method = RequestMethod.POST)
|
112
|
134
|
@ResponseBody
|
113
|
|
- public OtaPackageInfo saveOtaPackageInfo(@RequestBody SaveOtaPackageInfoRequest otaPackageInfo) throws ThingsboardException {
|
|
135
|
+ public OtaPackageInfo saveOtaPackageInfo(@ApiParam(value = "A JSON value representing the OTA Package.")
|
|
136
|
+ @RequestBody SaveOtaPackageInfoRequest otaPackageInfo) throws ThingsboardException {
|
114
|
137
|
boolean created = otaPackageInfo.getId() == null;
|
115
|
138
|
try {
|
116
|
139
|
otaPackageInfo.setTenantId(getTenantId());
|
...
|
...
|
@@ -126,13 +149,20 @@ public class OtaPackageController extends BaseController { |
126
|
149
|
}
|
127
|
150
|
}
|
128
|
151
|
|
|
152
|
+ @ApiOperation(value = "Save OTA Package data (saveOtaPackageData)",
|
|
153
|
+ notes = "Update the OTA Package. Adds the date to the existing OTA Package Info" + TENANT_AUTHORITY_PARAGRAPH,
|
|
154
|
+ produces = "application/json")
|
129
|
155
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
130
|
156
|
@RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.POST)
|
131
|
157
|
@ResponseBody
|
132
|
|
- public OtaPackageInfo saveOtaPackageData(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId,
|
133
|
|
- @RequestParam(required = false) String checksum,
|
134
|
|
- @RequestParam(CHECKSUM_ALGORITHM) String checksumAlgorithmStr,
|
135
|
|
- @RequestBody MultipartFile file) throws ThingsboardException {
|
|
158
|
+ public OtaPackageInfo saveOtaPackageData(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION)
|
|
159
|
+ @PathVariable(OTA_PACKAGE_ID) String strOtaPackageId,
|
|
160
|
+ @ApiParam(value = "OTA Package checksum. For example, '0xd87f7e0c'")
|
|
161
|
+ @RequestParam(required = false) String checksum,
|
|
162
|
+ @ApiParam(value = "OTA Package checksum algorithm.", allowableValues = OTA_PACKAGE_CHECKSUM_ALGORITHM_ALLOWABLE_VALUES)
|
|
163
|
+ @RequestParam(CHECKSUM_ALGORITHM) String checksumAlgorithmStr,
|
|
164
|
+ @ApiParam(value = "OTA Package data.")
|
|
165
|
+ @RequestBody MultipartFile file) throws ThingsboardException {
|
136
|
166
|
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
|
137
|
167
|
checkParameter(CHECKSUM_ALGORITHM, checksumAlgorithmStr);
|
138
|
168
|
try {
|
...
|
...
|
@@ -171,14 +201,23 @@ public class OtaPackageController extends BaseController { |
171
|
201
|
}
|
172
|
202
|
}
|
173
|
203
|
|
|
204
|
+ @ApiOperation(value = "Get OTA Package Infos (getOtaPackages)",
|
|
205
|
+ notes = "Returns a page of OTA Package Info objects owned by tenant. " +
|
|
206
|
+ PAGE_DATA_PARAMETERS + OTA_PACKAGE_INFO_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH,
|
|
207
|
+ produces = "application/json")
|
174
|
208
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
175
|
209
|
@RequestMapping(value = "/otaPackages", method = RequestMethod.GET)
|
176
|
210
|
@ResponseBody
|
177
|
|
- public PageData<OtaPackageInfo> getOtaPackages(@RequestParam int pageSize,
|
178
|
|
- @RequestParam int page,
|
179
|
|
- @RequestParam(required = false) String textSearch,
|
180
|
|
- @RequestParam(required = false) String sortProperty,
|
181
|
|
- @RequestParam(required = false) String sortOrder) throws ThingsboardException {
|
|
211
|
+ public PageData<OtaPackageInfo> getOtaPackages(@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
|
|
212
|
+ @RequestParam int pageSize,
|
|
213
|
+ @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
|
|
214
|
+ @RequestParam int page,
|
|
215
|
+ @ApiParam(value = OTA_PACKAGE_TEXT_SEARCH_DESCRIPTION)
|
|
216
|
+ @RequestParam(required = false) String textSearch,
|
|
217
|
+ @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = OTA_PACKAGE_SORT_PROPERTY_ALLOWABLE_VALUES)
|
|
218
|
+ @RequestParam(required = false) String sortProperty,
|
|
219
|
+ @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
|
220
|
+ @RequestParam(required = false) String sortOrder) throws ThingsboardException {
|
182
|
221
|
try {
|
183
|
222
|
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
184
|
223
|
return checkNotNull(otaPackageService.findTenantOtaPackagesByTenantId(getTenantId(), pageLink));
|
...
|
...
|
@@ -187,15 +226,26 @@ public class OtaPackageController extends BaseController { |
187
|
226
|
}
|
188
|
227
|
}
|
189
|
228
|
|
|
229
|
+ @ApiOperation(value = "Get OTA Package Infos (getOtaPackages)",
|
|
230
|
+ notes = "Returns a page of OTA Package Info objects owned by tenant. " +
|
|
231
|
+ PAGE_DATA_PARAMETERS + OTA_PACKAGE_INFO_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH,
|
|
232
|
+ produces = "application/json")
|
190
|
233
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
191
|
234
|
@RequestMapping(value = "/otaPackages/{deviceProfileId}/{type}", method = RequestMethod.GET)
|
192
|
235
|
@ResponseBody
|
193
|
|
- public PageData<OtaPackageInfo> getOtaPackages(@PathVariable("deviceProfileId") String strDeviceProfileId,
|
|
236
|
+ public PageData<OtaPackageInfo> getOtaPackages(@ApiParam(value = DEVICE_PROFILE_ID_PARAM_DESCRIPTION)
|
|
237
|
+ @PathVariable("deviceProfileId") String strDeviceProfileId,
|
|
238
|
+ @ApiParam(value = "OTA Package type.", allowableValues = "FIRMWARE, SOFTWARE")
|
194
|
239
|
@PathVariable("type") String strType,
|
|
240
|
+ @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
|
195
|
241
|
@RequestParam int pageSize,
|
|
242
|
+ @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
|
196
|
243
|
@RequestParam int page,
|
|
244
|
+ @ApiParam(value = OTA_PACKAGE_TEXT_SEARCH_DESCRIPTION)
|
197
|
245
|
@RequestParam(required = false) String textSearch,
|
|
246
|
+ @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = OTA_PACKAGE_SORT_PROPERTY_ALLOWABLE_VALUES)
|
198
|
247
|
@RequestParam(required = false) String sortProperty,
|
|
248
|
+ @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
199
|
249
|
@RequestParam(required = false) String sortOrder) throws ThingsboardException {
|
200
|
250
|
checkParameter("deviceProfileId", strDeviceProfileId);
|
201
|
251
|
checkParameter("type", strType);
|
...
|
...
|
@@ -208,10 +258,15 @@ public class OtaPackageController extends BaseController { |
208
|
258
|
}
|
209
|
259
|
}
|
210
|
260
|
|
|
261
|
+ @ApiOperation(value = "Delete OTA Package (deleteOtaPackage)",
|
|
262
|
+ notes = "Deletes the OTA Package. Referencing non-existing OTA Package Id will cause an error. " +
|
|
263
|
+ "Can't delete the OTA Package if it is referenced by existing devices or device profile." + TENANT_AUTHORITY_PARAGRAPH,
|
|
264
|
+ produces = "application/json")
|
211
|
265
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
212
|
266
|
@RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.DELETE)
|
213
|
267
|
@ResponseBody
|
214
|
|
- public void deleteOtaPackage(@PathVariable("otaPackageId") String strOtaPackageId) throws ThingsboardException {
|
|
268
|
+ public void deleteOtaPackage(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION)
|
|
269
|
+ @PathVariable("otaPackageId") String strOtaPackageId) throws ThingsboardException {
|
215
|
270
|
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
|
216
|
271
|
try {
|
217
|
272
|
OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId));
|
...
|
...
|
|