Skip to content

Commit

Permalink
Added validations before sync Huawei production data
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorKhan committed Apr 15, 2024
1 parent 5bb5703 commit e253d1a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.lucoenergia.conluz.domain.production.huawei.sync;

import org.lucoenergia.conluz.domain.production.huawei.HuaweiConfig;
import org.lucoenergia.conluz.domain.production.huawei.get.GetHuaweiConfigRepository;
import org.lucoenergia.conluz.domain.production.plant.Plant;
import org.lucoenergia.conluz.domain.production.InverterProvider;
import org.lucoenergia.conluz.domain.production.get.GetEnergyStationRepository;
Expand All @@ -8,25 +10,34 @@
import org.lucoenergia.conluz.domain.production.huawei.persist.PersistHuaweiProductionRepository;
import org.lucoenergia.conluz.infrastructure.production.huawei.get.GetHuaweiHourlyProductionRepositoryRest;
import org.lucoenergia.conluz.infrastructure.production.huawei.get.GetHuaweiRealTimeProductionRepositoryRest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class SyncHuaweiProductionService {

private static final Logger LOGGER = LoggerFactory.getLogger(SyncHuaweiProductionService.class);

private final PersistHuaweiProductionRepository persistHuaweiProductionRepository;
private final GetHuaweiRealTimeProductionRepositoryRest getHuaweiRealTimeProductionRepositoryRest;
private final GetHuaweiHourlyProductionRepositoryRest getHuaweiHourlyProductionRepositoryRest;
private final GetEnergyStationRepository getEnergyStationRepository;
private final GetHuaweiConfigRepository getHuaweiConfigRepository;

public SyncHuaweiProductionService(PersistHuaweiProductionRepository persistHuaweiProductionRepository,
GetHuaweiRealTimeProductionRepositoryRest getHuaweiRealTimeProductionRepositoryRest, GetHuaweiHourlyProductionRepositoryRest getHuaweiHourlyProductionRepositoryRest,
GetEnergyStationRepository getEnergyStationRepository) {
GetHuaweiRealTimeProductionRepositoryRest getHuaweiRealTimeProductionRepositoryRest,
GetHuaweiHourlyProductionRepositoryRest getHuaweiHourlyProductionRepositoryRest,
GetEnergyStationRepository getEnergyStationRepository,
GetHuaweiConfigRepository getHuaweiConfigRepository) {
this.persistHuaweiProductionRepository = persistHuaweiProductionRepository;
this.getHuaweiRealTimeProductionRepositoryRest = getHuaweiRealTimeProductionRepositoryRest;
this.getHuaweiHourlyProductionRepositoryRest = getHuaweiHourlyProductionRepositoryRest;
this.getEnergyStationRepository = getEnergyStationRepository;
this.getHuaweiConfigRepository = getHuaweiConfigRepository;
}

/**
Expand All @@ -36,8 +47,19 @@ public SyncHuaweiProductionService(PersistHuaweiProductionRepository persistHuaw
*/
public void syncRealTimeProduction() {

// Get Huawei configuration
Optional<HuaweiConfig> huaweiConfig = getHuaweiConfigRepository.getHuaweiConfig();
if (huaweiConfig.isEmpty()) {
LOGGER.debug("No Huawei config found");
return;
}

// Get all energy stations with Huawei inverter
List<Plant> huaweiStations = getEnergyStationRepository.findAllByInverterProvider(InverterProvider.HUAWEI);
if (huaweiStations.isEmpty()) {
LOGGER.debug("No Huawei stations found");
return;
}

// Get the productions for every station
List<RealTimeProduction> productions = getHuaweiRealTimeProductionRepositoryRest.getRealTimeProduction(huaweiStations);
Expand All @@ -48,8 +70,19 @@ public void syncRealTimeProduction() {

public void syncHourlyProduction() {

// Get Huawei configuration
Optional<HuaweiConfig> huaweiConfig = getHuaweiConfigRepository.getHuaweiConfig();
if (huaweiConfig.isEmpty()) {
LOGGER.debug("No Huawei config found");
return;
}

// Get all energy stations with Huawei inverter
List<Plant> huaweiStations = getEnergyStationRepository.findAllByInverterProvider(InverterProvider.HUAWEI);
if (huaweiStations.isEmpty()) {
LOGGER.debug("No Huawei stations found");
return;
}

// Get the productions for every station
List<HourlyProduction> productions = getHuaweiHourlyProductionRepositoryRest.getHourlyProduction(huaweiStations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.lucoenergia.conluz.infrastructure.shared.uuid.ValidUUID;

import java.time.LocalDate;
import java.util.Objects;
import java.util.UUID;

public class Plant {
Expand Down Expand Up @@ -147,4 +148,25 @@ public Plant build() {
return station;
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Plant plant)) return false;
return Objects.equals(getId(), plant.getId()) && Objects.equals(getName(), plant.getName()) && Objects.equals(getCode(), plant.getCode());
}

@Override
public int hashCode() {
return Objects.hash(getId(), getName(), getCode());
}

@Override
public String toString() {
return "Plant{" +
"name='" + name + '\'' +
", code='" + code + '\'' +
", id=" + id +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public List<HourlyProduction> getHourlyProduction(List<Plant> stations) {
List<HourlyProduction> result = new ArrayList<>();

if (stations == null || stations.isEmpty()) {
LOGGER.debug("No Huawei stations provided");
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public List<RealTimeProduction> getRealTimeProduction(List<Plant> stations) {
List<RealTimeProduction> result = new ArrayList<>();

if (stations == null || stations.isEmpty()) {
LOGGER.debug("No Huawei stations provided");
return result;
}

Expand Down

0 comments on commit e253d1a

Please sign in to comment.