Updated code for csv
This commit is contained in:
@@ -63,6 +63,7 @@ import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -594,11 +595,9 @@ public class ApplicationDao {
|
||||
String fieldType = content.getName();
|
||||
|
||||
// Define handlers for different (fieldType + settingName) combinations
|
||||
Map<String, Runnable> handlers = new HashMap<>();
|
||||
|
||||
// Add handler for isRequestedAmount
|
||||
if ("numberinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isRequestedAmount"))) {
|
||||
handlers.put("isRequestedAmount", () -> {
|
||||
try {
|
||||
BigDecimal amountRequested = new BigDecimal(fieldValue.toString());
|
||||
applicationFormEntity.getApplication().setAmountRequested(amountRequested);
|
||||
@@ -607,19 +606,20 @@ public class ApplicationDao {
|
||||
log.error("Invalid number format for requested amount: {}", fieldValue, e);
|
||||
throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add handler for isPecEmail
|
||||
if ("textinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isPecEmail"))) {
|
||||
handlers.put("isPecEmail", () -> {
|
||||
applicationFormEntity.getApplication().setPecEmail(fieldValue.toString());
|
||||
log.info("Set PEC to {} for Application ID: {}", fieldValue, applicationFormEntity.getApplication().getId());
|
||||
});
|
||||
}
|
||||
|
||||
if ("textinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isPIVA"))) {
|
||||
applicationFormEntity.getApplication().setVatNumber(fieldValue.toString());
|
||||
log.info("Set PEC to {} for Application ID: {}", fieldValue, applicationFormEntity.getApplication().getId());
|
||||
}
|
||||
|
||||
// Run all applicable handlers
|
||||
handlers.values().forEach(Runnable::run);
|
||||
});
|
||||
|
||||
|
||||
@@ -2433,10 +2433,11 @@ public class ApplicationDao {
|
||||
));
|
||||
|
||||
List<String> dynamicLabels = new ArrayList<>(); // Maintain insertion order, allow duplicates only once
|
||||
Map<Long, Map<String, BigDecimal>> appLabelScoresMap = new HashMap<>();
|
||||
Map<Long, Map<String, String>> appLabelScoresMap = new HashMap<>();
|
||||
|
||||
Map<Long, ApplicationEntity> applicationMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> appTotalScoreMap = new HashMap<>();
|
||||
Map<Long, String> appTotalScoreMap = new HashMap<>();
|
||||
Map<Long, String> appInstructorMap = new HashMap<>(); // New map to store instructor name per app
|
||||
|
||||
for (ApplicationEntity app : applications) {
|
||||
Long appId = app.getId();
|
||||
@@ -2445,8 +2446,19 @@ public class ApplicationDao {
|
||||
ApplicationEvaluationEntity evaluation =
|
||||
applicationEvaluationRepository.findByApplicationId(appId);
|
||||
|
||||
if (evaluation != null && evaluation.getAssignedApplicationsEntity() != null) {
|
||||
Long userId = evaluation.getAssignedApplicationsEntity().getUserId();
|
||||
if (userId != null) {
|
||||
userRepository.findById(userId).ifPresent(user -> {
|
||||
String firstName = user.getFirstName() != null ? user.getFirstName() : "";
|
||||
String lastName = user.getLastName() != null ? user.getLastName() : "";
|
||||
appInstructorMap.put(appId, firstName + " " + lastName);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
BigDecimal totalScore = applicationEvaluationDao.calculateTotalScore(evaluation.getCriteria());
|
||||
appTotalScoreMap.put(appId, totalScore);
|
||||
appTotalScoreMap.put(appId, Utils.convertToItalianFormatWithOnlyDecimalValue(String.valueOf(totalScore)));
|
||||
|
||||
List<CriteriaResponse> criteriaList =
|
||||
evaluation.getCriteria() != null ?
|
||||
@@ -2455,7 +2467,7 @@ public class ApplicationDao {
|
||||
|
||||
List<CriteriaResponse> dbCriteriaList = applicationEvaluationDao.getCriteriaResponse(appId);
|
||||
|
||||
Map<String, BigDecimal> scoreByLabel = new HashMap<>();
|
||||
Map<String, String> scoreByLabel = new HashMap<>();
|
||||
|
||||
for (CriteriaResponse criteria : criteriaList) {
|
||||
Optional<CriteriaResponse> matchedDb = dbCriteriaList.stream()
|
||||
@@ -2467,8 +2479,9 @@ public class ApplicationDao {
|
||||
if (!dynamicLabels.contains(label)) {
|
||||
dynamicLabels.add(label);
|
||||
}
|
||||
String criteriaScore= String.valueOf(criteria.getScore() != null ? criteria.getScore() : BigDecimal.ZERO);
|
||||
|
||||
scoreByLabel.put(label, criteria.getScore() != null ? criteria.getScore() : BigDecimal.ZERO);
|
||||
scoreByLabel.put(label, Utils.convertToItalianFormatWithOnlyDecimalValue(criteriaScore));
|
||||
}
|
||||
|
||||
appLabelScoresMap.put(appId, scoreByLabel);
|
||||
@@ -2476,7 +2489,7 @@ public class ApplicationDao {
|
||||
|
||||
// Build headers dynamically
|
||||
List<String> headers = new ArrayList<>(List.of(
|
||||
"ApplicationID", "VatNumber", "Company Name", "Protocol", "Requested Amount", "Status", "Total Score"
|
||||
"ApplicationID","Application VatNumber", "VatNumber", "Company Name", "Protocol", "Requested Amount", "Status","Instructor Name", "Total Score"
|
||||
));
|
||||
headers.addAll(dynamicLabels);
|
||||
|
||||
@@ -2490,17 +2503,20 @@ public class ApplicationDao {
|
||||
|
||||
List<Object> row = new ArrayList<>();
|
||||
row.add(appId);
|
||||
row.add(app.getVatNumber());
|
||||
row.add(company.getVatNumber());
|
||||
row.add(company.getCompanyName());
|
||||
row.add(protocolEntity != null ? protocolEntity.getProtocolNumber() : 0L);
|
||||
row.add(app.getAmountRequested());
|
||||
String formattedAmount=Utils.convertToItalianFormatWithOnlyDecimalValue(String.valueOf(app.getAmountRequested()));
|
||||
row.add(formattedAmount);
|
||||
row.add(app.getStatus());
|
||||
row.add(appInstructorMap.getOrDefault(appId, ""));
|
||||
row.add(appTotalScoreMap.get(appId));
|
||||
|
||||
Map<String, BigDecimal> scores = appLabelScoresMap.getOrDefault(appId, Collections.emptyMap());
|
||||
Map<String, String> scores = appLabelScoresMap.getOrDefault(appId, Collections.emptyMap());
|
||||
|
||||
for (String label : dynamicLabels) {
|
||||
row.add(scores.getOrDefault(label, BigDecimal.ZERO));
|
||||
row.add(scores.getOrDefault(label, ""));
|
||||
}
|
||||
|
||||
rows.add(row);
|
||||
@@ -2510,7 +2526,9 @@ public class ApplicationDao {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
|
||||
CSVPrinter csvPrinter = new CSVPrinter(writer,
|
||||
CSVFormat.DEFAULT.withHeader(headers.toArray(new String[0])))) {
|
||||
CSVFormat.DEFAULT
|
||||
.withDelimiter(';')
|
||||
.withHeader(headers.toArray(new String[0])))) {
|
||||
|
||||
for (List<Object> row : rows) {
|
||||
csvPrinter.printRecord(row);
|
||||
|
||||
Reference in New Issue
Block a user