Fixed Implementation of DAO and services after merge

This commit is contained in:
Andrew Shvayka 2017-05-30 13:14:51 +03:00
parent d1dad3c09a
commit 410d197a34
5 changed files with 10 additions and 12 deletions

View File

@ -193,7 +193,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
public ListenableFuture<Alarm> findAlarmByIdAsync(AlarmId alarmId) { public ListenableFuture<Alarm> findAlarmByIdAsync(AlarmId alarmId) {
log.trace("Executing findAlarmById [{}]", alarmId); log.trace("Executing findAlarmById [{}]", alarmId);
validateId(alarmId, "Incorrect alarmId " + alarmId); validateId(alarmId, "Incorrect alarmId " + alarmId);
return alarmDao.findByIdAsync(alarmId.getId()); return alarmDao.findAlarmByIdAsync(alarmId.getId());
} }
@Override @Override

View File

@ -102,6 +102,10 @@ public class CassandraAlarmDao extends CassandraAbstractModelDao<AlarmEntity, Al
@Override @Override
public ListenableFuture<Alarm> findAlarmByIdAsync(UUID key) { public ListenableFuture<Alarm> findAlarmByIdAsync(UUID key) {
return findByIdAsync(key); log.debug("Get alarm by id {}", key);
Select.Where query = select().from(ALARM_BY_ID_VIEW_NAME).where(eq(ModelConstants.ID_PROPERTY, key));
query.limit(1);
log.trace("Execute query {}", query);
return findOneByStatementAsync(query);
} }
} }

View File

@ -226,7 +226,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
(Function<List<TenantAssetType>, List<TenantAssetType>>) assetTypeEntities -> { (Function<List<TenantAssetType>, List<TenantAssetType>>) assetTypeEntities -> {
List<TenantAssetType> assetTypes = new ArrayList<>(); List<TenantAssetType> assetTypes = new ArrayList<>();
for (TenantAssetType assetType : assetTypeEntities) { for (TenantAssetType assetType : assetTypeEntities) {
if (assetType.getTenantId().equals(tenantId.getId())) { if (assetType.getTenantId().equals(tenantId)) {
assetTypes.add(assetType); assetTypes.add(assetType);
} }
} }
@ -252,7 +252,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
protected void validateUpdate(Asset asset) { protected void validateUpdate(Asset asset) {
assetDao.findAssetsByTenantIdAndName(asset.getTenantId().getId(), asset.getName()).ifPresent( assetDao.findAssetsByTenantIdAndName(asset.getTenantId().getId(), asset.getName()).ifPresent(
d -> { d -> {
if (!d.getId().equals(asset.getUuidId())) { if (!d.getId().equals(asset.getId())) {
throw new DataValidationException("Asset with such name already exists!"); throw new DataValidationException("Asset with such name already exists!");
} }
} }
@ -282,7 +282,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
if (customer == null) { if (customer == null) {
throw new DataValidationException("Can't assign asset to non-existent customer!"); throw new DataValidationException("Can't assign asset to non-existent customer!");
} }
if (!customer.getTenantId().equals(asset.getTenantId().getId())) { if (!customer.getTenantId().equals(asset.getTenantId())) {
throw new DataValidationException("Can't assign asset to customer from different tenant!"); throw new DataValidationException("Can't assign asset to customer from different tenant!");
} }
} }

View File

@ -54,12 +54,6 @@ public class CassandraAssetDao extends CassandraAbstractSearchTextDao<AssetEntit
return ASSET_COLUMN_FAMILY_NAME; return ASSET_COLUMN_FAMILY_NAME;
} }
@Override
public Asset save(Asset asset) {
log.debug("Save asset [{}] ", asset);
return save(asset);
}
@Override @Override
public List<Asset> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink) { public List<Asset> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink) {
log.debug("Try to find assets by tenantId [{}] and pageLink [{}]", tenantId, pageLink); log.debug("Try to find assets by tenantId [{}] and pageLink [{}]", tenantId, pageLink);

View File

@ -246,7 +246,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
(Function<List<TenantDeviceType>, List<TenantDeviceType>>) deviceTypeEntities -> { (Function<List<TenantDeviceType>, List<TenantDeviceType>>) deviceTypeEntities -> {
List<TenantDeviceType> deviceTypes = new ArrayList<>(); List<TenantDeviceType> deviceTypes = new ArrayList<>();
for (TenantDeviceType deviceType : deviceTypeEntities) { for (TenantDeviceType deviceType : deviceTypeEntities) {
if (deviceType.getTenantId().equals(tenantId.getId())) { if (deviceType.getTenantId().equals(tenantId)) {
deviceTypes.add(deviceType); deviceTypes.add(deviceType);
} }
} }