Commit ec8d1bd3d152b407d6793b6e1284f173cd69c157
Merge branch 'master' into 'master_dev'
Merge branch 'master' into 'master_dev' See merge request yunteng/thingskit!240
Showing
7 changed files
with
35 additions
and
25 deletions
@@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.*; | @@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.*; | ||
20 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 20 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
21 | import org.thingsboard.server.common.data.yunteng.dto.SysLogOperateDTO; | 21 | import org.thingsboard.server.common.data.yunteng.dto.SysLogOperateDTO; |
22 | import org.thingsboard.server.dao.audit.AuditLogService; | 22 | import org.thingsboard.server.dao.audit.AuditLogService; |
23 | +import org.thingsboard.server.dao.exception.DataValidationException; | ||
23 | import org.thingsboard.server.exception.ThingsboardErrorResponseHandler; | 24 | import org.thingsboard.server.exception.ThingsboardErrorResponseHandler; |
24 | import org.thingsboard.server.service.security.model.SecurityUser; | 25 | import org.thingsboard.server.service.security.model.SecurityUser; |
25 | import org.thingsboard.server.utils.yunteng.LogUtils; | 26 | import org.thingsboard.server.utils.yunteng.LogUtils; |
@@ -36,22 +37,27 @@ public class ThingsKitExceptionHandler { | @@ -36,22 +37,27 @@ public class ThingsKitExceptionHandler { | ||
36 | private final AuditLogService auditLogService; | 37 | private final AuditLogService auditLogService; |
37 | private final ThingsboardErrorResponseHandler errorResponseHandler; | 38 | private final ThingsboardErrorResponseHandler errorResponseHandler; |
38 | 39 | ||
39 | - @ExceptionHandler(RuntimeException.class) | 40 | + @ExceptionHandler(MethodArgumentNotValidException.class) |
40 | public void handleMethodArgumentNotValidException( | 41 | public void handleMethodArgumentNotValidException( |
41 | - RuntimeException ex, | ||
42 | - HttpServletRequest request, | ||
43 | - HttpServletResponse response) { | ||
44 | - if(ex instanceof ThingsKitException){ | ||
45 | - errorResponseHandler.handle( | ||
46 | - new ThingsKitException( | ||
47 | - ErrorMessage.INVALID_PARAMETER.setMessage( | ||
48 | - ex.getMessage()), | ||
49 | - HttpStatus.BAD_REQUEST), | ||
50 | - response); | ||
51 | - }else{ | 42 | + MethodArgumentNotValidException ex, |
43 | + HttpServletRequest request, | ||
44 | + HttpServletResponse response) { | ||
45 | + produceLog(request, ex); | ||
46 | + errorResponseHandler.handle( | ||
47 | + new ThingsKitException( | ||
48 | + ErrorMessage.VALIDATE_PARAM_FAILED.setMessage( | ||
49 | + Objects.requireNonNull(ex.getBindingResult().getFieldError()).getDefaultMessage()), | ||
50 | + HttpStatus.BAD_REQUEST), | ||
51 | + response); | ||
52 | + } | ||
53 | + | ||
54 | + @ExceptionHandler(RuntimeException.class) | ||
55 | + public void handleRuntimeException( | ||
56 | + RuntimeException ex, HttpServletRequest request, HttpServletResponse response) { | ||
57 | + if(!(ex instanceof ThingsKitException) && !(ex instanceof DataValidationException)){ | ||
52 | produceLog(request, ex); | 58 | produceLog(request, ex); |
53 | - errorResponseHandler.handle(ex,response); | ||
54 | } | 59 | } |
60 | + errorResponseHandler.handle(ex,response); | ||
55 | } | 61 | } |
56 | 62 | ||
57 | protected SecurityUser getCurrentUser() throws ThingsboardException { | 63 | protected SecurityUser getCurrentUser() throws ThingsboardException { |
@@ -6,7 +6,6 @@ import lombok.RequiredArgsConstructor; | @@ -6,7 +6,6 @@ import lombok.RequiredArgsConstructor; | ||
6 | import org.apache.commons.lang3.StringUtils; | 6 | import org.apache.commons.lang3.StringUtils; |
7 | import org.springframework.http.ResponseEntity; | 7 | import org.springframework.http.ResponseEntity; |
8 | import org.springframework.security.access.prepost.PreAuthorize; | 8 | import org.springframework.security.access.prepost.PreAuthorize; |
9 | -import org.springframework.transaction.annotation.Transactional; | ||
10 | import org.springframework.util.Assert; | 9 | import org.springframework.util.Assert; |
11 | import org.springframework.validation.annotation.Validated; | 10 | import org.springframework.validation.annotation.Validated; |
12 | import org.springframework.web.bind.annotation.*; | 11 | import org.springframework.web.bind.annotation.*; |
@@ -22,7 +21,6 @@ import org.thingsboard.server.common.data.id.UserId; | @@ -22,7 +21,6 @@ import org.thingsboard.server.common.data.id.UserId; | ||
22 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | 21 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
23 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | 22 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
24 | import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | 23 | import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; |
25 | -import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | ||
26 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 24 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
27 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | 25 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
28 | import org.thingsboard.server.common.data.yunteng.dto.MenuDTO; | 26 | import org.thingsboard.server.common.data.yunteng.dto.MenuDTO; |
@@ -162,7 +160,6 @@ public class TkAdminController extends BaseController { | @@ -162,7 +160,6 @@ public class TkAdminController extends BaseController { | ||
162 | } | 160 | } |
163 | 161 | ||
164 | @PostMapping("/tenant/adminUser") | 162 | @PostMapping("/tenant/adminUser") |
165 | - @Transactional | ||
166 | @PreAuthorize( | 163 | @PreAuthorize( |
167 | "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:adminUser:post'})") | 164 | "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:adminUser:post'})") |
168 | public ResponseEntity<UserDTO> createTenantAdmin( | 165 | public ResponseEntity<UserDTO> createTenantAdmin( |
@@ -11,7 +11,6 @@ import org.springframework.validation.annotation.Validated; | @@ -11,7 +11,6 @@ import org.springframework.validation.annotation.Validated; | ||
11 | import org.springframework.web.bind.annotation.*; | 11 | import org.springframework.web.bind.annotation.*; |
12 | import org.thingsboard.server.common.data.*; | 12 | import org.thingsboard.server.common.data.*; |
13 | import org.thingsboard.server.common.data.audit.ActionType; | 13 | import org.thingsboard.server.common.data.audit.ActionType; |
14 | -import org.thingsboard.server.common.data.device.profile.*; | ||
15 | import org.thingsboard.server.common.data.edge.EdgeEventActionType; | 14 | import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
16 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 15 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
17 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 16 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
@@ -20,7 +19,6 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -20,7 +19,6 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
20 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | 19 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
21 | import org.thingsboard.server.common.data.rule.RuleChain; | 20 | import org.thingsboard.server.common.data.rule.RuleChain; |
22 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | 21 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
23 | -import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | ||
24 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | 22 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
25 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 23 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
26 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | 24 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
@@ -38,7 +38,6 @@ import org.thingsboard.server.common.data.yunteng.enums.TkScriptFunctionType; | @@ -38,7 +38,6 @@ import org.thingsboard.server.common.data.yunteng.enums.TkScriptFunctionType; | ||
38 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 38 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
39 | import org.thingsboard.server.common.msg.queue.ServiceQueue; | 39 | import org.thingsboard.server.common.msg.queue.ServiceQueue; |
40 | import org.thingsboard.server.controller.BaseController; | 40 | import org.thingsboard.server.controller.BaseController; |
41 | -import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService; | ||
42 | import org.thingsboard.server.dao.yunteng.service.TkDeviceScriptService; | 41 | import org.thingsboard.server.dao.yunteng.service.TkDeviceScriptService; |
43 | import org.thingsboard.server.transport.tcp.script.TkScriptInvokeService; | 42 | import org.thingsboard.server.transport.tcp.script.TkScriptInvokeService; |
44 | 43 | ||
@@ -60,7 +59,6 @@ public class TkDeviceScriptController extends BaseController { | @@ -60,7 +59,6 @@ public class TkDeviceScriptController extends BaseController { | ||
60 | private static final JsonParser parser = new JsonParser(); | 59 | private static final JsonParser parser = new JsonParser(); |
61 | private static final ObjectMapper objectMapper = new ObjectMapper(); | 60 | private static final ObjectMapper objectMapper = new ObjectMapper(); |
62 | private final TkDeviceScriptService scriptService; | 61 | private final TkDeviceScriptService scriptService; |
63 | - private final TkDeviceProfileService ytDeviceProfileService; | ||
64 | private final TkScriptInvokeService jsEngine; | 62 | private final TkScriptInvokeService jsEngine; |
65 | 63 | ||
66 | @PostMapping() | 64 | @PostMapping() |
@@ -218,10 +216,18 @@ public class TkDeviceScriptController extends BaseController { | @@ -218,10 +216,18 @@ public class TkDeviceScriptController extends BaseController { | ||
218 | throw new TkDataValidationException(String.format(ErrorMessage.NEED_MAIN_PARAMETER.getMessage(),"设备地址码")); | 216 | throw new TkDataValidationException(String.format(ErrorMessage.NEED_MAIN_PARAMETER.getMessage(),"设备地址码")); |
219 | } | 217 | } |
220 | if(StringUtils.isEmpty(inputParams.getMethod()) || null == inputParams.getCrc() || | 218 | if(StringUtils.isEmpty(inputParams.getMethod()) || null == inputParams.getCrc() || |
221 | - null ==inputParams.getRegisterNumber() || null ==inputParams.getRegisterAddress() || | ||
222 | - null ==inputParams.getRegisterValues() || inputParams.getRegisterValues().isEmpty()){ | 219 | + null ==inputParams.getRegisterAddress()){ |
223 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | 220 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
224 | } | 221 | } |
222 | + if(null !=inputParams.getRegisterNumber() && null !=inputParams.getRegisterValues() && | ||
223 | + !inputParams.getRegisterValues().isEmpty()){ | ||
224 | + List<Integer> registerValues = inputParams.getRegisterValues(); | ||
225 | + for (Integer value : registerValues){ | ||
226 | + if(null == value){ | ||
227 | + throw new TkDataValidationException(ErrorMessage.REGISTER_VALUE_IS_NONE.getMessage()); | ||
228 | + } | ||
229 | + } | ||
230 | + } | ||
225 | return ResponseEntity.ok(scriptService.modbus(inputParams)); | 231 | return ResponseEntity.ok(scriptService.modbus(inputParams)); |
226 | } | 232 | } |
227 | 233 |
@@ -7,6 +7,7 @@ public enum ErrorMessage { | @@ -7,6 +7,7 @@ public enum ErrorMessage { | ||
7 | // ERROR STARTS FROM HERE | 7 | // ERROR STARTS FROM HERE |
8 | INTERNAL_ERROR(500000, "网络异常"), | 8 | INTERNAL_ERROR(500000, "网络异常"), |
9 | OPERATION_FAILED(500001, "操作失败"), | 9 | OPERATION_FAILED(500001, "操作失败"), |
10 | + VALIDATE_PARAM_FAILED(440000, "参数验证失败"), | ||
10 | NO_PERMISSION(403001, "没有操作权限"), | 11 | NO_PERMISSION(403001, "没有操作权限"), |
11 | ACCOUNT_DISABLED(403002, "账号已禁用"), | 12 | ACCOUNT_DISABLED(403002, "账号已禁用"), |
12 | ACCESS_DENIED(403003, "拒绝访问"), | 13 | ACCESS_DENIED(403003, "拒绝访问"), |
@@ -109,7 +110,8 @@ public enum ErrorMessage { | @@ -109,7 +110,8 @@ public enum ErrorMessage { | ||
109 | RESET_PASSWORD_SUCCESS(400085,"重置成功,请使用默认密码登录"), | 110 | RESET_PASSWORD_SUCCESS(400085,"重置成功,请使用默认密码登录"), |
110 | HAVE_NO_PERMISSION(500002,"没有修改权限"), | 111 | HAVE_NO_PERMISSION(500002,"没有修改权限"), |
111 | MESSAGE_TEMPLATE_DELETED(400020,"消息模板不存在!"), | 112 | MESSAGE_TEMPLATE_DELETED(400020,"消息模板不存在!"), |
112 | - NEED_MAIN_PARAMETER(400001, "缺少必要参数【%s】"), | 113 | + NEED_MAIN_PARAMETER(400021, "缺少必要参数【%s】"), |
114 | + REGISTER_VALUE_IS_NONE(400022, "寄存器值不能为空"), | ||
113 | NOT_ALLOED_ISOLATED_IN_MONOLITH(500003,"【monolith】模式下,不能选择【isolated】类型的租户配置"), | 115 | NOT_ALLOED_ISOLATED_IN_MONOLITH(500003,"【monolith】模式下,不能选择【isolated】类型的租户配置"), |
114 | MESSAGE_TEMPLATE_USING_CONFIG(500004,"删除消息配置前,需要禁用使用消息配置的消息模板%s。"); | 116 | MESSAGE_TEMPLATE_USING_CONFIG(500004,"删除消息配置前,需要禁用使用消息配置的消息模板%s。"); |
115 | private final int code; | 117 | private final int code; |
@@ -23,9 +23,9 @@ public class TkDeviceRpcDTO implements Serializable { | @@ -23,9 +23,9 @@ public class TkDeviceRpcDTO implements Serializable { | ||
23 | @ApiModelProperty(value = "寄存器地址", required = true) | 23 | @ApiModelProperty(value = "寄存器地址", required = true) |
24 | private Integer registerAddress; | 24 | private Integer registerAddress; |
25 | 25 | ||
26 | - @ApiModelProperty(value = "寄存器数量", required = true) | 26 | + @ApiModelProperty(value = "寄存器数量") |
27 | private Integer registerNumber; | 27 | private Integer registerNumber; |
28 | 28 | ||
29 | - @ApiModelProperty(value = "寄存器值", required = true) | 29 | + @ApiModelProperty(value = "寄存器值") |
30 | private List<Integer> registerValues; | 30 | private List<Integer> registerValues; |
31 | } | 31 | } |