Commit a852e11a3da348c1e1400f3068821a74865a5ec6
Committed by
Andrew Shvayka
1 parent
e2676f30
Refactor bulk import
Showing
2 changed files
with
9 additions
and
1 deletions
@@ -113,8 +113,10 @@ public class DeviceBulkImportService extends AbstractBulkImportService<Device> { | @@ -113,8 +113,10 @@ public class DeviceBulkImportService extends AbstractBulkImportService<Device> { | ||
113 | DeviceProfile deviceProfile; | 113 | DeviceProfile deviceProfile; |
114 | if (deviceCredentials.getCredentialsType() == DeviceCredentialsType.LWM2M_CREDENTIALS) { | 114 | if (deviceCredentials.getCredentialsType() == DeviceCredentialsType.LWM2M_CREDENTIALS) { |
115 | deviceProfile = setUpLwM2mDeviceProfile(user.getTenantId(), device); | 115 | deviceProfile = setUpLwM2mDeviceProfile(user.getTenantId(), device); |
116 | - } else { | 116 | + } else if (StringUtils.isNotEmpty(device.getType())) { |
117 | deviceProfile = deviceProfileService.findOrCreateDeviceProfile(user.getTenantId(), device.getType()); | 117 | deviceProfile = deviceProfileService.findOrCreateDeviceProfile(user.getTenantId(), device.getType()); |
118 | + } else { | ||
119 | + deviceProfile = deviceProfileService.findDefaultDeviceProfile(user.getTenantId()); | ||
118 | } | 120 | } |
119 | device.setDeviceProfileId(deviceProfile.getId()); | 121 | device.setDeviceProfileId(deviceProfile.getId()); |
120 | 122 |
@@ -23,6 +23,8 @@ import lombok.RequiredArgsConstructor; | @@ -23,6 +23,8 @@ import lombok.RequiredArgsConstructor; | ||
23 | import lombok.SneakyThrows; | 23 | import lombok.SneakyThrows; |
24 | import org.apache.commons.lang3.StringUtils; | 24 | import org.apache.commons.lang3.StringUtils; |
25 | import org.apache.commons.lang3.exception.ExceptionUtils; | 25 | import org.apache.commons.lang3.exception.ExceptionUtils; |
26 | +import org.springframework.security.core.context.SecurityContext; | ||
27 | +import org.springframework.security.core.context.SecurityContextHolder; | ||
26 | import org.thingsboard.common.util.DonAsynchron; | 28 | import org.thingsboard.common.util.DonAsynchron; |
27 | import org.thingsboard.common.util.ThingsBoardThreadFactory; | 29 | import org.thingsboard.common.util.ThingsBoardThreadFactory; |
28 | import org.thingsboard.server.cluster.TbClusterService; | 30 | import org.thingsboard.server.cluster.TbClusterService; |
@@ -93,7 +95,11 @@ public abstract class AbstractBulkImportService<E extends BaseData<? extends Ent | @@ -93,7 +95,11 @@ public abstract class AbstractBulkImportService<E extends BaseData<? extends Ent | ||
93 | BulkImportResult<E> result = new BulkImportResult<>(); | 95 | BulkImportResult<E> result = new BulkImportResult<>(); |
94 | CountDownLatch completionLatch = new CountDownLatch(entitiesData.size()); | 96 | CountDownLatch completionLatch = new CountDownLatch(entitiesData.size()); |
95 | 97 | ||
98 | + SecurityContext securityContext = SecurityContextHolder.getContext(); | ||
99 | + | ||
96 | entitiesData.forEach(entityData -> DonAsynchron.submit(() -> { | 100 | entitiesData.forEach(entityData -> DonAsynchron.submit(() -> { |
101 | + SecurityContextHolder.setContext(securityContext); | ||
102 | + | ||
97 | ImportedEntityInfo<E> importedEntityInfo = saveEntity(request, entityData.getFields(), user); | 103 | ImportedEntityInfo<E> importedEntityInfo = saveEntity(request, entityData.getFields(), user); |
98 | E entity = importedEntityInfo.getEntity(); | 104 | E entity = importedEntityInfo.getEntity(); |
99 | 105 |