Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
public class UserController {

private final LdapClientEmployeeService ldapClientEmployeeService;
private final LdapMapper ldapMapper;


@GetMapping("/{nni}")
public ResponseEntity<UserInfoDto> getUserByNni(@PathVariable String nni) {
UserInfoDto user = ldapMapper.toUserDto(ldapClientEmployeeService.getUserByNni(nni));
UserInfoDto user = LdapMapper.toUserDto(ldapClientEmployeeService.getUserByNni(nni));
if (user == null) {
return ResponseEntity.notFound().build();
}
Expand All @@ -29,7 +27,7 @@ public ResponseEntity<UserInfoDto> getUserByNni(@PathVariable String nni) {

@PostMapping("/list")
public ResponseEntity<List<UserInfoDto>> getUsersByListNni(@RequestBody List<String> listNni) {
List<UserInfoDto> users = ldapMapper.toUsersDto(ldapClientEmployeeService.getUsersByListNni(listNni));
List<UserInfoDto> users = LdapMapper.toUsersDto(ldapClientEmployeeService.getUsersByListNni(listNni));
return ResponseEntity.ok(users);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import com.rte_france.antares.datamanager_back.configuration.gaia.Employee;
import com.rte_france.antares.datamanager_back.dto.UserInfoDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import lombok.*;

import java.util.Collections;
import java.util.List;

@Component
@RequiredArgsConstructor
@Value
@Builder(toBuilder = true)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class LdapMapper {

public static List<UserInfoDto> toUsersDto(List<Employee> employees) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ public TrajectoryEntity processLinkFile(Path path, String horizon, Integer study
);
String createdBy = userService.getCurrentUserDetails().getNni();

List<String> areaNames = findListArea(studyId);

List<LinkEntity> listLink = buildLinkList(path, horizon, areaNames);
List<LinkEntity> listLink = buildLinkList(path, horizon);

TrajectoryEntity trajectory;
if (trajectoryEntity.isPresent() && checkTrajectoryVersion(path, trajectoryEntity.get())) {
Expand All @@ -86,6 +85,7 @@ public TrajectoryEntity processLinkFile(Path path, String horizon, Integer study
TrajectoryEntity secondTrajectory = trajectoryRepository.findByTypeAndStudyId(TrajectoryType.AREA.name(), studyId).stream().findFirst().orElse(null);
String userNni = findUserNni();

List<String> areaNames = findListArea(studyId);
checkForWarnings(path, horizon, studyId, warningMessageEntities, userNni, trajectory);
checkConsistencyTrajectoryLinkAndArea(listLink, areaNames, warningMessageEntities, studyId, trajectory.getId(), secondTrajectory, userNni);

Expand Down Expand Up @@ -186,7 +186,7 @@ public TrajectoryEntity saveTrajectory(TrajectoryEntity trajectory, List<LinkEnt
* @param path the path to the file to process
* @return a list of area configurations
*/
private List<LinkEntity> buildLinkList(Path path, String horizon, List<String> listArea) throws IOException {
private List<LinkEntity> buildLinkList(Path path, String horizon) {
List<LinkEntity> linkEntities = new ArrayList<>();
try (InputStream inputStream = Files.newInputStream(path);
Workbook workbook = WorkbookFactory.create(inputStream)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Set<WarningMessageEntity> checkForMissingLoadByAreaFromDb(String horizon,
studyId,
userNni,
trajectory,
getFileCheckerByDatabase(horizon, trajectory, studyId)
getFileCheckerByDatabase(horizon, trajectory)
);
}

Expand Down Expand Up @@ -164,7 +164,7 @@ private LoadChecker getFileCheckerByPath(Path trajectoryPath, String horizon) {
* Returns a LoadChecker that checks for file existence in the database.
* If the file does not exist, it creates a new LoadEntity and saves it.
*/
private LoadChecker getFileCheckerByDatabase(String horizon, TrajectoryEntity trajectory, Integer studyId) {
private LoadChecker getFileCheckerByDatabase(String horizon, TrajectoryEntity trajectory) {
if (trajectory.getLoadEntities() != null && !trajectory.getLoadEntities().isEmpty()) {
Set<String> areasInThisOthers = trajectory.getLoadEntities().stream()
.map(LoadEntity::getArea)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public class ThermalFileProcessorServiceImpl implements ThermalFileProcessorServ
private final StudyRepository studyRepository;

private static final String YEAR_MONTH_PATTERN = "%04d_%02d";
private static final String UNKNOWN_USER = "UNKNOWN__USER";

private record ThermalRow(Row row, Row header, String horizon, boolean isCivilYear, String technology,
String rowArea) {}

@Override
public List<ThermalCommonParameterEntity> buildThermalCommonParameterValuesList(Path path, String horizon) throws IOException {
Expand Down Expand Up @@ -102,7 +105,7 @@ public List<ThermalCommonParameterEntity> buildThermalCommonParameterValuesList(

@Override
public TrajectoryEntity processThermalCommonParameterFile(Path path, String horizon, List<ThermalCommonParameterEntity> list, TrajectoryType type) throws IOException {
String createdBy = userService.getCurrentUserDetails() != null ? userService.getCurrentUserDetails().getNni() : "UNKNOWN__USER";
String createdBy = userService.getCurrentUserDetails() != null ? userService.getCurrentUserDetails().getNni() : UNKNOWN_USER;
// Find existing trajectory for same file name/horizon/type
Optional<TrajectoryEntity> existingOpt = trajectoryRepository.findFirstByFileNameAndHorizonAndTypeOrderByVersionDesc(
getFileNameWithoutExtensionAndWithoutPrefix(path.getFileName().toString(), TrajectoryType.THERMAL_TECHNICAL_COMMON_PARAMETER.name()),
Expand All @@ -129,7 +132,7 @@ public TrajectoryEntity processThermalCommonParameterFile(Path path, String hori
* @param path the path to the file to process
*/
public TrajectoryEntity processThermalCapacityFile(Path path, String horizon, ThermalClusterCapacityDto thermalClusterCapacityDto, TrajectoryType type, String area, String technology) throws IOException {
String createdBy = userService.getCurrentUserDetails() != null ? userService.getCurrentUserDetails().getNni() : "UNKNOWN__USER";
String createdBy = userService.getCurrentUserDetails() != null ? userService.getCurrentUserDetails().getNni() : UNKNOWN_USER;
return saveThermalCapacitiesTrajectory(buildTrajectory(path, 0, horizon, createdBy, TrajectoryType.THERMAL_CAPACITY, area, technology), thermalClusterCapacityDto, type);
}

Expand Down Expand Up @@ -197,14 +200,16 @@ public ThermalClusterCapacityDto buildThermalClusterCapacityValuesList(
if (row.getRowNum() == 0) continue;
String rowArea = row.getCell(1).getStringCellValue().toUpperCase();

var thermalRow = new ThermalRow(row, header, horizon, isCivilYear, technology, rowArea);
if (!area.equals(OTHERS_AREA)) {
if (rowArea.equals(area.toUpperCase())) {
isSpecificAreaFound = true;
processThermalRow(row, header, horizon, isCivilYear, technology, rowArea, capacities, checksumBuilder);

processThermalRow(thermalRow, capacities, checksumBuilder);
}
} else {
otherAreas.add(rowArea);
processThermalRow(row, header, horizon, isCivilYear, technology, rowArea, capacities, checksumBuilder);
processThermalRow(thermalRow, capacities, checksumBuilder);
}
}
} catch (IOException e) {
Expand Down Expand Up @@ -280,7 +285,7 @@ public WarningMessageEntity buildWarningMessage(Path path, String area, Integer
.httpStatus(HttpStatus.NOT_FOUND)
.build()))
.creationDate(LocalDateTime.now())
.createdBy(userService.getCurrentUserDetails() != null ? userService.getCurrentUserDetails().getNni() : "UNKNOWN__USER")
.createdBy(userService.getCurrentUserDetails() != null ? userService.getCurrentUserDetails().getNni() : UNKNOWN_USER)
.isAck(false)
.build();
} else {
Expand All @@ -297,27 +302,26 @@ private List<String> getStudyAreasForCurrentStudy(Integer studyId) {
.toList();
}

private void processThermalRow(Row row, Row header, String horizon, boolean isCivilYear, String technology,
String rowArea, List<ThermalClusterCapacityEntity> result, StringBuilder checksum) {
String techName = row.getCell(2).getStringCellValue();
String clusterName = row.getCell(3).getStringCellValue();
String categoryStr = row.getCell(4).getStringCellValue().toLowerCase();
private void processThermalRow(ThermalRow thermalRow, List<ThermalClusterCapacityEntity> result, StringBuilder checksum) {
String techName = thermalRow.row().getCell(2).getStringCellValue();
String clusterName = thermalRow.row().getCell(3).getStringCellValue();
String categoryStr = thermalRow.row().getCell(4).getStringCellValue().toLowerCase();

if (technology != null && !technology.isEmpty() && !techName.equalsIgnoreCase(technology)) return;
if (thermalRow.technology() != null && !thermalRow.technology().isEmpty() && !techName.equalsIgnoreCase(thermalRow.technology())) return;

for (int i = 5; i < header.getLastCellNum(); i++) {
String monthYear = header.getCell(i).getStringCellValue();
if (!isCellInHorizon(monthYear, horizon, isCivilYear)) continue;
for (int i = 5; i < thermalRow.header().getLastCellNum(); i++) {
String monthYear = thermalRow.header().getCell(i).getStringCellValue();
if (!isCellInHorizon(monthYear, thermalRow.horizon(), thermalRow.isCivilYear())) continue;

ThermalCategoryEnum category = categoryStr.equals(ThermalCategoryEnum.POWER.name().toLowerCase())
? ThermalCategoryEnum.POWER
: ThermalCategoryEnum.NUMBER;

double value = capacityValue(row, i, horizon);
boolean toUse = row.getCell(0).getNumericCellValue() == 0;
double value = capacityValue(thermalRow.row(), i, thermalRow.horizon());
boolean toUse = thermalRow.row().getCell(0).getNumericCellValue() == 0;

// Ajout des valeurs au checksum
checksum.append(rowArea).append("|")
checksum.append(thermalRow.rowArea()).append("|")
.append(techName).append("|")
.append(clusterName).append("|")
.append(category.name()).append("|")
Expand All @@ -327,7 +331,7 @@ private void processThermalRow(Row row, Row header, String horizon, boolean isCi

ThermalClusterCapacityEntity entity = ThermalClusterCapacityEntity.builder()
.toUse(toUse)
.area(rowArea)
.area(thermalRow.rowArea())
.thermalClusterRef(findOrCreateThermalClusterRef(techName, clusterName))
.category(category)
.monthYear(monthYear)
Expand Down Expand Up @@ -476,8 +480,7 @@ public boolean isCellInHorizon(String monthYear, String horizon, boolean isCivil
} else {
// Année à cheval : juillet année horizon à juin année horizon+1
if (year == horizonYear && month >= 7) return true;
if (year == horizonYear + 1 && month <= 6) return true;
return false;
return year == horizonYear + 1 && month <= 6;
}
}

Expand Down Expand Up @@ -613,7 +616,7 @@ private String calculateChecksum(String input) {
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Erreur lors du calcul du checksum", e);
throw TechnicalException.builder().message("Erreur lors du calcul du checksum: " + e.getMessage()).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public TrajectoryEntity processTrajectory(TrajectoryType trajectoryType, String
* @throws IOException if an I/O error occurs
*/
public TrajectoryEntity processThermalCapacityTrajectory(String trajectoryToUse, String horizon, Integer studyId, boolean isCivilYear, String area, String technology) throws IOException {
if (trajectoryToUse == null || !trajectoryToUse.toLowerCase().startsWith("thermal_")) {
if (trajectoryToUse == null || !trajectoryToUse.toLowerCase().startsWith(CAPACITY_PREFIX)) {
throw BusinessException.builder()
.message("The trajectory file name must start with 'thermal_'")
.httpStatus(HttpStatus.BAD_REQUEST)
Expand Down Expand Up @@ -440,9 +440,9 @@ private boolean isValidTrajectoryFile(Path path, TrajectoryType trajectoryType)

@Override
public List<TrajectoryDTO> findTrajectoriesByTypeAndStudyId(String trajectoryType, Integer studyId) {
List<TrajectoryEntity> trajectoryEntities = trajectoryRepository.findByTypeAndStudyId(trajectoryType, studyId).stream()
.peek(trajectory ->
trajectory.setWarningMessages(filterWarningMessages(studyId, trajectory.getWarningMessages()))).toList();
List<TrajectoryEntity> trajectoryEntities = trajectoryRepository.findByTypeAndStudyId(trajectoryType, studyId);
trajectoryEntities.forEach(trajectory ->
trajectory.setWarningMessages(filterWarningMessages(studyId, trajectory.getWarningMessages())));
return TrajectoryMapper.toTrajectoryDtos(trajectoryEntities);
}

Expand Down Expand Up @@ -717,10 +717,10 @@ public List<TrajectoryDataDTO> getTrajectoryDataByTypeAndId(TrajectoryType traje

@Override
public Map<String, Integer> countWarningMessage(Integer studyId) {
return trajectoryRepository.findByTypeAndStudyId(null, studyId).stream()
.peek(trajectory ->
trajectory.setWarningMessages(filterWarningMessages(studyId, trajectory.getWarningMessages()))).toList()
.stream()
var trajectories = trajectoryRepository.findByTypeAndStudyId(null, studyId);
trajectories.forEach(trajectory ->
trajectory.setWarningMessages(filterWarningMessages(studyId, trajectory.getWarningMessages())));
return trajectories.stream()
.collect(Collectors.groupingBy(
TrajectoryEntity::getType,
Collectors.summingInt(trajectory -> trajectory.getWarningMessages() != null ? trajectory.getWarningMessages().size() : 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.Year;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
Expand Down Expand Up @@ -192,11 +191,6 @@ else if (Objects.equals(trajectoryType, TrajectoryType.THERMAL_TECHNICAL_COMMON_
return fileName.substring(0, lastDotIndex);
}

private static String isLinkTypePrefix(String trajectoryType) {
return Objects.equals(trajectoryType, TrajectoryType.LINK.toString()) ? LINKS_PREFIX : "";
}


public static boolean isSheetNameYearNumber(Sheet sheet) {
String sheetName = sheet.getSheetName();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.rte_france.antares.datamanager_back.exception.BusinessException;
import com.rte_france.antares.datamanager_back.exception.TechnicalException;
import com.rte_france.antares.datamanager_back.util.excel_file_validators.columns_enum.AreaColumns;
import lombok.NoArgsConstructor;
import org.apache.poi.ss.usermodel.*;
import org.springframework.http.HttpStatus;

Expand Down Expand Up @@ -39,7 +38,7 @@ public static void validateAreaColumns(Path path, String horizon) throws Busines

checkColumnsRules(sheet, horizon, AreaColumns.getBooleanColumnNames(), AreaColumns.getStringColumnNames(), TrajectoryType.AREA.name());
checkAreasValuesLength(sheet, horizon, AreaColumns.AREAS.getDisplayName());
checkForDuplicateValues(sheet, AreaColumns.AREAS.getDisplayName(), path, horizon, false, TrajectoryType.AREA.name());
checkForDuplicateValues(sheet, AreaColumns.AREAS.getDisplayName(), horizon, false, TrajectoryType.AREA.name());
} catch (IOException e) {
throw TechnicalException.builder()
.message("Error reading file: {0}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.rte_france.antares.datamanager_back.util.excel_file_validators.columns_enum.AreaColumns;
import com.rte_france.antares.datamanager_back.util.excel_file_validators.columns_enum.ExcelFileType;
import com.rte_france.antares.datamanager_back.util.excel_file_validators.columns_enum.LinksColumns;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*;
import org.springframework.http.HttpStatus;
Expand All @@ -22,6 +24,7 @@

@Slf4j
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ExcelCommonValidator {


Expand Down Expand Up @@ -200,7 +203,6 @@ public static void checkBooleanColumns(Sheet sheet, String horizon, List<String>
? LinksColumns.NAME.name()
: null);


int identifierColumnIndex = identifierColumn != null
? findColumnIndex(sheet, identifierColumn, horizon, trajectoryType)
: -1;
Expand Down Expand Up @@ -332,7 +334,7 @@ static int findColumnIndex(Sheet sheet, String columnName, String horizon, Strin
.build());
}

public static void checkForDuplicateValues(Sheet sheet, String columnName, Path path, String horizon, boolean checkSymmetric, String trajectoryType) {
public static void checkForDuplicateValues(Sheet sheet, String columnName, String horizon, boolean checkSymmetric, String trajectoryType) {
int columnIndex = findColumnIndex(sheet, columnName, horizon, trajectoryType);
Map<String, String> seenValues = new HashMap<>();
Set<String> identicalDuplicates = new TreeSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void linksDuplicateAndCellsValuesChecks(Path path, ExcelFileType f

Sheet sheet = workbook.getSheet(horizon);
if (fileType == ExcelFileType.LINKS) {
checkForDuplicateValues(sheet, LinksColumns.NAME.getDisplayName(), path, horizon, true, TrajectoryType.LINK.name());
checkForDuplicateValues(sheet, LinksColumns.NAME.getDisplayName(), horizon, true, TrajectoryType.LINK.name());
checkColumnsRules(sheet, horizon, LinksColumns.getNumericColumnNames(), LinksColumns.getBooleanColumnNames(), Collections.singletonList(LinksColumns.NAME.getDisplayName()),TrajectoryType.LINK.name());
}
} catch (IOException e) {
Expand Down
Loading