Browse Source

Minor refactoring

pull/6357/head
Viacheslav Klimov 5 years ago
parent
commit
428ff2851d
  1. 2
      application/src/main/java/org/thingsboard/server/service/sync/DefaultEntitiesExportImportService.java
  2. 2
      application/src/main/java/org/thingsboard/server/service/sync/exporting/impl/DeviceExportService.java
  3. 10
      application/src/main/java/org/thingsboard/server/service/sync/importing/impl/BaseEntityImportService.java

2
application/src/main/java/org/thingsboard/server/service/sync/DefaultEntitiesExportImportService.java

@ -153,7 +153,7 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
public void checkPermission(SecurityUser user, HasId<? extends EntityId> entity, EntityType entityType, Operation operation) throws ThingsboardException {
if (entity instanceof HasTenantId) {
accessControlService.checkPermission(user, Resource.of(entityType), operation, entity.getId(), (HasTenantId) entity);
} else if (entity != null) {
} else {
accessControlService.checkPermission(user, Resource.of(entityType), operation);
}
}

2
application/src/main/java/org/thingsboard/server/service/sync/exporting/impl/DeviceExportService.java

@ -36,7 +36,7 @@ public class DeviceExportService extends BaseEntityExportService<DeviceId, Devic
@Override
protected void setRelatedEntities(TenantId tenantId, Device device, DeviceExportData exportData) {
exportData.setCredentials(deviceCredentialsService.findDeviceCredentialsByDeviceId(TenantId.SYS_TENANT_ID, device.getId()));
exportData.setCredentials(deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId()));
}
@Override

10
application/src/main/java/org/thingsboard/server/service/sync/importing/impl/BaseEntityImportService.java

@ -100,11 +100,11 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
});
importResult.addSaveReferencesCallback(() -> {
List<EntityRelation> relations = exportData.getRelations();
if (relations == null || !importSettings.isUpdateRelations()) {
if (!importSettings.isUpdateRelations() || exportData.getRelations() == null) {
return;
}
relations = new ArrayList<>(relations);
List<EntityRelation> relations = new ArrayList<>(exportData.getRelations());
for (EntityRelation relation : relations) {
if (!relation.getTo().equals(savedEntity.getId())) {
@ -112,7 +112,7 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
exportableEntitiesService.checkPermission(user, to, to.getId().getEntityType(), Operation.WRITE);
relation.setTo(to.getId());
}
if (!relation.getFrom().equals(savedEntity.getId())){
if (!relation.getFrom().equals(savedEntity.getId())) {
HasId<EntityId> from = findInternalEntity(user.getTenantId(), relation.getFrom());
exportableEntitiesService.checkPermission(user, from, from.getId().getEntityType(), Operation.WRITE);
relation.setFrom(from.getId());
@ -129,7 +129,7 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
EntityId otherEntity = null;
if (!existingRelation.getTo().equals(savedEntity.getId())) {
otherEntity = existingRelation.getTo();
} else if (!existingRelation.getFrom().equals(savedEntity.getId())){
} else if (!existingRelation.getFrom().equals(savedEntity.getId())) {
otherEntity = existingRelation.getFrom();
}
if (otherEntity != null) {

Loading…
Cancel
Save