rollback optional changes for fetchEntityCustomerId method

This commit is contained in:
ShvaykaD 2022-12-14 12:37:19 +02:00
parent f167c7c48b
commit 7d9f437927
4 changed files with 6 additions and 6 deletions

View File

@ -561,7 +561,7 @@ public class DefaultDataUpdateService implements DataUpdateService {
while (hasNext) { while (hasNext) {
for (Alarm alarm : alarms.getData()) { for (Alarm alarm : alarms.getData()) {
if (alarm.getCustomerId() == null && alarm.getOriginator() != null) { if (alarm.getCustomerId() == null && alarm.getOriginator() != null) {
alarm.setCustomerId(entityService.fetchEntityCustomerId(tenantId, alarm.getOriginator()).get()); alarm.setCustomerId(entityService.fetchEntityCustomerId(tenantId, alarm.getOriginator()));
alarmDao.save(tenantId, alarm); alarmDao.save(tenantId, alarm);
} }
if (processed.incrementAndGet() % 1000 == 0) { if (processed.incrementAndGet() % 1000 == 0) {

View File

@ -29,7 +29,7 @@ public interface EntityService {
Optional<String> fetchEntityName(TenantId tenantId, EntityId entityId); Optional<String> fetchEntityName(TenantId tenantId, EntityId entityId);
Optional<CustomerId> fetchEntityCustomerId(TenantId tenantId, EntityId entityId); CustomerId fetchEntityCustomerId(TenantId tenantId, EntityId entityId);
long countEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityCountQuery query); long countEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityCountQuery query);

View File

@ -114,7 +114,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
if (alarm.getEndTs() == 0L) { if (alarm.getEndTs() == 0L) {
alarm.setEndTs(alarm.getStartTs()); alarm.setEndTs(alarm.getStartTs());
} }
alarm.setCustomerId(entityService.fetchEntityCustomerId(alarm.getTenantId(), alarm.getOriginator()).get()); alarm.setCustomerId(entityService.fetchEntityCustomerId(alarm.getTenantId(), alarm.getOriginator()));
if (alarm.getId() == null) { if (alarm.getId() == null) {
Alarm existing = alarmDao.findLatestByOriginatorAndType(alarm.getTenantId(), alarm.getOriginator(), alarm.getType()); Alarm existing = alarmDao.findLatestByOriginatorAndType(alarm.getTenantId(), alarm.getOriginator(), alarm.getType());
if (existing == null || existing.getStatus().isCleared()) { if (existing == null || existing.getStatus().isCleared()) {

View File

@ -90,7 +90,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
} }
@Override @Override
public Optional<CustomerId> fetchEntityCustomerId(TenantId tenantId, EntityId entityId) { public CustomerId fetchEntityCustomerId(TenantId tenantId, EntityId entityId) {
log.trace("Executing fetchEntityCustomerId [{}]", entityId); log.trace("Executing fetchEntityCustomerId [{}]", entityId);
TbEntityService tbEntityService = entityServiceBeanFactory.getServiceByEntityType(entityId.getEntityType()); TbEntityService tbEntityService = entityServiceBeanFactory.getServiceByEntityType(entityId.getEntityType());
Optional<HasId<?>> hasIdOpt = tbEntityService.fetchEntity(tenantId, entityId); Optional<HasId<?>> hasIdOpt = tbEntityService.fetchEntity(tenantId, entityId);
@ -98,10 +98,10 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
HasId<?> hasId = hasIdOpt.get(); HasId<?> hasId = hasIdOpt.get();
if (hasId instanceof HasCustomerId) { if (hasId instanceof HasCustomerId) {
HasCustomerId hasCustomerId = (HasCustomerId) hasId; HasCustomerId hasCustomerId = (HasCustomerId) hasId;
return Optional.ofNullable(hasCustomerId.getCustomerId()); return hasCustomerId.getCustomerId();
} }
} }
return Optional.of(NULL_CUSTOMER_ID); return NULL_CUSTOMER_ID;
} }
private static void validateEntityCountQuery(EntityCountQuery query) { private static void validateEntityCountQuery(EntityCountQuery query) {