Updated code for csv
This commit is contained in:
@@ -63,6 +63,7 @@ import java.math.BigDecimal;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.text.NumberFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -594,11 +595,9 @@ public class ApplicationDao {
|
|||||||
String fieldType = content.getName();
|
String fieldType = content.getName();
|
||||||
|
|
||||||
// Define handlers for different (fieldType + settingName) combinations
|
// Define handlers for different (fieldType + settingName) combinations
|
||||||
Map<String, Runnable> handlers = new HashMap<>();
|
|
||||||
|
|
||||||
// Add handler for isRequestedAmount
|
// Add handler for isRequestedAmount
|
||||||
if ("numberinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isRequestedAmount"))) {
|
if ("numberinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isRequestedAmount"))) {
|
||||||
handlers.put("isRequestedAmount", () -> {
|
|
||||||
try {
|
try {
|
||||||
BigDecimal amountRequested = new BigDecimal(fieldValue.toString());
|
BigDecimal amountRequested = new BigDecimal(fieldValue.toString());
|
||||||
applicationFormEntity.getApplication().setAmountRequested(amountRequested);
|
applicationFormEntity.getApplication().setAmountRequested(amountRequested);
|
||||||
@@ -607,19 +606,20 @@ public class ApplicationDao {
|
|||||||
log.error("Invalid number format for requested amount: {}", fieldValue, e);
|
log.error("Invalid number format for requested amount: {}", fieldValue, e);
|
||||||
throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
|
throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add handler for isPecEmail
|
// Add handler for isPecEmail
|
||||||
if ("textinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isPecEmail"))) {
|
if ("textinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isPecEmail"))) {
|
||||||
handlers.put("isPecEmail", () -> {
|
|
||||||
applicationFormEntity.getApplication().setPecEmail(fieldValue.toString());
|
applicationFormEntity.getApplication().setPecEmail(fieldValue.toString());
|
||||||
log.info("Set PEC to {} for Application ID: {}", fieldValue, applicationFormEntity.getApplication().getId());
|
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
|
// 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
|
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, 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) {
|
for (ApplicationEntity app : applications) {
|
||||||
Long appId = app.getId();
|
Long appId = app.getId();
|
||||||
@@ -2445,8 +2446,19 @@ public class ApplicationDao {
|
|||||||
ApplicationEvaluationEntity evaluation =
|
ApplicationEvaluationEntity evaluation =
|
||||||
applicationEvaluationRepository.findByApplicationId(appId);
|
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());
|
BigDecimal totalScore = applicationEvaluationDao.calculateTotalScore(evaluation.getCriteria());
|
||||||
appTotalScoreMap.put(appId, totalScore);
|
appTotalScoreMap.put(appId, Utils.convertToItalianFormatWithOnlyDecimalValue(String.valueOf(totalScore)));
|
||||||
|
|
||||||
List<CriteriaResponse> criteriaList =
|
List<CriteriaResponse> criteriaList =
|
||||||
evaluation.getCriteria() != null ?
|
evaluation.getCriteria() != null ?
|
||||||
@@ -2455,7 +2467,7 @@ public class ApplicationDao {
|
|||||||
|
|
||||||
List<CriteriaResponse> dbCriteriaList = applicationEvaluationDao.getCriteriaResponse(appId);
|
List<CriteriaResponse> dbCriteriaList = applicationEvaluationDao.getCriteriaResponse(appId);
|
||||||
|
|
||||||
Map<String, BigDecimal> scoreByLabel = new HashMap<>();
|
Map<String, String> scoreByLabel = new HashMap<>();
|
||||||
|
|
||||||
for (CriteriaResponse criteria : criteriaList) {
|
for (CriteriaResponse criteria : criteriaList) {
|
||||||
Optional<CriteriaResponse> matchedDb = dbCriteriaList.stream()
|
Optional<CriteriaResponse> matchedDb = dbCriteriaList.stream()
|
||||||
@@ -2467,8 +2479,9 @@ public class ApplicationDao {
|
|||||||
if (!dynamicLabels.contains(label)) {
|
if (!dynamicLabels.contains(label)) {
|
||||||
dynamicLabels.add(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);
|
appLabelScoresMap.put(appId, scoreByLabel);
|
||||||
@@ -2476,7 +2489,7 @@ public class ApplicationDao {
|
|||||||
|
|
||||||
// Build headers dynamically
|
// Build headers dynamically
|
||||||
List<String> headers = new ArrayList<>(List.of(
|
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);
|
headers.addAll(dynamicLabels);
|
||||||
|
|
||||||
@@ -2490,17 +2503,20 @@ public class ApplicationDao {
|
|||||||
|
|
||||||
List<Object> row = new ArrayList<>();
|
List<Object> row = new ArrayList<>();
|
||||||
row.add(appId);
|
row.add(appId);
|
||||||
|
row.add(app.getVatNumber());
|
||||||
row.add(company.getVatNumber());
|
row.add(company.getVatNumber());
|
||||||
row.add(company.getCompanyName());
|
row.add(company.getCompanyName());
|
||||||
row.add(protocolEntity != null ? protocolEntity.getProtocolNumber() : 0L);
|
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(app.getStatus());
|
||||||
|
row.add(appInstructorMap.getOrDefault(appId, ""));
|
||||||
row.add(appTotalScoreMap.get(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) {
|
for (String label : dynamicLabels) {
|
||||||
row.add(scores.getOrDefault(label, BigDecimal.ZERO));
|
row.add(scores.getOrDefault(label, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
rows.add(row);
|
rows.add(row);
|
||||||
@@ -2510,7 +2526,9 @@ public class ApplicationDao {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
try (OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
|
try (OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
|
||||||
CSVPrinter csvPrinter = new CSVPrinter(writer,
|
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) {
|
for (List<Object> row : rows) {
|
||||||
csvPrinter.printRecord(row);
|
csvPrinter.printRecord(row);
|
||||||
|
|||||||
@@ -76,4 +76,7 @@ public class ApplicationEntity extends BaseEntity {
|
|||||||
@Column(name = "PEC_EMAIL")
|
@Column(name = "PEC_EMAIL")
|
||||||
private String pecEmail;
|
private String pecEmail;
|
||||||
|
|
||||||
|
@Column(name="VAT_NUMBER")
|
||||||
|
private String vatNumber;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,9 +6,7 @@ import java.lang.reflect.Type;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.text.NumberFormat;
|
import java.text.*;
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
@@ -1063,6 +1061,37 @@ public class Utils {
|
|||||||
ServletRequestAttributes attributes = new ServletRequestAttributes(mockRequest);
|
ServletRequestAttributes attributes = new ServletRequestAttributes(mockRequest);
|
||||||
RequestContextHolder.setRequestAttributes(attributes, true);
|
RequestContextHolder.setRequestAttributes(attributes, true);
|
||||||
}
|
}
|
||||||
|
public static String convertToItalianFormatWithOnlyDecimalValue(String amount) {
|
||||||
|
try {
|
||||||
|
// Step 1: Sanitize and standardize the input
|
||||||
|
String sanitizedAmount = amount.trim();
|
||||||
|
|
||||||
|
// Remove thousand separators (either . or , depending on input style)
|
||||||
|
sanitizedAmount = sanitizedAmount.replace(",", "").replace(" ", "");
|
||||||
|
|
||||||
|
// Step 2: Ensure it uses '.' as decimal separator for parsing
|
||||||
|
if (sanitizedAmount.contains(".")) {
|
||||||
|
// It already uses dot as decimal separator
|
||||||
|
} else if (sanitizedAmount.contains(",")) {
|
||||||
|
// If input uses comma as decimal separator (like "1234,56")
|
||||||
|
sanitizedAmount = sanitizedAmount.replace(",", ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 3: Parse to double
|
||||||
|
double parsedAmount = Double.parseDouble(sanitizedAmount);
|
||||||
|
|
||||||
|
// Step 4: Format without thousand separator and with comma as decimal
|
||||||
|
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
|
||||||
|
symbols.setDecimalSeparator(',');
|
||||||
|
|
||||||
|
DecimalFormat italianDecimalFormat = new DecimalFormat("0.00", symbols);
|
||||||
|
italianDecimalFormat.setGroupingUsed(false); // no thousand separator
|
||||||
|
|
||||||
|
return italianDecimalFormat.format(parsedAmount);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return "Invalid amount format";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2984,4 +2984,10 @@
|
|||||||
<sqlFile dbms="postgresql"
|
<sqlFile dbms="postgresql"
|
||||||
path="db/dump/insert_system_email_template_technical_evaluation_rejected.sql"/>
|
path="db/dump/insert_system_email_template_technical_evaluation_rejected.sql"/>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="02-07_2025_RK_162833" author="Rajesh Khore">
|
||||||
|
<addColumn tableName="application">
|
||||||
|
<column name="vat_number" type="VARCHAR(255)"></column>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
Reference in New Issue
Block a user