Commit fea2f8799ed2a86b062e038c3013aa1ebc3b57b3
Committed by
Andrew Shvayka
1 parent
287e4bbb
improvements
Showing
16 changed files
with
58 additions
and
98 deletions
@@ -595,11 +595,11 @@ public abstract class BaseController { | @@ -595,11 +595,11 @@ public abstract class BaseController { | ||
595 | case ALARM_CLEAR: | 595 | case ALARM_CLEAR: |
596 | msgType = DataConstants.ALARM_CLEAR; | 596 | msgType = DataConstants.ALARM_CLEAR; |
597 | break; | 597 | break; |
598 | - case SWAPPED_FROM_TENANT: | ||
599 | - msgType = DataConstants.ENTITY_SWAPPED_FROM; | 598 | + case ASSIGNED_FROM_TENANT: |
599 | + msgType = DataConstants.ENTITY_ASSIGNED_FROM_TENANT; | ||
600 | break; | 600 | break; |
601 | - case SWAPPED_TO_TENANT: | ||
602 | - msgType = DataConstants.ENTITY_SWAPPED_TO; | 601 | + case ASSIGNED_TO_TENANT: |
602 | + msgType = DataConstants.ENTITY_ASSIGNED_TO_TENANT; | ||
603 | break; | 603 | break; |
604 | } | 604 | } |
605 | if (!StringUtils.isEmpty(msgType)) { | 605 | if (!StringUtils.isEmpty(msgType)) { |
@@ -620,16 +620,16 @@ public abstract class BaseController { | @@ -620,16 +620,16 @@ public abstract class BaseController { | ||
620 | String strCustomerName = extractParameter(String.class, 2, additionalInfo); | 620 | String strCustomerName = extractParameter(String.class, 2, additionalInfo); |
621 | metaData.putValue("unassignedCustomerId", strCustomerId); | 621 | metaData.putValue("unassignedCustomerId", strCustomerId); |
622 | metaData.putValue("unassignedCustomerName", strCustomerName); | 622 | metaData.putValue("unassignedCustomerName", strCustomerName); |
623 | - } else if (actionType == ActionType.SWAPPED_FROM_TENANT) { | 623 | + } else if (actionType == ActionType.ASSIGNED_FROM_TENANT) { |
624 | String strTenantId = extractParameter(String.class, 0, additionalInfo); | 624 | String strTenantId = extractParameter(String.class, 0, additionalInfo); |
625 | String strTenantName = extractParameter(String.class, 1, additionalInfo); | 625 | String strTenantName = extractParameter(String.class, 1, additionalInfo); |
626 | - metaData.putValue("swappedFromTenantId", strTenantId); | ||
627 | - metaData.putValue("swappedFromTenantName", strTenantName); | ||
628 | - } else if (actionType == ActionType.SWAPPED_TO_TENANT) { | 626 | + metaData.putValue("assignedFromTenantId", strTenantId); |
627 | + metaData.putValue("assignedFromTenantName", strTenantName); | ||
628 | + } else if (actionType == ActionType.ASSIGNED_TO_TENANT) { | ||
629 | String strTenantId = extractParameter(String.class, 0, additionalInfo); | 629 | String strTenantId = extractParameter(String.class, 0, additionalInfo); |
630 | String strTenantName = extractParameter(String.class, 1, additionalInfo); | 630 | String strTenantName = extractParameter(String.class, 1, additionalInfo); |
631 | - metaData.putValue("swappedToTenantId", strTenantId); | ||
632 | - metaData.putValue("swappedToTenantName", strTenantName); | 631 | + metaData.putValue("assignedToTenantId", strTenantId); |
632 | + metaData.putValue("assignedToTenantName", strTenantName); | ||
633 | } | 633 | } |
634 | ObjectNode entityNode; | 634 | ObjectNode entityNode; |
635 | if (entity != null) { | 635 | if (entity != null) { |
@@ -491,13 +491,13 @@ public class DeviceController extends BaseController { | @@ -491,13 +491,13 @@ public class DeviceController extends BaseController { | ||
491 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") | 491 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") |
492 | @RequestMapping(value = "/tenant/{tenantId}/device/{deviceId}", method = RequestMethod.POST) | 492 | @RequestMapping(value = "/tenant/{tenantId}/device/{deviceId}", method = RequestMethod.POST) |
493 | @ResponseBody | 493 | @ResponseBody |
494 | - public Device swapDevice(@PathVariable(TENANT_ID) String strTenantId, | ||
495 | - @PathVariable(DEVICE_ID) String strDeviceId) throws ThingsboardException { | 494 | + public Device assignDeviceToTenant(@PathVariable(TENANT_ID) String strTenantId, |
495 | + @PathVariable(DEVICE_ID) String strDeviceId) throws ThingsboardException { | ||
496 | checkParameter(TENANT_ID, strTenantId); | 496 | checkParameter(TENANT_ID, strTenantId); |
497 | checkParameter(DEVICE_ID, strDeviceId); | 497 | checkParameter(DEVICE_ID, strDeviceId); |
498 | try { | 498 | try { |
499 | DeviceId deviceId = new DeviceId(toUUID(strDeviceId)); | 499 | DeviceId deviceId = new DeviceId(toUUID(strDeviceId)); |
500 | - Device device = checkDeviceId(deviceId, Operation.WRITE); | 500 | + Device device = checkDeviceId(deviceId, Operation.ASSIGN_TO_TENANT); |
501 | 501 | ||
502 | TenantId newTenantId = new TenantId(toUUID(strTenantId)); | 502 | TenantId newTenantId = new TenantId(toUUID(strTenantId)); |
503 | Tenant newTenant = tenantService.findTenantById(newTenantId); | 503 | Tenant newTenant = tenantService.findTenantById(newTenantId); |
@@ -505,36 +505,36 @@ public class DeviceController extends BaseController { | @@ -505,36 +505,36 @@ public class DeviceController extends BaseController { | ||
505 | throw new ThingsboardException("Could not find the specified Tenant!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); | 505 | throw new ThingsboardException("Could not find the specified Tenant!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); |
506 | } | 506 | } |
507 | 507 | ||
508 | - Device swappedDevice = deviceService.swapDevice(newTenantId, device); | 508 | + Device assignedDevice = deviceService.assignDeviceToTenant(newTenantId, device); |
509 | 509 | ||
510 | - logEntityAction(getCurrentUser(), deviceId, swappedDevice, | ||
511 | - swappedDevice.getCustomerId(), | ||
512 | - ActionType.SWAPPED_TO_TENANT, null, strTenantId, newTenant.getName()); | 510 | + logEntityAction(getCurrentUser(), deviceId, assignedDevice, |
511 | + assignedDevice.getCustomerId(), | ||
512 | + ActionType.ASSIGNED_TO_TENANT, null, strTenantId, newTenant.getName()); | ||
513 | 513 | ||
514 | Tenant currentTenant = tenantService.findTenantById(getTenantId()); | 514 | Tenant currentTenant = tenantService.findTenantById(getTenantId()); |
515 | - pushSwappedFromNotification(currentTenant, newTenantId, swappedDevice); | 515 | + pushAssignedFromNotification(currentTenant, newTenantId, assignedDevice); |
516 | 516 | ||
517 | - return swappedDevice; | 517 | + return assignedDevice; |
518 | } catch (Exception e) { | 518 | } catch (Exception e) { |
519 | logEntityAction(getCurrentUser(), emptyId(EntityType.DEVICE), null, | 519 | logEntityAction(getCurrentUser(), emptyId(EntityType.DEVICE), null, |
520 | null, | 520 | null, |
521 | - ActionType.SWAPPED_TO_TENANT, e, strTenantId); | 521 | + ActionType.ASSIGNED_TO_TENANT, e, strTenantId); |
522 | throw handleException(e); | 522 | throw handleException(e); |
523 | } | 523 | } |
524 | } | 524 | } |
525 | 525 | ||
526 | - private void pushSwappedFromNotification(Tenant currentTenant, TenantId newTenantId, Device swappedDevice) { | ||
527 | - String data = entityToStr(swappedDevice); | 526 | + private void pushAssignedFromNotification(Tenant currentTenant, TenantId newTenantId, Device assignedDevice) { |
527 | + String data = entityToStr(assignedDevice); | ||
528 | if (data != null) { | 528 | if (data != null) { |
529 | - TbMsg tbMsg = TbMsg.newMsg(DataConstants.ENTITY_SWAPPED_FROM, swappedDevice.getId(), getMetaDataForSwappedFrom(currentTenant), TbMsgDataType.JSON, data); | ||
530 | - tbClusterService.pushMsgToRuleEngine(newTenantId, swappedDevice.getId(), tbMsg, null); | 529 | + TbMsg tbMsg = TbMsg.newMsg(DataConstants.ENTITY_ASSIGNED_FROM_TENANT, assignedDevice.getId(), getMetaDataForAssignedFrom(currentTenant), TbMsgDataType.JSON, data); |
530 | + tbClusterService.pushMsgToRuleEngine(newTenantId, assignedDevice.getId(), tbMsg, null); | ||
531 | } | 531 | } |
532 | } | 532 | } |
533 | 533 | ||
534 | - private TbMsgMetaData getMetaDataForSwappedFrom(Tenant tenant) { | 534 | + private TbMsgMetaData getMetaDataForAssignedFrom(Tenant tenant) { |
535 | TbMsgMetaData metaData = new TbMsgMetaData(); | 535 | TbMsgMetaData metaData = new TbMsgMetaData(); |
536 | - metaData.putValue("swappedFromTenantId", tenant.getId().getId().toString()); | ||
537 | - metaData.putValue("swappedFromTenantName", tenant.getName()); | 536 | + metaData.putValue("assignedFromTenantId", tenant.getId().getId().toString()); |
537 | + metaData.putValue("assignedFromTenantName", tenant.getName()); | ||
538 | return metaData; | 538 | return metaData; |
539 | } | 539 | } |
540 | } | 540 | } |
@@ -18,6 +18,6 @@ package org.thingsboard.server.service.security.permission; | @@ -18,6 +18,6 @@ package org.thingsboard.server.service.security.permission; | ||
18 | public enum Operation { | 18 | public enum Operation { |
19 | 19 | ||
20 | ALL, CREATE, READ, WRITE, DELETE, ASSIGN_TO_CUSTOMER, UNASSIGN_FROM_CUSTOMER, RPC_CALL, | 20 | ALL, CREATE, READ, WRITE, DELETE, ASSIGN_TO_CUSTOMER, UNASSIGN_FROM_CUSTOMER, RPC_CALL, |
21 | - READ_CREDENTIALS, WRITE_CREDENTIALS, READ_ATTRIBUTES, WRITE_ATTRIBUTES, READ_TELEMETRY, WRITE_TELEMETRY, CLAIM_DEVICES | 21 | + READ_CREDENTIALS, WRITE_CREDENTIALS, READ_ATTRIBUTES, WRITE_ATTRIBUTES, READ_TELEMETRY, WRITE_TELEMETRY, CLAIM_DEVICES, ASSIGN_TO_TENANT |
22 | 22 | ||
23 | } | 23 | } |
@@ -800,7 +800,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -800,7 +800,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
800 | } | 800 | } |
801 | 801 | ||
802 | @Test | 802 | @Test |
803 | - public void testSwapDeviceFromOneTenantToAnother() throws Exception { | 803 | + public void testAssignDeviceToTenant() throws Exception { |
804 | Device device = new Device(); | 804 | Device device = new Device(); |
805 | device.setName("My device"); | 805 | device.setName("My device"); |
806 | device.setType("default"); | 806 | device.setType("default"); |
@@ -816,7 +816,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -816,7 +816,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
816 | relation.setTo(savedAnotherDevice.getId()); | 816 | relation.setTo(savedAnotherDevice.getId()); |
817 | relation.setTypeGroup(RelationTypeGroup.COMMON); | 817 | relation.setTypeGroup(RelationTypeGroup.COMMON); |
818 | relation.setType("Contains"); | 818 | relation.setType("Contains"); |
819 | - doPost("/api/relation", relation); | 819 | + doPost("/api/relation", relation).andExpect(status().isOk()); |
820 | 820 | ||
821 | loginSysAdmin(); | 821 | loginSysAdmin(); |
822 | Tenant tenant = new Tenant(); | 822 | Tenant tenant = new Tenant(); |
@@ -834,13 +834,13 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -834,13 +834,13 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
834 | createUserAndLogin(user, "testPassword1"); | 834 | createUserAndLogin(user, "testPassword1"); |
835 | 835 | ||
836 | login("tenant2@thingsboard.org", "testPassword1"); | 836 | login("tenant2@thingsboard.org", "testPassword1"); |
837 | - Device swappedDevice = doPost("/api/tenant/" + savedDifferentTenant.getId().getId() + "/device/" + savedDevice.getId().getId(), Device.class); | 837 | + Device assignedDevice = doPost("/api/tenant/" + savedDifferentTenant.getId().getId() + "/device/" + savedDevice.getId().getId(), Device.class); |
838 | 838 | ||
839 | - doGet("/api/device/" + swappedDevice.getId().getId().toString(), Device.class, status().isNotFound()); | 839 | + doGet("/api/device/" + assignedDevice.getId().getId().toString(), Device.class, status().isNotFound()); |
840 | 840 | ||
841 | login("tenant9@thingsboard.org", "testPassword1"); | 841 | login("tenant9@thingsboard.org", "testPassword1"); |
842 | 842 | ||
843 | - Device foundDevice1 = doGet("/api/device/" + swappedDevice.getId().getId().toString(), Device.class); | 843 | + Device foundDevice1 = doGet("/api/device/" + assignedDevice.getId().getId().toString(), Device.class); |
844 | Assert.assertNotNull(foundDevice1); | 844 | Assert.assertNotNull(foundDevice1); |
845 | 845 | ||
846 | doGet("/api/relation?fromId=" + savedDevice.getId().getId() + "&fromType=DEVICE&relationType=Contains&toId=" + savedAnotherDevice.getId().getId() + "&toType=DEVICE", EntityRelation.class, status().isNotFound()); | 846 | doGet("/api/relation?fromId=" + savedDevice.getId().getId() + "&fromType=DEVICE&relationType=Contains&toId=" + savedAnotherDevice.getId().getId() + "&toType=DEVICE", EntityRelation.class, status().isNotFound()); |
@@ -47,6 +47,4 @@ public interface AuditLogService { | @@ -47,6 +47,4 @@ public interface AuditLogService { | ||
47 | E entity, | 47 | E entity, |
48 | ActionType actionType, | 48 | ActionType actionType, |
49 | Exception e, Object... additionalInfo); | 49 | Exception e, Object... additionalInfo); |
50 | - | ||
51 | - void removeAuditLogs(TenantId tenantId, EntityId entityId); | ||
52 | } | 50 | } |
@@ -65,6 +65,6 @@ public interface DeviceService { | @@ -65,6 +65,6 @@ public interface DeviceService { | ||
65 | 65 | ||
66 | ListenableFuture<List<EntitySubtype>> findDeviceTypesByTenantId(TenantId tenantId); | 66 | ListenableFuture<List<EntitySubtype>> findDeviceTypesByTenantId(TenantId tenantId); |
67 | 67 | ||
68 | - Device swapDevice(TenantId tenantId, Device device); | 68 | + Device assignDeviceToTenant(TenantId tenantId, Device device); |
69 | 69 | ||
70 | } | 70 | } |
@@ -57,8 +57,8 @@ public class DataConstants { | @@ -57,8 +57,8 @@ public class DataConstants { | ||
57 | public static final String ATTRIBUTES_DELETED = "ATTRIBUTES_DELETED"; | 57 | public static final String ATTRIBUTES_DELETED = "ATTRIBUTES_DELETED"; |
58 | public static final String ALARM_ACK = "ALARM_ACK"; | 58 | public static final String ALARM_ACK = "ALARM_ACK"; |
59 | public static final String ALARM_CLEAR = "ALARM_CLEAR"; | 59 | public static final String ALARM_CLEAR = "ALARM_CLEAR"; |
60 | - public static final String ENTITY_SWAPPED_FROM = "ENTITY_SWAPPED_FROM"; | ||
61 | - public static final String ENTITY_SWAPPED_TO = "ENTITY_SWAPPED_TO"; | 60 | + public static final String ENTITY_ASSIGNED_FROM_TENANT = "ENTITY_ASSIGNED_FROM_TENANT"; |
61 | + public static final String ENTITY_ASSIGNED_TO_TENANT = "ENTITY_ASSIGNED_TO_TENANT"; | ||
62 | 62 | ||
63 | public static final String RPC_CALL_FROM_SERVER_TO_DEVICE = "RPC_CALL_FROM_SERVER_TO_DEVICE"; | 63 | public static final String RPC_CALL_FROM_SERVER_TO_DEVICE = "RPC_CALL_FROM_SERVER_TO_DEVICE"; |
64 | 64 |
@@ -41,8 +41,8 @@ public enum ActionType { | @@ -41,8 +41,8 @@ public enum ActionType { | ||
41 | LOGIN(false), | 41 | LOGIN(false), |
42 | LOGOUT(false), | 42 | LOGOUT(false), |
43 | LOCKOUT(false), | 43 | LOCKOUT(false), |
44 | - SWAPPED_FROM_TENANT(false), | ||
45 | - SWAPPED_TO_TENANT(false); | 44 | + ASSIGNED_FROM_TENANT(false), |
45 | + ASSIGNED_TO_TENANT(false); | ||
46 | 46 | ||
47 | private final boolean isRead; | 47 | private final boolean isRead; |
48 | 48 |
@@ -159,7 +159,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ | @@ -159,7 +159,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ | ||
159 | try { | 159 | try { |
160 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(asset.getTenantId(), assetId).get(); | 160 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(asset.getTenantId(), assetId).get(); |
161 | if (entityViews != null && !entityViews.isEmpty()) { | 161 | if (entityViews != null && !entityViews.isEmpty()) { |
162 | - throw new DataValidationException("Can't delete asset that is assigned to entity views!"); | 162 | + throw new DataValidationException("Can't delete asset that has entity views!"); |
163 | } | 163 | } |
164 | } catch (ExecutionException | InterruptedException e) { | 164 | } catch (ExecutionException | InterruptedException e) { |
165 | log.error("Exception while finding entity views for assetId [{}]", assetId, e); | 165 | log.error("Exception while finding entity views for assetId [{}]", assetId, e); |
@@ -51,8 +51,6 @@ import org.thingsboard.server.dao.service.DataValidator; | @@ -51,8 +51,6 @@ import org.thingsboard.server.dao.service.DataValidator; | ||
51 | 51 | ||
52 | import java.io.PrintWriter; | 52 | import java.io.PrintWriter; |
53 | import java.io.StringWriter; | 53 | import java.io.StringWriter; |
54 | -import java.util.ArrayList; | ||
55 | -import java.util.Arrays; | ||
56 | import java.util.List; | 54 | import java.util.List; |
57 | 55 | ||
58 | import static org.thingsboard.server.dao.service.Validator.validateEntityId; | 56 | import static org.thingsboard.server.dao.service.Validator.validateEntityId; |
@@ -158,25 +156,6 @@ public class AuditLogServiceImpl implements AuditLogService { | @@ -158,25 +156,6 @@ public class AuditLogServiceImpl implements AuditLogService { | ||
158 | } | 156 | } |
159 | } | 157 | } |
160 | 158 | ||
161 | - @Override | ||
162 | - public void removeAuditLogs(TenantId tenantId, EntityId entityId) { | ||
163 | - List<AuditLog> auditLogs = new ArrayList<>(); | ||
164 | - TimePageData<AuditLog> auditLogPageData; | ||
165 | - TimePageLink auditLogPageLink = new TimePageLink(1000); | ||
166 | - do { | ||
167 | - auditLogPageData = findAuditLogsByTenantIdAndEntityId(tenantId, entityId, | ||
168 | - new ArrayList<>(Arrays.asList(ActionType.values())), auditLogPageLink); | ||
169 | - auditLogs.addAll(auditLogPageData.getData()); | ||
170 | - if (auditLogPageData.hasNext()) { | ||
171 | - auditLogPageLink = auditLogPageData.getNextPageLink(); | ||
172 | - } | ||
173 | - } while (auditLogPageData.hasNext()); | ||
174 | - | ||
175 | - for (AuditLog auditLog : auditLogs) { | ||
176 | - auditLogDao.removeById(tenantId, auditLog.getUuidId()); | ||
177 | - } | ||
178 | - } | ||
179 | - | ||
180 | private <E extends HasName, I extends EntityId> JsonNode constructActionData(I entityId, E entity, | 159 | private <E extends HasName, I extends EntityId> JsonNode constructActionData(I entityId, E entity, |
181 | ActionType actionType, | 160 | ActionType actionType, |
182 | Object... additionalInfo) { | 161 | Object... additionalInfo) { |
@@ -187,7 +166,7 @@ public class AuditLogServiceImpl implements AuditLogService { | @@ -187,7 +166,7 @@ public class AuditLogServiceImpl implements AuditLogService { | ||
187 | case ALARM_ACK: | 166 | case ALARM_ACK: |
188 | case ALARM_CLEAR: | 167 | case ALARM_CLEAR: |
189 | case RELATIONS_DELETED: | 168 | case RELATIONS_DELETED: |
190 | - case SWAPPED_TO_TENANT: | 169 | + case ASSIGNED_TO_TENANT: |
191 | if (entity != null) { | 170 | if (entity != null) { |
192 | ObjectNode entityNode = objectMapper.valueToTree(entity); | 171 | ObjectNode entityNode = objectMapper.valueToTree(entity); |
193 | if (entityId.getEntityType() == EntityType.DASHBOARD) { | 172 | if (entityId.getEntityType() == EntityType.DASHBOARD) { |
@@ -58,8 +58,4 @@ public class DummyAuditLogServiceImpl implements AuditLogService { | @@ -58,8 +58,4 @@ public class DummyAuditLogServiceImpl implements AuditLogService { | ||
58 | public <E extends HasName, I extends EntityId> ListenableFuture<List<Void>> logEntityAction(TenantId tenantId, CustomerId customerId, UserId userId, String userName, I entityId, E entity, ActionType actionType, Exception e, Object... additionalInfo) { | 58 | public <E extends HasName, I extends EntityId> ListenableFuture<List<Void>> logEntityAction(TenantId tenantId, CustomerId customerId, UserId userId, String userName, I entityId, E entity, ActionType actionType, Exception e, Object... additionalInfo) { |
59 | return null; | 59 | return null; |
60 | } | 60 | } |
61 | - | ||
62 | - @Override | ||
63 | - public void removeAuditLogs(TenantId tenantId, EntityId entityId) { | ||
64 | - } | ||
65 | } | 61 | } |
@@ -48,7 +48,6 @@ import org.thingsboard.server.common.data.relation.EntityRelation; | @@ -48,7 +48,6 @@ import org.thingsboard.server.common.data.relation.EntityRelation; | ||
48 | import org.thingsboard.server.common.data.relation.EntitySearchDirection; | 48 | import org.thingsboard.server.common.data.relation.EntitySearchDirection; |
49 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 49 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
50 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; | 50 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
51 | -import org.thingsboard.server.dao.audit.AuditLogService; | ||
52 | import org.thingsboard.server.dao.customer.CustomerDao; | 51 | import org.thingsboard.server.dao.customer.CustomerDao; |
53 | import org.thingsboard.server.dao.entity.AbstractEntityService; | 52 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
54 | import org.thingsboard.server.dao.entityview.EntityViewService; | 53 | import org.thingsboard.server.dao.entityview.EntityViewService; |
@@ -104,9 +103,6 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -104,9 +103,6 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
104 | @Autowired | 103 | @Autowired |
105 | private EventService eventService; | 104 | private EventService eventService; |
106 | 105 | ||
107 | - @Autowired | ||
108 | - private AuditLogService auditLogService; | ||
109 | - | ||
110 | @Override | 106 | @Override |
111 | public Device findDeviceById(TenantId tenantId, DeviceId deviceId) { | 107 | public Device findDeviceById(TenantId tenantId, DeviceId deviceId) { |
112 | log.trace("Executing findDeviceById [{}]", deviceId); | 108 | log.trace("Executing findDeviceById [{}]", deviceId); |
@@ -201,7 +197,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -201,7 +197,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
201 | try { | 197 | try { |
202 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), deviceId).get(); | 198 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), deviceId).get(); |
203 | if (entityViews != null && !entityViews.isEmpty()) { | 199 | if (entityViews != null && !entityViews.isEmpty()) { |
204 | - throw new DataValidationException("Can't delete device that is assigned to entity views!"); | 200 | + throw new DataValidationException("Can't delete device that has entity views!"); |
205 | } | 201 | } |
206 | } catch (ExecutionException | InterruptedException e) { | 202 | } catch (ExecutionException | InterruptedException e) { |
207 | log.error("Exception while finding entity views for deviceId [{}]", deviceId, e); | 203 | log.error("Exception while finding entity views for deviceId [{}]", deviceId, e); |
@@ -338,13 +334,13 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -338,13 +334,13 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
338 | @Transactional | 334 | @Transactional |
339 | @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}") | 335 | @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}") |
340 | @Override | 336 | @Override |
341 | - public Device swapDevice(TenantId tenantId, Device device) { | ||
342 | - log.trace("Executing swapDevice [{}]", device); | 337 | + public Device assignDeviceToTenant(TenantId tenantId, Device device) { |
338 | + log.trace("Executing assignDeviceToTenant [{}][{}]", tenantId, device); | ||
343 | 339 | ||
344 | try { | 340 | try { |
345 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), device.getId()).get(); | 341 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), device.getId()).get(); |
346 | if (!CollectionUtils.isEmpty(entityViews)) { | 342 | if (!CollectionUtils.isEmpty(entityViews)) { |
347 | - throw new DataValidationException("Can't swap device that is assigned to entity views!"); | 343 | + throw new DataValidationException("Can't assign device that has entity views to another tenant!"); |
348 | } | 344 | } |
349 | } catch (ExecutionException | InterruptedException e) { | 345 | } catch (ExecutionException | InterruptedException e) { |
350 | log.error("Exception while finding entity views for deviceId [{}]", device.getId(), e); | 346 | log.error("Exception while finding entity views for deviceId [{}]", device.getId(), e); |
@@ -355,11 +351,6 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -355,11 +351,6 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
355 | 351 | ||
356 | relationService.removeRelations(device.getTenantId(), device.getId()); | 352 | relationService.removeRelations(device.getTenantId(), device.getId()); |
357 | 353 | ||
358 | - // TODO: 30/07/2020 implement for Cassandra | ||
359 | - if (sqlDatabaseUsed) { | ||
360 | - auditLogService.removeAuditLogs(device.getTenantId(), device.getId()); | ||
361 | - } | ||
362 | - | ||
363 | device.setTenantId(tenantId); | 354 | device.setTenantId(tenantId); |
364 | device.setCustomerId(null); | 355 | device.setCustomerId(null); |
365 | return doSaveDevice(device, null); | 356 | return doSaveDevice(device, null); |
@@ -28,7 +28,6 @@ import org.thingsboard.server.common.data.page.TimePageLink; | @@ -28,7 +28,6 @@ import org.thingsboard.server.common.data.page.TimePageLink; | ||
28 | import org.thingsboard.server.dao.exception.DataValidationException; | 28 | import org.thingsboard.server.dao.exception.DataValidationException; |
29 | import org.thingsboard.server.dao.service.DataValidator; | 29 | import org.thingsboard.server.dao.service.DataValidator; |
30 | 30 | ||
31 | -import java.util.ArrayList; | ||
32 | import java.util.List; | 31 | import java.util.List; |
33 | import java.util.Optional; | 32 | import java.util.Optional; |
34 | 33 | ||
@@ -97,20 +96,17 @@ public class BaseEventService implements EventService { | @@ -97,20 +96,17 @@ public class BaseEventService implements EventService { | ||
97 | 96 | ||
98 | @Override | 97 | @Override |
99 | public void removeEvents(TenantId tenantId, EntityId entityId) { | 98 | public void removeEvents(TenantId tenantId, EntityId entityId) { |
100 | - List<Event> events = new ArrayList<>(); | ||
101 | TimePageData<Event> eventPageData; | 99 | TimePageData<Event> eventPageData; |
102 | TimePageLink eventPageLink = new TimePageLink(1000); | 100 | TimePageLink eventPageLink = new TimePageLink(1000); |
103 | do { | 101 | do { |
104 | eventPageData = findEvents(tenantId, entityId, eventPageLink); | 102 | eventPageData = findEvents(tenantId, entityId, eventPageLink); |
105 | - events.addAll(eventPageData.getData()); | 103 | + for (Event event : eventPageData.getData()) { |
104 | + eventDao.removeById(tenantId, event.getUuidId()); | ||
105 | + } | ||
106 | if (eventPageData.hasNext()) { | 106 | if (eventPageData.hasNext()) { |
107 | eventPageLink = eventPageData.getNextPageLink(); | 107 | eventPageLink = eventPageData.getNextPageLink(); |
108 | } | 108 | } |
109 | } while (eventPageData.hasNext()); | 109 | } while (eventPageData.hasNext()); |
110 | - | ||
111 | - for (Event event : events) { | ||
112 | - eventDao.removeById(tenantId, event.getUuidId()); | ||
113 | - } | ||
114 | } | 110 | } |
115 | 111 | ||
116 | private DataValidator<Event> eventValidator = | 112 | private DataValidator<Event> eventValidator = |
@@ -35,7 +35,7 @@ import org.thingsboard.server.common.msg.session.SessionMsgType; | @@ -35,7 +35,7 @@ import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
35 | configClazz = EmptyNodeConfiguration.class, | 35 | configClazz = EmptyNodeConfiguration.class, |
36 | relationTypes = {"Post attributes", "Post telemetry", "RPC Request from Device", "RPC Request to Device", "Activity Event", "Inactivity Event", | 36 | relationTypes = {"Post attributes", "Post telemetry", "RPC Request from Device", "RPC Request to Device", "Activity Event", "Inactivity Event", |
37 | "Connect Event", "Disconnect Event", "Entity Created", "Entity Updated", "Entity Deleted", "Entity Assigned", | 37 | "Connect Event", "Disconnect Event", "Entity Created", "Entity Updated", "Entity Deleted", "Entity Assigned", |
38 | - "Entity Unassigned", "Attributes Updated", "Attributes Deleted", "Alarm Acknowledged", "Alarm Cleared", "Other", "Entity Swapped From", "Entity Swapped To"}, | 38 | + "Entity Unassigned", "Attributes Updated", "Attributes Deleted", "Alarm Acknowledged", "Alarm Cleared", "Other", "Entity Assigned From Tenant", "Entity Assigned To Tenant"}, |
39 | nodeDescription = "Route incoming messages by Message Type", | 39 | nodeDescription = "Route incoming messages by Message Type", |
40 | nodeDetails = "Sends messages with message types <b>\"Post attributes\", \"Post telemetry\", \"RPC Request\"</b> etc. via corresponding chain, otherwise <b>Other</b> chain is used.", | 40 | nodeDetails = "Sends messages with message types <b>\"Post attributes\", \"Post telemetry\", \"RPC Request\"</b> etc. via corresponding chain, otherwise <b>Other</b> chain is used.", |
41 | uiResources = {"static/rulenode/rulenode-core-config.js"}, | 41 | uiResources = {"static/rulenode/rulenode-core-config.js"}, |
@@ -86,10 +86,10 @@ public class TbMsgTypeSwitchNode implements TbNode { | @@ -86,10 +86,10 @@ public class TbMsgTypeSwitchNode implements TbNode { | ||
86 | relationType = "Alarm Cleared"; | 86 | relationType = "Alarm Cleared"; |
87 | } else if (msg.getType().equals(DataConstants.RPC_CALL_FROM_SERVER_TO_DEVICE)) { | 87 | } else if (msg.getType().equals(DataConstants.RPC_CALL_FROM_SERVER_TO_DEVICE)) { |
88 | relationType = "RPC Request to Device"; | 88 | relationType = "RPC Request to Device"; |
89 | - } else if (msg.getType().equals(DataConstants.ENTITY_SWAPPED_FROM)) { | ||
90 | - relationType = "Entity Swapped From"; | ||
91 | - } else if (msg.getType().equals(DataConstants.ENTITY_SWAPPED_TO)) { | ||
92 | - relationType = "Entity Swapped To"; | 89 | + } else if (msg.getType().equals(DataConstants.ENTITY_ASSIGNED_FROM_TENANT)) { |
90 | + relationType = "Entity Assigned From Tenant"; | ||
91 | + } else if (msg.getType().equals(DataConstants.ENTITY_ASSIGNED_TO_TENANT)) { | ||
92 | + relationType = "Entity Assigned To Tenant"; | ||
93 | } else { | 93 | } else { |
94 | relationType = "Other"; | 94 | relationType = "Other"; |
95 | } | 95 | } |
@@ -223,11 +223,11 @@ export default angular.module('thingsboard.types', []) | @@ -223,11 +223,11 @@ export default angular.module('thingsboard.types', []) | ||
223 | "LOCKOUT": { | 223 | "LOCKOUT": { |
224 | name: "audit-log.type-lockout" | 224 | name: "audit-log.type-lockout" |
225 | }, | 225 | }, |
226 | - "SWAPPED_FROM_TENANT": { | ||
227 | - name: "audit-log.type-swapped-from-tenant" | 226 | + "ASSIGNED_FROM_TENANT": { |
227 | + name: "audit-log.type-assigned-from-tenant" | ||
228 | }, | 228 | }, |
229 | - "SWAPPED_TO_TENANT": { | ||
230 | - name: "audit-log.type-swapped-to-tenant" | 229 | + "ASSIGNED_TO_TENANT": { |
230 | + name: "audit-log.type-assigned-to-tenant" | ||
231 | } | 231 | } |
232 | }, | 232 | }, |
233 | auditLogActionStatus: { | 233 | auditLogActionStatus: { |
@@ -357,8 +357,8 @@ | @@ -357,8 +357,8 @@ | ||
357 | "failure-details": "Failure details", | 357 | "failure-details": "Failure details", |
358 | "search": "Search audit logs", | 358 | "search": "Search audit logs", |
359 | "clear-search": "Clear search", | 359 | "clear-search": "Clear search", |
360 | - "type-swapped-from-tenant": "Swapped from Tenant", | ||
361 | - "type-swapped-to-tenant": "Swapped to Tenant" | 360 | + "type-assigned-from-tenant": "Assigned from Tenant", |
361 | + "type-assigned-to-tenant": "Assigned to Tenant" | ||
362 | }, | 362 | }, |
363 | "confirm-on-exit": { | 363 | "confirm-on-exit": { |
364 | "message": "You have unsaved changes. Are you sure you want to leave this page?", | 364 | "message": "You have unsaved changes. Are you sure you want to leave this page?", |