Resolved conflicts

This commit is contained in:
rajesh
2025-08-01 13:37:35 +05:30
42 changed files with 952 additions and 120 deletions

View File

@@ -56,15 +56,14 @@ import org.springframework.web.multipart.MultipartFile;
import jakarta.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.*;
import java.lang.reflect.Method;
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;
@@ -217,6 +216,12 @@ public class ApplicationDao {
@Autowired
private ApplicationEvaluationDao applicationEvaluationDao;
@Autowired
private EvaluationCriteriaRepository evaluationCriteriaRepository;
@Autowired
private CallRepository callRepository;
public final Random random = new Random();
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
@@ -593,11 +598,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);
@@ -606,19 +609,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);
});
@@ -641,7 +645,6 @@ public class ApplicationDao {
}
}
}
calculationProcessForFormula(applicationFormEntity,contentResponseBeans,applicationFormFieldRequestBean,fieldValidator);
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
if (applicationFormFieldRequestBean.getFieldValue() != null) {
@@ -988,10 +991,12 @@ public class ApplicationDao {
// call = callService.validatePublishedCall(call.getId());
// checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
HubEntity hubEntity = hubService.valdateHub(call.getHub().getId());
if(hubEntity.getUniqueUuid().equals(defaultHubUuid)){
checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
if(call.getAllowMultipleApplications() == null || Boolean.FALSE.equals(call.getAllowMultipleApplications())){
if(hubEntity.getUniqueUuid().equals(defaultHubUuid)){
checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
}
}
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, userWithCompanyEntity);
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, userWithCompanyEntity);
applicationEntity.setComments(applicationRequest.getComments());
applicationEntity = saveApplicationEntity(applicationEntity);
return getApplicationResponse(applicationEntity);
@@ -1059,9 +1064,9 @@ public class ApplicationDao {
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId(),true);
protocolDao.saveProtocolEntity(protocolEntity);
applicationEntity.setProtocol(protocolEntity);
if(Boolean.TRUE.equals(hub.getUniqueUuid().equals(sviluppumbriaUuid))) {
protocolEntity = protocolDao.createExternalProtocol(applicationEntity, company, protocolEntity);
}
// if(Boolean.TRUE.equals(hub.getUniqueUuid().equals(sviluppumbriaUuid))) {
// protocolEntity = protocolDao.createExternalProtocol(applicationEntity, company, protocolEntity);
// }
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
applicationEntity.setSubmissionDate(protocolEntity.getCreatedDate());
applicationEntity = applicationRepository.save(applicationEntity);
@@ -1665,12 +1670,12 @@ public class ApplicationDao {
// }
}
public void calculationProcessForFormula(ApplicationFormEntity applicationFormEntity, List<ContentResponseBean> contentResponseBeans, ApplicationFormFieldRequestBean applicationFormFieldRequestBean,FieldValidator fieldValidator) {
public void calculationProcessForFormula(ApplicationFormEntity applicationFormEntity, List<ContentResponseBean> contentResponseBeans,String fromFieldId,String formFieldValue,FieldValidator fieldValidator) {
List<String> formulaValue = new ArrayList<>();
String formulaValueOpt=null;
String label=null;
for (ContentResponseBean contentResponseBean:contentResponseBeans){
if(contentResponseBean.getId().equals(applicationFormFieldRequestBean.getFieldId())){
if(contentResponseBean.getId().equals(fromFieldId)){
for (SettingResponseBean settingResponseBean:contentResponseBean.getSettings()){
if (settingResponseBean.getName().equals("label")){
label= String.valueOf(settingResponseBean.getValue());
@@ -1684,7 +1689,7 @@ public class ApplicationDao {
}
}
Map<String, String> mappedFormulaValue = new HashMap<>();
Object fieldValue = applicationFormFieldRequestBean.getFieldValue();
Object fieldValue = formFieldValue;
if (formulaValueOpt != null && fieldValue==null) {
fieldValue=0;
}
@@ -2422,4 +2427,128 @@ public class ApplicationDao {
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(GepafinConstant.RINALDO_EMAIL),emailLogRequest);
}
public byte[] downloadRankingCsv(Long callId,UserEntity userEntity) {
CallEntity callEntity = validator.validateUserWithCall(userEntity,callId);
List<ApplicationEntity> applications =
applicationRepository.findByCallIdAndIsDeletedFalseAndStatusIn(
callId,
List.of(
ApplicationStatusForEvaluation.APPROVED.getValue(),
ApplicationStatusForEvaluation.ADMISSIBLE.getValue(),
ApplicationStatusForEvaluation.TECHNICAL_EVALUATION.getValue()
));
List<String> dynamicLabels = new ArrayList<>(); // Maintain insertion order, allow duplicates only once
Map<Long, Map<String, String>> appLabelScoresMap = new HashMap<>();
Map<Long, ApplicationEntity> applicationMap = 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();
applicationMap.put(appId, app);
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, Utils.convertToItalianFormatWithOnlyDecimalValue(String.valueOf(totalScore)));
List<CriteriaResponse> criteriaList =
evaluation.getCriteria() != null ?
Utils.convertJsonToList(evaluation.getCriteria(), new TypeReference<List<CriteriaResponse>>() {}) :
List.of();
List<CriteriaResponse> dbCriteriaList = applicationEvaluationDao.getCriteriaResponse(appId);
Map<String, String> scoreByLabel = new HashMap<>();
for (CriteriaResponse criteria : criteriaList) {
Optional<CriteriaResponse> matchedDb = dbCriteriaList.stream()
.filter(db -> Objects.equals(db.getId(), criteria.getId()))
.findFirst();
String label = matchedDb.map(CriteriaResponse::getLabel).orElse("");
if (!dynamicLabels.contains(label)) {
dynamicLabels.add(label);
}
String criteriaScore= String.valueOf(criteria.getScore() != null ? criteria.getScore() : BigDecimal.ZERO);
scoreByLabel.put(label, Utils.convertToItalianFormatWithOnlyDecimalValue(criteriaScore));
}
appLabelScoresMap.put(appId, scoreByLabel);
}
// Build headers dynamically
List<String> headers = new ArrayList<>(List.of(
"ApplicationID","Application VatNumber", "VatNumber", "Company Name", "Protocol", "Requested Amount", "Status","Instructor Name","Application PEC","Company PEC","Total Score"
));
headers.addAll(dynamicLabels);
// Prepare data rows
List<List<Object>> rows = new ArrayList<>();
for (ApplicationEntity app : applications) {
Long appId = app.getId();
CompanyEntity company = companyService.validateCompany(app.getCompanyId());
ProtocolEntity protocolEntity = app.getProtocol();
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);
String formattedAmount=Utils.convertToItalianFormatWithOnlyDecimalValue(String.valueOf(app.getAmountRequested()));
row.add(formattedAmount);
row.add(app.getStatus());
row.add(appInstructorMap.getOrDefault(appId, ""));
row.add(app.getPecEmail());
row.add(company.getPec());
row.add(appTotalScoreMap.get(appId));
Map<String, String> scores = appLabelScoresMap.getOrDefault(appId, Collections.emptyMap());
for (String label : dynamicLabels) {
row.add(scores.getOrDefault(label, ""));
}
rows.add(row);
}
// Generate CSV
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
CSVPrinter csvPrinter = new CSVPrinter(writer,
CSVFormat.DEFAULT
.withDelimiter(';')
.withHeader(headers.toArray(new String[0])))) {
for (List<Object> row : rows) {
csvPrinter.printRecord(row);
}
csvPrinter.flush();
} catch (IOException e) {
throw new RuntimeException("Error while generating CSV", e);
}
return out.toByteArray();
}
}