Browse Source

Export/import API improvements and refactoring

pull/6357/head
Viacheslav Klimov 5 years ago
parent
commit
19a27f93f4
  1. 275
      application/src/main/java/org/thingsboard/server/controller/EntitiesExportImportController.java
  2. 8
      application/src/main/java/org/thingsboard/server/service/exportimport/DefaultEntitiesExportImportService.java
  3. 2
      application/src/main/java/org/thingsboard/server/service/exportimport/EntitiesExportImportService.java
  4. 2
      application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/AssetExportService.java
  5. 3
      application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/BaseEntityExportService.java
  6. 2
      application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/CustomerExportService.java
  7. 2
      application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/DashboardExportService.java
  8. 3
      application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/DeviceExportService.java
  9. 2
      application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/DeviceProfileExportService.java
  10. 3
      application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/RuleChainExportService.java
  11. 3
      application/src/main/java/org/thingsboard/server/service/exportimport/importing/EntityImportSettings.java
  12. 8
      application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/AssetImportService.java
  13. 65
      application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/BaseEntityImportService.java
  14. 4
      application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/CustomerImportService.java
  15. 46
      application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/DashboardImportService.java
  16. 8
      application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/DeviceImportService.java
  17. 8
      application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/DeviceProfileImportService.java
  18. 57
      application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/RuleChainImportService.java
  19. 2
      dao/src/main/java/org/thingsboard/server/dao/sql/query/DefaultEntityQueryRepository.java
  20. 1
      dao/src/main/java/org/thingsboard/server/dao/sql/query/EntityKeyMapping.java

275
application/src/main/java/org/thingsboard/server/controller/EntitiesExportImportController.java

