Set external ids of referenced entities on export
This commit is contained in:
parent
d6959ca7e2
commit
e3ec5db618
@ -75,7 +75,7 @@ public class DefaultExportableEntitiesService implements ExportableEntitiesServi
|
||||
E entity = null;
|
||||
|
||||
if (dao instanceof ExportableEntityDao) {
|
||||
ExportableEntityDao<E> exportableEntityDao = (ExportableEntityDao<E>) dao;
|
||||
ExportableEntityDao<I, E> exportableEntityDao = (ExportableEntityDao<I, E>) dao;
|
||||
entity = exportableEntityDao.findByTenantIdAndExternalId(tenantId.getId(), externalId.getId());
|
||||
}
|
||||
if (entity == null || !belongsToTenant(entity, tenantId)) {
|
||||
@ -113,7 +113,7 @@ public class DefaultExportableEntitiesService implements ExportableEntitiesServi
|
||||
E entity = null;
|
||||
|
||||
if (dao instanceof ExportableEntityDao) {
|
||||
ExportableEntityDao<E> exportableEntityDao = (ExportableEntityDao<E>) dao;
|
||||
ExportableEntityDao<I, E> exportableEntityDao = (ExportableEntityDao<I, E>) dao;
|
||||
try {
|
||||
entity = exportableEntityDao.findByTenantIdAndName(tenantId.getId(), name);
|
||||
} catch (UnsupportedOperationException ignored) {
|
||||
@ -128,13 +128,23 @@ public class DefaultExportableEntitiesService implements ExportableEntitiesServi
|
||||
|
||||
@Override
|
||||
public <E extends ExportableEntity<I>, I extends EntityId> PageData<E> findEntitiesByTenantId(TenantId tenantId, EntityType entityType, PageLink pageLink) {
|
||||
Dao<E> dao = getDao(entityType);
|
||||
if (dao instanceof ExportableEntityDao) {
|
||||
ExportableEntityDao<E> exportableEntityDao = (ExportableEntityDao<E>) dao;
|
||||
return exportableEntityDao.findByTenantId(tenantId.getId(), pageLink);
|
||||
}
|
||||
ExportableEntityDao<I, E> dao = getExportableEntityDao(entityType);
|
||||
if (dao != null) {
|
||||
return dao.findByTenantId(tenantId.getId(), pageLink);
|
||||
} else {
|
||||
return new PageData<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <I extends EntityId> I getExternalIdByInternal(I internalId) {
|
||||
ExportableEntityDao<I, ?> dao = getExportableEntityDao(internalId.getEntityType());
|
||||
if (dao != null) {
|
||||
return dao.getExternalIdByInternal(internalId);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean belongsToTenant(HasId<? extends EntityId> entity, TenantId tenantId) {
|
||||
return tenantId.equals(((HasTenantId) entity).getTenantId());
|
||||
@ -151,6 +161,15 @@ public class DefaultExportableEntitiesService implements ExportableEntitiesServi
|
||||
entityRemover.accept(tenantId, id);
|
||||
}
|
||||
|
||||
private <I extends EntityId, E extends ExportableEntity<I>> ExportableEntityDao<I, E> getExportableEntityDao(EntityType entityType) {
|
||||
Dao<E> dao = getDao(entityType);
|
||||
if (dao instanceof ExportableEntityDao) {
|
||||
return (ExportableEntityDao<I, E>) dao;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <E> Dao<E> getDao(EntityType entityType) {
|
||||
return (Dao<E>) daos.get(entityType);
|
||||
|
||||
@ -38,6 +38,8 @@ public interface ExportableEntitiesService {
|
||||
|
||||
<E extends ExportableEntity<I>, I extends EntityId> PageData<E> findEntitiesByTenantId(TenantId tenantId, EntityType entityType, PageLink pageLink);
|
||||
|
||||
<I extends EntityId> I getExternalIdByInternal(I internalId);
|
||||
|
||||
<I extends EntityId> void removeById(TenantId tenantId, I id);
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package org.thingsboard.server.service.sync.ie.exporting.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.asset.Asset;
|
||||
import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
|
||||
import org.thingsboard.server.common.data.sync.ie.EntityExportSettings;
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@TbCoreComponent
|
||||
@RequiredArgsConstructor
|
||||
public class AssetExportService extends BaseEntityExportService<AssetId, Asset, EntityExportData<Asset>> {
|
||||
|
||||
@Override
|
||||
protected void setRelatedEntities(TenantId tenantId, Asset asset, EntityExportData<Asset> exportData, EntityExportSettings settings) {
|
||||
asset.setCustomerId(getExternalIdOrElseInternal(asset.getCustomerId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<EntityType> getSupportedEntityTypes() {
|
||||
return Set.of(EntityType.ASSET);
|
||||
}
|
||||
|
||||
}
|
||||
@ -24,6 +24,7 @@ import org.thingsboard.server.service.security.model.SecurityUser;
|
||||
import org.thingsboard.server.common.data.sync.ie.EntityExportSettings;
|
||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class BaseEntityExportService<I extends EntityId, E extends ExportableEntity<I>, D extends EntityExportData<E>> extends DefaultEntityExportService<I, E, D> {
|
||||
@ -36,7 +37,15 @@ public abstract class BaseEntityExportService<I extends EntityId, E extends Expo
|
||||
|
||||
protected void setRelatedEntities(TenantId tenantId, E mainEntity, D exportData, EntityExportSettings settings) {}
|
||||
|
||||
protected abstract D newExportData();
|
||||
protected <ID extends EntityId> ID getExternalIdOrElseInternal(ID internalId) {
|
||||
if (internalId == null || internalId.isNullUid()) return internalId;
|
||||
return Optional.ofNullable(exportableEntitiesService.getExternalIdByInternal(internalId))
|
||||
.orElse(internalId);
|
||||
}
|
||||
|
||||
protected D newExportData() {
|
||||
return (D) new EntityExportData<E>();
|
||||
};
|
||||
|
||||
public abstract Set<EntityType> getSupportedEntityTypes();
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ import java.util.stream.Collectors;
|
||||
public class DefaultEntityExportService<I extends EntityId, E extends ExportableEntity<I>, D extends EntityExportData<E>> implements EntityExportService<I, E, D> {
|
||||
|
||||
@Autowired @Lazy
|
||||
private ExportableEntitiesService exportableEntitiesService;
|
||||
protected ExportableEntitiesService exportableEntitiesService;
|
||||
@Autowired
|
||||
private RelationService relationService;
|
||||
@Autowired
|
||||
|
||||
@ -16,12 +16,13 @@
|
||||
package org.thingsboard.server.dao;
|
||||
|
||||
import org.thingsboard.server.common.data.ExportableEntity;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ExportableEntityDao<T extends ExportableEntity<?>> extends Dao<T> {
|
||||
public interface ExportableEntityDao<I extends EntityId, T extends ExportableEntity<?>> extends Dao<T> {
|
||||
|
||||
T findByTenantIdAndExternalId(UUID tenantId, UUID externalId);
|
||||
|
||||
@ -29,4 +30,6 @@ public interface ExportableEntityDao<T extends ExportableEntity<?>> extends Dao<
|
||||
|
||||
PageData<T> findByTenantId(UUID tenantId, PageLink pageLink);
|
||||
|
||||
I getExternalIdByInternal(I internalId);
|
||||
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.asset.Asset;
|
||||
import org.thingsboard.server.common.data.asset.AssetInfo;
|
||||
import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -34,7 +35,7 @@ import java.util.UUID;
|
||||
* The Interface AssetDao.
|
||||
*
|
||||
*/
|
||||
public interface AssetDao extends Dao<Asset>, TenantEntityDao, ExportableEntityDao<Asset> {
|
||||
public interface AssetDao extends Dao<Asset>, TenantEntityDao, ExportableEntityDao<AssetId, Asset> {
|
||||
|
||||
/**
|
||||
* Find asset info by id.
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
package org.thingsboard.server.dao.customer;
|
||||
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -29,7 +30,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* The Interface CustomerDao.
|
||||
*/
|
||||
public interface CustomerDao extends Dao<Customer>, TenantEntityDao, ExportableEntityDao<Customer> {
|
||||
public interface CustomerDao extends Dao<Customer>, TenantEntityDao, ExportableEntityDao<CustomerId, Customer> {
|
||||
|
||||
/**
|
||||
* Save or update customer object
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
package org.thingsboard.server.dao.dashboard;
|
||||
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.dao.Dao;
|
||||
import org.thingsboard.server.dao.ExportableEntityDao;
|
||||
@ -27,7 +28,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* The Interface DashboardDao.
|
||||
*/
|
||||
public interface DashboardDao extends Dao<Dashboard>, TenantEntityDao, ExportableEntityDao<Dashboard> {
|
||||
public interface DashboardDao extends Dao<Dashboard>, TenantEntityDao, ExportableEntityDao<DashboardId, Dashboard> {
|
||||
|
||||
/**
|
||||
* Save or update dashboard object
|
||||
|
||||
@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceInfo;
|
||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.ota.OtaPackageType;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
@ -36,7 +37,7 @@ import java.util.UUID;
|
||||
* The Interface DeviceDao.
|
||||
*
|
||||
*/
|
||||
public interface DeviceDao extends Dao<Device>, TenantEntityDao, ExportableEntityDao<Device> {
|
||||
public interface DeviceDao extends Dao<Device>, TenantEntityDao, ExportableEntityDao<DeviceId, Device> {
|
||||
|
||||
/**
|
||||
* Find device info by id.
|
||||
|
||||
@ -17,6 +17,7 @@ package org.thingsboard.server.dao.device;
|
||||
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.DeviceProfileInfo;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -25,7 +26,7 @@ import org.thingsboard.server.dao.ExportableEntityDao;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface DeviceProfileDao extends Dao<DeviceProfile>, ExportableEntityDao<DeviceProfile> {
|
||||
public interface DeviceProfileDao extends Dao<DeviceProfile>, ExportableEntityDao<DeviceProfileId, DeviceProfile> {
|
||||
|
||||
DeviceProfileInfo findDeviceProfileInfoById(TenantId tenantId, UUID deviceProfileId);
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.EntityView;
|
||||
import org.thingsboard.server.common.data.EntityViewInfo;
|
||||
import org.thingsboard.server.common.data.id.EntityViewId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -32,7 +33,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* Created by Victor Basanets on 8/28/2017.
|
||||
*/
|
||||
public interface EntityViewDao extends Dao<EntityView>, ExportableEntityDao<EntityView> {
|
||||
public interface EntityViewDao extends Dao<EntityView>, ExportableEntityDao<EntityViewId, EntityView> {
|
||||
|
||||
/**
|
||||
* Find entity view info by id.
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.server.dao.rule;
|
||||
|
||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -30,7 +31,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* Created by igor on 3/12/18.
|
||||
*/
|
||||
public interface RuleChainDao extends Dao<RuleChain>, TenantEntityDao, ExportableEntityDao<RuleChain> {
|
||||
public interface RuleChainDao extends Dao<RuleChain>, TenantEntityDao, ExportableEntityDao<RuleChainId, RuleChain> {
|
||||
|
||||
/**
|
||||
* Find rule chains by tenantId and page link.
|
||||
|
||||
@ -144,4 +144,8 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
Pageable pageable);
|
||||
|
||||
Long countByTenantIdAndTypeIsNot(UUID tenantId, String type);
|
||||
|
||||
@Query("SELECT externalId FROM AssetEntity WHERE id = :id")
|
||||
UUID getExternalIdById(@Param("id") UUID id);
|
||||
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.asset.Asset;
|
||||
import org.thingsboard.server.common.data.asset.AssetInfo;
|
||||
import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -224,6 +225,12 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
|
||||
return findAssetsByTenantId(tenantId, pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssetId getExternalIdByInternal(AssetId internalId) {
|
||||
return Optional.ofNullable(assetRepository.getExternalIdById(internalId.getId()))
|
||||
.map(AssetId::new).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.ASSET;
|
||||
|
||||
@ -39,4 +39,8 @@ public interface CustomerRepository extends JpaRepository<CustomerEntity, UUID>,
|
||||
CustomerEntity findByTenantIdAndTitle(UUID tenantId, String title);
|
||||
|
||||
Long countByTenantId(UUID tenantId);
|
||||
|
||||
@Query("SELECT externalId FROM CustomerEntity WHERE id = :id")
|
||||
UUID getExternalIdById(@Param("id") UUID id);
|
||||
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -85,6 +86,12 @@ public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Cus
|
||||
return findCustomersByTenantId(tenantId, pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomerId getExternalIdByInternal(CustomerId internalId) {
|
||||
return Optional.ofNullable(customerRepository.getExternalIdById(internalId.getId()))
|
||||
.map(CustomerId::new).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.CUSTOMER;
|
||||
|
||||
@ -18,6 +18,8 @@ package org.thingsboard.server.dao.sql.dashboard;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.thingsboard.server.dao.ExportableEntityRepository;
|
||||
import org.thingsboard.server.dao.model.sql.DashboardEntity;
|
||||
|
||||
@ -35,4 +37,7 @@ public interface DashboardRepository extends JpaRepository<DashboardEntity, UUID
|
||||
|
||||
Page<DashboardEntity> findByTenantId(UUID tenantId, Pageable pageable);
|
||||
|
||||
@Query("SELECT externalId FROM DashboardEntity WHERE id = :id")
|
||||
UUID getExternalIdById(@Param("id") UUID id);
|
||||
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -29,6 +30,7 @@ import org.thingsboard.server.dao.model.sql.DashboardEntity;
|
||||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -65,6 +67,12 @@ public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, D
|
||||
return DaoUtil.toPageData(dashboardRepository.findByTenantId(tenantId, DaoUtil.toPageable(pageLink)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardId getExternalIdByInternal(DashboardId internalId) {
|
||||
return Optional.ofNullable(dashboardRepository.getExternalIdById(internalId.getId()))
|
||||
.map(DashboardId::new).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dashboard> findByTenantIdAndTitle(UUID tenantId, String title) {
|
||||
return DaoUtil.convertDataList(dashboardRepository.findByTenantIdAndTitle(tenantId, title));
|
||||
|
||||
@ -67,4 +67,8 @@ public interface DeviceProfileRepository extends JpaRepository<DeviceProfileEnti
|
||||
DeviceProfileEntity findByTenantIdAndName(UUID id, String profileName);
|
||||
|
||||
DeviceProfileEntity findByProvisionDeviceKey(@Param("provisionDeviceKey") String provisionDeviceKey);
|
||||
|
||||
@Query("SELECT externalId FROM DeviceProfileEntity WHERE id = :id")
|
||||
UUID getExternalIdById(@Param("id") UUID id);
|
||||
|
||||
}
|
||||
|
||||
@ -245,4 +245,8 @@ public interface DeviceRepository extends JpaRepository<DeviceEntity, UUID>, Exp
|
||||
"INNER JOIN DeviceProfileEntity p ON d.deviceProfileId = p.id " +
|
||||
"WHERE p.transportType = :transportType")
|
||||
Page<UUID> findIdsByDeviceProfileTransportType(@Param("transportType") DeviceTransportType transportType, Pageable pageable);
|
||||
|
||||
@Query("SELECT externalId FROM DeviceEntity WHERE id = :id")
|
||||
UUID getExternalIdById(@Param("id") UUID id);
|
||||
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ import org.thingsboard.server.common.data.DeviceInfo;
|
||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.ota.OtaPackageType;
|
||||
import org.thingsboard.server.common.data.ota.OtaPackageUtil;
|
||||
@ -318,6 +319,12 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
|
||||
return findDevicesByTenantId(tenantId, pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceId getExternalIdByInternal(DeviceId internalId) {
|
||||
return Optional.ofNullable(deviceRepository.getExternalIdById(internalId.getId()))
|
||||
.map(DeviceId::new).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DEVICE;
|
||||
|
||||
@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.DeviceProfileInfo;
|
||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -33,6 +34,7 @@ import org.thingsboard.server.dao.model.sql.DeviceProfileEntity;
|
||||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
@ -126,6 +128,12 @@ public class JpaDeviceProfileDao extends JpaAbstractSearchTextDao<DeviceProfileE
|
||||
return findDeviceProfiles(TenantId.fromUUID(tenantId), pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceProfileId getExternalIdByInternal(DeviceProfileId internalId) {
|
||||
return Optional.ofNullable(deviceProfileRepository.getExternalIdById(internalId.getId()))
|
||||
.map(DeviceProfileId::new).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DEVICE_PROFILE;
|
||||
|
||||
@ -140,4 +140,7 @@ public interface EntityViewRepository extends JpaRepository<EntityViewEntity, UU
|
||||
@Param("type") String type,
|
||||
@Param("searchText") String searchText,
|
||||
Pageable pageable);
|
||||
@Query("SELECT externalId FROM EntityViewEntity WHERE id = :id")
|
||||
UUID getExternalIdById(@Param("id") UUID id);
|
||||
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.EntityView;
|
||||
import org.thingsboard.server.common.data.EntityViewInfo;
|
||||
import org.thingsboard.server.common.data.id.EntityViewId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -211,6 +212,12 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
|
||||
return findEntityViewsByTenantId(tenantId, pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityViewId getExternalIdByInternal(EntityViewId internalId) {
|
||||
return Optional.ofNullable(entityViewRepository.getExternalIdById(internalId.getId()))
|
||||
.map(EntityViewId::new).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityView findByTenantIdAndName(UUID tenantId, String name) {
|
||||
return findEntityViewByTenantIdAndName(tenantId, name).orElse(null);
|
||||
|
||||
@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
@ -32,6 +33,7 @@ import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@ -119,6 +121,12 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R
|
||||
return findRuleChainsByTenantId(tenantId, pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleChainId getExternalIdByInternal(RuleChainId internalId) {
|
||||
return Optional.ofNullable(ruleChainRepository.getExternalIdById(internalId.getId()))
|
||||
.map(RuleChainId::new).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.RULE_CHAIN;
|
||||
|
||||
@ -67,4 +67,7 @@ public interface RuleChainRepository extends JpaRepository<RuleChainEntity, UUID
|
||||
|
||||
List<RuleChainEntity> findByTenantIdAndTypeAndName(UUID tenantId, RuleChainType type, String name);
|
||||
|
||||
@Query("SELECT externalId FROM RuleChainEntity WHERE id = :id")
|
||||
UUID getExternalIdById(@Param("id") UUID id);
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.WidgetsBundleId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.widget.WidgetsBundle;
|
||||
@ -29,6 +31,7 @@ import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
|
||||
import org.thingsboard.server.dao.widget.WidgetsBundleDao;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
|
||||
@ -88,11 +91,6 @@ public class JpaWidgetsBundleDao extends JpaAbstractSearchTextDao<WidgetsBundleE
|
||||
DaoUtil.toPageable(pageLink)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.WIDGETS_BUNDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WidgetsBundle findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
|
||||
return DaoUtil.getData(widgetsBundleRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||
@ -108,4 +106,15 @@ public class JpaWidgetsBundleDao extends JpaAbstractSearchTextDao<WidgetsBundleE
|
||||
return findTenantWidgetsBundlesByTenantId(tenantId, pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WidgetsBundleId getExternalIdByInternal(WidgetsBundleId internalId) {
|
||||
return Optional.ofNullable(widgetsBundleRepository.getExternalIdById(internalId.getId()))
|
||||
.map(WidgetsBundleId::new).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.WIDGETS_BUNDLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -53,4 +53,7 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
|
||||
|
||||
WidgetsBundleEntity findFirstByTenantIdAndTitle(UUID tenantId, String title);
|
||||
|
||||
@Query("SELECT externalId FROM WidgetsBundleEntity WHERE id = :id")
|
||||
UUID getExternalIdById(@Param("id") UUID id);
|
||||
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* The Interface WidgetsBundleDao.
|
||||
*/
|
||||
public interface WidgetsBundleDao extends Dao<WidgetsBundle>, ExportableEntityDao<WidgetsBundle> {
|
||||
public interface WidgetsBundleDao extends Dao<WidgetsBundle>, ExportableEntityDao<WidgetsBundleId, WidgetsBundle> {
|
||||
|
||||
/**
|
||||
* Save or update widgets bundle object
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user