Commit b158528c2a6d56f1617f7c83460e33841aa53cd4
1 parent
6d0e6b35
Wrapper for OtaPackageInfo with usesUrl boolean field
Showing
3 changed files
with
73 additions
and
23 deletions
... | ... | @@ -32,6 +32,7 @@ import org.springframework.web.multipart.MultipartFile; |
32 | 32 | import org.thingsboard.server.common.data.EntityType; |
33 | 33 | import org.thingsboard.server.common.data.OtaPackage; |
34 | 34 | import org.thingsboard.server.common.data.OtaPackageInfo; |
35 | +import org.thingsboard.server.common.data.SaveOtaPackageInfoRequest; | |
35 | 36 | import org.thingsboard.server.common.data.audit.ActionType; |
36 | 37 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
37 | 38 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
... | ... | @@ -109,12 +110,12 @@ public class OtaPackageController extends BaseController { |
109 | 110 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") |
110 | 111 | @RequestMapping(value = "/otaPackage", method = RequestMethod.POST) |
111 | 112 | @ResponseBody |
112 | - public OtaPackageInfo saveOtaPackageInfo(@RequestBody OtaPackageInfo otaPackageInfo, @RequestParam boolean isUrl) throws ThingsboardException { | |
113 | + public OtaPackageInfo saveOtaPackageInfo(@RequestBody SaveOtaPackageInfoRequest otaPackageInfo) throws ThingsboardException { | |
113 | 114 | boolean created = otaPackageInfo.getId() == null; |
114 | 115 | try { |
115 | 116 | otaPackageInfo.setTenantId(getTenantId()); |
116 | 117 | checkEntity(otaPackageInfo.getId(), otaPackageInfo, Resource.OTA_PACKAGE); |
117 | - OtaPackageInfo savedOtaPackageInfo = otaPackageService.saveOtaPackageInfo(otaPackageInfo, isUrl); | |
118 | + OtaPackageInfo savedOtaPackageInfo = otaPackageService.saveOtaPackageInfo(new OtaPackageInfo(otaPackageInfo), otaPackageInfo.isUsesUrl()); | |
118 | 119 | logEntityAction(savedOtaPackageInfo.getId(), savedOtaPackageInfo, |
119 | 120 | null, created ? ActionType.ADDED : ActionType.UPDATED, null); |
120 | 121 | return savedOtaPackageInfo; | ... | ... |
... | ... | @@ -27,6 +27,7 @@ import org.thingsboard.common.util.JacksonUtil; |
27 | 27 | import org.thingsboard.server.common.data.DeviceProfile; |
28 | 28 | import org.thingsboard.server.common.data.OtaPackage; |
29 | 29 | import org.thingsboard.server.common.data.OtaPackageInfo; |
30 | +import org.thingsboard.server.common.data.SaveOtaPackageInfoRequest; | |
30 | 31 | import org.thingsboard.server.common.data.Tenant; |
31 | 32 | import org.thingsboard.server.common.data.User; |
32 | 33 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
... | ... | @@ -92,13 +93,14 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes |
92 | 93 | |
93 | 94 | @Test |
94 | 95 | public void testSaveFirmware() throws Exception { |
95 | - OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
96 | + SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest(); | |
96 | 97 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
97 | 98 | firmwareInfo.setType(FIRMWARE); |
98 | 99 | firmwareInfo.setTitle(TITLE); |
99 | 100 | firmwareInfo.setVersion(VERSION); |
101 | + firmwareInfo.setUsesUrl(false); | |
100 | 102 | |
101 | - OtaPackageInfo savedFirmwareInfo = save(firmwareInfo, false); | |
103 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
102 | 104 | |
103 | 105 | Assert.assertNotNull(savedFirmwareInfo); |
104 | 106 | Assert.assertNotNull(savedFirmwareInfo.getId()); |
... | ... | @@ -109,7 +111,7 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes |
109 | 111 | |
110 | 112 | savedFirmwareInfo.setAdditionalInfo(JacksonUtil.newObjectNode()); |
111 | 113 | |
112 | - save(savedFirmwareInfo, false); | |
114 | + save(new SaveOtaPackageInfoRequest(savedFirmwareInfo, false)); | |
113 | 115 | |
114 | 116 | OtaPackageInfo foundFirmwareInfo = doGet("/api/otaPackage/info/" + savedFirmwareInfo.getId().getId().toString(), OtaPackageInfo.class); |
115 | 117 | Assert.assertEquals(foundFirmwareInfo.getTitle(), savedFirmwareInfo.getTitle()); |
... | ... | @@ -117,13 +119,14 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes |
117 | 119 | |
118 | 120 | @Test |
119 | 121 | public void testSaveFirmwareData() throws Exception { |
120 | - OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
122 | + SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest(); | |
121 | 123 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
122 | 124 | firmwareInfo.setType(FIRMWARE); |
123 | 125 | firmwareInfo.setTitle(TITLE); |
124 | 126 | firmwareInfo.setVersion(VERSION); |
127 | + firmwareInfo.setUsesUrl(false); | |
125 | 128 | |
126 | - OtaPackageInfo savedFirmwareInfo = save(firmwareInfo, false); | |
129 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
127 | 130 | |
128 | 131 | Assert.assertNotNull(savedFirmwareInfo); |
129 | 132 | Assert.assertNotNull(savedFirmwareInfo.getId()); |
... | ... | @@ -134,7 +137,7 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes |
134 | 137 | |
135 | 138 | savedFirmwareInfo.setAdditionalInfo(JacksonUtil.newObjectNode()); |
136 | 139 | |
137 | - save(savedFirmwareInfo, false); | |
140 | + save(new SaveOtaPackageInfoRequest(savedFirmwareInfo, false)); | |
138 | 141 | |
139 | 142 | OtaPackageInfo foundFirmwareInfo = doGet("/api/otaPackage/info/" + savedFirmwareInfo.getId().getId().toString(), OtaPackageInfo.class); |
140 | 143 | Assert.assertEquals(foundFirmwareInfo.getTitle(), savedFirmwareInfo.getTitle()); |
... | ... | @@ -151,28 +154,33 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes |
151 | 154 | |
152 | 155 | @Test |
153 | 156 | public void testUpdateFirmwareFromDifferentTenant() throws Exception { |
154 | - OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
157 | + SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest(); | |
155 | 158 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
156 | 159 | firmwareInfo.setType(FIRMWARE); |
157 | 160 | firmwareInfo.setTitle(TITLE); |
158 | 161 | firmwareInfo.setVersion(VERSION); |
162 | + firmwareInfo.setUsesUrl(false); | |
159 | 163 | |
160 | - OtaPackageInfo savedFirmwareInfo = save(firmwareInfo, false); | |
164 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
161 | 165 | |
162 | 166 | loginDifferentTenant(); |
163 | - doPost("/api/otaPackage?isUrl=false", savedFirmwareInfo, OtaPackageInfo.class, status().isForbidden()); | |
167 | + doPost("/api/otaPackage", | |
168 | + new SaveOtaPackageInfoRequest(savedFirmwareInfo, false), | |
169 | + OtaPackageInfo.class, | |
170 | + status().isForbidden()); | |
164 | 171 | deleteDifferentTenant(); |
165 | 172 | } |
166 | 173 | |
167 | 174 | @Test |
168 | 175 | public void testFindFirmwareInfoById() throws Exception { |
169 | - OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
176 | + SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest(); | |
170 | 177 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
171 | 178 | firmwareInfo.setType(FIRMWARE); |
172 | 179 | firmwareInfo.setTitle(TITLE); |
173 | 180 | firmwareInfo.setVersion(VERSION); |
181 | + firmwareInfo.setUsesUrl(false); | |
174 | 182 | |
175 | - OtaPackageInfo savedFirmwareInfo = save(firmwareInfo, false); | |
183 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
176 | 184 | |
177 | 185 | OtaPackageInfo foundFirmware = doGet("/api/otaPackage/info/" + savedFirmwareInfo.getId().getId().toString(), OtaPackageInfo.class); |
178 | 186 | Assert.assertNotNull(foundFirmware); |
... | ... | @@ -181,13 +189,14 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes |
181 | 189 | |
182 | 190 | @Test |
183 | 191 | public void testFindFirmwareById() throws Exception { |
184 | - OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
192 | + SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest(); | |
185 | 193 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
186 | 194 | firmwareInfo.setType(FIRMWARE); |
187 | 195 | firmwareInfo.setTitle(TITLE); |
188 | 196 | firmwareInfo.setVersion(VERSION); |
197 | + firmwareInfo.setUsesUrl(false); | |
189 | 198 | |
190 | - OtaPackageInfo savedFirmwareInfo = save(firmwareInfo, false); | |
199 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
191 | 200 | |
192 | 201 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); |
193 | 202 | |
... | ... | @@ -201,13 +210,14 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes |
201 | 210 | |
202 | 211 | @Test |
203 | 212 | public void testDeleteFirmware() throws Exception { |
204 | - OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
213 | + SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest(); | |
205 | 214 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
206 | 215 | firmwareInfo.setType(FIRMWARE); |
207 | 216 | firmwareInfo.setTitle(TITLE); |
208 | 217 | firmwareInfo.setVersion(VERSION); |
218 | + firmwareInfo.setUsesUrl(false); | |
209 | 219 | |
210 | - OtaPackageInfo savedFirmwareInfo = save(firmwareInfo, false); | |
220 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
211 | 221 | |
212 | 222 | doDelete("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString()) |
213 | 223 | .andExpect(status().isOk()); |
... | ... | @@ -220,13 +230,14 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes |
220 | 230 | public void testFindTenantFirmwares() throws Exception { |
221 | 231 | List<OtaPackageInfo> otaPackages = new ArrayList<>(); |
222 | 232 | for (int i = 0; i < 165; i++) { |
223 | - OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
233 | + SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest(); | |
224 | 234 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
225 | 235 | firmwareInfo.setType(FIRMWARE); |
226 | 236 | firmwareInfo.setTitle(TITLE); |
227 | 237 | firmwareInfo.setVersion(VERSION + i); |
238 | + firmwareInfo.setUsesUrl(false); | |
228 | 239 | |
229 | - OtaPackageInfo savedFirmwareInfo = save(firmwareInfo, false); | |
240 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
230 | 241 | |
231 | 242 | if (i > 100) { |
232 | 243 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); |
... | ... | @@ -263,13 +274,14 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes |
263 | 274 | List<OtaPackageInfo> allOtaPackages = new ArrayList<>(); |
264 | 275 | |
265 | 276 | for (int i = 0; i < 165; i++) { |
266 | - OtaPackageInfo firmwareInfo = new OtaPackageInfo(); | |
277 | + SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest(); | |
267 | 278 | firmwareInfo.setDeviceProfileId(deviceProfileId); |
268 | 279 | firmwareInfo.setType(FIRMWARE); |
269 | 280 | firmwareInfo.setTitle(TITLE); |
270 | 281 | firmwareInfo.setVersion(VERSION + i); |
282 | + firmwareInfo.setUsesUrl(false); | |
271 | 283 | |
272 | - OtaPackageInfo savedFirmwareInfo = save(firmwareInfo, false); | |
284 | + OtaPackageInfo savedFirmwareInfo = save(firmwareInfo); | |
273 | 285 | |
274 | 286 | if (i > 100) { |
275 | 287 | MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array()); |
... | ... | @@ -316,8 +328,8 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes |
316 | 328 | Assert.assertEquals(allOtaPackages, allLoadedOtaPackages); |
317 | 329 | } |
318 | 330 | |
319 | - private OtaPackageInfo save(OtaPackageInfo firmwareInfo, boolean isUrl) throws Exception { | |
320 | - return doPost("/api/otaPackage?isUrl=" + isUrl, firmwareInfo, OtaPackageInfo.class); | |
331 | + private OtaPackageInfo save(SaveOtaPackageInfoRequest firmwareInfo) throws Exception { | |
332 | + return doPost("/api/otaPackage", firmwareInfo, OtaPackageInfo.class); | |
321 | 333 | } |
322 | 334 | |
323 | 335 | protected OtaPackageInfo savaData(String urlTemplate, MockMultipartFile content, String... params) throws Exception { | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/SaveOtaPackageInfoRequest.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2021 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.common.data; | |
17 | + | |
18 | +import lombok.Data; | |
19 | +import lombok.EqualsAndHashCode; | |
20 | +import lombok.NoArgsConstructor; | |
21 | + | |
22 | +@Data | |
23 | +@EqualsAndHashCode(callSuper = true) | |
24 | +@NoArgsConstructor | |
25 | +public class SaveOtaPackageInfoRequest extends OtaPackageInfo{ | |
26 | + boolean usesUrl; | |
27 | + | |
28 | + public SaveOtaPackageInfoRequest(OtaPackageInfo otaPackageInfo, boolean usesUrl) { | |
29 | + super(otaPackageInfo); | |
30 | + this.usesUrl = usesUrl; | |
31 | + } | |
32 | + | |
33 | + public SaveOtaPackageInfoRequest(SaveOtaPackageInfoRequest saveOtaPackageInfoRequest) { | |
34 | + super(saveOtaPackageInfoRequest); | |
35 | + this.usesUrl = saveOtaPackageInfoRequest.isUsesUrl(); | |
36 | + } | |
37 | +} | ... | ... |