@ -15,9 +15,7 @@
*/
package org.thingsboard.server.controller;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@ -27,10 +25,11 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.ExportableEntity;
import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
import org.thingsboard.server.common.data.exception.ThingsboardException;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityIdFactory;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.query.EntityData;
import org.thingsboard.server.common.data.query.EntityDataPageLink;
import org.thingsboard.server.common.data.query.EntityDataQuery;
@ -38,169 +37,263 @@ import org.thingsboard.server.common.data.query.EntityDataSortOrder;
import org.thingsboard.server.common.data.query.EntityFilter;
import org.thingsboard.server.common.data.query.EntityKey;
import org.thingsboard.server.common.data.query.EntityKeyType;
import org.thingsboard.server.common.data.query.EntityTypeFilter;
import org.thingsboard.server.common.data.relation.EntityRelation;
import org.thingsboard.server.common.data.relation.RelationTypeGroup;
import org.thingsboard.server.dao.entity.EntityService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.exportimport.EntitiesExportImportService;
import org.thingsboard.server.service.exportimport.ExportableEntitiesService;
import org.thingsboard.server.service.exportimport.exporting.EntityExportSettings;
import org.thingsboard.server.service.exportimport.exporting.data.EntityExportData;
import org.thingsboard.server.service.exportimport.importing.EntityImportResult;
import org.thingsboard.server.service.exportimport.importing.EntityImportSettings;
import org.thingsboard.server.service.query.EntityQueryService;
import org.thingsboard.server.service.security.model.SecurityUser;
import org.thingsboard.server.service.security.permission.Operation;
import org.thingsboard.server.service.security.permission.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
import static org.thingsboard.server.dao.sql.query.EntityKeyMapping.CREATED_TIME;
@RestController
@RequestMapping("/api/entities")
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@TbCoreComponent
@RequiredArgsConstructor
public class EntitiesExportImportController extends BaseController {
private final EntitiesExportImportService exportImportService;
private final EntityQueryService entityQueryService;
private final ExportableEntitiesService exportableEntitiesService;
private final EntityService entityService;
// TODO [viacheslav]: export and import of batches
// TODO [viacheslav]: api to export and import whole customer, whole tenant
@PostMapping("/export/{entityType}/{id}")
public EntityExportData<ExportableEntity<EntityId>> exportSingleEntity(@PathVariable EntityType entityType,
@PathVariable UUID id,
@RequestParam Map<String, String> exportSettingsParams) throws ThingsboardException {
EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, id);
try {
return exportEntity(getTenantId(), entityId, toExportSettings(exportSettingsParams));
} catch (Exception e) {
throw handleException(e);
}
}
@PostMapping("/export/{entityType}/{entityId}")
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
public EntityExportData<?> exportEntity(@ApiParam(allowableValues = "DEVICE, DEVICE_PROFILE, ASSET, RULE_CHAIN, DASHBOARD, CUSTOMER")
@PathVariable EntityType entityType,
@PathVariable("entityId") UUID entityUuid,
@RequestParam(defaultValue = "false") boolean exportInboundRelations) throws ThingsboardException {
EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, entityUuid);
checkEntityId(entityId, Operation.READ);
@PostMapping(value = "/export/{entityType}", params = "ids")
public List<EntityExportData<ExportableEntity<EntityId>>> exportEntitiesByIds(@PathVariable EntityType entityType,
@RequestParam UUID[] ids,
@RequestParam Map<String, String> exportSettingsParams) throws ThingsboardException {
List<EntityId> entitiesIds = Arrays.stream(ids)
.map(id -> EntityIdFactory.getByTypeAndUuid(entityType, id))
.collect(Collectors.toList());
try {
return exportEntitiesByIds(getTenantId(), entitiesIds, toExportSettings(exportSettingsParams));
} catch (Exception e) {
throw handleException(e);
}
}
SecurityUser user = getCurrentUser();
EntityExportSettings exportSettings = toExportSettings(exportInboundRelations);
@PostMapping(value = "/export/{entityType}", params = "ids")
public List<EntityExportData<ExportableEntity<EntityId>>> exportAllEntitiesByEntityType(@PathVariable EntityType entityType,
@RequestParam Map<String, String> exportSettingsParams,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "2147483647") int pageSize,
@RequestParam(name = "customerId", required = false) UUID customerUuid) throws ThingsboardException {
TenantId tenantId = getTenantId();
CustomerId customerId = toCustomerId(customerUuid);
try { // FIXME [viacheslav]: check read permission for relation fromId
return exportImportService.exportEntity(user.getTenantId(), entityId, exportSettings);
EntityTypeFilter entityTypeFilter = new EntityTypeFilter();
entityTypeFilter.setEntityType(entityType);
try {
return exportEntitiesByFilter(tenantId, customerId, entityTypeFilter, page, pageSize, toExportSettings(exportSettingsParams));
} catch (Exception e) {
throw handleException(e);
}
}
@PostMapping("/exportByFilter")
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
public List<EntityExportData<?>> exportEntitiesByFilter(@RequestBody EntityFilter filter, // TODO [viacheslav]: exportInboundRelations, exportOutboundRelations
@RequestParam(defaultValue = "false") boolean exportInboundRelations,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "100") int pageSize) throws ThingsboardException {
EntityDataPageLink pageLink = new EntityDataPageLink();
pageLink.setPage(page);
pageLink.setPageSize(pageSize);
pageLink.setSortOrder(new EntityDataSortOrder(new EntityKey(EntityKeyType.ENTITY_FIELD, CREATED_TIME), EntityDataSortOrder.Direction.DESC));
EntityDataQuery entityDataQuery = new EntityDataQuery(filter, pageLink, List.of(new EntityKey(EntityKeyType.ENTITY_FIELD, CREATED_TIME)),
Collections.emptyList(), Collections.emptyList());
SecurityUser user = getCurrentUser();
EntityExportSettings exportSettings = toExportSettings(exportInboundRelations);
public List<EntityExportData<ExportableEntity<EntityId>>> exportEntitiesByFilter(@RequestBody EntityFilter filter,
@RequestParam Map<String, String> exportSettingsParams,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "2147483647") int pageSize,
@RequestParam(name = "customerId", required = false) UUID customerUuid) throws ThingsboardException {
TenantId tenantId = getTenantId();
CustomerId customerId = toCustomerId(customerUuid);
try {
return exportEntitiesByFilter(tenantId, customerId, filter, page, pageSize, toExportSettings(exportSettingsParams));
} catch (Exception e) {
throw handleException(e);
}
}
// FIXME: too aggressive
@PostMapping("/exportByFilters")
public List<EntityExportData<ExportableEntity<EntityId>>> exportAllEntitiesByFilters(@RequestBody List<EntityFilter> filters,
@RequestParam Map<String, String> exportSettingsParams,
@RequestParam(name = "customerId", required = false) UUID customerUuid) throws ThingsboardException {
TenantId tenantId = getTenantId();
CustomerId customerId = toCustomerId(customerUuid);
try {
// FIXME [viacheslav]: check read permission for relation fromId
return entityQueryService.findEntityDataByQuery(user, entityDataQuery).getData().stream()
.map(EntityData::getEntityId)
.map(entityId -> {
return exportImportService.exportEntity(user.getTenantId(), entityId, exportSettings);
})
.collect(Collectors.toList());
List<EntityExportData<ExportableEntity<EntityId>>> exportDataList = new ArrayList<>();
for (EntityFilter filter : filters) {
exportDataList.addAll(exportEntitiesByFilter(tenantId, customerId, filter, 0, Integer.MAX_VALUE, toExportSettings(exportSettingsParams)));
}
return exportDataList;
} catch (Exception e) {
throw handleException(e);
}
}
@PostMapping("/exportByQuery")
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
public List<EntityExportData<?>> exportEntitiesByQuery(@RequestBody EntityDataQuery query,
@RequestParam(defaultValue = "false") boolean exportInboundRelations) throws ThingsboardException {
SecurityUser user = getCurrentUser();
EntityExportSettings exportSettings = toExportSettings(exportInboundRelations);
// FIXME [viacheslav]: check read permission for relation fromId
public List<EntityExportData<ExportableEntity<EntityId>>> exportEntitiesByQuery(@RequestBody EntityDataQuery entitiesQuery,
@RequestParam Map<String, String> exportSettingsParams,
@RequestParam(name = "customerId", required = false) UUID customerUuid) throws ThingsboardException {
TenantId tenantId = getTenantId();
CustomerId customerId = toCustomerId(customerUuid);
try {
return entityQueryService.findEntityDataByQuery(user, query).getData().stream()
.map(EntityData::getEntityId)
.map(entityId -> exportImportService.exportEntity(user.getTenantId(), entityId, exportSettings))
.collect(Collectors.toList());
return exportEntitiesByQuery(tenantId, customerId, entitiesQuery, toExportSettings(exportSettingsParams));
} catch (Exception e) {
throw handleException(e);
}
}
@PostMapping("/import")
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
public List<EntityImportResult<ExportableEntity<EntityId>>> importEntity(@RequestBody List<EntityExportData<ExportableEntity<EntityId>>> exportDataList,
@RequestParam(defaultValue = "false") boolean importInboundRelations) throws ThingsboardException {
SecurityUser user = getCurrentUser();
EntityImportSettings importSettings = toImportSettings(importInboundRelations);
private List<EntityExportData<ExportableEntity<EntityId>>> exportEntitiesByFilter(TenantId tenantId, CustomerId customerId, EntityFilter filter, int page, int pageSize, EntityExportSettings exportSettings) throws ThingsboardException {
EntityDataPageLink pageLink = new EntityDataPageLink();
pageLink.setPage(page);
pageLink.setPageSize(pageSize);
EntityKey sortProperty = new EntityKey(EntityKeyType.ENTITY_FIELD, CREATED_TIME);
pageLink.setSortOrder(new EntityDataSortOrder(sortProperty, EntityDataSortOrder.Direction.DESC));
for (EntityExportData<ExportableEntity<EntityId>> exportData : exportDataList) {
checkPermissionsForImport(user, exportData, importSettings);
}
EntityDataQuery query = new EntityDataQuery(filter, pageLink, List.of(sortProperty), Collections.emptyList(), Collections.emptyList());
return exportEntitiesByQuery(tenantId, customerId, query, exportSettings);
}
try {
List<EntityImportResult<ExportableEntity<EntityId>>> importResultList = exportImportService.importEntities(user.getTenantId(), exportDataList, importSettings);
importResultList.forEach(entityImportResult -> {
onEntityUpdatedOrCreated(user, entityImportResult.getSavedEntity(), entityImportResult.getOldEntity(), entityImportResult.getOldEntity() == null);
});
return importResultList;
} catch (Exception e) {
throw handleException(e);
private List<EntityExportData<ExportableEntity<EntityId>>> exportEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityDataQuery query, EntityExportSettings exportSettings) throws ThingsboardException {
List<EntityId> entitiesIds = entityService.findEntityDataByQuery(tenantId, customerId, query).getData().stream()
.map(EntityData::getEntityId)
.collect(Collectors.toList());
return exportEntitiesByIds(tenantId, entitiesIds, exportSettings);
}
private List<EntityExportData<ExportableEntity<EntityId>>> exportEntitiesByIds(TenantId tenantId, List<EntityId> entitiesIds, EntityExportSettings exportSettings) throws ThingsboardException {
List<EntityExportData<ExportableEntity<EntityId>>> exportDataList = new ArrayList<>();
for (EntityId entityId : entitiesIds) {
exportDataList.add(exportEntity(tenantId, entityId, exportSettings));
}
return exportDataList;
}
public void checkPermissionsForExport(SecurityUser user, EntityId entityId, EntityExportSettings exportSettings) throws ThingsboardException {
private <E extends ExportableEntity<I>, I extends EntityId> EntityExportData<E> exportEntity(TenantId tenantId, I entityId, EntityExportSettings exportSettings) throws ThingsboardException {
checkEntityId(entityId, Operation.READ);
List<EntityRelation> relations = new LinkedList<>();
if (exportSettings.isExportInboundRelations()) {
for (EntityRelation entityRelation : relationService.findByTo(user.getTenantId(), entityId, RelationTypeGroup.COMMON)) {
EntityId fromId = entityRelation.getFrom();
checkEntityId(fromId, Operation.READ);
relations.addAll(relationService.findByTo(tenantId, entityId, RelationTypeGroup.COMMON));
}
if (exportSettings.isExportOutboundRelations()) {
relations.addAll(relationService.findByFrom(tenantId, entityId, RelationTypeGroup.COMMON));
}
for (EntityRelation relation : relations) {
if (!relation.getFrom().equals(entityId)) {
checkEntityId(relation.getFrom(), Operation.READ);
} else if (!relation.getTo().equals(entityId)) {
checkEntityId(relation.getTo(), Operation.READ);
}
}
return exportImportService.exportEntity(tenantId, entityId, exportSettings);
}
public void checkPermissionsForImport(SecurityUser user, EntityExportData<ExportableEntity<EntityId>> exportData, EntityImportSettings importSettings) throws ThingsboardException {
ExportableEntity<EntityId> existingEntity = exportImportService.findEntityByExternalId(user.getTenantId(), exportData.getMainEntity().getId());
if (existingEntity != null) {
checkEntityId(existingEntity.getId(), Operation.WRITE);
} else {
accessControlService.checkPermission(user, Resource.of(exportData.getEntityType()), Operation.CREATE);
@PostMapping("/import")
public List<EntityImportResult<ExportableEntity<EntityId>>> importEntity(@RequestBody List<EntityExportData<ExportableEntity<EntityId>>> exportDataList,
@RequestParam Map<String, String> importSettingsParams) throws ThingsboardException {
SecurityUser user = getCurrentUser();
EntityImportSettings importSettings = toImportSettings(importSettingsParams);
try {
return importEntities(user, exportDataList, importSettings)
.stream().peek(entityImportResult -> {
onEntityUpdatedOrCreated(user, entityImportResult.getSavedEntity(), entityImportResult.getOldEntity(), entityImportResult.getOldEntity() == null);
})
.collect(Collectors.toList());
} catch (Exception e) {
throw handleException(e);
}
}
if (importSettings.isImportInboundRelations() && CollectionUtils.isNotEmpty(exportData.getInboundRelations())) {
for (EntityRelation entityRelation : exportData.getInboundRelations()) {
ExportableEntity<EntityId> entityFrom = exportImportService.findEntityByExternalId(user.getTenantId(), entityRelation.getFrom());
if (entityFrom != null) {
accessControlService.checkPermission(user, Resource.of(entityFrom.getId().getEntityType()), Operation.WRITE, entityFrom.getId(), entityFrom);
} else {
throw new ThingsboardException("Relation with non-existing entity", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
public List<EntityImportResult<ExportableEntity<EntityId>>> importEntities(SecurityUser user, List<EntityExportData<ExportableEntity<EntityId>>> exportDataList, EntityImportSettings importSettings) throws ThingsboardException {
for (EntityExportData<ExportableEntity<EntityId>> exportData : exportDataList) {
ExportableEntity<EntityId> existingEntity = exportableEntitiesService.findEntityByExternalId(user.getTenantId(), exportData.getMainEntity().getId());
if (existingEntity != null) {
checkEntityId(existingEntity.getId(), Operation.WRITE);
} else {
accessControlService.checkPermission(user, Resource.of(exportData.getEntityType()), Operation.CREATE);
}
List<EntityRelation> relations = new LinkedList<>();
if (importSettings.isImportInboundRelations() && exportData.getInboundRelations() != null) {
relations.addAll(exportData.getInboundRelations());
}
if (importSettings.isImportOutboundRelations() && exportData.getOutboundRelations() != null) {
relations.addAll(exportData.getOutboundRelations());
}
for (EntityRelation relation : relations) {
EntityId otherEntityId = null;
if (!relation.getFrom().equals(exportData.getMainEntity().getId())) {
otherEntityId = relation.getFrom();
} else if (!relation.getTo().equals(exportData.getMainEntity().getId())) {
otherEntityId = relation.getTo();
}
if (otherEntityId != null) {
ExportableEntity<EntityId> otherEntity = exportableEntitiesService.findEntityByExternalId(user.getTenantId(), otherEntityId);
if (otherEntity != null) {
checkEntityId(otherEntity.getId(), Operation.WRITE);
} else {
throw new IllegalArgumentException("Relation is referencing non-existing entity");
}
}
}
}
return exportImportService.importEntities(user.getTenantId(), exportDataList, importSettings);
}
private EntityImportSettings toImportSettings(boolean importInboundRelations) {
return EntityImportSettings.builder()
.importInboundRelations(importInboundRelations)
private EntityExportSettings toExportSettings(Map<String, String> exportSettingsParams) {
return EntityExportSettings.builder()
.exportInboundRelations(getParam(exportSettingsParams, "exportInboundRelations", false, Boolean::parseBoolean))
.exportOutboundRelations(getParam(exportSettingsParams, "exportOutboundRelations", false, Boolean::parseBoolean))
.build();
}
private EntityExportSettings toExportSettings(boolean exportInboundRelations) {
return EntityExportSettings.builder()
.exportInboundRelations(exportInboundRelations)
private EntityImportSettings toImportSettings(Map<String, String> importSettingsParams) {
return EntityImportSettings.builder()
.importInboundRelations(getParam(importSettingsParams, "importInboundRelations", false, Boolean::parseBoolean))
.importOutboundRelations(getParam(importSettingsParams, "importOutboundRelations", false, Boolean::parseBoolean))
.removeExistingRelations(getParam(importSettingsParams, "removeExistingRelations", true, Boolean::parseBoolean))
.updateReferencesToOtherEntities(getParam(importSettingsParams, "updateReferencesToOtherEntities", true, Boolean::parseBoolean))
.build();
}
protected <T> T getParam(Map<String, String> requestParams, String key, T defaultValue, Function<String, T> parsingFunction) {
return parsingFunction.apply(requestParams.getOrDefault(key, defaultValue.toString()));
}
private CustomerId toCustomerId(UUID customerUuid) {
return new CustomerId(Optional.ofNullable(customerUuid).orElse(EntityId.NULL_UUID));
}
}

8
application/src/main/java/org/thingsboard/server/service/exportimport/DefaultEntitiesExportImportService.java

@ -39,10 +39,9 @@ import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
// FIXME [viacheslav]: review packages and classes naming
@Service
@TbCoreComponent
public class DefaultEntitiesExportImportService implements EntitiesExportImportService {
public class DefaultEntitiesExportImportService implements EntitiesExportImportService, ExportableEntitiesService {
private final Map<EntityType, EntityExportService<?, ?, ?>> exportServices = new HashMap<>();
private final Map<EntityType, EntityImportService<?, ?, ?>> importServices = new HashMap<>();
@ -54,8 +53,6 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
);
// TODO [viacheslav]: export and import of the whole tenant
// TODO [viacheslav]: export and import of the whole customer ?
@Override
public <E extends ExportableEntity<I>, I extends EntityId> EntityExportData<E> exportEntity(TenantId tenantId, I entityId, EntityExportSettings exportSettings) {
EntityType entityType = entityId.getEntityType();
@ -65,7 +62,7 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
}
// FIXME [viacheslav]: somehow validate export data
// TODO [viacheslav]: validate export data
@Transactional
@Override
public <E extends ExportableEntity<I>, I extends EntityId> EntityImportResult<E> importEntity(TenantId tenantId, EntityExportData<E> exportData, EntityImportSettings importSettings) {
@ -80,6 +77,7 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
public <E extends ExportableEntity<I>, I extends EntityId> List<EntityImportResult<E>> importEntities(TenantId tenantId, List<EntityExportData<E>> exportDataList, EntityImportSettings importSettings) {
return exportDataList.stream()
.sorted(Comparator.comparing(exportData -> SUPPORTED_ENTITY_TYPES.indexOf(exportData.getEntityType())))
// TODO [viacheslav]: order for rule chains (depending on references)
.map(exportData -> importEntity(tenantId, exportData, importSettings))
.collect(Collectors.toList());
}

2
application/src/main/java/org/thingsboard/server/service/exportimport/EntitiesExportImportService.java

@ -25,7 +25,7 @@ import org.thingsboard.server.service.exportimport.importing.EntityImportSetting
import java.util.List;
public interface EntitiesExportImportService extends ExportableEntitiesService {
public interface EntitiesExportImportService {
<E extends ExportableEntity<I>, I extends EntityId> EntityExportData<E> exportEntity(TenantId tenantId, I entityId, EntityExportSettings exportSettings);

2
application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/AssetExportService.java

@ -24,7 +24,7 @@ import org.thingsboard.server.service.exportimport.exporting.data.AssetExportDat
@Service
@TbCoreComponent
public class AssetExportService extends AbstractEntityExportService<AssetId, Asset, AssetExportData> {
public class AssetExportService extends BaseEntityExportService<AssetId, Asset, AssetExportData> {
@Override
protected AssetExportData newExportData() {

3
application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/AbstractEntityExportService.java → application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/BaseEntityExportService.java

@ -30,14 +30,13 @@ import org.thingsboard.server.service.exportimport.exporting.data.EntityExportDa
import java.util.List;
public abstract class AbstractEntityExportService<I extends EntityId, E extends ExportableEntity<I>, D extends EntityExportData<E>> implements EntityExportService<I, E, D> {
public abstract class BaseEntityExportService<I extends EntityId, E extends ExportableEntity<I>, D extends EntityExportData<E>> implements EntityExportService<I, E, D> {
@Autowired @Lazy
private ExportableEntitiesService exportableEntitiesService;
@Autowired
private RelationService relationService;
@Override
public final D getExportData(TenantId tenantId, I entityId, EntityExportSettings exportSettings) {
D exportData = newExportData();

2
application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/CustomerExportService.java

@ -24,7 +24,7 @@ import org.thingsboard.server.service.exportimport.exporting.data.CustomerExport
@Service
@TbCoreComponent
public class CustomerExportService extends AbstractEntityExportService<CustomerId, Customer, CustomerExportData> {
public class CustomerExportService extends BaseEntityExportService<CustomerId, Customer, CustomerExportData> {
@Override
protected CustomerExportData newExportData() {

2
application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/DashboardExportService.java

@ -24,7 +24,7 @@ import org.thingsboard.server.service.exportimport.exporting.data.DashboardExpor
@Service
@TbCoreComponent
public class DashboardExportService extends AbstractEntityExportService<DashboardId, Dashboard, DashboardExportData> {
public class DashboardExportService extends BaseEntityExportService<DashboardId, Dashboard, DashboardExportData> {
@Override
protected DashboardExportData newExportData() {

3
application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/DeviceExportService.java

@ -28,11 +28,10 @@ import org.thingsboard.server.service.exportimport.exporting.data.DeviceExportDa
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DeviceExportService extends AbstractEntityExportService<DeviceId, Device, DeviceExportData> {
public class DeviceExportService extends BaseEntityExportService<DeviceId, Device, DeviceExportData> {
private final DeviceCredentialsService deviceCredentialsService;
@Override
protected void setRelatedEntities(TenantId tenantId, Device device, DeviceExportData exportData) {
exportData.setCredentials(deviceCredentialsService.findDeviceCredentialsByDeviceId(TenantId.SYS_TENANT_ID, device.getId()));

2
application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/DeviceProfileExportService.java

@ -24,7 +24,7 @@ import org.thingsboard.server.service.exportimport.exporting.data.DeviceProfileE
@Service
@TbCoreComponent
public class DeviceProfileExportService extends AbstractEntityExportService<DeviceProfileId, DeviceProfile, DeviceProfileExportData> {
public class DeviceProfileExportService extends BaseEntityExportService<DeviceProfileId, DeviceProfile, DeviceProfileExportData> {
@Override
protected DeviceProfileExportData newExportData() {

3
application/src/main/java/org/thingsboard/server/service/exportimport/exporting/impl/RuleChainExportService.java

@ -28,11 +28,10 @@ import org.thingsboard.server.service.exportimport.exporting.data.RuleChainExpor
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class RuleChainExportService extends AbstractEntityExportService<RuleChainId, RuleChain, RuleChainExportData> {
public class RuleChainExportService extends BaseEntityExportService<RuleChainId, RuleChain, RuleChainExportData> {
private final RuleChainService ruleChainService;
@Override
protected void setRelatedEntities(TenantId tenantId, RuleChain ruleChain, RuleChainExportData exportData) {
exportData.setMetaData(ruleChainService.loadRuleChainMetaData(tenantId, ruleChain.getId()));

3
application/src/main/java/org/thingsboard/server/service/exportimport/importing/EntityImportSettings.java

@ -27,7 +27,6 @@ import lombok.NoArgsConstructor;
public class EntityImportSettings {
private boolean importInboundRelations;
private boolean importOutboundRelations;
private boolean removeExistingRelationsAndSaveNew;
private boolean removeExistingRelations;
private boolean updateReferencesToOtherEntities;
}

8
application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/AssetImportService.java

@ -28,17 +28,13 @@ import org.thingsboard.server.service.exportimport.exporting.data.AssetExportDat
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class AssetImportService extends AbstractEntityImportService<AssetId, Asset, AssetExportData> {
public class AssetImportService extends BaseEntityImportService<AssetId, Asset, AssetExportData> {
private final AssetService assetService;
@Override
protected void setLinkedEntitiesIds(TenantId tenantId, Asset asset, IdProvider<Asset> idProvider) {
protected Asset prepareAndSave(TenantId tenantId, Asset asset, AssetExportData exportData, NewIdProvider idProvider) {
asset.setCustomerId(idProvider.get(tenantId, Asset::getCustomerId));
}
@Override
protected Asset saveEntity(TenantId tenantId, Asset asset, Asset existingAsset, AssetExportData exportData) {
return assetService.saveAsset(asset);
}

65
application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/AbstractEntityImportService.java → application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/BaseEntityImportService.java

@ -15,10 +15,12 @@
*/
package org.thingsboard.server.service.exportimport.importing.impl;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.transaction.annotation.Transactional;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.ExportableEntity;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.HasId;
@ -32,12 +34,16 @@ import org.thingsboard.server.service.exportimport.importing.EntityImportResult;
import org.thingsboard.server.service.exportimport.importing.EntityImportService;
import org.thingsboard.server.service.exportimport.importing.EntityImportSettings;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
public abstract class AbstractEntityImportService<I extends EntityId, E extends ExportableEntity<I>, D extends EntityExportData<E>> implements EntityImportService<I, E, D> {
public abstract class BaseEntityImportService<I extends EntityId, E extends ExportableEntity<I>, D extends EntityExportData<E>> implements EntityImportService<I, E, D> {
@Autowired @Lazy
private ExportableEntitiesService exportableEntitiesService;
@ -59,18 +65,7 @@ public abstract class AbstractEntityImportService<I extends EntityId, E extends
entity.setId(existingEntity.getId());
}
setLinkedEntitiesIds(tenantId, entity, new IdProvider<E>() {
@Override
public <ID extends EntityId> ID get(TenantId tenantId, Function<E, ID> idExtractor) {
if (existingEntity == null || importSettings.isUpdateReferencesToOtherEntities()) {
return getInternalId(tenantId, idExtractor.apply(entity));
} else {
return idExtractor.apply(existingEntity);
}
}
});
E savedEntity = saveEntity(tenantId, entity, existingEntity, exportData);
E savedEntity = prepareAndSave(tenantId, entity, exportData, new NewIdProvider(entity, existingEntity, importSettings));
importRelations(tenantId, savedEntity, existingEntity, exportData, importSettings);
EntityImportResult<E> importResult = new EntityImportResult<>();
@ -79,9 +74,7 @@ public abstract class AbstractEntityImportService<I extends EntityId, E extends
return importResult;
}
protected void setLinkedEntitiesIds(TenantId tenantId, E entity, IdProvider<E> idProvider) {}
protected abstract E saveEntity(TenantId tenantId, E entity, E existingEntity, D exportData);
protected abstract E prepareAndSave(TenantId tenantId, E entity, D exportData, NewIdProvider idProvider);
private void importRelations(TenantId tenantId, E savedEntity, E existingEntity, D exportData, EntityImportSettings importSettings) {
@ -94,7 +87,7 @@ public abstract class AbstractEntityImportService<I extends EntityId, E extends
relation.setFrom(getInternalId(tenantId, relation.getFrom()));
})
.collect(Collectors.toList()));
if (importSettings.isRemoveExistingRelationsAndSaveNew() && existingEntity != null) {
if (importSettings.isRemoveExistingRelations() && existingEntity != null) {
relationService.findByTo(tenantId, savedEntity.getId(), RelationTypeGroup.COMMON).forEach(existingRelation -> {
relationService.deleteRelation(tenantId, existingRelation);
});
@ -107,14 +100,16 @@ public abstract class AbstractEntityImportService<I extends EntityId, E extends
relation.setFrom(savedEntity.getId());
})
.collect(Collectors.toList()));
if (importSettings.isRemoveExistingRelationsAndSaveNew() && existingEntity != null) {
if (importSettings.isRemoveExistingRelations() && existingEntity != null) {
relationService.findByFrom(tenantId, savedEntity.getId(), RelationTypeGroup.COMMON).forEach(existingRelation -> {
relationService.deleteRelation(tenantId, existingRelation);
});
}
}
newRelations.forEach(relation -> relationService.saveRelation(tenantId, relation));
newRelations.forEach(relation -> {
relationService.saveRelation(tenantId, relation);
});
}
private <ID extends EntityId> ID getInternalId(TenantId tenantId, ID externalId) {
@ -128,8 +123,36 @@ public abstract class AbstractEntityImportService<I extends EntityId, E extends
return entity.getId();
}
protected interface IdProvider<E> {
<I extends EntityId> I get(TenantId tenantId, Function<E, I> idExtractor);
@RequiredArgsConstructor
protected class NewIdProvider {
private final E entity;
private final E existingEntity;
private final EntityImportSettings importSettings;
private final Set<EntityType> ALWAYS_UPDATE_REFERENCED_IDS = Set.of(
EntityType.RULE_CHAIN
);
public <ID extends EntityId> ID get(TenantId tenantId, Function<E, ID> idExtractor) {
if (existingEntity == null || importSettings.isUpdateReferencesToOtherEntities()
|| ALWAYS_UPDATE_REFERENCED_IDS.contains(getEntityType())) {
return getInternalId(tenantId, idExtractor.apply(entity));
} else {
return idExtractor.apply(existingEntity);
}
}
public <ID extends EntityId, T> Set<T> get(TenantId tenantId, Function<E, Set<T>> listExtractor, Function<T, ID> idGetter, BiConsumer<T, ID> idSetter) {
if (existingEntity == null || importSettings.isUpdateReferencesToOtherEntities()) {
return Optional.ofNullable(listExtractor.apply(entity)).orElse(Collections.emptySet()).stream()
.peek(t -> {
idSetter.accept(t, getInternalId(tenantId, idGetter.apply(t)));
})
.collect(Collectors.toSet());
} else {
return listExtractor.apply(existingEntity);
}
}
}
}

4
application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/CustomerImportService.java

@ -28,12 +28,12 @@ import org.thingsboard.server.service.exportimport.exporting.data.CustomerExport
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class CustomerImportService extends AbstractEntityImportService<CustomerId, Customer, CustomerExportData> {
public class CustomerImportService extends BaseEntityImportService<CustomerId, Customer, CustomerExportData> {
private final CustomerService customerService;
@Override
protected Customer saveEntity(TenantId tenantId, Customer customer, Customer existingCustomer, CustomerExportData exportData) {
protected Customer prepareAndSave(TenantId tenantId, Customer customer, CustomerExportData exportData, NewIdProvider idProvider) {
return customerService.saveCustomer(customer);
}

46
application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/DashboardImportService.java

@ -19,31 +19,55 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.ShortCustomerInfo;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.exportimport.exporting.data.DashboardExportData;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DashboardImportService extends AbstractEntityImportService<DashboardId, Dashboard, DashboardExportData> {
public class DashboardImportService extends BaseEntityImportService<DashboardId, Dashboard, DashboardExportData> {
private final DashboardService dashboardService;
// TODO [viacheslav]: improve the code
@Override
protected void setLinkedEntitiesIds(TenantId tenantId, Dashboard dashboard, IdProvider<Dashboard> idProvider) {
// if (existingDashboard == null) {
// dashboard.setAssignedCustomers(null); // FIXME [viacheslav]: need to assign dashboard to customers ?
// } else {
// dashboard.setAssignedCustomers(existingDashboard.getAssignedCustomers());
// }
}
protected Dashboard prepareAndSave(TenantId tenantId, Dashboard dashboard, DashboardExportData exportData, NewIdProvider idProvider) {
if (dashboard.getId() == null) {
Set<ShortCustomerInfo> assignedCustomers = idProvider.get(tenantId, Dashboard::getAssignedCustomers, ShortCustomerInfo::getCustomerId, ShortCustomerInfo::setCustomerId);
dashboard.setAssignedCustomers(null);
dashboard = dashboardService.saveDashboard(dashboard);
for (ShortCustomerInfo customerInfo : assignedCustomers) {
dashboardService.assignDashboardToCustomer(tenantId, dashboard.getId(), customerInfo.getCustomerId());
}
} else {
Set<CustomerId> existingAssignedCustomers = dashboardService.findDashboardById(tenantId, dashboard.getId()).getAssignedCustomers().stream()
.map(ShortCustomerInfo::getCustomerId).collect(Collectors.toSet());
Set<CustomerId> newAssignedCustomers = idProvider.get(tenantId, Dashboard::getAssignedCustomers, ShortCustomerInfo::getCustomerId, ShortCustomerInfo::setCustomerId).stream()
.map(ShortCustomerInfo::getCustomerId).collect(Collectors.toSet());
@Override
protected Dashboard saveEntity(TenantId tenantId, Dashboard dashboard, Dashboard existingDashboard, DashboardExportData exportData) {
return dashboardService.saveDashboard(dashboard);
Set<CustomerId> toUnassign = new HashSet<>(existingAssignedCustomers);
toUnassign.removeAll(newAssignedCustomers);
for (CustomerId customerId : toUnassign) {
dashboardService.unassignDashboardFromCustomer(tenantId, dashboard.getId(), customerId);
}
Set<CustomerId> toAssign = new HashSet<>(newAssignedCustomers);
toAssign.removeAll(existingAssignedCustomers);
for (CustomerId customerId : toAssign) {
dashboardService.assignDashboardToCustomer(tenantId, dashboard.getId(), customerId);
}
dashboard.setAssignedCustomers(dashboardService.findDashboardById(tenantId, dashboard.getId()).getAssignedCustomers());
dashboard = dashboardService.saveDashboard(dashboard);
}
return dashboard;
}
@Override

8
application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/DeviceImportService.java

@ -28,20 +28,16 @@ import org.thingsboard.server.service.exportimport.exporting.data.DeviceExportDa
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DeviceImportService extends AbstractEntityImportService<DeviceId, Device, DeviceExportData> {
public class DeviceImportService extends BaseEntityImportService<DeviceId, Device, DeviceExportData> {
private final DeviceService deviceService;
@Override
protected void setLinkedEntitiesIds(TenantId tenantId, Device device, IdProvider<Device> idProvider) {
protected Device prepareAndSave(TenantId tenantId, Device device, DeviceExportData exportData, NewIdProvider idProvider) {
device.setCustomerId(idProvider.get(tenantId, Device::getCustomerId));
device.setDeviceProfileId(idProvider.get(tenantId, Device::getDeviceProfileId));
device.setFirmwareId(idProvider.get(tenantId, Device::getFirmwareId));
device.setSoftwareId(idProvider.get(tenantId, Device::getSoftwareId));
}
@Override
protected Device saveEntity(TenantId tenantId, Device device, Device existingDevice, DeviceExportData exportData) {
return deviceService.saveDeviceWithCredentials(device, exportData.getCredentials());
}

8
application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/DeviceProfileImportService.java

@ -28,20 +28,16 @@ import org.thingsboard.server.service.exportimport.exporting.data.DeviceProfileE
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DeviceProfileImportService extends AbstractEntityImportService<DeviceProfileId, DeviceProfile, DeviceProfileExportData> {
public class DeviceProfileImportService extends BaseEntityImportService<DeviceProfileId, DeviceProfile, DeviceProfileExportData> {
private final DeviceProfileService deviceProfileService;
@Override
protected void setLinkedEntitiesIds(TenantId tenantId, DeviceProfile deviceProfile, IdProvider<DeviceProfile> idProvider) {
protected DeviceProfile prepareAndSave(TenantId tenantId, DeviceProfile deviceProfile, DeviceProfileExportData exportData, NewIdProvider idProvider) {
deviceProfile.setDefaultRuleChainId(idProvider.get(tenantId, DeviceProfile::getDefaultRuleChainId));
deviceProfile.setDefaultDashboardId(idProvider.get(tenantId, DeviceProfile::getDefaultDashboardId));
deviceProfile.setFirmwareId(idProvider.get(tenantId, DeviceProfile::getFirmwareId));
deviceProfile.setSoftwareId(idProvider.get(tenantId, DeviceProfile::getSoftwareId));
}
@Override
protected DeviceProfile saveEntity(TenantId tenantId, DeviceProfile deviceProfile, DeviceProfile existingDeviceProfile, DeviceProfileExportData exportData) {
return deviceProfileService.saveDeviceProfile(deviceProfile);
}

57
application/src/main/java/org/thingsboard/server/service/exportimport/importing/impl/RuleChainImportService.java

@ -15,6 +15,9 @@
*/
package org.thingsboard.server.service.exportimport.importing.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.EntityType;
@ -26,39 +29,47 @@ import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.exportimport.exporting.data.RuleChainExportData;
import java.util.Collections;
import java.util.Optional;
import java.util.UUID;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class RuleChainImportService extends AbstractEntityImportService<RuleChainId, RuleChain, RuleChainExportData> {
public class RuleChainImportService extends BaseEntityImportService<RuleChainId, RuleChain, RuleChainExportData> {
private final RuleChainService ruleChainService;
@Override
protected void setLinkedEntitiesIds(TenantId tenantId, RuleChain ruleChain, IdProvider<RuleChain> idProvider) {
}
protected RuleChain prepareAndSave(TenantId tenantId, RuleChain ruleChain, RuleChainExportData exportData, NewIdProvider idProvider) {
RuleChainMetaData metaData = exportData.getMetaData();
Optional.ofNullable(metaData.getNodes()).orElse(Collections.emptyList())
.forEach(ruleNode -> {
ruleNode.setId(null);
ruleNode.setRuleChainId(null);
JsonNode ruleNodeConfig = ruleNode.getConfiguration();
Optional.ofNullable(ruleNodeConfig)
.flatMap(config -> Optional.ofNullable(config.get("ruleChainId")).filter(JsonNode::isTextual))
.map(JsonNode::asText).map(UUID::fromString)
.ifPresent(otherRuleChainUuid -> {
((ObjectNode) ruleNodeConfig).set("ruleChainId", new TextNode(
idProvider.get(tenantId, rc -> new RuleChainId(otherRuleChainUuid)).toString()
));
ruleNode.setConfiguration(ruleNodeConfig);
});
});
Optional.ofNullable(metaData.getRuleChainConnections()).orElse(Collections.emptyList())
.forEach(ruleChainConnectionInfo -> {
ruleChainConnectionInfo.setTargetRuleChainId(idProvider.get(tenantId, rc -> ruleChainConnectionInfo.getTargetRuleChainId()));
});
ruleChain.setFirstRuleNodeId(null);
@Override
protected RuleChain saveEntity(TenantId tenantId, RuleChain ruleChain, RuleChain existingRuleChain, RuleChainExportData exportData) {
ruleChain.setFirstRuleNodeId(null); // will be set during metadata persisting
if (existingRuleChain != null) {
ruleChainService.deleteRuleNodes(tenantId, existingRuleChain.getId());
if (ruleChain.getId() != null) {
ruleChainService.deleteRuleNodes(tenantId, ruleChain.getId());
}
ruleChain = ruleChainService.saveRuleChain(ruleChain);
RuleChainMetaData metaData = exportData.getMetaData();
metaData.setRuleChainId(ruleChain.getId());
metaData.getNodes().forEach(ruleNode -> {
ruleNode.setId(null);
ruleNode.setRuleChainId(null);
});
metaData.getRuleChainConnections().forEach(ruleChainConnectionInfo -> {
// ruleChainConnectionInfo.setTargetRuleChainId();
// TODO [viacheslav]: check if this thing is needed for "Other Rule Chain Node"
// TODO [viacheslav]: and check import of tenant rule chains
});
ruleChainService.saveRuleChainMetaData(tenantId, metaData);
exportData.getMetaData().setRuleChainId(ruleChain.getId());
ruleChainService.saveRuleChainMetaData(tenantId, exportData.getMetaData());
return ruleChain;
}

2
dao/src/main/java/org/thingsboard/server/dao/sql/query/DefaultEntityQueryRepository.java

@ -238,6 +238,8 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository {
entityTableMap.put(EntityType.TENANT, "tenant");
entityTableMap.put(EntityType.API_USAGE_STATE, SELECT_API_USAGE_STATE);
entityTableMap.put(EntityType.EDGE, "edge");
entityTableMap.put(EntityType.RULE_CHAIN, "rule_chain");
entityTableMap.put(EntityType.DEVICE_PROFILE, "device_profile");
}
public static EntityType[] RELATION_QUERY_ENTITY_TYPES = new EntityType[]{

1
dao/src/main/java/org/thingsboard/server/dao/sql/query/EntityKeyMapping.java

@ -102,6 +102,7 @@ public class EntityKeyMapping {
allowedEntityFieldMap.put(EntityType.WIDGET_TYPE, new HashSet<>(widgetEntityFields));
allowedEntityFieldMap.put(EntityType.WIDGETS_BUNDLE, new HashSet<>(widgetEntityFields));
allowedEntityFieldMap.put(EntityType.API_USAGE_STATE, apiUsageStateEntityFields);
allowedEntityFieldMap.put(EntityType.DEVICE_PROFILE, Set.of(CREATED_TIME, NAME, TYPE));
entityFieldColumnMap.put(CREATED_TIME, ModelConstants.CREATED_TIME_PROPERTY);
entityFieldColumnMap.put(ENTITY_TYPE, ModelConstants.ENTITY_TYPE_PROPERTY);

Loading…
Cancel
Save