Export/import api improvements
This commit is contained in:
parent
2a77c90d13
commit
9b8fca9973
@ -924,7 +924,7 @@ public abstract class BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
protected <E extends HasName & HasId<I> & HasTenantId, I extends EntityId> void onEntityUpdatedOrCreated(User user, E savedEntity, E oldEntity, boolean isNewEntity) {
|
||||
protected <E extends HasName & HasId<I>, I extends EntityId> void onEntityUpdatedOrCreated(User user, E savedEntity, E oldEntity, boolean isNewEntity) {
|
||||
boolean notifyEdgeService = false;
|
||||
|
||||
EntityType entityType = savedEntity.getId().getEntityType();
|
||||
@ -954,7 +954,7 @@ public abstract class BaseController {
|
||||
case RULE_CHAIN:
|
||||
RuleChainType ruleChainType = ((RuleChain) savedEntity).getType();
|
||||
if (RuleChainType.CORE.equals(ruleChainType)) {
|
||||
tbClusterService.broadcastEntityStateChangeEvent(savedEntity.getTenantId(), savedEntity.getId(),
|
||||
tbClusterService.broadcastEntityStateChangeEvent(user.getTenantId(), savedEntity.getId(),
|
||||
isNewEntity ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
||||
}
|
||||
if (RuleChainType.EDGE.equals(ruleChainType)) {
|
||||
@ -981,7 +981,7 @@ public abstract class BaseController {
|
||||
log.error("Failed to log entity action", e);
|
||||
}
|
||||
if (notifyEdgeService) {
|
||||
sendEntityNotificationMsg(savedEntity.getTenantId(), savedEntity.getId(), isNewEntity ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
||||
sendEntityNotificationMsg(user.getTenantId(), savedEntity.getId(), isNewEntity ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.HasTenantId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.dao.Dao;
|
||||
import org.thingsboard.server.dao.ExportableEntityDao;
|
||||
import org.thingsboard.server.dao.TenantEntityDao;
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||
@ -48,7 +49,7 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
||||
|
||||
private final Map<EntityType, EntityExportService<?, ?, ?>> exportServices = new HashMap<>();
|
||||
private final Map<EntityType, EntityImportService<?, ?, ?>> importServices = new HashMap<>();
|
||||
private final Map<EntityType, TenantEntityDao<?>> daos = new HashMap<>();
|
||||
private final Map<EntityType, Dao<?>> daos = new HashMap<>();
|
||||
|
||||
protected static final List<EntityType> SUPPORTED_ENTITY_TYPES = List.of(
|
||||
EntityType.CUSTOMER, EntityType.ASSET, EntityType.RULE_CHAIN,
|
||||
@ -86,12 +87,6 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <E extends HasId<I> & HasTenantId, I extends EntityId> E findEntityById(TenantId tenantId, I id) {
|
||||
TenantEntityDao<E> dao = (TenantEntityDao<E>) getDao(id.getEntityType());
|
||||
return dao.findByTenantIdAndId(tenantId.getId(), id.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends ExportableEntity<I>, I extends EntityId> E findEntityByExternalId(TenantId tenantId, I externalId) {
|
||||
EntityType entityType = externalId.getEntityType();
|
||||
@ -105,6 +100,12 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
||||
return findEntityById(tenantId, externalId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends HasId<I>, I extends EntityId> E findEntityById(TenantId tenantId, I id) {
|
||||
Dao<E> dao = (Dao<E>) getDao(id.getEntityType());
|
||||
return dao.findById(tenantId, id.getId());
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <I extends EntityId, E extends ExportableEntity<I>, D extends EntityExportData<E>> EntityExportService<I, E, D> getExportService(EntityType entityType) {
|
||||
@ -122,14 +123,14 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
||||
return (EntityImportService<I, E, D>) importServices.get(entityType);
|
||||
}
|
||||
|
||||
private TenantEntityDao<?> getDao(EntityType entityType) {
|
||||
private Dao<?> getDao(EntityType entityType) {
|
||||
return daos.get(entityType);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setServices(Collection<EntityExportService<?, ?, ?>> exportServices,
|
||||
Collection<EntityImportService<?, ?, ?>> importServices,
|
||||
Collection<TenantEntityDao<?>> daos) {
|
||||
Collection<Dao<?>> daos) {
|
||||
exportServices.forEach(entityExportService -> {
|
||||
this.exportServices.put(entityExportService.getEntityType(), entityExportService);
|
||||
});
|
||||
@ -137,7 +138,9 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
||||
this.importServices.put(entityImportService.getEntityType(), entityImportService);
|
||||
});
|
||||
daos.forEach(dao -> {
|
||||
if (dao.getEntityType() != null) {
|
||||
this.daos.put(dao.getEntityType(), dao);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -16,13 +16,14 @@
|
||||
package org.thingsboard.server.service.sync.exporting;
|
||||
|
||||
import org.thingsboard.server.common.data.ExportableEntity;
|
||||
import org.thingsboard.server.common.data.HasTenantId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
public interface ExportableEntitiesService extends TenantEntitiesService {
|
||||
public interface ExportableEntitiesService {
|
||||
|
||||
<E extends ExportableEntity<I>, I extends EntityId> E findEntityByExternalId(TenantId tenantId, I externalId);
|
||||
|
||||
<E extends HasId<I>, I extends EntityId> E findEntityById(TenantId tenantId, I id);
|
||||
|
||||
}
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.service.sync.exporting;
|
||||
|
||||
import org.thingsboard.server.common.data.HasTenantId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
public interface TenantEntitiesService {
|
||||
|
||||
<E extends HasId<I> & HasTenantId, I extends EntityId> E findEntityById(TenantId tenantId, I id);
|
||||
|
||||
}
|
||||
@ -34,6 +34,7 @@ public class AssetImportService extends BaseEntityImportService<AssetId, Asset,
|
||||
|
||||
@Override
|
||||
protected Asset prepareAndSave(TenantId tenantId, Asset asset, AssetExportData exportData, NewIdProvider idProvider) {
|
||||
asset.setTenantId(tenantId);
|
||||
asset.setCustomerId(idProvider.get(tenantId, Asset::getCustomerId));
|
||||
return assetService.saveAsset(asset);
|
||||
}
|
||||
|
||||
@ -57,7 +57,6 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
|
||||
E existingEntity = exportableEntitiesService.findEntityByExternalId(tenantId, entity.getId());
|
||||
|
||||
entity.setExternalId(entity.getId());
|
||||
entity.setTenantId(tenantId);
|
||||
|
||||
if (existingEntity == null) {
|
||||
entity.setId(null);
|
||||
|
||||
@ -34,6 +34,7 @@ public class CustomerImportService extends BaseEntityImportService<CustomerId, C
|
||||
|
||||
@Override
|
||||
protected Customer prepareAndSave(TenantId tenantId, Customer customer, CustomerExportData exportData, NewIdProvider idProvider) {
|
||||
customer.setTenantId(tenantId);
|
||||
return customerService.saveCustomer(customer);
|
||||
}
|
||||
|
||||
|
||||
@ -43,6 +43,7 @@ public class DashboardImportService extends BaseEntityImportService<DashboardId,
|
||||
// TODO [viacheslav]: improve the code
|
||||
@Override
|
||||
protected Dashboard prepareAndSave(TenantId tenantId, Dashboard dashboard, DashboardExportData exportData, NewIdProvider idProvider) {
|
||||
dashboard.setTenantId(tenantId);
|
||||
if (dashboard.getId() == null) {
|
||||
Set<ShortCustomerInfo> assignedCustomers = idProvider.get(tenantId, Dashboard::getAssignedCustomers, ShortCustomerInfo::getCustomerId, ShortCustomerInfo::setCustomerId);
|
||||
dashboard.setAssignedCustomers(null);
|
||||
|
||||
@ -34,6 +34,7 @@ public class DeviceImportService extends BaseEntityImportService<DeviceId, Devic
|
||||
|
||||
@Override
|
||||
protected Device prepareAndSave(TenantId tenantId, Device device, DeviceExportData exportData, NewIdProvider idProvider) {
|
||||
device.setTenantId(tenantId);
|
||||
device.setCustomerId(idProvider.get(tenantId, Device::getCustomerId));
|
||||
device.setDeviceProfileId(idProvider.get(tenantId, Device::getDeviceProfileId));
|
||||
device.setFirmwareId(idProvider.get(tenantId, Device::getFirmwareId));
|
||||
|
||||
@ -34,6 +34,7 @@ public class DeviceProfileImportService extends BaseEntityImportService<DevicePr
|
||||
|
||||
@Override
|
||||
protected DeviceProfile prepareAndSave(TenantId tenantId, DeviceProfile deviceProfile, DeviceProfileExportData exportData, NewIdProvider idProvider) {
|
||||
deviceProfile.setTenantId(tenantId);
|
||||
deviceProfile.setDefaultRuleChainId(idProvider.get(tenantId, DeviceProfile::getDefaultRuleChainId));
|
||||
deviceProfile.setDefaultDashboardId(idProvider.get(tenantId, DeviceProfile::getDefaultDashboardId));
|
||||
deviceProfile.setFirmwareId(idProvider.get(tenantId, DeviceProfile::getFirmwareId));
|
||||
|
||||
@ -42,6 +42,7 @@ public class RuleChainImportService extends BaseEntityImportService<RuleChainId,
|
||||
|
||||
@Override
|
||||
protected RuleChain prepareAndSave(TenantId tenantId, RuleChain ruleChain, RuleChainExportData exportData, NewIdProvider idProvider) {
|
||||
ruleChain.setTenantId(tenantId);
|
||||
RuleChainMetaData metaData = exportData.getMetaData();
|
||||
Optional.ofNullable(metaData.getNodes()).orElse(Collections.emptyList())
|
||||
.forEach(ruleNode -> {
|
||||
|
||||
@ -28,11 +28,10 @@ import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.ExportableEntity;
|
||||
import org.thingsboard.server.common.data.HasTenantId;
|
||||
import org.thingsboard.server.common.data.Tenant;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
import org.thingsboard.server.common.data.asset.Asset;
|
||||
import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.rule.RuleChain;
|
||||
@ -52,7 +51,6 @@ import org.thingsboard.server.service.sync.importing.EntityImportResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.as;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@ -358,7 +356,7 @@ public class EntitiesExportImportControllerSqlTest extends BaseEntitiesExportImp
|
||||
}
|
||||
|
||||
|
||||
private <E extends ExportableEntity<?>> void checkImportedEntity(TenantId tenantId1, E initialEntity, TenantId tenantId2, EntityImportResult<E> importResult) {
|
||||
private <E extends ExportableEntity<?> & HasTenantId> void checkImportedEntity(TenantId tenantId1, E initialEntity, TenantId tenantId2, EntityImportResult<E> importResult) {
|
||||
E importedEntity = importResult.getSavedEntity();
|
||||
|
||||
assertThat(initialEntity.getTenantId()).isEqualTo(tenantId1);
|
||||
|
||||
@ -17,9 +17,8 @@ package org.thingsboard.server.common.data;
|
||||
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
public interface ExportableEntity<I extends EntityId> extends HasId<I>, HasTenantId, HasName {
|
||||
public interface ExportableEntity<I extends EntityId> extends HasId<I>, HasName {
|
||||
|
||||
I getId();
|
||||
void setId(I id);
|
||||
@ -27,7 +26,4 @@ public interface ExportableEntity<I extends EntityId> extends HasId<I>, HasTenan
|
||||
I getExternalId();
|
||||
void setExternalId(I externalId);
|
||||
|
||||
TenantId getTenantId();
|
||||
void setTenantId(TenantId tenantId);
|
||||
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
package org.thingsboard.server.dao;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -40,4 +41,6 @@ public interface Dao<T> {
|
||||
|
||||
void removeAllByIds(Collection<UUID> ids);
|
||||
|
||||
default EntityType getEntityType() { return null; }
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ import org.thingsboard.server.common.data.ExportableEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ExportableEntityDao<T extends ExportableEntity<?>> extends TenantEntityDao<T> {
|
||||
public interface ExportableEntityDao<T extends ExportableEntity<?>> extends Dao<T> {
|
||||
|
||||
T findByTenantIdAndExternalId(UUID tenantId, UUID externalId);
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ package org.thingsboard.server.dao;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ExportableEntityRepository<D> extends TenantEntityRepository<D> {
|
||||
public interface ExportableEntityRepository<D> {
|
||||
|
||||
D findByTenantIdAndExternalId(UUID tenantId, UUID externalId);
|
||||
|
||||
|
||||
@ -15,18 +15,9 @@
|
||||
*/
|
||||
package org.thingsboard.server.dao;
|
||||
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.HasTenantId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface TenantEntityDao<T extends HasTenantId> {
|
||||
public interface TenantEntityDao {
|
||||
|
||||
Long countByTenantId(TenantId tenantId);
|
||||
|
||||
T findByTenantIdAndId(UUID tenantId, UUID id);
|
||||
|
||||
EntityType getEntityType();
|
||||
|
||||
}
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.dao;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface TenantEntityRepository<D> {
|
||||
|
||||
D findByTenantIdAndId(UUID tenantId, UUID id);
|
||||
|
||||
Long countByTenantId(UUID tenantId);
|
||||
|
||||
}
|
||||
@ -34,7 +34,7 @@ import java.util.UUID;
|
||||
* The Interface AssetDao.
|
||||
*
|
||||
*/
|
||||
public interface AssetDao extends Dao<Asset>, ExportableEntityDao<Asset> {
|
||||
public interface AssetDao extends Dao<Asset>, TenantEntityDao, ExportableEntityDao<Asset> {
|
||||
|
||||
/**
|
||||
* Find asset info by id.
|
||||
|
||||
@ -29,7 +29,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* The Interface CustomerDao.
|
||||
*/
|
||||
public interface CustomerDao extends Dao<Customer>, ExportableEntityDao<Customer> {
|
||||
public interface CustomerDao extends Dao<Customer>, TenantEntityDao, ExportableEntityDao<Customer> {
|
||||
|
||||
/**
|
||||
* Save or update customer object
|
||||
|
||||
@ -24,7 +24,7 @@ import org.thingsboard.server.dao.TenantEntityDao;
|
||||
/**
|
||||
* The Interface DashboardDao.
|
||||
*/
|
||||
public interface DashboardDao extends Dao<Dashboard>, ExportableEntityDao<Dashboard> {
|
||||
public interface DashboardDao extends Dao<Dashboard>, TenantEntityDao, ExportableEntityDao<Dashboard> {
|
||||
|
||||
/**
|
||||
* Save or update dashboard object
|
||||
|
||||
@ -36,7 +36,7 @@ import java.util.UUID;
|
||||
* The Interface DeviceDao.
|
||||
*
|
||||
*/
|
||||
public interface DeviceDao extends Dao<Device>, ExportableEntityDao<Device> {
|
||||
public interface DeviceDao extends Dao<Device>, TenantEntityDao, ExportableEntityDao<Device> {
|
||||
|
||||
/**
|
||||
* Find device info by id.
|
||||
|
||||
@ -21,6 +21,6 @@ import org.thingsboard.server.dao.Dao;
|
||||
import org.thingsboard.server.dao.TenantEntityDao;
|
||||
import org.thingsboard.server.dao.TenantEntityWithDataDao;
|
||||
|
||||
public interface OtaPackageDao extends Dao<OtaPackage>, TenantEntityWithDataDao, TenantEntityDao<OtaPackage> {
|
||||
public interface OtaPackageDao extends Dao<OtaPackage>, TenantEntityWithDataDao {
|
||||
Long sumDataSizeByTenantId(TenantId tenantId);
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* Created by igor on 3/12/18.
|
||||
*/
|
||||
public interface RuleChainDao extends Dao<RuleChain>, ExportableEntityDao<RuleChain> {
|
||||
public interface RuleChainDao extends Dao<RuleChain>, TenantEntityDao, ExportableEntityDao<RuleChain> {
|
||||
|
||||
/**
|
||||
* Find rule chains by tenantId and page link.
|
||||
@ -80,6 +80,4 @@ public interface RuleChainDao extends Dao<RuleChain>, ExportableEntityDao<RuleCh
|
||||
|
||||
Collection<RuleChain> findByTenantIdAndTypeAndName(TenantId tenantId, RuleChainType type, String name);
|
||||
|
||||
RuleChain findByTenantIdAndExternalId(UUID tenantId, UUID externalId);
|
||||
|
||||
}
|
||||
|
||||
@ -214,11 +214,6 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
|
||||
return DaoUtil.getData(assetRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Asset findByTenantIdAndId(UUID tenantId, UUID id) {
|
||||
return DaoUtil.getData(assetRepository.findByTenantIdAndId(tenantId, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.ASSET;
|
||||
|
||||
@ -38,4 +38,5 @@ public interface CustomerRepository extends JpaRepository<CustomerEntity, UUID>,
|
||||
|
||||
CustomerEntity findByTenantIdAndTitle(UUID tenantId, String title);
|
||||
|
||||
Long countByTenantId(UUID tenantId);
|
||||
}
|
||||
|
||||
@ -75,11 +75,6 @@ public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Cus
|
||||
return DaoUtil.getData(customerRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Customer findByTenantIdAndId(UUID tenantId, UUID id) {
|
||||
return DaoUtil.getData(customerRepository.findByTenantIdAndId(tenantId, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.CUSTOMER;
|
||||
|
||||
@ -57,11 +57,6 @@ public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, D
|
||||
return DaoUtil.getData(dashboardRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dashboard findByTenantIdAndId(UUID tenantId, UUID id) {
|
||||
return DaoUtil.getData(dashboardRepository.findByTenantIdAndId(tenantId, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DASHBOARD;
|
||||
|
||||
@ -308,11 +308,6 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
|
||||
return DaoUtil.getData(deviceRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device findByTenantIdAndId(UUID tenantId, UUID id) {
|
||||
return findDeviceByTenantIdAndId(TenantId.fromUUID(tenantId), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DEVICE;
|
||||
|
||||
@ -116,16 +116,6 @@ public class JpaDeviceProfileDao extends JpaAbstractSearchTextDao<DeviceProfileE
|
||||
return DaoUtil.getData(deviceProfileRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countByTenantId(TenantId tenantId) {
|
||||
return deviceProfileRepository.countByTenantId(tenantId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceProfile findByTenantIdAndId(UUID tenantId, UUID id) {
|
||||
return DaoUtil.getData(deviceProfileRepository.findByTenantIdAndId(tenantId, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DEVICE_PROFILE;
|
||||
|
||||
@ -22,7 +22,6 @@ import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.OtaPackage;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.dao.DaoUtil;
|
||||
import org.thingsboard.server.dao.ota.OtaPackageDao;
|
||||
import org.thingsboard.server.dao.model.sql.OtaPackageEntity;
|
||||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
|
||||
@ -51,16 +50,6 @@ public class JpaOtaPackageDao extends JpaAbstractSearchTextDao<OtaPackageEntity,
|
||||
return otaPackageRepository.sumDataSizeByTenantId(tenantId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countByTenantId(TenantId tenantId) {
|
||||
return otaPackageRepository.countByTenantId(tenantId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OtaPackage findByTenantIdAndId(UUID tenantId, UUID id) {
|
||||
return DaoUtil.getData(otaPackageRepository.findByTenantIdAndId(tenantId, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.OTA_PACKAGE;
|
||||
|
||||
@ -18,12 +18,11 @@ package org.thingsboard.server.dao.sql.ota;
|
||||
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.TenantEntityRepository;
|
||||
import org.thingsboard.server.dao.model.sql.OtaPackageEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface OtaPackageRepository extends JpaRepository<OtaPackageEntity, UUID>, TenantEntityRepository<OtaPackageEntity> {
|
||||
public interface OtaPackageRepository extends JpaRepository<OtaPackageEntity, UUID> {
|
||||
@Query(value = "SELECT COALESCE(SUM(ota.data_size), 0) FROM ota_package ota WHERE ota.tenant_id = :tenantId AND ota.data IS NOT NULL", nativeQuery = true)
|
||||
Long sumDataSizeByTenantId(@Param("tenantId") UUID tenantId);
|
||||
}
|
||||
|
||||
@ -114,11 +114,6 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R
|
||||
return DaoUtil.getData(ruleChainRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleChain findByTenantIdAndId(UUID tenantId, UUID id) {
|
||||
return DaoUtil.getData(ruleChainRepository.findByTenantIdAndId(tenantId, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.RULE_CHAIN;
|
||||
|
||||
@ -63,6 +63,8 @@ public interface RuleChainRepository extends JpaRepository<RuleChainEntity, UUID
|
||||
|
||||
RuleChainEntity findByTenantIdAndTypeAndRootIsTrue(UUID tenantId, RuleChainType ruleChainType);
|
||||
|
||||
Long countByTenantId(UUID tenantId);
|
||||
|
||||
List<RuleChainEntity> findByTenantIdAndTypeAndName(UUID tenantId, RuleChainType type, String name);
|
||||
|
||||
}
|
||||
|
||||
@ -18,8 +18,6 @@ package org.thingsboard.server.dao.sql.user;
|
||||
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.HasTenantId;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
@ -98,15 +96,4 @@ public class JpaUserDao extends JpaAbstractSearchTextDao<UserEntity, User> imple
|
||||
public Long countByTenantId(TenantId tenantId) {
|
||||
return userRepository.countByTenantId(tenantId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findByTenantIdAndId(UUID tenantId, UUID id) {
|
||||
return DaoUtil.getData(userRepository.findByTenantIdAndId(tenantId, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.USER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,8 +21,6 @@ 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.common.data.security.Authority;
|
||||
import org.thingsboard.server.dao.TenantEntityDao;
|
||||
import org.thingsboard.server.dao.TenantEntityRepository;
|
||||
import org.thingsboard.server.dao.model.sql.UserEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -30,7 +28,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* @author Valerii Sosliuk
|
||||
*/
|
||||
public interface UserRepository extends JpaRepository<UserEntity, UUID>, TenantEntityRepository<UserEntity> {
|
||||
public interface UserRepository extends JpaRepository<UserEntity, UUID> {
|
||||
|
||||
UserEntity findByEmail(String email);
|
||||
|
||||
@ -49,4 +47,5 @@ public interface UserRepository extends JpaRepository<UserEntity, UUID>, TenantE
|
||||
@Param("searchText") String searchText,
|
||||
Pageable pageable);
|
||||
|
||||
Long countByTenantId(UUID tenantId);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ import org.thingsboard.server.dao.TenantEntityDao;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface UserDao extends Dao<User>, TenantEntityDao<User> {
|
||||
public interface UserDao extends Dao<User>, TenantEntityDao {
|
||||
|
||||
/**
|
||||
* Save or update user object
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user