Showing
34 changed files
with
333 additions
and
153 deletions
application/src/main/java/org/thingsboard/server/config/yunteng/ControllerExceptionHandler.java
0 → 100644
1 | +package org.thingsboard.server.config.yunteng; | |
2 | +import lombok.RequiredArgsConstructor; | |
3 | +import org.springframework.http.HttpStatus; | |
4 | +import org.springframework.security.access.AccessDeniedException; | |
5 | +import org.springframework.web.bind.MethodArgumentNotValidException; | |
6 | +import org.springframework.web.bind.annotation.ControllerAdvice; | |
7 | +import org.springframework.web.bind.annotation.ExceptionHandler; | |
8 | +import org.thingsboard.server.common.data.yunteng.core.exception.NoneTenantAssetException; | |
9 | +import org.thingsboard.server.common.data.yunteng.core.exception.TooManyRequestException; | |
10 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.YunTengException; | |
12 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
13 | +import org.thingsboard.server.exception.yunteng.YunTengErrorResponseHandler; | |
14 | + | |
15 | +import javax.servlet.http.HttpServletRequest; | |
16 | +import javax.servlet.http.HttpServletResponse; | |
17 | +import java.util.Objects; | |
18 | +@ControllerAdvice(basePackages = "org.thingsboard.server.controller.yunteng") | |
19 | +@RequiredArgsConstructor | |
20 | +public class ControllerExceptionHandler { | |
21 | + | |
22 | + private final YunTengErrorResponseHandler errorResponseHandler; | |
23 | + | |
24 | + @ExceptionHandler(YunTengException.class) | |
25 | + public void handleYunTengException(YunTengException ex, HttpServletResponse response) { | |
26 | + response.setCharacterEncoding("utf-8"); | |
27 | + errorResponseHandler.handle(ex, response); | |
28 | + } | |
29 | + | |
30 | + @ExceptionHandler(MethodArgumentNotValidException.class) | |
31 | + public void handleMethodArgumentNotValidException( | |
32 | + MethodArgumentNotValidException ex, HttpServletResponse response) { | |
33 | + response.setCharacterEncoding("utf-8"); | |
34 | + errorResponseHandler.handle( | |
35 | + new YunTengException( | |
36 | + ErrorMessage.INVALID_PARAMETER.setMessage( | |
37 | + Objects.requireNonNull(ex.getBindingResult().getFieldError()).getDefaultMessage()), | |
38 | + HttpStatus.BAD_REQUEST), | |
39 | + response); | |
40 | + } | |
41 | + | |
42 | + @ExceptionHandler(YtDataValidationException.class) | |
43 | + public void handleDataValidationException( | |
44 | + YtDataValidationException ex, HttpServletRequest request, HttpServletResponse response) { | |
45 | + response.setCharacterEncoding("utf-8"); | |
46 | + YunTengException YunTengException = | |
47 | + new YunTengException( | |
48 | + ErrorMessage.BAD_PARAMETER.setMessage(ex.getMessage()), HttpStatus.BAD_REQUEST); | |
49 | + errorResponseHandler.handle(YunTengException, response); | |
50 | + } | |
51 | + | |
52 | + @ExceptionHandler(TooManyRequestException.class) | |
53 | + public void handleTooManyRequestException(HttpServletResponse response) { | |
54 | + response.setCharacterEncoding("utf-8"); | |
55 | + errorResponseHandler.handle( | |
56 | + new YunTengException(ErrorMessage.TOO_MANY_REQUEST, HttpStatus.TOO_MANY_REQUESTS), | |
57 | + response); | |
58 | + } | |
59 | + | |
60 | + @ExceptionHandler(AccessDeniedException.class) | |
61 | + public void handleAccessDeniedException(AccessDeniedException ex, HttpServletResponse response) { | |
62 | + response.setCharacterEncoding("utf-8"); | |
63 | + errorResponseHandler.handle( | |
64 | + new YunTengException( | |
65 | + ErrorMessage.ACCESS_DENIED.setMessage(ex.getMessage()), HttpStatus.FORBIDDEN), | |
66 | + response); | |
67 | + } | |
68 | + | |
69 | + @ExceptionHandler(NoneTenantAssetException.class) | |
70 | + public void handleNoneTenantAssetException( | |
71 | + NoneTenantAssetException ex, HttpServletResponse response) { | |
72 | + response.setCharacterEncoding("utf-8"); | |
73 | + errorResponseHandler.handle( | |
74 | + new YunTengException( | |
75 | + ErrorMessage.NONE_TENANT_ASSET.setMessage(ex.getMessage()), HttpStatus.NOT_FOUND), | |
76 | + response); | |
77 | + } | |
78 | +} | ... | ... |
... | ... | @@ -289,6 +289,7 @@ public abstract class BaseController { |
289 | 289 | |
290 | 290 | @ExceptionHandler(ThingsboardException.class) |
291 | 291 | public void handleThingsboardException(ThingsboardException ex, HttpServletResponse response) { |
292 | + response.setCharacterEncoding("utf-8"); | |
292 | 293 | errorResponseHandler.handle(ex, response); |
293 | 294 | } |
294 | 295 | ... | ... |
... | ... | @@ -7,9 +7,11 @@ import org.springframework.util.Assert; |
7 | 7 | import org.springframework.validation.annotation.Validated; |
8 | 8 | import org.springframework.web.bind.annotation.*; |
9 | 9 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
10 | +import org.thingsboard.server.common.data.Tenant; | |
10 | 11 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
12 | +import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | |
11 | 13 | import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; |
12 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
14 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
13 | 15 | import org.thingsboard.server.common.data.yunteng.dto.MenuDTO; |
14 | 16 | import org.thingsboard.server.common.data.yunteng.dto.TenantDTO; |
15 | 17 | import org.thingsboard.server.common.data.yunteng.dto.UserDTO; |
... | ... | @@ -17,10 +19,13 @@ import org.thingsboard.server.common.data.yunteng.dto.request.TenantReqDTO; |
17 | 19 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
18 | 20 | import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; |
19 | 21 | import org.thingsboard.server.controller.BaseController; |
22 | +import org.thingsboard.server.dao.tenant.TenantService; | |
20 | 23 | import org.thingsboard.server.dao.yunteng.service.MenuService; |
21 | 24 | import org.thingsboard.server.dao.yunteng.service.YtTenantService; |
22 | 25 | import org.thingsboard.server.dao.yunteng.service.YtUserService; |
26 | +import org.thingsboard.server.service.install.InstallScripts; | |
23 | 27 | |
28 | +import java.io.IOException; | |
24 | 29 | import java.net.URI; |
25 | 30 | import java.util.*; |
26 | 31 | |
... | ... | @@ -29,12 +34,14 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. |
29 | 34 | @RestController |
30 | 35 | @RequestMapping("api/yt/admin") |
31 | 36 | @RequiredArgsConstructor |
32 | -//@PreAuthorize("hasAnyRole('SYS_ADMIN','PLATFORM_ADMIN')") | |
37 | +@PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") | |
33 | 38 | public class YtAdminController extends BaseController { |
34 | 39 | |
35 | 40 | private final YtTenantService ytTenantService; |
36 | 41 | private final MenuService menuService; |
37 | 42 | private final YtUserService userService; |
43 | + private final TenantService tenantService; | |
44 | + private final InstallScripts installScripts; | |
38 | 45 | |
39 | 46 | @PostMapping("/tenant") |
40 | 47 | public ResponseEntity<TenantDTO> saveTenant(@RequestBody TenantReqDTO tenantReqDTO) { |
... | ... | @@ -84,7 +91,7 @@ public class YtAdminController extends BaseController { |
84 | 91 | public void deleteTenant(@RequestBody String[] ids) { |
85 | 92 | Assert.notNull(ids, "ids cannot be null"); |
86 | 93 | if (ids.length == 0) { |
87 | - throw new DataValidationException("id cannot be empty"); | |
94 | + throw new YtDataValidationException("id cannot be empty"); | |
88 | 95 | } |
89 | 96 | ytTenantService.deleteTenants(ids); |
90 | 97 | } |
... | ... | @@ -147,7 +154,21 @@ public class YtAdminController extends BaseController { |
147 | 154 | |
148 | 155 | @PostMapping("tenant/updateOrCreateTenant") |
149 | 156 | public TenantDTO updateOrCreateTenant( |
150 | - @Validated(UpdateGroup.class) @RequestBody TenantReqDTO tenantReqDTO) { | |
157 | + @Validated(UpdateGroup.class) @RequestBody TenantReqDTO tenantReqDTO) throws IOException { | |
158 | + boolean newTenant = tenantReqDTO.getId() == null; | |
159 | + //增加TB的租户创建 | |
160 | + Tenant tbTenant = new Tenant(); | |
161 | + tbTenant.setTitle(tenantReqDTO.getName()); | |
162 | + tbTenant = tenantService.saveTenant(tbTenant); | |
163 | + if(newTenant){ | |
164 | + installScripts.createDefaultRuleChains(tbTenant.getId()); | |
165 | + installScripts.createDefaultEdgeRuleChains(tbTenant.getId()); | |
166 | + } | |
167 | + tenantProfileCache.evict(tbTenant.getId()); | |
168 | + tbClusterService.onTenantChange(tbTenant, null); | |
169 | + tbClusterService.broadcastEntityStateChangeEvent(tbTenant.getId(), tbTenant.getId(), | |
170 | + newTenant ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | |
171 | + tenantReqDTO.setTenantId(tbTenant.getTenantId().toString()); | |
151 | 172 | return ytTenantService.updateOrCreateTenant(tenantReqDTO); |
152 | 173 | } |
153 | 174 | } | ... | ... |
... | ... | @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*; |
10 | 10 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
11 | 11 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
13 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
13 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
14 | 14 | import org.thingsboard.server.common.data.yunteng.dto.AlarmContactDTO; |
15 | 15 | import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; |
16 | 16 | import org.thingsboard.server.controller.BaseController; |
... | ... | @@ -82,7 +82,7 @@ public class YtAlarmContactController extends BaseController { |
82 | 82 | @DeleteMapping |
83 | 83 | public void deleteById(@RequestBody String[] ids) { |
84 | 84 | if (ids.length == 0) { |
85 | - throw new DataValidationException("please provide alarm ids to delete"); | |
85 | + throw new YtDataValidationException("please provide alarm ids to delete"); | |
86 | 86 | } |
87 | 87 | alarmService.delete(ids); |
88 | 88 | } | ... | ... |
... | ... | @@ -10,7 +10,6 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
10 | 10 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
13 | -import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
14 | 13 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
15 | 14 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
16 | 15 | import org.thingsboard.server.common.data.yunteng.enums.DeviceState; |
... | ... | @@ -34,7 +33,7 @@ public class YtDeviceController extends BaseController { |
34 | 33 | |
35 | 34 | @PostMapping |
36 | 35 | public ResponseEntity<DeviceDTO> saveDevice(@Validated(AddGroup.class)@RequestBody DeviceDTO deviceDTO) |
37 | - throws FastIotException, ThingsboardException { | |
36 | + throws ThingsboardException { | |
38 | 37 | DeviceDTO newDeviceDTO = deviceService.insertOrUpdate(getCurrentUser().getCurrentTenantId(), deviceDTO); |
39 | 38 | return Optional.ofNullable(newDeviceDTO) |
40 | 39 | .map( | ... | ... |
... | ... | @@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.*; |
9 | 9 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
10 | 10 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
12 | -import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
13 | 12 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
14 | 13 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
15 | 14 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
... | ... | @@ -33,7 +32,7 @@ public class YtDeviceProfileController extends BaseController { |
33 | 32 | @PostMapping |
34 | 33 | @PreAuthorize("hasRole('ROLE_TENANT_ADMIN')") |
35 | 34 | public ResponseEntity<DeviceProfileDTO> saveDeviceProfile( |
36 | - @RequestBody DeviceProfileDTO deviceProfileDTO) throws FastIotException, ThingsboardException { | |
35 | + @RequestBody DeviceProfileDTO deviceProfileDTO) throws ThingsboardException { | |
37 | 36 | DeviceProfileDTO newDeviceProfileDTO = deviceProfileService.insertOrUpdate(getCurrentUser().getCurrentTenantId(), deviceProfileDTO); |
38 | 37 | return Optional.ofNullable(newDeviceProfileDTO) |
39 | 38 | .map( | ... | ... |
... | ... | @@ -8,8 +8,7 @@ import org.springframework.util.Assert; |
8 | 8 | import org.springframework.web.bind.annotation.*; |
9 | 9 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
10 | 10 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
12 | -import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
13 | 12 | import org.thingsboard.server.common.data.yunteng.dto.MenuDTO; |
14 | 13 | import org.thingsboard.server.controller.BaseController; |
15 | 14 | import org.thingsboard.server.dao.yunteng.service.MenuService; |
... | ... | @@ -62,7 +61,7 @@ public class YtMenuController extends BaseController { |
62 | 61 | @PostMapping |
63 | 62 | @PreAuthorize("hasAnyRole('SYS_ADMIN','TENANT_ADMIN')") |
64 | 63 | public ResponseEntity<MenuDTO> saveMenu(@RequestBody MenuDTO menuDTO) |
65 | - throws FastIotException, ThingsboardException { | |
64 | + throws ThingsboardException { | |
66 | 65 | MenuDTO newMenuDTO = |
67 | 66 | menuService.saveMenu( |
68 | 67 | getCurrentUser().getCurrentTenantId(), getCurrentUser().isPtSysadmin(), menuDTO); |
... | ... | @@ -83,7 +82,7 @@ public class YtMenuController extends BaseController { |
83 | 82 | @PreAuthorize("hasAnyRole('SYS_ADMIN','TENANT_ADMIN')") |
84 | 83 | public void deleteMenus(@RequestBody String[] ids) throws ThingsboardException { |
85 | 84 | if (ids.length == 0) { |
86 | - throw new DataValidationException("please provide menu ids to delete"); | |
85 | + throw new YtDataValidationException("please provide menu ids to delete"); | |
87 | 86 | } |
88 | 87 | menuService.deleteMenus(getCurrentUser().getCurrentTenantId(), ids); |
89 | 88 | } | ... | ... |
... | ... | @@ -8,7 +8,6 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
8 | 8 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
9 | 9 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; |
11 | -import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
12 | 11 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
13 | 12 | import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; |
14 | 13 | import org.thingsboard.server.controller.BaseController; |
... | ... | @@ -27,7 +26,7 @@ public class YtOrganizationController extends BaseController { |
27 | 26 | |
28 | 27 | @PostMapping |
29 | 28 | public ResponseEntity<OrganizationDTO> saveGroup(@RequestBody OrganizationDTO groupDTO) |
30 | - throws FastIotException, ThingsboardException { | |
29 | + throws ThingsboardException { | |
31 | 30 | OrganizationDTO newGroupDTO = |
32 | 31 | organizationService.saveOrganization(groupDTO, getCurrentUser().getCurrentTenantId()); |
33 | 32 | return Optional.ofNullable(newGroupDTO) | ... | ... |
... | ... | @@ -8,13 +8,17 @@ import lombok.RequiredArgsConstructor; |
8 | 8 | import org.apache.commons.lang3.StringUtils; |
9 | 9 | import org.springframework.http.ResponseEntity; |
10 | 10 | import org.springframework.security.access.prepost.PreAuthorize; |
11 | -import org.springframework.util.Assert; | |
12 | 11 | import org.springframework.validation.annotation.Validated; |
13 | 12 | import org.springframework.web.bind.annotation.*; |
14 | 13 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
14 | +import org.thingsboard.server.common.data.User; | |
15 | +import org.thingsboard.server.common.data.audit.ActionType; | |
16 | +import org.thingsboard.server.common.data.edge.EdgeEventActionType; | |
15 | 17 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
18 | +import org.thingsboard.server.common.data.id.TenantId; | |
16 | 19 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
17 | 20 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
21 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
18 | 22 | import org.thingsboard.server.common.data.yunteng.utils.Demo; |
19 | 23 | import org.thingsboard.server.common.data.yunteng.utils.ExcelUtil; |
20 | 24 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
... | ... | @@ -27,6 +31,7 @@ import org.thingsboard.server.common.data.yunteng.enums.RoleEnum; |
27 | 31 | import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; |
28 | 32 | import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; |
29 | 33 | import org.thingsboard.server.controller.BaseController; |
34 | +import org.thingsboard.server.dao.user.UserService; | |
30 | 35 | import org.thingsboard.server.dao.yunteng.service.YtUserService; |
31 | 36 | |
32 | 37 | import javax.servlet.http.HttpServletRequest; |
... | ... | @@ -35,6 +40,7 @@ import java.io.IOException; |
35 | 40 | import java.net.URI; |
36 | 41 | import java.util.HashMap; |
37 | 42 | import java.util.List; |
43 | +import java.util.UUID; | |
38 | 44 | |
39 | 45 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
40 | 46 | |
... | ... | @@ -45,7 +51,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. |
45 | 51 | public class YtUserController extends BaseController { |
46 | 52 | |
47 | 53 | private final YtUserService userService; |
48 | - | |
54 | + private final UserService tbUserService; | |
49 | 55 | @GetMapping("{userId}") |
50 | 56 | public ResponseEntity<UserDTO> getUser(@PathVariable("userId") String userId) |
51 | 57 | throws ThingsboardException { |
... | ... | @@ -131,14 +137,22 @@ public class YtUserController extends BaseController { |
131 | 137 | return ResponseEntity.created(location).body(newUserDTO); |
132 | 138 | } |
133 | 139 | |
134 | - @PreAuthorize("hasRole('SYS_ADMIN')") | |
140 | + @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") | |
135 | 141 | @PostMapping("saveTenantAdmin") |
136 | - public UserDTO saveTenantAdmin(@RequestBody UserDTO userDTO) throws ThingsboardException { | |
137 | - Assert.isTrue(StringUtils.isNotBlank(userDTO.getTenantId()), "tenant code must exist"); | |
138 | - Assert.notNull(userDTO.getUsername(), "username must exist"); | |
139 | - Assert.notNull(userDTO.getRealName(), "real name must exist"); | |
142 | + public UserDTO saveTenantAdmin(@Validated(AddGroup.class)@RequestBody UserDTO userDTO) throws ThingsboardException { | |
143 | + //创建TB的租户管理员 | |
144 | + User tbUser = new User(); | |
145 | + TenantId tenantId = new TenantId(UUID.fromString(userDTO.getTenantId())); | |
146 | + tbUser.setTenantId(tenantId); | |
147 | + tbUser.setEmail(userDTO.getUsername()+ FastIotConstants.DEFAULT_EMAIL_SUFFIX_FOR_TB); | |
148 | + tbUser = tbUserService.saveUser(tbUser); | |
149 | + logEntityAction(tbUser.getId(), tbUser, | |
150 | + tbUser.getCustomerId(), | |
151 | + userDTO.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); | |
152 | + sendEntityNotificationMsg(tenantId, tbUser.getId(), | |
153 | + userDTO.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); | |
140 | 154 | return userService.saveTenantAdmin( |
141 | - userDTO, getCurrentUser().isPtSysadmin(), getCurrentUser().getCurrentTenantId()); | |
155 | + userDTO, getCurrentUser().isPtSysadmin(), tenantId.getId().toString()); | |
142 | 156 | } |
143 | 157 | |
144 | 158 | @DeleteMapping | ... | ... |
application/src/main/java/org/thingsboard/server/exception/yunteng/YunTengErrorResponseHandler.java
0 → 100644
1 | +package org.thingsboard.server.exception.yunteng; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
4 | +import lombok.extern.slf4j.Slf4j; | |
5 | +import org.springframework.beans.factory.annotation.Autowired; | |
6 | +import org.springframework.http.HttpStatus; | |
7 | +import org.springframework.http.MediaType; | |
8 | +import org.springframework.security.access.AccessDeniedException; | |
9 | +import org.springframework.security.authentication.BadCredentialsException; | |
10 | +import org.springframework.security.authentication.DisabledException; | |
11 | +import org.springframework.security.authentication.LockedException; | |
12 | +import org.springframework.security.core.AuthenticationException; | |
13 | +import org.springframework.security.web.access.AccessDeniedHandler; | |
14 | +import org.springframework.stereotype.Component; | |
15 | +import org.thingsboard.server.common.data.yunteng.core.Result; | |
16 | +import org.thingsboard.server.common.data.yunteng.core.exception.YunTengException; | |
17 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
18 | +import org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException; | |
19 | +import org.thingsboard.server.service.security.exception.JwtExpiredTokenException; | |
20 | + | |
21 | +import javax.servlet.http.HttpServletRequest; | |
22 | +import javax.servlet.http.HttpServletResponse; | |
23 | +import java.io.IOException; | |
24 | + | |
25 | +@Component | |
26 | +@Slf4j | |
27 | +public class YunTengErrorResponseHandler implements AccessDeniedHandler { | |
28 | + | |
29 | + private final ObjectMapper mapper; | |
30 | + | |
31 | + @Autowired | |
32 | + public YunTengErrorResponseHandler(ObjectMapper mapper) { | |
33 | + this.mapper = mapper; | |
34 | + } | |
35 | + | |
36 | + @Override | |
37 | + public void handle( | |
38 | + HttpServletRequest request, | |
39 | + HttpServletResponse response, | |
40 | + AccessDeniedException accessDeniedException) | |
41 | + throws IOException { | |
42 | + if (!response.isCommitted()) { | |
43 | + response.setContentType(MediaType.APPLICATION_JSON_VALUE); | |
44 | + response.setStatus(HttpStatus.FORBIDDEN.value()); | |
45 | + mapper.writeValue(response.getWriter(), Result.error(ErrorMessage.NO_PERMISSION)); | |
46 | + } | |
47 | + } | |
48 | + | |
49 | + public void handle(Exception exception, HttpServletResponse response) { | |
50 | + log.debug("Processing exception {}", exception.getMessage(), exception); | |
51 | + if (!response.isCommitted()) { | |
52 | + try { | |
53 | + response.setContentType(MediaType.APPLICATION_JSON_VALUE); | |
54 | + | |
55 | + if (exception instanceof AccessDeniedException) { | |
56 | + response.setStatus(HttpStatus.FORBIDDEN.value()); | |
57 | + mapper.writeValue(response.getWriter(), Result.error(ErrorMessage.ACCESS_DENIED)); | |
58 | + } else if (exception instanceof AuthenticationException) { | |
59 | + handleAuthenticationException((AuthenticationException) exception, response); | |
60 | + } else if (exception instanceof YunTengException) { | |
61 | + response.setStatus(((YunTengException) exception).getHttpStatus().value()); | |
62 | + mapper.writeValue( | |
63 | + response.getWriter(), Result.error(((YunTengException) exception).getError())); | |
64 | + } else { | |
65 | + response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); | |
66 | + mapper.writeValue(response.getWriter(), Result.error(exception.getMessage())); | |
67 | + } | |
68 | + } catch (IOException e) { | |
69 | + log.error("Can't handle exception", e); | |
70 | + } | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + private void handleAuthenticationException( | |
75 | + AuthenticationException authenticationException, HttpServletResponse response) | |
76 | + throws IOException { | |
77 | + response.setStatus(HttpStatus.UNAUTHORIZED.value()); | |
78 | + if (authenticationException instanceof BadCredentialsException) { | |
79 | + mapper.writeValue( | |
80 | + response.getWriter(), Result.error(ErrorMessage.USERNAME_PASSWORD_INCORRECT)); | |
81 | + } else if (authenticationException instanceof DisabledException) { | |
82 | + mapper.writeValue(response.getWriter(), Result.error(ErrorMessage.ACCOUNT_DISABLED)); | |
83 | + } else if (authenticationException instanceof LockedException) { | |
84 | + mapper.writeValue(response.getWriter(), Result.error(ErrorMessage.ACCOUNT_DISABLED)); | |
85 | + } else if (authenticationException instanceof JwtExpiredTokenException) { | |
86 | + mapper.writeValue(response.getWriter(), Result.error(ErrorMessage.TOKEN_EXPIRED)); | |
87 | + } else if (authenticationException instanceof AuthMethodNotSupportedException) { | |
88 | + mapper.writeValue( | |
89 | + response.getWriter(), Result.error(ErrorMessage.AUTHENTICATION_METHOD_NOT_SUPPORTED)); | |
90 | + } else { | |
91 | + mapper.writeValue( | |
92 | + response.getWriter(), | |
93 | + Result.error(HttpStatus.UNAUTHORIZED.value(), authenticationException.getMessage())); | |
94 | + } | |
95 | + } | |
96 | +} | ... | ... |
... | ... | @@ -2,7 +2,7 @@ package org.thingsboard.server.common.data.yunteng.config.sms; |
2 | 2 | |
3 | 3 | import lombok.extern.slf4j.Slf4j; |
4 | 4 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
5 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
5 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
6 | 6 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
7 | 7 | |
8 | 8 | @Slf4j |
... | ... | @@ -11,7 +11,7 @@ public abstract class AbstractSmsSender implements SmsSender { |
11 | 11 | protected void validatePhoneNumber(String phoneNumber) { |
12 | 12 | phoneNumber = phoneNumber.trim(); |
13 | 13 | if (!FastIotConstants.CHINA_MOBILE_PATTERN.matcher(phoneNumber).matches()) { |
14 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
14 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
15 | 15 | } |
16 | 16 | } |
17 | 17 | } |
\ No newline at end of file | ... | ... |
... | ... | @@ -8,12 +8,11 @@ import com.aliyuncs.exceptions.ClientException; |
8 | 8 | import com.aliyuncs.http.MethodType; |
9 | 9 | import com.aliyuncs.profile.DefaultProfile; |
10 | 10 | import com.aliyuncs.profile.IClientProfile; |
11 | -import lombok.Data; | |
12 | 11 | import lombok.extern.slf4j.Slf4j; |
13 | 12 | import org.apache.commons.lang3.StringUtils; |
14 | 13 | import org.thingsboard.common.util.JacksonUtil; |
15 | 14 | import org.thingsboard.server.common.data.yunteng.config.sms.AbstractSmsSender; |
16 | -import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
15 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
17 | 16 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
18 | 17 | import org.thingsboard.server.common.data.yunteng.enums.ResponseCodeEnum; |
19 | 18 | |
... | ... | @@ -30,7 +29,7 @@ public class AliSmsSender extends AbstractSmsSender { |
30 | 29 | public AliSmsSender(AliSmsProviderConfiguration config) { |
31 | 30 | if (StringUtils.isEmpty(config.getAccessKeyId()) |
32 | 31 | || StringUtils.isEmpty(config.getAccessKeyId())) { |
33 | - throw new FastIotException(ErrorMessage.INVALID_PARAMETER); | |
32 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
34 | 33 | } |
35 | 34 | this.config = config; |
36 | 35 | initProfile(); | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/core/exception/YtDataValidationException.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/core/exception/DataValidationException.java
... | ... | @@ -2,16 +2,16 @@ package org.thingsboard.server.common.data.yunteng.core.exception; |
2 | 2 | |
3 | 3 | import lombok.Getter; |
4 | 4 | |
5 | -public class DataValidationException extends RuntimeException { | |
5 | +public class YtDataValidationException extends RuntimeException { | |
6 | 6 | private static final long serialVersionUID = 3556952261254572635L; |
7 | 7 | |
8 | 8 | @Getter public boolean log = false; |
9 | 9 | |
10 | - public DataValidationException(String message) { | |
10 | + public YtDataValidationException(String message) { | |
11 | 11 | super(message); |
12 | 12 | } |
13 | 13 | |
14 | - public DataValidationException(String message, boolean log) { | |
14 | + public YtDataValidationException(String message, boolean log) { | |
15 | 15 | super(message); |
16 | 16 | this.log = log; |
17 | 17 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/core/exception/YunTengException.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/core/exception/FastIotException.java
... | ... | @@ -4,26 +4,26 @@ import lombok.Getter; |
4 | 4 | import org.springframework.http.HttpStatus; |
5 | 5 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
6 | 6 | |
7 | -public class FastIotException extends RuntimeException { | |
7 | +public class YunTengException extends RuntimeException { | |
8 | 8 | private static final long serialVersionUID = 4036257507478854844L; |
9 | 9 | |
10 | 10 | @Getter private final HttpStatus httpStatus; |
11 | 11 | |
12 | 12 | @Getter private final ErrorMessage error; |
13 | 13 | |
14 | - public FastIotException(ErrorMessage errorMessage) { | |
14 | + public YunTengException(ErrorMessage errorMessage) { | |
15 | 15 | super(errorMessage.getMessage()); |
16 | 16 | this.httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; |
17 | 17 | this.error = errorMessage; |
18 | 18 | } |
19 | 19 | |
20 | - public FastIotException(ErrorMessage errorMessage, HttpStatus httpStatus) { | |
20 | + public YunTengException(ErrorMessage errorMessage, HttpStatus httpStatus) { | |
21 | 21 | super(errorMessage.getMessage()); |
22 | 22 | this.httpStatus = httpStatus; |
23 | 23 | this.error = errorMessage; |
24 | 24 | } |
25 | 25 | |
26 | - public FastIotException() { | |
26 | + public YunTengException() { | |
27 | 27 | super(ErrorMessage.INTERNAL_ERROR.getMessage()); |
28 | 28 | this.error = ErrorMessage.INTERNAL_ERROR; |
29 | 29 | this.httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; | ... | ... |
... | ... | @@ -45,6 +45,7 @@ public class UserDTO extends BaseDTO { |
45 | 45 | private boolean hasPassword; |
46 | 46 | |
47 | 47 | @JsonInclude(JsonInclude.Include.NON_NULL) |
48 | + @NotEmpty(message = "租户ID不能为空或者空字符串", groups = AddGroup.class) | |
48 | 49 | private String tenantId; |
49 | 50 | |
50 | 51 | @JsonInclude(JsonInclude.Include.NON_NULL) | ... | ... |
... | ... | @@ -4,17 +4,17 @@ public enum RoleEnum { |
4 | 4 | /** |
5 | 5 | * 超级管理员 |
6 | 6 | */ |
7 | - ROLE_SYS_ADMIN, | |
7 | + SYS_ADMIN, | |
8 | 8 | /** |
9 | 9 | * 租户管理员 |
10 | 10 | */ |
11 | - ROLE_TENANT_ADMIN, | |
11 | + TENANT_ADMIN, | |
12 | 12 | /** |
13 | 13 | * 租户下普通用户 |
14 | 14 | */ |
15 | - ROLE_NORMAL_USER, | |
15 | + CUSTOMER_USER, | |
16 | 16 | /** |
17 | 17 | * 平台系统管理员 |
18 | 18 | */ |
19 | - ROLE_PLATFORM_ADMIN; | |
19 | + PLATFORM_ADMIN; | |
20 | 20 | } | ... | ... |
... | ... | @@ -12,8 +12,7 @@ import org.springframework.stereotype.Service; |
12 | 12 | import org.springframework.transaction.annotation.Transactional; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
14 | 14 | import org.thingsboard.server.common.data.yunteng.core.cache.CacheUtils; |
15 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
16 | -import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
15 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
17 | 16 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
18 | 17 | import org.thingsboard.server.common.data.yunteng.dto.MenuDTO; |
19 | 18 | import org.thingsboard.server.common.data.yunteng.enums.MenuTypeEnum; |
... | ... | @@ -84,19 +83,17 @@ public class MenuServiceImpl extends AbstractBaseService<MenuMapper, Menu> imple |
84 | 83 | } |
85 | 84 | if (!isSysAdmin |
86 | 85 | && menuDTO.getType().equals(MenuTypeEnum.SYSADMIN)) { |
87 | - throw new FastIotException( | |
88 | - ErrorMessage.ACCESS_DENIED.setMessage("Non-system admin cannot save system menu"), | |
89 | - HttpStatus.FORBIDDEN); | |
86 | + throw new AccessDeniedException("Non-system admin cannot save system menu"); | |
90 | 87 | } |
91 | 88 | if (menuDTO.getType().equals(MenuTypeEnum.CUSTOM) |
92 | 89 | && StringUtils.isAllBlank(menuDTO.getName())) { |
93 | - throw new DataValidationException("menu name is required when save custom menu"); | |
90 | + throw new YtDataValidationException("menu name is required when save custom menu"); | |
94 | 91 | } |
95 | 92 | int count = |
96 | 93 | baseMapper.selectCount( |
97 | 94 | new QueryWrapper<Menu>().lambda().eq(Menu::getPath, menuDTO.getPath())); |
98 | 95 | if (count > 0) { |
99 | - throw new DataValidationException("menu with path " + menuDTO + " already exist"); | |
96 | + throw new YtDataValidationException("menu with path " + menuDTO + " already exist"); | |
100 | 97 | } |
101 | 98 | menuDTO.setTenantId(tenantId); |
102 | 99 | Menu menu = menuDTO.getEntity(Menu.class); |
... | ... | @@ -118,7 +115,7 @@ public class MenuServiceImpl extends AbstractBaseService<MenuMapper, Menu> imple |
118 | 115 | public MenuDTO updateMenu(String tenantId,boolean isSysAdmin,MenuDTO menuDTO) { |
119 | 116 | Menu menu = baseMapper.selectById(menuDTO.getId()); |
120 | 117 | if (menu == null) { |
121 | - throw new DataValidationException("cannot find menu to update"); | |
118 | + throw new YtDataValidationException("cannot find menu to update"); | |
122 | 119 | } else { |
123 | 120 | if (!isSysAdmin) { |
124 | 121 | if (!tenantId.equals(menuDTO.getTenantId())) { |
... | ... | @@ -166,7 +163,7 @@ public class MenuServiceImpl extends AbstractBaseService<MenuMapper, Menu> imple |
166 | 163 | int menuCountInDB = |
167 | 164 | baseMapper.selectCount(new QueryWrapper<Menu>().lambda().in(Menu::getId, ids)); |
168 | 165 | if (menuCountInDB != menuId.length) { |
169 | - throw new DataValidationException("please ensure all menu id are valid"); | |
166 | + throw new YtDataValidationException("please ensure all menu id are valid"); | |
170 | 167 | } |
171 | 168 | Set<String> existMenus = baseMapper.selectTenantMenuIds(tenantId); |
172 | 169 | Set<String> toDel = Sets.difference(existMenus, ids); |
... | ... | @@ -193,7 +190,7 @@ public class MenuServiceImpl extends AbstractBaseService<MenuMapper, Menu> imple |
193 | 190 | int menuCountInDB = |
194 | 191 | baseMapper.selectCount(new QueryWrapper<Menu>().lambda().in(Menu::getId, ids)); |
195 | 192 | if (menuCountInDB != menuId.length) { |
196 | - throw new DataValidationException("please ensure all menu id are valid"); | |
193 | + throw new YtDataValidationException("please ensure all menu id are valid"); | |
197 | 194 | } |
198 | 195 | } |
199 | 196 | Set<String> existMenus = baseMapper.selectRoleMenuIds(roleId); | ... | ... |
... | ... | @@ -12,7 +12,7 @@ import org.springframework.stereotype.Service; |
12 | 12 | import org.springframework.transaction.annotation.Transactional; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
14 | 14 | import org.thingsboard.server.common.data.yunteng.core.cache.CacheUtils; |
15 | -import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
15 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
16 | 16 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
17 | 17 | import org.thingsboard.server.common.data.yunteng.dto.RoleDTO; |
18 | 18 | import org.thingsboard.server.common.data.yunteng.dto.request.RoleReqDTO; |
... | ... | @@ -54,12 +54,12 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
54 | 54 | .lambda() |
55 | 55 | .eq(queryMap.get("status") != null, Role::isEnabled, queryMap.get("status")) |
56 | 56 | .eq(queryMap.get("roleType") != null, Role::getRoleType, queryMap.get("roleType")) |
57 | - .ne(queryMap.get("roleType") == null, Role::getRoleType, RoleEnum.ROLE_TENANT_ADMIN) | |
57 | + .ne(queryMap.get("roleType") == null, Role::getRoleType, RoleEnum.TENANT_ADMIN) | |
58 | 58 | .ne( |
59 | 59 | queryMap.get("roleType") == null |
60 | 60 | && isPlatformAdmin, |
61 | 61 | Role::getRoleType, |
62 | - RoleEnum.ROLE_SYS_ADMIN) | |
62 | + RoleEnum.SYS_ADMIN) | |
63 | 63 | .eq( |
64 | 64 | !isSysadmin, |
65 | 65 | Role::getTenantId, |
... | ... | @@ -87,7 +87,7 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
87 | 87 | // 判断该角色下面是否有用户 |
88 | 88 | Set<String> userIds = baseMapper.checkRoleUserMappingByRoleIds(ids); |
89 | 89 | if (null != userIds && userIds.size() > 0) { |
90 | - throw new FastIotException(ErrorMessage.ROLE_IN_USE); | |
90 | + throw new YtDataValidationException(ErrorMessage.ROLE_IN_USE.getMessage()); | |
91 | 91 | } |
92 | 92 | // delete sys_role_menu mapping |
93 | 93 | baseMapper.deleteRoleMenuMappingByRoleIds(ids); |
... | ... | @@ -106,7 +106,7 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
106 | 106 | boolean cachePresent; |
107 | 107 | if (isSysadmin) { |
108 | 108 | cacheKey = |
109 | - FastIotConstants.CacheConfigKey.USER_PERMISSION_PREFIX + RoleEnum.ROLE_SYS_ADMIN.name(); | |
109 | + FastIotConstants.CacheConfigKey.USER_PERMISSION_PREFIX + RoleEnum.SYS_ADMIN.name(); | |
110 | 110 | Optional<Set<String>> optionalPermission = |
111 | 111 | cacheUtils.get(FastIotConstants.CacheConfigKey.CACHE_CONFIG_KEY, cacheKey); |
112 | 112 | cachePresent = optionalPermission.isPresent(); |
... | ... | @@ -168,13 +168,13 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
168 | 168 | public RoleDTO saveOrUpdateRoleInfoWithMenu(RoleReqDTO roleReqDTO,boolean isSysadmin,boolean isPlatformAdmin,String tenantId) { |
169 | 169 | Role role; |
170 | 170 | // 默认普通管理员角色,即租户管理员添加的角色 |
171 | - var roleType = RoleEnum.ROLE_NORMAL_USER.name(); | |
171 | + var roleType = RoleEnum.CUSTOMER_USER.name(); | |
172 | 172 | if (null != roleReqDTO.getRoleType()) { |
173 | 173 | roleType = roleReqDTO.getRoleType().name(); |
174 | 174 | } else { |
175 | 175 | if (isSysadmin |
176 | 176 | || isPlatformAdmin) { |
177 | - roleType = RoleEnum.ROLE_PLATFORM_ADMIN.name(); | |
177 | + roleType = RoleEnum.PLATFORM_ADMIN.name(); | |
178 | 178 | } |
179 | 179 | } |
180 | 180 | boolean update = StringUtils.isNotBlank(roleReqDTO.getId()); |
... | ... | @@ -212,7 +212,7 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
212 | 212 | menuService.assignMenuToRole( |
213 | 213 | roleReqDTO.getMenu().toArray(new String[roleReqDTO.getMenu().size()]), role.getId()); |
214 | 214 | // 如果是租户管理员角色并且是更新,则需要更新租户菜单表 |
215 | - if (role.getRoleType().equals(RoleEnum.ROLE_TENANT_ADMIN.name()) && update) { | |
215 | + if (role.getRoleType().equals(RoleEnum.TENANT_ADMIN.name()) && update) { | |
216 | 216 | List<String> menus = roleReqDTO.getMenu(); |
217 | 217 | // 先删除以前的租户菜单,再更新新的租户菜单 |
218 | 218 | // 1、查询这个角色有几个租户用户 | ... | ... |
... | ... | @@ -6,10 +6,10 @@ import lombok.extern.slf4j.Slf4j; |
6 | 6 | import org.apache.commons.lang3.StringUtils; |
7 | 7 | import org.springframework.stereotype.Service; |
8 | 8 | import org.springframework.transaction.annotation.Transactional; |
9 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
10 | 9 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
11 | 10 | import org.thingsboard.server.common.data.yunteng.dto.SysDictItemDTO; |
12 | 11 | import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; |
12 | +import org.thingsboard.server.dao.exception.DataValidationException; | |
13 | 13 | import org.thingsboard.server.dao.yunteng.entities.SysDictItem; |
14 | 14 | import org.thingsboard.server.dao.yunteng.mapper.SysDictItemMapper; |
15 | 15 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | ... | ... |
... | ... | @@ -5,7 +5,7 @@ import lombok.RequiredArgsConstructor; |
5 | 5 | import lombok.extern.slf4j.Slf4j; |
6 | 6 | import org.springframework.stereotype.Service; |
7 | 7 | import org.springframework.transaction.annotation.Transactional; |
8 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
8 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
9 | 9 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.dto.SysDictDTO; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.dto.SysDictItemDTO; |
... | ... | @@ -52,7 +52,7 @@ public class SysDictServiceImpl extends AbstractBaseService<SysDictMapper, SysDi |
52 | 52 | // 新增之前先判断该租户是否已添加 |
53 | 53 | SysDictDTO querySysDict = baseMapper.getDictInfoByCode(tenantId, sysDictDTO.getDictCode()); |
54 | 54 | if (querySysDict != null) { |
55 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
55 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
56 | 56 | } |
57 | 57 | SysDict sysDict = new SysDict(); |
58 | 58 | sysDictDTO.copyToEntity(sysDict); |
... | ... | @@ -69,7 +69,7 @@ public class SysDictServiceImpl extends AbstractBaseService<SysDictMapper, SysDi |
69 | 69 | List<SysDictItemDTO> sysDictItemDTO = |
70 | 70 | sysDictItemMapper.getDictItemInfo(id,null); |
71 | 71 | if (sysDictItemDTO != null) { |
72 | - throw new DataValidationException( | |
72 | + throw new YtDataValidationException( | |
73 | 73 | "There is a relationship between superiors and subordinates"); |
74 | 74 | } |
75 | 75 | } | ... | ... |
... | ... | @@ -7,7 +7,7 @@ import lombok.RequiredArgsConstructor; |
7 | 7 | import org.apache.commons.lang3.StringUtils; |
8 | 8 | import org.springframework.stereotype.Service; |
9 | 9 | import org.springframework.transaction.annotation.Transactional; |
10 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
10 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
11 | 11 | import org.thingsboard.server.common.data.yunteng.dto.AlarmContactDTO; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; |
... | ... | @@ -72,7 +72,7 @@ public class YtAlarmContactServiceImpl extends AbstractBaseService<AlarmContactM |
72 | 72 | tenantWapper(tenantId).eq(AlarmContact::getUsername, alarmContactDTO.getUsername()); |
73 | 73 | int Count = baseMapper.selectCount(Wrapper); |
74 | 74 | if (Count > 0) { |
75 | - throw new DataValidationException("department for this name is exited"); | |
75 | + throw new YtDataValidationException("department for this name is exited"); | |
76 | 76 | } |
77 | 77 | alarmContactDTO.setTenantId(tenantId); |
78 | 78 | AlarmContact alarmContact = alarmContactDTO.getEntity(AlarmContact.class); |
... | ... | @@ -111,7 +111,7 @@ public class YtAlarmContactServiceImpl extends AbstractBaseService<AlarmContactM |
111 | 111 | // 得到对象 |
112 | 112 | AlarmContact alarmContact = baseMapper.selectById(alarmContactDTO.getId()); |
113 | 113 | if (alarmContact == null) { |
114 | - throw new DataValidationException("此数据不存在"); | |
114 | + throw new YtDataValidationException("此数据不存在"); | |
115 | 115 | } else { |
116 | 116 | AlarmContact entity = alarmContactDTO.getEntity(AlarmContact.class); |
117 | 117 | System.out.println(alarmContact); | ... | ... |
... | ... | @@ -3,7 +3,7 @@ package org.thingsboard.server.dao.yunteng.impl; |
3 | 3 | import lombok.RequiredArgsConstructor; |
4 | 4 | import lombok.extern.slf4j.Slf4j; |
5 | 5 | import org.springframework.stereotype.Service; |
6 | -import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
6 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
7 | 7 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
8 | 8 | import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; |
9 | 9 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
... | ... | @@ -131,7 +131,7 @@ public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { |
131 | 131 | return pageData; |
132 | 132 | } catch (Exception e) { |
133 | 133 | log.error("create TBAlarmInfo error {}", e.getMessage()); |
134 | - throw new FastIotException(ErrorMessage.CONNECT_TO_TB_ERROR); | |
134 | + throw new YtDataValidationException(ErrorMessage.CONNECT_TO_TB_ERROR.getMessage()); | |
135 | 135 | } |
136 | 136 | //return getPageData(alarmInfoIPage,AlarmInfoDTO.class); |
137 | 137 | } | ... | ... |
... | ... | @@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j; |
6 | 6 | import org.apache.commons.lang3.StringUtils; |
7 | 7 | import org.springframework.stereotype.Service; |
8 | 8 | import org.springframework.transaction.annotation.Transactional; |
9 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
9 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
10 | 10 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
... | ... | @@ -49,7 +49,7 @@ public class YtAlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileM |
49 | 49 | @Override |
50 | 50 | public AlarmProfileDTO findAlarmProfileByDeviceProfileId(String tenantId,String deviceProfileId) { |
51 | 51 | if (StringUtils.isEmpty(deviceProfileId)) { |
52 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
52 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
53 | 53 | } |
54 | 54 | List<AlarmProfile> alarmProfileList = |
55 | 55 | baseMapper.selectList( | ... | ... |
... | ... | @@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils; |
8 | 8 | import org.springframework.security.access.AccessDeniedException; |
9 | 9 | import org.springframework.stereotype.Service; |
10 | 10 | import org.springframework.transaction.annotation.Transactional; |
11 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
12 | 12 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.dto.AlarmContactDTO; |
14 | 14 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
... | ... | @@ -71,7 +71,7 @@ public class YtAlarmServiceImpl extends AbstractBaseService<AlarmContactMapper, |
71 | 71 | .eq( AlarmContact::getUsername, alarmContactDTO.getUsername()); |
72 | 72 | int Count = baseMapper.selectCount(Wrapper); |
73 | 73 | if (Count > 0) { |
74 | - throw new DataValidationException("department for this name is exited"); | |
74 | + throw new YtDataValidationException("department for this name is exited"); | |
75 | 75 | } |
76 | 76 | alarmContactDTO.setTenantId(tenantId); |
77 | 77 | AlarmContact alarmContact = alarmContactDTO.getEntity(AlarmContact.class); |
... | ... | @@ -112,7 +112,7 @@ public class YtAlarmServiceImpl extends AbstractBaseService<AlarmContactMapper, |
112 | 112 | AlarmContact alarmContact = alarmContactMapper.selectById(alarmContactDTO.getId()); |
113 | 113 | if (alarmContact == null) { |
114 | 114 | //为空则抛出无效参数的异常 |
115 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
115 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
116 | 116 | } else { |
117 | 117 | if (!istenantAdmin) { |
118 | 118 | if (!tenantId.equals(alarmContactDTO.getTenantId())) { | ... | ... |
... | ... | @@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils; |
8 | 8 | import org.springframework.stereotype.Service; |
9 | 9 | import org.springframework.transaction.annotation.Transactional; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.core.cache.CacheUtils; |
11 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
12 | 12 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; |
14 | 14 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
... | ... | @@ -68,7 +68,7 @@ public class YtDeviceProfileServiceImpl |
68 | 68 | YtDeviceProfile deviceProfile = new YtDeviceProfile(); |
69 | 69 | // 判断数据库是否已存在名字相同的设备配置 |
70 | 70 | if (findDeviceProfile(tenantId,deviceProfileDTO).size() > 0) { |
71 | - throw new DataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | |
71 | + throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | |
72 | 72 | } |
73 | 73 | deviceProfileDTO.copyToEntity(deviceProfile); |
74 | 74 | deviceProfile.setTenantId(tenantId); |
... | ... | @@ -90,7 +90,7 @@ public class YtDeviceProfileServiceImpl |
90 | 90 | int count = |
91 | 91 | deviceMapper.selectCount(new QueryWrapper<YtDevice>().lambda().in(YtDevice::getProfileId, ids)); |
92 | 92 | if (count > 0) { |
93 | - throw new DataValidationException("有设备使用待删除配置,请先删除设备或者修改设备配置"); | |
93 | + throw new YtDataValidationException("有设备使用待删除配置,请先删除设备或者修改设备配置"); | |
94 | 94 | } |
95 | 95 | // TODO check if ids bind to iotfs_key_value_mapping |
96 | 96 | // 删除本地时,先删除TB的DeviceProfile | ... | ... |
... | ... | @@ -11,7 +11,7 @@ import org.springframework.stereotype.Service; |
11 | 11 | import org.springframework.transaction.annotation.Transactional; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; |
14 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
14 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
15 | 15 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
16 | 16 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
17 | 17 | import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; |
... | ... | @@ -70,7 +70,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
70 | 70 | // 如果device token已经存在,那么必定只有一个,不会有多个 |
71 | 71 | YtDevice deviceExistWithSameToken = devices.get(0); |
72 | 72 | if (!deviceExistWithSameToken.getId().equals(deviceDTO.getId())) { |
73 | - throw new DataValidationException("设备Device Token已经存在!"); | |
73 | + throw new YtDataValidationException("设备Device Token已经存在!"); | |
74 | 74 | } |
75 | 75 | } |
76 | 76 | // 首先update tb, 需要更新的字段有 |
... | ... | @@ -145,7 +145,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
145 | 145 | |
146 | 146 | private void validateUpdate(DeviceDTO deviceDTO) { |
147 | 147 | if (StringUtils.isAllBlank(deviceDTO.getName())) { |
148 | - throw new DataValidationException("device name must be specific"); | |
148 | + throw new YtDataValidationException("device name must be specific"); | |
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
... | ... | @@ -190,35 +190,35 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
190 | 190 | |
191 | 191 | private void validateDeviceDTO(String tenantId,DeviceDTO deviceDTO, boolean insert) { |
192 | 192 | if (StringUtils.isBlank(deviceDTO.getName())) { |
193 | - throw new DataValidationException("device name cannot be black"); | |
193 | + throw new YtDataValidationException("device name cannot be black"); | |
194 | 194 | } |
195 | 195 | // validate IOT DB |
196 | 196 | if (StringUtils.isBlank(deviceDTO.getProfileId())) { |
197 | - throw new DataValidationException("device profile cannot be black"); | |
197 | + throw new YtDataValidationException("device profile cannot be black"); | |
198 | 198 | } |
199 | 199 | if (StringUtils.isBlank(deviceDTO.getDeviceToken()) && !insert) { |
200 | - throw new DataValidationException("device token cannot be black"); | |
200 | + throw new YtDataValidationException("device token cannot be black"); | |
201 | 201 | } |
202 | 202 | // 验证设备名称是否已经存在 如果此处直接使用deviceDTO 将有误 |
203 | 203 | if (insert) { |
204 | 204 | DeviceDTO check = new DeviceDTO(); |
205 | 205 | check.setName(deviceDTO.getName()); |
206 | 206 | if (findDeviceInfo(tenantId,check).size() > 0) { |
207 | - throw new DataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | |
207 | + throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | |
208 | 208 | } |
209 | 209 | } |
210 | 210 | // 验证数据profileId的正确性 |
211 | 211 | YtDeviceProfile deviceProfile = deviceProfileMapper.selectById(deviceDTO.getProfileId()); |
212 | 212 | Organization organization = organizationMapper.selectById(deviceDTO.getOrganizationId()); |
213 | 213 | if (null == deviceProfile || null == organization) { |
214 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
214 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
215 | 215 | // } else if (StringUtils.isEmpty(deviceProfile.getTbProfileId())) { |
216 | 216 | // throw new DataValidationException("tb_device profile is nonexistent"); |
217 | 217 | } else if (!deviceProfile |
218 | 218 | .getTenantId() |
219 | 219 | .equals(tenantId) |
220 | 220 | || !organization.getTenantId().equals(tenantId)) { |
221 | - throw new DataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage()); | |
221 | + throw new YtDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage()); | |
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
... | ... | @@ -231,7 +231,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
231 | 231 | .lambda() |
232 | 232 | .eq(YtDevice::getDeviceToken, deviceDTO.getDeviceToken())); |
233 | 233 | if (!devices.isEmpty()) { |
234 | - throw new DataValidationException("设备Device Token已经存在!"); | |
234 | + throw new YtDataValidationException("设备Device Token已经存在!"); | |
235 | 235 | } |
236 | 236 | } |
237 | 237 | YtDevice device = new YtDevice(); | ... | ... |
... | ... | @@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
4 | 4 | import org.apache.commons.lang3.StringUtils; |
5 | 5 | import org.springframework.stereotype.Service; |
6 | 6 | import org.springframework.transaction.annotation.Transactional; |
7 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
7 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
8 | 8 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
9 | 9 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.dto.DeviceTypeDTO; |
... | ... | @@ -24,7 +24,7 @@ public class YtDeviceTypeServiceImpl extends AbstractBaseService<DeviceTypeMappe |
24 | 24 | public List<DeviceTypeDTO> getDeviceTypeTree(String tenantId) { |
25 | 25 | if (StringUtils.isEmpty(tenantId)) { |
26 | 26 | if (StringUtils.isEmpty(tenantId)) { |
27 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
27 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
28 | 28 | } |
29 | 29 | } |
30 | 30 | List<DeviceType> typeList = baseMapper.selectList( | ... | ... |
... | ... | @@ -11,7 +11,7 @@ import lombok.extern.slf4j.Slf4j; |
11 | 11 | import org.springframework.stereotype.Service; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.config.email.EmailConfiguration; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
14 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
14 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
15 | 15 | import org.thingsboard.server.common.data.yunteng.dto.request.EmailReqDTO; |
16 | 16 | import org.thingsboard.server.common.data.yunteng.enums.EmailFormatEnum; |
17 | 17 | import org.thingsboard.server.common.data.yunteng.enums.ResponseCodeEnum; |
... | ... | @@ -47,11 +47,11 @@ public class YtMailServiceImpl implements YtMailService { |
47 | 47 | //查询模板信息 |
48 | 48 | MessageTemplate messageTemplate = messageTemplateMapper.selectById(emailReqDTO.getId()); |
49 | 49 | if(null == messageTemplate){ |
50 | - throw new DataValidationException("invalid parameters"); | |
50 | + throw new YtDataValidationException("invalid parameters"); | |
51 | 51 | } |
52 | 52 | MessageConfig messageConfig =messageConfigMapper.selectById(messageTemplate.getMessageConfigId()); |
53 | 53 | if (messageConfig.getStatus() != FastIotConstants.StateValue.ENABLE) { |
54 | - throw new DataValidationException("messageConfig is disable"); | |
54 | + throw new YtDataValidationException("messageConfig is disable"); | |
55 | 55 | } |
56 | 56 | JsonNode configNode = messageConfig.getConfig(); |
57 | 57 | EmailConfiguration emailConfiguration = JacksonUtil.convertValue(configNode, EmailConfiguration.class); | ... | ... |
... | ... | @@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils; |
8 | 8 | import org.springframework.stereotype.Service; |
9 | 9 | import org.springframework.transaction.annotation.Transactional; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
11 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
12 | 12 | import org.thingsboard.server.common.data.yunteng.dto.MessageConfigDTO; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
14 | 14 | import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; |
... | ... | @@ -77,7 +77,7 @@ public class YtMessageConfigServiceImpl |
77 | 77 | MessageConfig config = baseMapper.selectById(configDTO.getId()); |
78 | 78 | if (configDTO.getStatus() == FastIotConstants.StateValue.ENABLE) { |
79 | 79 | if (StringUtils.isEmpty(config.getId())) { |
80 | - throw new DataValidationException("invalid parameters"); | |
80 | + throw new YtDataValidationException("invalid parameters"); | |
81 | 81 | } |
82 | 82 | checkMessageConfig(configDTO, tenantId); |
83 | 83 | } |
... | ... | @@ -145,7 +145,7 @@ public class YtMessageConfigServiceImpl |
145 | 145 | getEnableConfigByMessageAndPlatform( |
146 | 146 | configDTO.getMessageType(), configDTO.getPlatformType(), tenantId); |
147 | 147 | if (null != enableConfig && !enableConfig.getId().equalsIgnoreCase(configDTO.getId())) { |
148 | - throw new DataValidationException("enabled config is existed"); | |
148 | + throw new YtDataValidationException("enabled config is existed"); | |
149 | 149 | } |
150 | 150 | } |
151 | 151 | } | ... | ... |
... | ... | @@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils; |
6 | 6 | import org.springframework.stereotype.Service; |
7 | 7 | import org.springframework.transaction.annotation.Transactional; |
8 | 8 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
9 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
9 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
10 | 10 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.dto.MessageTemplateDTO; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; |
... | ... | @@ -61,11 +61,11 @@ public class YtMessageTemplateServiceImpl |
61 | 61 | queryTemplate.setMessageType(templateDTO.getMessageType()); |
62 | 62 | // queryTemplate.setTemplateCode(tenantCode); |
63 | 63 | if(StringUtils.isEmpty(templateDTO.getTemplatePurpose()) || StringUtils.isEmpty(templateDTO.getMessageType())){ |
64 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
64 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
65 | 65 | } |
66 | 66 | List<MessageTemplateDTO> messageTemplateDTOList = baseMapper.findMessageTemplate(queryTemplate); |
67 | 67 | if(null!=messageTemplateDTOList && messageTemplateDTOList.size()>0){ |
68 | - throw new DataValidationException(ErrorMessage.NOT_SET_PASSWORD_TEMPLATE.getMessage()); | |
68 | + throw new YtDataValidationException(ErrorMessage.NOT_SET_PASSWORD_TEMPLATE.getMessage()); | |
69 | 69 | } |
70 | 70 | MessageTemplate messageTemplate = baseMapper.selectById(templateDTO.getId()); |
71 | 71 | templateDTO.copyToEntity(messageTemplate); | ... | ... |
... | ... | @@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils; |
8 | 8 | import org.springframework.stereotype.Service; |
9 | 9 | import org.springframework.transaction.annotation.Transactional; |
10 | 10 | import org.springframework.util.Assert; |
11 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
12 | 12 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
14 | 14 | import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; |
... | ... | @@ -41,12 +41,12 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
41 | 41 | if (StringUtils.isNotBlank(organizationDTO.getParentId())) { |
42 | 42 | Organization organization = baseMapper.selectById(organizationDTO.getParentId()); |
43 | 43 | if (organization == null) { |
44 | - throw new DataValidationException("parent organization not exist!"); | |
44 | + throw new YtDataValidationException("parent organization not exist!"); | |
45 | 45 | } else { |
46 | 46 | if (!organization |
47 | 47 | .getTenantId() |
48 | 48 | .equals(null)) {//TODO getCurrentUser().getTenantId() |
49 | - throw new DataValidationException("parent organization not exist."); | |
49 | + throw new YtDataValidationException("parent organization not exist."); | |
50 | 50 | } |
51 | 51 | } |
52 | 52 | } |
... | ... | @@ -62,7 +62,7 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
62 | 62 | @Transactional |
63 | 63 | public boolean deleteOrganizations(DeleteDTO deleteDTO,String tenantId) { |
64 | 64 | if(null == deleteDTO || deleteDTO.getIds().isEmpty()){ |
65 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
65 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
66 | 66 | } |
67 | 67 | String[] ids = deleteDTO.getIds().toArray(new String[deleteDTO.getIds().size()]); |
68 | 68 | Set<String> idToDelete = |
... | ... | @@ -73,7 +73,7 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
73 | 73 | .map(OrganizationDTO::getId) |
74 | 74 | .collect(Collectors.toSet()); |
75 | 75 | if (idToDelete.size() != ids.length) { |
76 | - throw new DataValidationException("待删除数据存在子项,不能删除!"); | |
76 | + throw new YtDataValidationException("待删除数据存在子项,不能删除!"); | |
77 | 77 | } |
78 | 78 | List<UserOrganizationMapping> userOrganizationMappingList = |
79 | 79 | userOrganizationMappingMapper.selectList( |
... | ... | @@ -81,7 +81,7 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
81 | 81 | .lambda() |
82 | 82 | .in(UserOrganizationMapping::getOrganizationId, idToDelete)); |
83 | 83 | if (!userOrganizationMappingList.isEmpty()) { |
84 | - throw new DataValidationException("待删除数据存在关联用户,不能删除!"); | |
84 | + throw new YtDataValidationException("待删除数据存在关联用户,不能删除!"); | |
85 | 85 | } |
86 | 86 | // 查询是否有设备使用该组织 |
87 | 87 | // List<Device> deviceList = deviceMapper.selectList( |
... | ... | @@ -241,7 +241,7 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
241 | 241 | for (String userId : userIds) { |
242 | 242 | User user = userMapper.selectById(userId); |
243 | 243 | if (user == null) { |
244 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
244 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
245 | 245 | } |
246 | 246 | userOrganizationMappingMapper.delete( |
247 | 247 | new QueryWrapper<UserOrganizationMapping>() | ... | ... |
... | ... | @@ -15,7 +15,7 @@ import org.thingsboard.server.common.data.yunteng.config.sms.YtDefaultSmsSenderF |
15 | 15 | import org.thingsboard.server.common.data.yunteng.config.sms.SmsProviderConfiguration; |
16 | 16 | import org.thingsboard.server.common.data.yunteng.config.sms.SmsSender; |
17 | 17 | import org.thingsboard.server.common.data.yunteng.core.cache.CacheUtils; |
18 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
18 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
19 | 19 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
20 | 20 | import org.thingsboard.server.common.data.yunteng.dto.request.CodeTTL; |
21 | 21 | import org.thingsboard.server.common.data.yunteng.dto.request.SmsReqDTO; |
... | ... | @@ -63,7 +63,7 @@ public class YtSmsServiceImpl implements YtSmsService { |
63 | 63 | LinkedHashMap<String, String> templateParam = smsReqDTO.getParams(); |
64 | 64 | String templateId = smsReqDTO.getId(); |
65 | 65 | if (StringUtils.isEmpty(phoneNumbers) || StringUtils.isEmpty(templateId)) { |
66 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
66 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
67 | 67 | } |
68 | 68 | MessageTemplate messageTemplate = messageTemplateMapper.selectById(templateId); |
69 | 69 | if (null != messageTemplate) { |
... | ... | @@ -113,7 +113,7 @@ public class YtSmsServiceImpl implements YtSmsService { |
113 | 113 | if (userMapper |
114 | 114 | .selectList(new QueryWrapper<User>().lambda().eq(User::getPhoneNumber, phoneNumber)) |
115 | 115 | .isEmpty()) { |
116 | - throw new DataValidationException("电话号码未在系统注册,请联系你的管理员"); | |
116 | + throw new YtDataValidationException("电话号码未在系统注册,请联系你的管理员"); | |
117 | 117 | } |
118 | 118 | // 获取是否有验证码存在,防止发送数量过多 |
119 | 119 | String key = |
... | ... | @@ -142,7 +142,7 @@ public class YtSmsServiceImpl implements YtSmsService { |
142 | 142 | .eq(MessageTemplate::getTemplatePurpose, MsgTemplatePurposeEnum.FOR_LOGIN.name()) |
143 | 143 | .eq(MessageTemplate::getMessageType, MessageTypeEnum.PHONE_MESSAGE.name())); |
144 | 144 | if (messageTemplates.isEmpty()) { |
145 | - throw new DataValidationException("no sms provider config"); | |
145 | + throw new YtDataValidationException("no sms provider config"); | |
146 | 146 | } |
147 | 147 | String code = RandomStringUtils.randomNumeric(6); |
148 | 148 | LinkedHashMap<String, String> params = new LinkedHashMap<>(); | ... | ... |
... | ... | @@ -3,13 +3,12 @@ package org.thingsboard.server.dao.yunteng.impl; |
3 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
4 | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | 5 | import lombok.RequiredArgsConstructor; |
6 | -import org.apache.commons.lang3.RandomStringUtils; | |
7 | 6 | import org.apache.commons.lang3.StringUtils; |
8 | 7 | import org.springframework.beans.BeanUtils; |
9 | 8 | import org.springframework.stereotype.Service; |
10 | 9 | import org.springframework.transaction.annotation.Transactional; |
11 | 10 | import org.thingsboard.server.common.data.id.EntityId; |
12 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
13 | 12 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
14 | 13 | import org.thingsboard.server.common.data.yunteng.dto.TenantDTO; |
15 | 14 | import org.thingsboard.server.common.data.yunteng.dto.request.TenantReqDTO; |
... | ... | @@ -42,10 +41,8 @@ public class YtTenantServiceImpl extends AbstractBaseService<TenantMapper, Tenan |
42 | 41 | public TenantDTO createNewTenant(TenantReqDTO tenantReqDTO) { |
43 | 42 | TenantDTO tenantDTO = new TenantDTO(); |
44 | 43 | BeanUtils.copyProperties(tenantReqDTO, tenantDTO); |
45 | - processTenantId(tenantDTO); | |
46 | 44 | Tenant tenant = tenantDTO.getEntity(Tenant.class); |
47 | 45 | baseMapper.insert(tenant); |
48 | - // 调用TB API | |
49 | 46 | tenant.copyToDTO(tenantDTO); |
50 | 47 | saveTenantMapping(tenantDTO.getTenantId(), tenantReqDTO.getRoleIds()); |
51 | 48 | return tenantDTO; |
... | ... | @@ -75,31 +72,12 @@ public class YtTenantServiceImpl extends AbstractBaseService<TenantMapper, Tenan |
75 | 72 | } |
76 | 73 | }); |
77 | 74 | } |
78 | - | |
79 | - private void processTenantId(TenantDTO tenantDTO) { | |
80 | - if (tenantDTO.getTenantId() != null) { | |
81 | - if (tenantDTO.getTenantId().length() > 30) { | |
82 | - throw new DataValidationException("tenant code too long"); | |
83 | - } | |
84 | - int count = | |
85 | - baseMapper.selectCount( | |
86 | - new QueryWrapper<Tenant>() | |
87 | - .lambda() | |
88 | - .eq(Tenant::getTenantId, tenantDTO.getTenantId())); | |
89 | - if (count > 0) { | |
90 | - throw new DataValidationException("tenant code already exist"); | |
91 | - } | |
92 | - } else { | |
93 | - tenantDTO.setTenantId(RandomStringUtils.randomAlphabetic(20)); | |
94 | - } | |
95 | - } | |
96 | - | |
97 | 75 | @Override |
98 | 76 | @Transactional |
99 | 77 | public TenantDTO updateTenant(TenantDTO tenantDTO) { |
100 | 78 | Tenant tenant = baseMapper.selectById(tenantDTO.getId()); |
101 | 79 | if (tenant == null) { |
102 | - throw new DataValidationException("tenant does not exist"); | |
80 | + throw new YtDataValidationException("tenant does not exist"); | |
103 | 81 | } |
104 | 82 | String existTenantId = tenant.getTenantId(); |
105 | 83 | tenantDTO.copyToEntity(tenant); |
... | ... | @@ -187,7 +165,7 @@ public class YtTenantServiceImpl extends AbstractBaseService<TenantMapper, Tenan |
187 | 165 | @Override |
188 | 166 | public List<String> getTenantRolesByTenantId(String tenantId) { |
189 | 167 | if(StringUtils.isEmpty(tenantId)){ |
190 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
168 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
191 | 169 | } |
192 | 170 | List<String> roles = new ArrayList<>(); |
193 | 171 | List<TenantRole> tenantRoleList = tenantRoleMapper | ... | ... |
... | ... | @@ -17,8 +17,7 @@ import org.springframework.transaction.annotation.Transactional; |
17 | 17 | import org.springframework.util.Assert; |
18 | 18 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
19 | 19 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; |
20 | -import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
21 | -import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
20 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
22 | 21 | import org.thingsboard.server.common.data.yunteng.core.exception.NoneTenantAssetException; |
23 | 22 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
24 | 23 | import org.thingsboard.server.common.data.yunteng.dto.*; |
... | ... | @@ -78,15 +77,15 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
78 | 77 | public UserDTO saveAccount(UserDTO userDTO, boolean sendEmail, boolean sendMsg,boolean isPtSysadmin,String tenantId) { |
79 | 78 | boolean isAdminOperate = isPtSysadmin; |
80 | 79 | if (StringUtils.isAllBlank(userDTO.getUsername())) { |
81 | - throw new DataValidationException("username is required"); | |
80 | + throw new YtDataValidationException("username is required"); | |
82 | 81 | } |
83 | 82 | validatePhoneNumberAndEmail(userDTO); |
84 | 83 | if (sendMsg && StringUtils.isAllBlank(userDTO.getPhoneNumber())) { |
85 | - throw new DataValidationException( | |
84 | + throw new YtDataValidationException( | |
86 | 85 | "you must specify user phone number if you want send activate email to this user"); |
87 | 86 | } |
88 | 87 | if (sendEmail && StringUtils.isAllBlank(userDTO.getEmail())) { |
89 | - throw new DataValidationException( | |
88 | + throw new YtDataValidationException( | |
90 | 89 | "you must specify user email if you want send activate email to this user"); |
91 | 90 | } |
92 | 91 | User user = new User(); |
... | ... | @@ -106,7 +105,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
106 | 105 | .lambda() |
107 | 106 | .eq(Tenant::getTenantId, userDTO.getTenantId())); |
108 | 107 | if (tenantExist == 0) { |
109 | - throw new DataValidationException("tenant must exist"); | |
108 | + throw new YtDataValidationException("tenant must exist"); | |
110 | 109 | } |
111 | 110 | } else { |
112 | 111 | // 添加的平台系统其他用户 |
... | ... | @@ -132,7 +131,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
132 | 131 | > 0; |
133 | 132 | } |
134 | 133 | if (userExist) { |
135 | - throw new DataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | |
134 | + throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | |
136 | 135 | } else { |
137 | 136 | baseMapper.insert(user); |
138 | 137 | for (String roleId : userDTO.getRoleIds()) { |
... | ... | @@ -152,17 +151,17 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
152 | 151 | private void validatePhoneNumberAndEmail(UserDTO userDTO) { |
153 | 152 | if (StringUtils.isNotBlank(userDTO.getPhoneNumber())) { |
154 | 153 | if (!CHINA_MOBILE_PATTERN.matcher(userDTO.getPhoneNumber()).matches()) { |
155 | - throw new DataValidationException(ErrorMessage.PROVIDE_CORRECT_PHONE_NUMBER.getMessage()); | |
154 | + throw new YtDataValidationException(ErrorMessage.PROVIDE_CORRECT_PHONE_NUMBER.getMessage()); | |
156 | 155 | } |
157 | 156 | } |
158 | 157 | if (StringUtils.isNotBlank(userDTO.getEmail())) { |
159 | 158 | if (!EMAIL_PATTERN.matcher(userDTO.getEmail()).matches()) { |
160 | - throw new DataValidationException(ErrorMessage.PROVIDE_CORRECT_EMAIL.getMessage()); | |
159 | + throw new YtDataValidationException(ErrorMessage.PROVIDE_CORRECT_EMAIL.getMessage()); | |
161 | 160 | } |
162 | 161 | } |
163 | 162 | if (StringUtils.isAllBlank(userDTO.getEmail()) |
164 | 163 | && StringUtils.isAllBlank(userDTO.getPhoneNumber())) { |
165 | - throw new DataValidationException(ErrorMessage.PHONE_NUMBER_OR_EMAIL_REQUIRED.getMessage()); | |
164 | + throw new YtDataValidationException(ErrorMessage.PHONE_NUMBER_OR_EMAIL_REQUIRED.getMessage()); | |
166 | 165 | } |
167 | 166 | } |
168 | 167 | |
... | ... | @@ -175,7 +174,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
175 | 174 | "you don't have permission to get activation link for this user"); |
176 | 175 | } |
177 | 176 | if (StringUtils.isAllBlank(user.getActivateToken())) { |
178 | - throw new DataValidationException("user already activated"); | |
177 | + throw new YtDataValidationException("user already activated"); | |
179 | 178 | } |
180 | 179 | try { |
181 | 180 | List<AdminSetting> generalSetting = |
... | ... | @@ -243,7 +242,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
243 | 242 | throw new NoneTenantAssetException("this user not belong to current tenant"); |
244 | 243 | } |
245 | 244 | if (!user.getUsername().equals(userDTO.getUsername())) { |
246 | - throw new DataValidationException("username is immutable"); | |
245 | + throw new YtDataValidationException("username is immutable"); | |
247 | 246 | } |
248 | 247 | validatePhoneNumberAndEmail(userDTO); |
249 | 248 | user.setRealName(userDTO.getRealName()); |
... | ... | @@ -271,7 +270,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
271 | 270 | if (isPtSysadmin) { |
272 | 271 | String roleType = (String) queryMap.get("roleType"); |
273 | 272 | if (StringUtils.isEmpty(roleType)) { |
274 | - roleType = RoleEnum.ROLE_PLATFORM_ADMIN.name(); | |
273 | + roleType = RoleEnum.PLATFORM_ADMIN.name(); | |
275 | 274 | } |
276 | 275 | userPage = |
277 | 276 | baseMapper.getAdminUserPage( |
... | ... | @@ -358,7 +357,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
358 | 357 | baseMapper.selectList( |
359 | 358 | new QueryWrapper<User>().lambda().eq(User::getUsername, userDTO.getUsername())); |
360 | 359 | if (!users.isEmpty()) { |
361 | - throw new DataValidationException("用户已存在"); | |
360 | + throw new YtDataValidationException("用户已存在"); | |
362 | 361 | } |
363 | 362 | baseMapper.insert(user); |
364 | 363 | List<TenantRole> tenantRoleList = |
... | ... | @@ -368,7 +367,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
368 | 367 | .eq(TenantRole::getTenantId, userDTO.getTenantId())); |
369 | 368 | // 保存用户与角色的映射信息 |
370 | 369 | if (null == tenantRoleList || tenantRoleList.size() == 0) { |
371 | - throw new FastIotException(ErrorMessage.INVALID_PARAMETER); | |
370 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
372 | 371 | } |
373 | 372 | for (TenantRole tenantRole : tenantRoleList) { |
374 | 373 | roleMapper.saveUserRoleMapping(user.getId(), tenantRole.getRoleId()); |
... | ... | @@ -405,7 +404,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
405 | 404 | // 通过用户ID查询用户信息 |
406 | 405 | User user = baseMapper.selectById(msg.getUserId()); |
407 | 406 | if (null == user) { |
408 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
407 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
409 | 408 | } |
410 | 409 | |
411 | 410 | // 通过模板用途和状态查询模板信息 |
... | ... | @@ -417,7 +416,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
417 | 416 | List<MessageTemplateDTO> templateDTOList = |
418 | 417 | messageTemplateService.findMessageTemplate(messageTemplateDTO); |
419 | 418 | if (null == templateDTOList || templateDTOList.size() < 1) { |
420 | - throw new DataValidationException(ErrorMessage.EXIST_ENABLE_TEMPLATE.getMessage()); | |
419 | + throw new YtDataValidationException(ErrorMessage.EXIST_ENABLE_TEMPLATE.getMessage()); | |
421 | 420 | } |
422 | 421 | if (messageType.equalsIgnoreCase(MessageTypeEnum.PHONE_MESSAGE.name())) { |
423 | 422 | SmsReqDTO smsReqDTO = new SmsReqDTO(); |
... | ... | @@ -454,7 +453,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
454 | 453 | public String[] getUserRoleOrOrganization(RoleOrOrganizationReqDTO roleOrGroupReqDTO) { |
455 | 454 | String userId = roleOrGroupReqDTO.getUserId(); |
456 | 455 | if (StringUtils.isEmpty(userId)) { |
457 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
456 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
458 | 457 | } |
459 | 458 | if (roleOrGroupReqDTO.isQueryRole()) { |
460 | 459 | List<String> roleIds = |
... | ... | @@ -487,13 +486,13 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
487 | 486 | if (null == user |
488 | 487 | || StringUtils.isEmpty(accountReqDTO.getPassword()) |
489 | 488 | || StringUtils.isEmpty(accountReqDTO.getResetPassword())) { |
490 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
489 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
491 | 490 | } |
492 | 491 | if (!StringUtils.isEmpty(user.getPassword())) { |
493 | 492 | // 判断用户密码是否正确 |
494 | 493 | boolean isMatch = passwordEncoder.matches(accountReqDTO.getPassword(), user.getPassword()); |
495 | 494 | if (!isMatch) { |
496 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
495 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
497 | 496 | } |
498 | 497 | } |
499 | 498 | // 修改密码 |
... | ... | @@ -505,7 +504,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
505 | 504 | @Override |
506 | 505 | public UserDTO accountExist(String userName,String tenantId) { |
507 | 506 | if (StringUtils.isEmpty(userName)) { |
508 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
507 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
509 | 508 | } |
510 | 509 | UserDTO userDTO = new UserDTO(); |
511 | 510 | userDTO.setTenantId(tenantId); | ... | ... |