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;
|
boolean notifyEdgeService = false;
|
||||||
|
|
||||||
EntityType entityType = savedEntity.getId().getEntityType();
|
EntityType entityType = savedEntity.getId().getEntityType();
|
||||||
@ -954,7 +954,7 @@ public abstract class BaseController {
|
|||||||
case RULE_CHAIN:
|
case RULE_CHAIN:
|
||||||
RuleChainType ruleChainType = ((RuleChain) savedEntity).getType();
|
RuleChainType ruleChainType = ((RuleChain) savedEntity).getType();
|
||||||
if (RuleChainType.CORE.equals(ruleChainType)) {
|
if (RuleChainType.CORE.equals(ruleChainType)) {
|
||||||
tbClusterService.broadcastEntityStateChangeEvent(savedEntity.getTenantId(), savedEntity.getId(),
|
tbClusterService.broadcastEntityStateChangeEvent(user.getTenantId(), savedEntity.getId(),
|
||||||
isNewEntity ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
isNewEntity ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
||||||
}
|
}
|
||||||
if (RuleChainType.EDGE.equals(ruleChainType)) {
|
if (RuleChainType.EDGE.equals(ruleChainType)) {
|
||||||
@ -981,7 +981,7 @@ public abstract class BaseController {
|
|||||||
log.error("Failed to log entity action", e);
|
log.error("Failed to log entity action", e);
|
||||||
}
|
}
|
||||||
if (notifyEdgeService) {
|
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.EntityId;
|
||||||
import org.thingsboard.server.common.data.id.HasId;
|
import org.thingsboard.server.common.data.id.HasId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
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.ExportableEntityDao;
|
||||||
import org.thingsboard.server.dao.TenantEntityDao;
|
import org.thingsboard.server.dao.TenantEntityDao;
|
||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
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, EntityExportService<?, ?, ?>> exportServices = new HashMap<>();
|
||||||
private final Map<EntityType, EntityImportService<?, ?, ?>> importServices = 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(
|
protected static final List<EntityType> SUPPORTED_ENTITY_TYPES = List.of(
|
||||||
EntityType.CUSTOMER, EntityType.ASSET, EntityType.RULE_CHAIN,
|
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
|
@Override
|
||||||
public <E extends ExportableEntity<I>, I extends EntityId> E findEntityByExternalId(TenantId tenantId, I externalId) {
|
public <E extends ExportableEntity<I>, I extends EntityId> E findEntityByExternalId(TenantId tenantId, I externalId) {
|
||||||
EntityType entityType = externalId.getEntityType();
|
EntityType entityType = externalId.getEntityType();
|
||||||
@ -105,6 +100,12 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
|||||||
return findEntityById(tenantId, externalId);
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
private <I extends EntityId, E extends ExportableEntity<I>, D extends EntityExportData<E>> EntityExportService<I, E, D> getExportService(EntityType entityType) {
|
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);
|
return (EntityImportService<I, E, D>) importServices.get(entityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TenantEntityDao<?> getDao(EntityType entityType) {
|
private Dao<?> getDao(EntityType entityType) {
|
||||||
return daos.get(entityType);
|
return daos.get(entityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private void setServices(Collection<EntityExportService<?, ?, ?>> exportServices,
|
private void setServices(Collection<EntityExportService<?, ?, ?>> exportServices,
|
||||||
Collection<EntityImportService<?, ?, ?>> importServices,
|
Collection<EntityImportService<?, ?, ?>> importServices,
|
||||||
Collection<TenantEntityDao<?>> daos) {
|
Collection<Dao<?>> daos) {
|
||||||
exportServices.forEach(entityExportService -> {
|
exportServices.forEach(entityExportService -> {
|
||||||
this.exportServices.put(entityExportService.getEntityType(), entityExportService);
|
this.exportServices.put(entityExportService.getEntityType(), entityExportService);
|
||||||
});
|
});
|
||||||
@ -137,7 +138,9 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
|||||||
this.importServices.put(entityImportService.getEntityType(), entityImportService);
|
this.importServices.put(entityImportService.getEntityType(), entityImportService);
|
||||||
});
|
});
|
||||||
daos.forEach(dao -> {
|
daos.forEach(dao -> {
|
||||||
this.daos.put(dao.getEntityType(), dao);
|
if (dao.getEntityType() != null) {
|
||||||
|
this.daos.put(dao.getEntityType(), dao);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,13 +16,14 @@
|
|||||||
package org.thingsboard.server.service.sync.exporting;
|
package org.thingsboard.server.service.sync.exporting;
|
||||||
|
|
||||||
import org.thingsboard.server.common.data.ExportableEntity;
|
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.EntityId;
|
||||||
import org.thingsboard.server.common.data.id.HasId;
|
import org.thingsboard.server.common.data.id.HasId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
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 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
|
@Override
|
||||||
protected Asset prepareAndSave(TenantId tenantId, Asset asset, AssetExportData exportData, NewIdProvider idProvider) {
|
protected Asset prepareAndSave(TenantId tenantId, Asset asset, AssetExportData exportData, NewIdProvider idProvider) {
|
||||||
|
asset.setTenantId(tenantId);
|
||||||
asset.setCustomerId(idProvider.get(tenantId, Asset::getCustomerId));
|
asset.setCustomerId(idProvider.get(tenantId, Asset::getCustomerId));
|
||||||
return assetService.saveAsset(asset);
|
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());
|
E existingEntity = exportableEntitiesService.findEntityByExternalId(tenantId, entity.getId());
|
||||||
|
|
||||||
entity.setExternalId(entity.getId());
|
entity.setExternalId(entity.getId());
|
||||||
entity.setTenantId(tenantId);
|
|
||||||
|
|
||||||
if (existingEntity == null) {
|
if (existingEntity == null) {
|
||||||
entity.setId(null);
|
entity.setId(null);
|
||||||
|
|||||||
@ -34,6 +34,7 @@ public class CustomerImportService extends BaseEntityImportService<CustomerId, C
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Customer prepareAndSave(TenantId tenantId, Customer customer, CustomerExportData exportData, NewIdProvider idProvider) {
|
protected Customer prepareAndSave(TenantId tenantId, Customer customer, CustomerExportData exportData, NewIdProvider idProvider) {
|
||||||
|
customer.setTenantId(tenantId);
|
||||||
return customerService.saveCustomer(customer);
|
return customerService.saveCustomer(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,6 +43,7 @@ public class DashboardImportService extends BaseEntityImportService<DashboardId,
|
|||||||
// TODO [viacheslav]: improve the code
|
// TODO [viacheslav]: improve the code
|
||||||
@Override
|
@Override
|
||||||
protected Dashboard prepareAndSave(TenantId tenantId, Dashboard dashboard, DashboardExportData exportData, NewIdProvider idProvider) {
|
protected Dashboard prepareAndSave(TenantId tenantId, Dashboard dashboard, DashboardExportData exportData, NewIdProvider idProvider) {
|
||||||
|
dashboard.setTenantId(tenantId);
|
||||||
if (dashboard.getId() == null) {
|
if (dashboard.getId() == null) {
|
||||||
Set<ShortCustomerInfo> assignedCustomers = idProvider.get(tenantId, Dashboard::getAssignedCustomers, ShortCustomerInfo::getCustomerId, ShortCustomerInfo::setCustomerId);
|
Set<ShortCustomerInfo> assignedCustomers = idProvider.get(tenantId, Dashboard::getAssignedCustomers, ShortCustomerInfo::getCustomerId, ShortCustomerInfo::setCustomerId);
|
||||||
dashboard.setAssignedCustomers(null);
|
dashboard.setAssignedCustomers(null);
|
||||||
|
|||||||
@ -34,6 +34,7 @@ public class DeviceImportService extends BaseEntityImportService<DeviceId, Devic
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Device prepareAndSave(TenantId tenantId, Device device, DeviceExportData exportData, NewIdProvider idProvider) {
|
protected Device prepareAndSave(TenantId tenantId, Device device, DeviceExportData exportData, NewIdProvider idProvider) {
|
||||||
|
device.setTenantId(tenantId);
|
||||||
device.setCustomerId(idProvider.get(tenantId, Device::getCustomerId));
|
device.setCustomerId(idProvider.get(tenantId, Device::getCustomerId));
|
||||||
device.setDeviceProfileId(idProvider.get(tenantId, Device::getDeviceProfileId));
|
device.setDeviceProfileId(idProvider.get(tenantId, Device::getDeviceProfileId));
|
||||||
device.setFirmwareId(idProvider.get(tenantId, Device::getFirmwareId));
|
device.setFirmwareId(idProvider.get(tenantId, Device::getFirmwareId));
|
||||||
|
|||||||
@ -34,6 +34,7 @@ public class DeviceProfileImportService extends BaseEntityImportService<DevicePr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DeviceProfile prepareAndSave(TenantId tenantId, DeviceProfile deviceProfile, DeviceProfileExportData exportData, NewIdProvider idProvider) {
|
protected DeviceProfile prepareAndSave(TenantId tenantId, DeviceProfile deviceProfile, DeviceProfileExportData exportData, NewIdProvider idProvider) {
|
||||||
|
deviceProfile.setTenantId(tenantId);
|
||||||
deviceProfile.setDefaultRuleChainId(idProvider.get(tenantId, DeviceProfile::getDefaultRuleChainId));
|
deviceProfile.setDefaultRuleChainId(idProvider.get(tenantId, DeviceProfile::getDefaultRuleChainId));
|
||||||
deviceProfile.setDefaultDashboardId(idProvider.get(tenantId, DeviceProfile::getDefaultDashboardId));
|
deviceProfile.setDefaultDashboardId(idProvider.get(tenantId, DeviceProfile::getDefaultDashboardId));
|
||||||
deviceProfile.setFirmwareId(idProvider.get(tenantId, DeviceProfile::getFirmwareId));
|
deviceProfile.setFirmwareId(idProvider.get(tenantId, DeviceProfile::getFirmwareId));
|
||||||
|
|||||||
@ -42,6 +42,7 @@ public class RuleChainImportService extends BaseEntityImportService<RuleChainId,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RuleChain prepareAndSave(TenantId tenantId, RuleChain ruleChain, RuleChainExportData exportData, NewIdProvider idProvider) {
|
protected RuleChain prepareAndSave(TenantId tenantId, RuleChain ruleChain, RuleChainExportData exportData, NewIdProvider idProvider) {
|
||||||
|
ruleChain.setTenantId(tenantId);
|
||||||
RuleChainMetaData metaData = exportData.getMetaData();
|
RuleChainMetaData metaData = exportData.getMetaData();
|
||||||
Optional.ofNullable(metaData.getNodes()).orElse(Collections.emptyList())
|
Optional.ofNullable(metaData.getNodes()).orElse(Collections.emptyList())
|
||||||
.forEach(ruleNode -> {
|
.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.Device;
|
||||||
import org.thingsboard.server.common.data.DeviceProfile;
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
import org.thingsboard.server.common.data.ExportableEntity;
|
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.Tenant;
|
||||||
import org.thingsboard.server.common.data.User;
|
import org.thingsboard.server.common.data.User;
|
||||||
import org.thingsboard.server.common.data.asset.Asset;
|
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.EntityId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.rule.RuleChain;
|
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 java.util.List;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.as;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
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();
|
E importedEntity = importResult.getSavedEntity();
|
||||||
|
|
||||||
assertThat(initialEntity.getTenantId()).isEqualTo(tenantId1);
|
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.EntityId;
|
||||||
import org.thingsboard.server.common.data.id.HasId;
|
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();
|
I getId();
|
||||||
void setId(I id);
|
void setId(I id);
|
||||||
@ -27,7 +26,4 @@ public interface ExportableEntity<I extends EntityId> extends HasId<I>, HasTenan
|
|||||||
I getExternalId();
|
I getExternalId();
|
||||||
void setExternalId(I externalId);
|
void setExternalId(I externalId);
|
||||||
|
|
||||||
TenantId getTenantId();
|
|
||||||
void setTenantId(TenantId tenantId);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
package org.thingsboard.server.dao;
|
package org.thingsboard.server.dao;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -40,4 +41,6 @@ public interface Dao<T> {
|
|||||||
|
|
||||||
void removeAllByIds(Collection<UUID> ids);
|
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;
|
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);
|
T findByTenantIdAndExternalId(UUID tenantId, UUID externalId);
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ package org.thingsboard.server.dao;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface ExportableEntityRepository<D> extends TenantEntityRepository<D> {
|
public interface ExportableEntityRepository<D> {
|
||||||
|
|
||||||
D findByTenantIdAndExternalId(UUID tenantId, UUID externalId);
|
D findByTenantIdAndExternalId(UUID tenantId, UUID externalId);
|
||||||
|
|
||||||
|
|||||||
@ -15,18 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.dao;
|
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 org.thingsboard.server.common.data.id.TenantId;
|
||||||
|
|
||||||
import java.util.UUID;
|
public interface TenantEntityDao {
|
||||||
|
|
||||||
public interface TenantEntityDao<T extends HasTenantId> {
|
|
||||||
|
|
||||||
Long countByTenantId(TenantId tenantId);
|
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.
|
* 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.
|
* Find asset info by id.
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* The Interface CustomerDao.
|
* 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
|
* Save or update customer object
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import org.thingsboard.server.dao.TenantEntityDao;
|
|||||||
/**
|
/**
|
||||||
* The Interface DashboardDao.
|
* 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
|
* Save or update dashboard object
|
||||||
|
|||||||
@ -36,7 +36,7 @@ import java.util.UUID;
|
|||||||
* The Interface DeviceDao.
|
* 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.
|
* 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.TenantEntityDao;
|
||||||
import org.thingsboard.server.dao.TenantEntityWithDataDao;
|
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);
|
Long sumDataSizeByTenantId(TenantId tenantId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* Created by igor on 3/12/18.
|
* 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.
|
* 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);
|
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));
|
return DaoUtil.getData(assetRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Asset findByTenantIdAndId(UUID tenantId, UUID id) {
|
|
||||||
return DaoUtil.getData(assetRepository.findByTenantIdAndId(tenantId, id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityType getEntityType() {
|
public EntityType getEntityType() {
|
||||||
return EntityType.ASSET;
|
return EntityType.ASSET;
|
||||||
|
|||||||
@ -38,4 +38,5 @@ public interface CustomerRepository extends JpaRepository<CustomerEntity, UUID>,
|
|||||||
|
|
||||||
CustomerEntity findByTenantIdAndTitle(UUID tenantId, String title);
|
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));
|
return DaoUtil.getData(customerRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Customer findByTenantIdAndId(UUID tenantId, UUID id) {
|
|
||||||
return DaoUtil.getData(customerRepository.findByTenantIdAndId(tenantId, id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityType getEntityType() {
|
public EntityType getEntityType() {
|
||||||
return EntityType.CUSTOMER;
|
return EntityType.CUSTOMER;
|
||||||
|
|||||||
@ -57,11 +57,6 @@ public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, D
|
|||||||
return DaoUtil.getData(dashboardRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
return DaoUtil.getData(dashboardRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dashboard findByTenantIdAndId(UUID tenantId, UUID id) {
|
|
||||||
return DaoUtil.getData(dashboardRepository.findByTenantIdAndId(tenantId, id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityType getEntityType() {
|
public EntityType getEntityType() {
|
||||||
return EntityType.DASHBOARD;
|
return EntityType.DASHBOARD;
|
||||||
|
|||||||
@ -308,11 +308,6 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
|
|||||||
return DaoUtil.getData(deviceRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
return DaoUtil.getData(deviceRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Device findByTenantIdAndId(UUID tenantId, UUID id) {
|
|
||||||
return findDeviceByTenantIdAndId(TenantId.fromUUID(tenantId), id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityType getEntityType() {
|
public EntityType getEntityType() {
|
||||||
return EntityType.DEVICE;
|
return EntityType.DEVICE;
|
||||||
|
|||||||
@ -116,16 +116,6 @@ public class JpaDeviceProfileDao extends JpaAbstractSearchTextDao<DeviceProfileE
|
|||||||
return DaoUtil.getData(deviceProfileRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
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
|
@Override
|
||||||
public EntityType getEntityType() {
|
public EntityType getEntityType() {
|
||||||
return EntityType.DEVICE_PROFILE;
|
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.EntityType;
|
||||||
import org.thingsboard.server.common.data.OtaPackage;
|
import org.thingsboard.server.common.data.OtaPackage;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
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.ota.OtaPackageDao;
|
||||||
import org.thingsboard.server.dao.model.sql.OtaPackageEntity;
|
import org.thingsboard.server.dao.model.sql.OtaPackageEntity;
|
||||||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
|
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
|
||||||
@ -51,16 +50,6 @@ public class JpaOtaPackageDao extends JpaAbstractSearchTextDao<OtaPackageEntity,
|
|||||||
return otaPackageRepository.sumDataSizeByTenantId(tenantId.getId());
|
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
|
@Override
|
||||||
public EntityType getEntityType() {
|
public EntityType getEntityType() {
|
||||||
return EntityType.OTA_PACKAGE;
|
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.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.thingsboard.server.dao.TenantEntityRepository;
|
|
||||||
import org.thingsboard.server.dao.model.sql.OtaPackageEntity;
|
import org.thingsboard.server.dao.model.sql.OtaPackageEntity;
|
||||||
|
|
||||||
import java.util.UUID;
|
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)
|
@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);
|
Long sumDataSizeByTenantId(@Param("tenantId") UUID tenantId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -114,11 +114,6 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R
|
|||||||
return DaoUtil.getData(ruleChainRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
return DaoUtil.getData(ruleChainRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public RuleChain findByTenantIdAndId(UUID tenantId, UUID id) {
|
|
||||||
return DaoUtil.getData(ruleChainRepository.findByTenantIdAndId(tenantId, id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityType getEntityType() {
|
public EntityType getEntityType() {
|
||||||
return EntityType.RULE_CHAIN;
|
return EntityType.RULE_CHAIN;
|
||||||
|
|||||||
@ -63,6 +63,8 @@ public interface RuleChainRepository extends JpaRepository<RuleChainEntity, UUID
|
|||||||
|
|
||||||
RuleChainEntity findByTenantIdAndTypeAndRootIsTrue(UUID tenantId, RuleChainType ruleChainType);
|
RuleChainEntity findByTenantIdAndTypeAndRootIsTrue(UUID tenantId, RuleChainType ruleChainType);
|
||||||
|
|
||||||
|
Long countByTenantId(UUID tenantId);
|
||||||
|
|
||||||
List<RuleChainEntity> findByTenantIdAndTypeAndName(UUID tenantId, RuleChainType type, String name);
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Component;
|
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.User;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.page.PageData;
|
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) {
|
public Long countByTenantId(TenantId tenantId) {
|
||||||
return userRepository.countByTenantId(tenantId.getId());
|
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.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.thingsboard.server.common.data.security.Authority;
|
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 org.thingsboard.server.dao.model.sql.UserEntity;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -30,7 +28,7 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* @author Valerii Sosliuk
|
* @author Valerii Sosliuk
|
||||||
*/
|
*/
|
||||||
public interface UserRepository extends JpaRepository<UserEntity, UUID>, TenantEntityRepository<UserEntity> {
|
public interface UserRepository extends JpaRepository<UserEntity, UUID> {
|
||||||
|
|
||||||
UserEntity findByEmail(String email);
|
UserEntity findByEmail(String email);
|
||||||
|
|
||||||
@ -49,4 +47,5 @@ public interface UserRepository extends JpaRepository<UserEntity, UUID>, TenantE
|
|||||||
@Param("searchText") String searchText,
|
@Param("searchText") String searchText,
|
||||||
Pageable pageable);
|
Pageable pageable);
|
||||||
|
|
||||||
|
Long countByTenantId(UUID tenantId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import org.thingsboard.server.dao.TenantEntityDao;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface UserDao extends Dao<User>, TenantEntityDao<User> {
|
public interface UserDao extends Dao<User>, TenantEntityDao {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save or update user object
|
* Save or update user object
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user