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 | 113 | DeviceProfile deviceProfile; |
114 | 114 | if (deviceCredentials.getCredentialsType() == DeviceCredentialsType.LWM2M_CREDENTIALS) { |
115 | 115 | deviceProfile = setUpLwM2mDeviceProfile(user.getTenantId(), device); |
116 | - } else { | |
116 | + } else if (StringUtils.isNotEmpty(device.getType())) { | |
117 | 117 | deviceProfile = deviceProfileService.findOrCreateDeviceProfile(user.getTenantId(), device.getType()); |
118 | + } else { | |
119 | + deviceProfile = deviceProfileService.findDefaultDeviceProfile(user.getTenantId()); | |
118 | 120 | } |
119 | 121 | device.setDeviceProfileId(deviceProfile.getId()); |
120 | 122 | ... | ... |
... | ... | @@ -23,6 +23,8 @@ import lombok.RequiredArgsConstructor; |
23 | 23 | import lombok.SneakyThrows; |
24 | 24 | import org.apache.commons.lang3.StringUtils; |
25 | 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 | 28 | import org.thingsboard.common.util.DonAsynchron; |
27 | 29 | import org.thingsboard.common.util.ThingsBoardThreadFactory; |
28 | 30 | import org.thingsboard.server.cluster.TbClusterService; |
... | ... | @@ -93,7 +95,11 @@ public abstract class AbstractBulkImportService<E extends BaseData<? extends Ent |
93 | 95 | BulkImportResult<E> result = new BulkImportResult<>(); |
94 | 96 | CountDownLatch completionLatch = new CountDownLatch(entitiesData.size()); |
95 | 97 | |
98 | + SecurityContext securityContext = SecurityContextHolder.getContext(); | |
99 | + | |
96 | 100 | entitiesData.forEach(entityData -> DonAsynchron.submit(() -> { |
101 | + SecurityContextHolder.setContext(securityContext); | |
102 | + | |
97 | 103 | ImportedEntityInfo<E> importedEntityInfo = saveEntity(request, entityData.getFields(), user); |
98 | 104 | E entity = importedEntityInfo.getEntity(); |
99 | 105 | ... | ... |