Commit f9d1f1a1ee046773ce28218c63455631c686390f
1 parent
b5983c7c
fix: 创建和编辑事务问题修复
1、创建设备时设备凭证已被使用,事务问题修复 2、创建租户时创建规则链失败,事务问题修复
Showing
4 changed files
with
9 additions
and
20 deletions
@@ -38,6 +38,7 @@ import org.thingsboard.server.dao.yunteng.service.TkUserService; | @@ -38,6 +38,7 @@ import org.thingsboard.server.dao.yunteng.service.TkUserService; | ||
38 | import org.thingsboard.server.service.install.InstallScripts; | 38 | import org.thingsboard.server.service.install.InstallScripts; |
39 | import org.thingsboard.server.service.security.permission.Operation; | 39 | import org.thingsboard.server.service.security.permission.Operation; |
40 | 40 | ||
41 | +import java.io.IOException; | ||
41 | import java.net.URI; | 42 | import java.net.URI; |
42 | import java.util.HashMap; | 43 | import java.util.HashMap; |
43 | import java.util.List; | 44 | import java.util.List; |
@@ -212,7 +213,7 @@ public class TkAdminController extends BaseController { | @@ -212,7 +213,7 @@ public class TkAdminController extends BaseController { | ||
212 | @Transactional | 213 | @Transactional |
213 | public TenantDTO updateOrCreateTenant( | 214 | public TenantDTO updateOrCreateTenant( |
214 | @Validated(UpdateGroup.class) @RequestBody TenantReqDTO tenantReqDTO) | 215 | @Validated(UpdateGroup.class) @RequestBody TenantReqDTO tenantReqDTO) |
215 | - throws ThingsboardException { | 216 | + throws ThingsboardException, IOException { |
216 | updateOrSaveTenant(tenantReqDTO); | 217 | updateOrSaveTenant(tenantReqDTO); |
217 | return tkTenantService.updateOrCreateTenant(tenantReqDTO); | 218 | return tkTenantService.updateOrCreateTenant(tenantReqDTO); |
218 | } | 219 | } |
@@ -252,8 +253,7 @@ public class TkAdminController extends BaseController { | @@ -252,8 +253,7 @@ public class TkAdminController extends BaseController { | ||
252 | } | 253 | } |
253 | } | 254 | } |
254 | 255 | ||
255 | - private void updateOrSaveTenant(TenantReqDTO tenantReqDTO) throws ThingsboardException { | ||
256 | - try { | 256 | + private void updateOrSaveTenant(TenantReqDTO tenantReqDTO) throws IOException { |
257 | boolean isCreate = tenantReqDTO.getTenantId() == null; | 257 | boolean isCreate = tenantReqDTO.getTenantId() == null; |
258 | Tenant tbTenant; | 258 | Tenant tbTenant; |
259 | if (isCreate) { | 259 | if (isCreate) { |
@@ -276,9 +276,6 @@ public class TkAdminController extends BaseController { | @@ -276,9 +276,6 @@ public class TkAdminController extends BaseController { | ||
276 | tbTenant.getId(), | 276 | tbTenant.getId(), |
277 | isCreate ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | 277 | isCreate ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); |
278 | tenantReqDTO.setTenantId(tbTenant.getTenantId().toString()); | 278 | tenantReqDTO.setTenantId(tbTenant.getTenantId().toString()); |
279 | - } catch (Exception e) { | ||
280 | - throw handleException(e); | ||
281 | - } | ||
282 | } | 279 | } |
283 | 280 | ||
284 | private void deleteTenant(String strTenantId) throws ThingsboardException { | 281 | private void deleteTenant(String strTenantId) throws ThingsboardException { |
@@ -147,7 +147,6 @@ public class TkDeviceController extends BaseController { | @@ -147,7 +147,6 @@ public class TkDeviceController extends BaseController { | ||
147 | tbClusterService.onDeviceUpdated(savedDevice, oldDevice); | 147 | tbClusterService.onDeviceUpdated(savedDevice, oldDevice); |
148 | DeviceId tbDeviceId = savedDevice.getId(); | 148 | DeviceId tbDeviceId = savedDevice.getId(); |
149 | DeviceCredentials deviceCredentials = null; | 149 | DeviceCredentials deviceCredentials = null; |
150 | - try { | ||
151 | logEntityAction( | 150 | logEntityAction( |
152 | getCurrentUser(), | 151 | getCurrentUser(), |
153 | savedDevice.getId(), | 152 | savedDevice.getId(), |
@@ -185,17 +184,6 @@ public class TkDeviceController extends BaseController { | @@ -185,17 +184,6 @@ public class TkDeviceController extends BaseController { | ||
185 | null, | 184 | null, |
186 | deviceCredentials); | 185 | deviceCredentials); |
187 | } | 186 | } |
188 | - } catch (Exception e) { | ||
189 | - logEntityAction( | ||
190 | - emptyId(EntityType.DEVICE), | ||
191 | - null, | ||
192 | - null, | ||
193 | - ActionType.CREDENTIALS_UPDATED, | ||
194 | - e, | ||
195 | - deviceCredentials); | ||
196 | - deleteTbDevice(tbDeviceId.getId().toString()); | ||
197 | - throw handleException(e); | ||
198 | - } | ||
199 | return tbDeviceId; | 187 | return tbDeviceId; |
200 | } | 188 | } |
201 | 189 |
@@ -103,6 +103,7 @@ public enum ErrorMessage { | @@ -103,6 +103,7 @@ public enum ErrorMessage { | ||
103 | DEVICE_IDENTIFIER_REPEATED(400079,"设备地址码或标识码【%s】与设备【%s】重复"), | 103 | DEVICE_IDENTIFIER_REPEATED(400079,"设备地址码或标识码【%s】与设备【%s】重复"), |
104 | CURRENT_DATA_IN_USE(400080,"当前数据正在被【%s】使用,不能被禁用"), | 104 | CURRENT_DATA_IN_USE(400080,"当前数据正在被【%s】使用,不能被禁用"), |
105 | REPORT_NAME_ERROR(400081,"报表配置的名称包含斜杠或反斜杠!!!"), | 105 | REPORT_NAME_ERROR(400081,"报表配置的名称包含斜杠或反斜杠!!!"), |
106 | + DEVICE_CREDENTIALS_ASSIGNED(400082,"设备凭证【%s】已分配给其它设备!"), | ||
106 | HAVE_NO_PERMISSION(500002,"没有修改权限"); | 107 | HAVE_NO_PERMISSION(500002,"没有修改权限"); |
107 | private final int code; | 108 | private final int code; |
108 | private String message; | 109 | private String message; |
@@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.Device; | @@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.Device; | ||
21 | import org.thingsboard.server.common.data.StringUtils; | 21 | import org.thingsboard.server.common.data.StringUtils; |
22 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 23 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
24 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
24 | import org.thingsboard.server.dao.device.DeviceCredentialsDao; | 25 | import org.thingsboard.server.dao.device.DeviceCredentialsDao; |
25 | import org.thingsboard.server.dao.device.DeviceService; | 26 | import org.thingsboard.server.dao.device.DeviceService; |
26 | import org.thingsboard.server.dao.exception.DeviceCredentialsValidationException; | 27 | import org.thingsboard.server.dao.exception.DeviceCredentialsValidationException; |
@@ -41,7 +42,8 @@ public class DeviceCredentialsDataValidator extends DataValidator<DeviceCredenti | @@ -41,7 +42,8 @@ public class DeviceCredentialsDataValidator extends DataValidator<DeviceCredenti | ||
41 | throw new DeviceCredentialsValidationException("Credentials for this device are already specified!"); | 42 | throw new DeviceCredentialsValidationException("Credentials for this device are already specified!"); |
42 | } | 43 | } |
43 | if (deviceCredentialsDao.findByCredentialsId(tenantId, deviceCredentials.getCredentialsId()) != null) { | 44 | if (deviceCredentialsDao.findByCredentialsId(tenantId, deviceCredentials.getCredentialsId()) != null) { |
44 | - throw new DeviceCredentialsValidationException("Device credentials are already assigned to another device!"); | 45 | + throw new DeviceCredentialsValidationException( |
46 | + String.format(ErrorMessage.DEVICE_CREDENTIALS_ASSIGNED.getMessage(),deviceCredentials.getCredentialsValue()==null?deviceCredentials.getCredentialsId():deviceCredentials.getCredentialsValue())); | ||
45 | } | 47 | } |
46 | } | 48 | } |
47 | 49 | ||
@@ -52,7 +54,8 @@ public class DeviceCredentialsDataValidator extends DataValidator<DeviceCredenti | @@ -52,7 +54,8 @@ public class DeviceCredentialsDataValidator extends DataValidator<DeviceCredenti | ||
52 | } | 54 | } |
53 | DeviceCredentials existingCredentials = deviceCredentialsDao.findByCredentialsId(tenantId, deviceCredentials.getCredentialsId()); | 55 | DeviceCredentials existingCredentials = deviceCredentialsDao.findByCredentialsId(tenantId, deviceCredentials.getCredentialsId()); |
54 | if (existingCredentials != null && !existingCredentials.getId().equals(deviceCredentials.getId())) { | 56 | if (existingCredentials != null && !existingCredentials.getId().equals(deviceCredentials.getId())) { |
55 | - throw new DeviceCredentialsValidationException("Device credentials are already assigned to another device!"); | 57 | + throw new DeviceCredentialsValidationException( |
58 | + String.format(ErrorMessage.DEVICE_CREDENTIALS_ASSIGNED.getMessage(),deviceCredentials.getCredentialsValue()==null?deviceCredentials.getCredentialsId():deviceCredentials.getCredentialsValue())); | ||
56 | } | 59 | } |
57 | } | 60 | } |
58 | 61 |