Resolved conflicts

This commit is contained in:
piyushkag
2025-01-15 11:12:21 +05:30
64 changed files with 1505 additions and 238 deletions

View File

@@ -306,7 +306,7 @@ public class ApplicationAmendmentRequestDao {
ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity, null, VersionActionTypeEnum.INSERT);
String evaluationStatusType = applicationEvaluationEntity.getStatus();
if (Boolean.FALSE.equals(evaluationStatusType.equals((ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue())))){
applicationEvaluationEntity.setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
// applicationEvaluationEntity.setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
//Set Status
applicationEvaluationEntity.setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());

View File

@@ -47,6 +47,7 @@ import jakarta.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.util.*;
@@ -221,7 +222,7 @@ public class ApplicationDao {
}
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call, UserWithCompanyEntity userWithCompany) {
validateDelegation(user,userWithCompany);
// validateDelegation(user,userWithCompany);
ApplicationEntity entity = new ApplicationEntity();
entity.setUserId(user.getId());
entity.setCompanyId(userWithCompany.getCompanyId());
@@ -297,7 +298,12 @@ public class ApplicationDao {
log.info("Deleting application with ID: {}", id);
ApplicationEntity applicationEntity= validateApplication(id);
if (Boolean.FALSE.equals(ApplicationStatusTypeEnum.DRAFT.getValue().equals(applicationEntity.getStatus()))) {
throw new CustomValidationException(
Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS)
);
}
ApplicationEntity oldApplicationDataEntity = Utils.getClonedEntityForData(applicationEntity);
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
@@ -420,6 +426,10 @@ public class ApplicationDao {
if(applicationEntity.getProtocol() != null) {
responseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
}
responseBean.setAmountAccepted(applicationEntity.getAmountAccepted());
responseBean.setAmountRequested(applicationEntity.getAmountRequested());
responseBean.setDateAccepted(applicationEntity.getDateAccepted());
responseBean.setDateRejected(applicationEntity.getDateRejected());
return responseBean;
}
@@ -439,6 +449,10 @@ public class ApplicationDao {
response.setCallId(entity.getCall().getId());
response.setCreatedDate(entity.getCreatedDate());
response.setUpdatedDate(entity.getUpdatedDate());
response.setAmountAccepted(entity.getAmountAccepted());
response.setAmountRequested(entity.getAmountRequested());
response.setDateAccepted(entity.getDateAccepted());
response.setDateRejected(entity.getDateRejected());
if(entity.getProtocol() != null) {
response.setProtocolNumber(entity.getProtocol().getProtocolNumber());
}
@@ -477,6 +491,30 @@ public class ApplicationDao {
List<Long> newDocumentIds = validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
VersionActionTypeEnum actionType = VersionActionTypeEnum.INSERT;
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
contentResponseBeans.stream()
.filter(content -> "numberinput".equals(content.getName()))
.map(ContentResponseBean::getSettings)
.flatMap(List::stream)
.filter(setting -> "isRequestedAmount".equals(setting.getName()) && Boolean.TRUE.equals(setting.getValue()))
.findFirst()
.ifPresent(setting -> {
Object fieldValue = applicationFormFieldRequestBean.getFieldValue();
if(fieldValue!=null) {
if (fieldValue instanceof String) {
try {
BigDecimal amountRequested = new BigDecimal((String) fieldValue);
applicationFormEntity.getApplication().setAmountRequested(amountRequested);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
}
} else {
throw new IllegalArgumentException("Field value is not a String: " + fieldValue);
}
}
});
ApplicationFormFieldEntity oldApplicationFormFieldData = null;
@@ -808,6 +846,10 @@ public class ApplicationDao {
applicationGetResponseBean.setCallId(applicationEntity.getCall().getId());
applicationGetResponseBean.setCallTitle(applicationEntity.getCall().getName());
applicationGetResponseBean.setCompanyId(applicationEntity.getCompanyId());
applicationGetResponseBean.setAmountAccepted(applicationEntity.getAmountAccepted());
applicationGetResponseBean.setAmountRequested(applicationEntity.getAmountRequested());
applicationGetResponseBean.setDateAccepted(applicationEntity.getDateAccepted());
applicationGetResponseBean.setDateRejected(applicationEntity.getDateRejected());
if(applicationEntity.getProtocol() != null) {
applicationGetResponseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
}
@@ -867,7 +909,7 @@ public class ApplicationDao {
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId(),true);
applicationEntity.setProtocol(protocolEntity);
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
applicationEntity.setSubmissionDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
applicationEntity.setSubmissionDate(protocolEntity.getCreatedDate());
applicationEntity = applicationRepository.save(applicationEntity);
Map<String ,String> placeHolders=notificationDao.sendNotificationToBeneficiary(applicationEntity,NotificationTypeEnum.APPLICATION_SUBMISSION);
notificationDao.sendNotificationToSuperUser(applicationEntity,placeHolders,NotificationTypeEnum.APPLICATION_SUBMISSION);

View File

@@ -24,7 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -580,6 +583,10 @@ public class ApplicationEvaluationDao {
CompanyEntity company = companyService.validateCompany(application.getCompanyId());
response.setCompanyName(company.getCompanyName());
}
response.setAmountAccepted(application.getAmountAccepted());
response.setAmountRequested(application.getAmountRequested());
response.setDateAccepted(application.getDateAccepted());
response.setDateRejected(application.getDateRejected());
}
@@ -594,7 +601,8 @@ public class ApplicationEvaluationDao {
Optional<AssignedApplicationsEntity> assignedApplications =
assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplicationId);
ApplicationEvaluationEntity oldApplicationEvaluation = null;
VersionActionTypeEnum actionType;
ApplicationEntity application = applicationService.validateApplication(assignedApplications.get().getApplication().getId());
VersionActionTypeEnum actionType = VersionActionTypeEnum.INSERT;
if (existingEntityOptional.isPresent()) {
entity = existingEntityOptional.get();
oldApplicationEvaluation = Utils.getClonedEntityForData(entity);
@@ -610,10 +618,15 @@ public class ApplicationEvaluationDao {
entity.setIsDeleted(false);
setIfUpdated(entity::getNote, entity::setNote, req.getNote());
setIfUpdated(entity::getMotivation, entity::setMotivation, req.getMotivation());
if(Boolean.TRUE.equals(req.getApplicationStatus().equals(ApplicationStatusForEvaluation.APPROVED)) && (req.getAmountAccepted()==null || req.getAmountAccepted().compareTo(BigDecimal.ZERO) < 0)){
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.AMOUNT_ACCEPTED_REQUIRED_WHILE_APPROVING_APPLICATION));
}
if (req.getAmountAccepted() != null && req.getAmountAccepted().compareTo(BigDecimal.ZERO) > 0) {
application.setAmountAccepted(req.getAmountAccepted());
}
actionType = VersionActionTypeEnum.UPDATE;
} else {
AssignedApplicationsEntity assignedApplicationsEntity = assignedApplicationsService.validateAssignedApplication(assignedApplicationId);
ApplicationEntity application = applicationService.validateApplication(assignedApplicationsEntity.getApplication().getId());
entity = convertToEntity(user, req, assignedApplicationId);
actionType = VersionActionTypeEnum.INSERT;
@@ -642,7 +655,6 @@ public class ApplicationEvaluationDao {
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(actionType).oldData(oldApplicationEvaluation).newData(entity).build());
if (status != null) {
ApplicationEntity application = applicationService.validateApplication(assignedApplications.get().getApplication().getId());
AssignedApplicationsEntity assignedApplicationsEntity = assignedApplications.get();
return updateApplicationEvaluationStatus(application, assignedApplicationsEntity, status);
} else {
@@ -1800,6 +1812,11 @@ public class ApplicationEvaluationDao {
existingEntity.setClosingDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.CLOSE.getValue());
}
if (existingEntity.getStartDate() != null && existingEntity.getClosingDate() != null) {
long activeDays = ChronoUnit.DAYS.between(existingEntity.getStartDate(), existingEntity.getClosingDate());
activeDays -= existingEntity.getSuspendedDays() != null ? existingEntity.getSuspendedDays() : 0;
existingEntity.setActiveDays(activeDays);
}
entity = applicationEvaluationRepository.save(existingEntity);
assignedApplicationsRepository.save(assignedApplicationsEntity);
@@ -1814,9 +1831,15 @@ public class ApplicationEvaluationDao {
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.APPROVED.getValue())))) {
application.setDateAccepted(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
application.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
application = applicationRepository.save(application);
emailNotificationDao.sendAdmissibilityNotificationEmailForApprovedApplication(application);
}
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.REJECTED.getValue())))) {
application.setDateRejected(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
application.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
application = applicationRepository.save(application);
emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity);
}

View File

@@ -124,7 +124,6 @@ public class CompanyDao {
userWithCompanyEntity.setContactEmail(companyRequest.getContactEmail());
userWithCompanyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) );
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity);
/** This code is responsible for adding a version history log for the "adding user with company" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(userWithCompany).build());
return userWithCompany;
@@ -144,6 +143,22 @@ public class CompanyDao {
entity.setNumberOfEmployees(request.getNumberOfEmployees());
entity.setAnnualRevenue(request.getAnnualRevenue());
entity.setHub(userEntity.getHub());
Map<String, Object> vatCheckResponse = request.getVatCheckResponse();
if (request.getVatCheckResponse() != null) {
if (vatCheckResponse.containsKey("dettaglio")) {
Map<String, Object> dettaglio = (Map<String, Object>) vatCheckResponse.get("dettaglio");
if (dettaglio != null) {
if (dettaglio.containsKey("codice_ateco")) {
Object codiceAtecoObj = dettaglio.get("codice_ateco");
String codiceAteco = (codiceAtecoObj != null) ? codiceAtecoObj.toString() : null;
if (codiceAteco != null) {
entity.setCodiceAteco(codiceAteco);
}
}
}
}
}
return entity;
}
@@ -165,6 +180,7 @@ public class CompanyDao {
response.setAnnualRevenue(entity.getAnnualRevenue());
if(userWithCompanyEntity!=null) {
response.setIsLegalRepresentant(userWithCompanyEntity.getIsLegalRepresentant());
response.setCodiceAteco(entity.getCodiceAteco());
}
response.setCreatedDate(entity.getCreatedDate());
response.setUpdatedDate(entity.getUpdatedDate());
@@ -189,15 +205,15 @@ public class CompanyDao {
setIfUpdated(companyEntity::getCountry, companyEntity::setCountry, companyRequest.getCountry());
setIfUpdated(companyEntity::getNumberOfEmployees, companyEntity::setNumberOfEmployees, companyRequest.getNumberOfEmployees());
setIfUpdated(companyEntity::getAnnualRevenue, companyEntity::setAnnualRevenue, companyRequest.getAnnualRevenue());
if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
CompanyEntity existingCompany = companyRepository.findByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId());
if(existingCompany!=null){
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
}
companyEntity.setVatNumber(companyRequest.getVatNumber());
}
//
// if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
// CompanyEntity existingCompany = companyRepository.findByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId());
// if(existingCompany!=null){
// throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
// }
// companyEntity.setVatNumber(companyRequest.getVatNumber());
//
// }
companyRepository.save(companyEntity);
/** This code is responsible for adding a version history log for the "Update company" operation. **/

View File

@@ -1,23 +1,36 @@
package net.gepafin.tendermanagement.dao;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.CompanyEntity;
import net.gepafin.tendermanagement.entities.UserActionEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.enums.CallStatusEnum;
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
import net.gepafin.tendermanagement.enums.UserStatusEnum;
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.Widget1;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
import net.gepafin.tendermanagement.repositories.CallRepository;
import net.gepafin.tendermanagement.repositories.CompanyRepository;
import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.repositories.*;
import net.gepafin.tendermanagement.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class DashboardDao {
@@ -33,15 +46,24 @@ public class DashboardDao {
@Autowired
private CompanyRepository companyRepository;
@Autowired
private CompanyService companyService;
@Autowired
private BeneficiaryPreferredCallRepository beneficiaryPreferredCallRepository;
@Autowired
private ApplicationEvaluationRepository applicationEvaluationRepository;
@Autowired
private UserActionsRepository userActionsRepository;
public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) {
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
// List<Object[]> widgetBars = callRepository.findApplicationsPerCall();
// widgetResponseBean.setWidgetBars(widgetBars);
Map<String, Object> widgetBars =getStatistics(requestedUserEntity);
widgetResponseBean.setWidgetBars(widgetBars);
return widgetResponseBean;
}
@@ -54,7 +76,8 @@ public class DashboardDao {
setSubmittedApplications(widget1, requestedUserEntity);
setDraftApplications(widget1, requestedUserEntity);
setNumberOfCompanies(widget1, requestedUserEntity);
setAmountRequested(widget1,requestedUserEntity);
setAmountAccepted(widget1,requestedUserEntity);
return widget1;
}
@@ -71,6 +94,20 @@ public class DashboardDao {
}
}
private void setAmountRequested(Widget1 widget1, UserEntity requestedUserEntity) {
BigDecimal amountRequested = applicationRepository.findTotalAmountRequestedOfApplication(requestedUserEntity.getHub().getId());
if (amountRequested != null) {
widget1.setTotalAmountRequested(amountRequested);
}
}
private void setAmountAccepted(Widget1 widget1, UserEntity requestedUserEntity) {
BigDecimal amountAccepted = applicationRepository.findTotalAmountAcceptedOfApplication(requestedUserEntity.getHub().getId());
if (amountAccepted != null) {
widget1.setTotalAmountAccepted(amountAccepted);
}
}
private void setRegisteredUsers(Widget1 widget1, UserEntity requestedUserEntity) {
Long activeUsers = userRepository.countByStatusAndRoleEntityRoleTypeAndHubId(UserStatusEnum.ACTIVE.getValue(),
RoleStatusEnum.ROLE_BENEFICIARY.getValue(), requestedUserEntity.getHub().getId());
@@ -106,14 +143,26 @@ public class DashboardDao {
}
public BeneficiaryWidgetResponseBean getDashboardWidgetForBeneficiary(UserEntity userEntity,
CompanyEntity company) {
CompanyEntity company) {
BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder()
.numberOfApplications(0L).numberOfCalls(0L).numberOfIntegratedDocuments(0L).build();
Long activeCalls = callRepository.countByStatusAndHubId(CallStatusEnum.PUBLISH.getValue(), userEntity.getHub().getId());
if (activeCalls != null) {
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls);
UserWithCompanyEntity userWithCompanyEntity = companyService.getUserWithCompany(userEntity.getId(), company.getId());
List<BeneficiaryPreferredCallEntity> preferredCalls = beneficiaryPreferredCallRepository
.findByUserIdAndUserWithCompanyIdAndIsDeletedFalse(userEntity.getId(), userWithCompanyEntity.getId());
if (preferredCalls != null && !preferredCalls.isEmpty()) {
List<Long> callIds = preferredCalls.stream()
.map(BeneficiaryPreferredCallEntity::getCallId)
.collect(Collectors.toList());
List<CallEntity> callEntities = callRepository.findByIdIn(callIds);
long activeCallsCount = callEntities.stream()
.filter(call -> CallStatusEnum.PUBLISH.getValue().equals(call.getStatus())
&& userEntity.getHub().getId().equals(call.getHub().getId()))
.count();
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCallsCount);
}
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),company.getId());
Long activeApplication = applicationRepository.countSubmittedApplicationsByUserId(userEntity.getId(),
userWithCompanyEntity.getId());
if (activeApplication != null) {
@@ -121,4 +170,99 @@ public class DashboardDao {
}
return beneficiaryWidgetResponseBean;
}
public Map<String, Object> getStatistics(UserEntity requestedUser) {
Map<String, Object> stats = new HashMap<>();
// Get applications per call
List<Object[]> applicationsPerCall = applicationRepository.findApplicationsPerCallWithName(requestedUser.getHub().getId());
stats.put(GepafinConstant.APPLICATION_PER_CALL, applicationsPerCall.stream().map(result -> {
Map<String, Object> callData = new HashMap<>();
callData.put(GepafinConstant.CALL_NAME, result[0]); // Call name
callData.put(GepafinConstant.NUMBER_OF_APPLICATIONS, result[1]); // Application count
return callData;
}).toList());
// Get applications grouped by status
List<Object[]> applicationsByStatus = applicationRepository.findApplicationsByStatus(requestedUser.getHub().getId());
stats.put(GepafinConstant.APPLICATION_PER_STATUS, applicationsByStatus.stream().map(result -> {
Map<String, Object> statusData = new HashMap<>();
statusData.put(GepafinConstant.STATUS, result[0]); // Application status
statusData.put(GepafinConstant.NUMBER_OF_APPLICATIONS, result[1]); // Count of applications
return statusData;
}).toList());
return stats;
}
// public Page<UserActionEntity> getUserAction(UserEntity requestedUserEntity){
// Pageable pageable = PageRequest.of(0, 20); // Get the first 20 records
// List<String> roles=List.of(RoleStatusEnum.ROLE_PRE_INSTRUCTOR.getValue(),RoleStatusEnum.ROLE_GEPAFIN_OPERATOR.getValue(),RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue());
// Page<UserActionEntity> userActionEntities=userActionsRepository.findActionsByRoleNamesAndHubId(roles,requestedUserEntity.getHub().getId(),pageable);
// return userActionEntities;
// }
public ApplicationWidgetResponseBean getApplicationDetails(UserEntity userEntity) {
ApplicationWidgetResponseBean applicationWidgetResponseBean = initializeResponseBean();
Long hubId = userEntity.getHub().getId();
setApplicationCounts(applicationWidgetResponseBean, hubId);
calculateEvaluationAverageTime(applicationWidgetResponseBean, hubId);
return applicationWidgetResponseBean;
}
private ApplicationWidgetResponseBean initializeResponseBean() {
return ApplicationWidgetResponseBean.builder()
.numberOfApplication(0L)
.numberOfAssignedApplication(0L)
.numberOfAcceptedApplication(0L)
.numberOfApplicationInAmendmentState(0L)
.numberOfDueApplication(0L)
.evaluationAverageTime(BigDecimal.ZERO)
.build();
}
private void setApplicationCounts(ApplicationWidgetResponseBean responseBean, Long hubId) {
Long activeApplications = applicationRepository.countApplicationsByHubId(hubId);
if (activeApplications != null) {
responseBean.setNumberOfApplication(activeApplications);
}
Long assignedApplications = applicationRepository.countAssignedApplicationsByHubId(hubId);
if (assignedApplications != null) {
responseBean.setNumberOfAssignedApplication(assignedApplications);
}
Long approvedApplications = applicationRepository.countApprovedApplicationsByHubId(hubId);
if (approvedApplications != null) {
responseBean.setNumberOfAcceptedApplication(approvedApplications);
}
Long soccorsoApplications = applicationRepository.countSoccorsoApplicationsByHubId(hubId);
if (soccorsoApplications != null) {
responseBean.setNumberOfApplicationInAmendmentState(soccorsoApplications);
}
}
private void calculateEvaluationAverageTime(ApplicationWidgetResponseBean responseBean, Long hubId) {
List<Long> applicationIds = applicationRepository.findApplicationIdsByHubId(hubId);
if (Boolean.FALSE.equals(applicationIds.isEmpty())) {
BigDecimal averageTime = applicationEvaluationRepository.findAverageEvaluationTimeByApplicationIds(applicationIds);
responseBean.setEvaluationAverageTime(averageTime != null ? averageTime : BigDecimal.ZERO);
}
LocalDate twoDaysLater = LocalDate.now().plusDays(2);
Long dueApplications = applicationEvaluationRepository.countDueApplicationsBetween(
applicationIds,
LocalDate.now(),
twoDaysLater
);
if (dueApplications != null) {
responseBean.setNumberOfDueApplication(dueApplications);
}
}
}

View File

@@ -309,6 +309,10 @@ public class FlowFormDao {
if(applicationEntity.getProtocol() != null) {
nextOrPreviousFormResponse.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
}
nextOrPreviousFormResponse.setAmountAccepted(applicationEntity.getAmountAccepted());
nextOrPreviousFormResponse.setAmountRequested(applicationEntity.getAmountRequested());
nextOrPreviousFormResponse.setDateAccepted(applicationEntity.getDateAccepted());
nextOrPreviousFormResponse.setDateRejected(applicationEntity.getDateRejected());
return nextOrPreviousFormResponse;
}

View File

@@ -109,76 +109,7 @@ public class PdfDao {
document.add(new Paragraph(" ")); // Add line break
}
document.add(new Paragraph("\n")); // Add line break
Font boldSmallFont = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD,new BaseColor(105, 105, 105));
// Adding the "Documenti Allegati" section title
// document.add(new Paragraph(" "));
//
//// pageEvent.setTotalPages(writer.getPageNumber());
// document.newPage();
//// pageEvent.setTotalPages(writer.getPageNumber());
// document.add(new Paragraph("Documenti Allegati", sectionFont));
// document.add(new Paragraph(" "));
//
//
//// 1. Autocertificazione possesso Requisiti
// Paragraph p1 = new Paragraph();
// p1.add(new Chunk("1. ", boldSmallFont));
// p1.add(new Chunk("Autocertificazione possesso Requisiti ", boldSmallFont));
// p1.add(new Chunk("ai sensi degli artt. 46 e 47 del DPR 445/2000", smallFont));
// document.add(p1);
// document.add(new Paragraph(" "));
//
//
//
//// 2. Informativa Privacy relativa al trattamento dei dati personali
// Paragraph p2 = new Paragraph();
// p2.add(new Chunk("2. ", boldSmallFont));
// p2.add(new Chunk("Informativa Privacy relativa al trattamento dei dati personali", boldSmallFont));
// document.add(p2);
// document.add(new Paragraph(" "));
//
//
//// 3. Dati richiesti per la valutazione delladeguatezza dei flussi finanziari
// Paragraph p3 = new Paragraph();
// p3.add(new Chunk("3. ", boldSmallFont));
// p3.add(new Chunk("Dati richiesti per la valutazione delladeguatezza dei flussi finanziari prospettici come da tabella di cui allAppendice 9", boldSmallFont));
// document.add(p3);
// document.add(new Paragraph(" "));
//
//
//// 4. Rilevazione Centrale dei Rischi
// Paragraph p4 = new Paragraph();
// p4.add(new Chunk("4. ", boldSmallFont));
// p4.add(new Chunk("Rilevazione Centrale dei Rischi riferita agli ultimi 36 mesi disponibili alla data di presentazione della Domanda", boldSmallFont));
// document.add(p4);
// document.add(new Paragraph(" "));
//
//
//// 5. Schema di presentazione dei dati di bilancio
// Paragraph p5 = new Paragraph();
// p5.add(new Chunk("5. ", boldSmallFont));
// p5.add(new Chunk("Schema di presentazione dei dati di bilancio", boldSmallFont));
// document.add(p5);
// document.add(new Paragraph(" "));
//
//
//// 6. Dettagli bilanci in forma abbreviata
// Paragraph p6 = new Paragraph();
// p6.add(new Chunk("6. ", boldSmallFont));
// p6.add(new Chunk("Dettagli bilanci in forma abbreviata", boldSmallFont));
// document.add(p6);
// document.add(new Paragraph(" "));
//
//
//// 7. Relazione aziendale illustrativa
// Paragraph p7 = new Paragraph();
// p7.add(new Chunk("7. ", boldSmallFont));
// p7.add(new Chunk("Relazione aziendale illustrativa", boldSmallFont));
// document.add(p7);
// document.add(new Paragraph(" "));
//
// addColoredLines(writer,document,greenColor);
document.close();
@@ -488,12 +419,19 @@ public class PdfDao {
.orElse(null); // If no match is found, set label to null
// Find the form field in the response that matches the contentId
if (name.equals("paragraph")){
String paragraph = content.getSettings().stream()
.filter(setting -> "text".equals(setting.getName())) // Filter settings by name
.map(SettingResponseBean::getValue) // Extract the value from the matching setting
.map(Object::toString) // Convert the value to a string
.findFirst() // Get the first matching value
.orElse(null);
// String paragraph = content.getSettings().stream()
// .filter(setting -> "text".equals(setting.getName())) // Filter settings by name
// .map(SettingResponseBean::getValue) // Extract the value from the matching setting
// .map(Object::toString) // Convert the value to a string
// .findFirst() // Get the first matching value
// .orElse(null);
String paragraph = content.getSettings().stream()
.filter(setting -> "text".equals(setting.getName())) // Filter settings by name
.map(SettingResponseBean::getValue) // Extract the value from the matching setting
.map(value -> value != null ? value.toString() : " ") // Replace null with an empty string
.findFirst() // Get the first matching value
.orElse(null); // Return null if no value is found
Paragraph labelParagraph = new Paragraph();
PdfPCell labelCell = new PdfPCell(PdfUtils.htmlToPdfPCell(paragraph,labelFont));
labelCell.setBorder(Rectangle.NO_BORDER);

View File

@@ -6,21 +6,15 @@ import net.gepafin.tendermanagement.config.SamlSuccessHandler;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.enums.UserStatusEnum;
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
import net.gepafin.tendermanagement.enums.*;
import net.gepafin.tendermanagement.model.request.*;
import net.gepafin.tendermanagement.model.response.CompanyResponse;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
import net.gepafin.tendermanagement.model.response.UserSamlResponse;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.util.JWTToken;
import net.gepafin.tendermanagement.repositories.BeneficiaryRepository;
import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.service.HubService;
import net.gepafin.tendermanagement.service.RoleService;
import net.gepafin.tendermanagement.service.SystemEmailTemplatesService;
import net.gepafin.tendermanagement.service.impl.AuthenticationService;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Utils;
@@ -39,6 +33,7 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
@@ -90,6 +85,18 @@ public class UserDao {
@Autowired
private HttpServletRequest request;
@Autowired
private SystemEmailTemplatesService systemEmailTemplatesService;
@Autowired
private EmailLogDao emailLogDao;
@Autowired
private EmailNotificationDao emailNotificationDao;
@Value("${fe.base.url}")
private String feBaseUrl;
public JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq) {
if (StringUtils.isEmpty(userReq.getHubUuid())) {
@@ -120,9 +127,35 @@ public class UserDao {
/** This code is responsible for adding a version history log for the "Create user" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).newData(userEntity).build());
if(beneficiary == null){
sendEmailToOnboardingUser(userEntity);
}
return token;
}
public void sendEmailToOnboardingUser(UserEntity userEntity){
SystemEmailTemplateResponse emailTemplate = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.USER_ONBOARDING, userEntity.getHub(), null);
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(), RecipientTypeEnum.USER, userEntity.getId(), userEntity.getEmail(),
userEntity.getId(), null, null, null);
String firstName = userEntity.getFirstName() != null ? userEntity.getFirstName() : "";
String lastName = userEntity.getLastName() != null ? userEntity.getLastName() : "";
String userName = String.join(" ", firstName, lastName).trim();
String subject = Utils.replacePlaceholders(emailTemplate.getSubject(), Map.of(
"{{user_name}}", userName
));
String body = Utils.replacePlaceholders(emailTemplate.getHtmlContent(), Map.of(
"{{user_name}}", userName,
"{{user_email}}", userEntity.getEmail()
));
emailNotificationDao.sendMail(
userEntity.getHub().getId(),
subject,
body,
List.of(userEntity.getEmail()),
emailLogRequest
);
}
private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq, HubEntity hub) {
BeneficiaryEntity beneficiaryEntity = null;
if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) {
@@ -157,6 +190,8 @@ public class UserDao {
userReq.setHubUuid(userEntity.getHub().getUniqueUuid());
}else {
samlSuccessHandler.validateToken(tempToken, userReq.getCodiceFiscale(), userReq.getHubUuid());
RoleEntity roleEntity = roleDao.getRoleByType(RoleStatusEnum.ROLE_BENEFICIARY);
userReq.setRoleId(roleEntity.getId());
}
if (Boolean.FALSE.equals(Utils.isValidEmail(userReq.getEmail()))) {
@@ -164,12 +199,10 @@ public class UserDao {
Translator.toLocale(GepafinConstant.VALIDATE_EMAIL));
}
log.info("Creating user with email: {}", userReq.getEmail());
if (userRepository.existsByEmailIgnoreCaseAndHubUniqueUuid(userReq.getEmail(), userReq.getHubUuid())) {
log.error("User creation failed: Email {} already exists", userReq.getEmail());
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
}
if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale()))
RoleEntity roleEntity = roleService.validateRole(userReq.getRoleId());
validateDuplicateEmail(userReq.getEmail(), userReq.getHubUuid(), roleEntity.getRoleType());
if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale()))
&& userRepository.existsByBeneficiaryCodiceFiscaleAndHubId(userReq.getCodiceFiscale(), hub.getId())) {
log.error("User creation failed: CodiceFiscale {} already exists", userReq.getCodiceFiscale());
throw new CustomValidationException(Status.VALIDATION_ERROR,
@@ -192,7 +225,30 @@ public class UserDao {
}
}
private void validatePassword(String password, String confirmPassword, String tempToken) {
private void validateDuplicateEmail(String email, String hubUuid, String roleType) {
String beneficiaryRoleType = RoleStatusEnum.ROLE_BENEFICIARY.getValue();
if (beneficiaryRoleType.equals(roleType)) {
Boolean beneficiaryExistsInHub = userRepository.existsByEmailIgnoreCaseForBeneficiaries(
email, hubUuid, beneficiaryRoleType);
if (Boolean.TRUE.equals(beneficiaryExistsInHub)) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
}
} else {
Boolean existsForNonBeneficiaries = userRepository.existsByEmailIgnoreCaseForNonBeneficiaries(
email, hubUuid, beneficiaryRoleType);
if (Boolean.TRUE.equals(existsForNonBeneficiaries)) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
}
}
}
private void validatePassword(String password, String confirmPassword, String tempToken) {
if (StringUtils.isEmpty(password) || StringUtils.isEmpty(confirmPassword)) {
if(tempToken == null) {
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.VALIDATE_PASSWORD));
@@ -219,7 +275,7 @@ public class UserDao {
log.info("Current user details: {}", userEntity);
log.info("New user details: {}", userReq);
String newStatus = userReq.getStatus() != null ? userReq.getStatus().getValue() : null;
if (Boolean.FALSE.equals(userEntity.getStatus().equals(newStatus))) {
if (newStatus!=null && Boolean.FALSE.equals(userEntity.getStatus().equals(newStatus))) {
userEntity.setStatus(newStatus);
}
setIfUpdated(userEntity::getFirstName, userEntity::setFirstName, userReq.getFirstName());
@@ -228,15 +284,19 @@ public class UserDao {
setIfUpdated(userEntity::getAddress, userEntity::setAddress, userReq.getAddress());
setIfUpdated(userEntity::getPhoneNumber, userEntity::setPhoneNumber, userReq.getPhoneNumber());
setIfUpdated(userEntity::getDateOfBirth, userEntity::setDateOfBirth, userReq.getDateOfBirth());
setIfUpdated(userEntity.getBeneficiary()::getCodiceFiscale, userEntity.getBeneficiary()::setCodiceFiscale, userReq.getCodiceFiscale());
setIfUpdated(userEntity.getBeneficiary()::getMarketing, userEntity.getBeneficiary()::setMarketing, userReq.getMarketing());
setIfUpdated(userEntity.getBeneficiary()::getOffers, userEntity.getBeneficiary()::setOffers, userReq.getOffers());
setIfUpdated(userEntity.getBeneficiary()::getThirdParty, userEntity.getBeneficiary()::setThirdParty, userReq.getThirdParty());
if (userReq.getRoleId() != null) {
RoleEntity roleEntity = roleDao.validateRole(userReq.getRoleId());
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
if((userEntity.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue()) && roleEntity.getRoleType().equals(RoleStatusEnum.ROLE_PRE_INSTRUCTOR.getValue())) || (userEntity.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_PRE_INSTRUCTOR.getValue()) && roleEntity.getRoleType().equals(RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue()))) {
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
}
}
if(userEntity.getBeneficiary()!=null) {
setIfUpdated(userEntity.getBeneficiary()::getCodiceFiscale, userEntity.getBeneficiary()::setCodiceFiscale, userReq.getCodiceFiscale());
setIfUpdated(userEntity.getBeneficiary()::getMarketing, userEntity.getBeneficiary()::setMarketing, userReq.getMarketing());
setIfUpdated(userEntity.getBeneficiary()::getOffers, userEntity.getBeneficiary()::setOffers, userReq.getOffers());
setIfUpdated(userEntity.getBeneficiary()::getThirdParty, userEntity.getBeneficiary()::setThirdParty, userReq.getThirdParty());
setIfUpdated(userEntity.getBeneficiary()::getEmailPec, userEntity.getBeneficiary()::setEmailPec, userReq.getEmailPec());
}
setIfUpdated(userEntity.getBeneficiary()::getEmailPec, userEntity.getBeneficiary()::setEmailPec, userReq.getEmailPec());
userEntity = userRepository.save(userEntity);
/** This code is responsible for adding a version history log for the "Update user details" operation **/
@@ -263,7 +323,7 @@ public class UserDao {
userEntity.setAddress(userReq.getAddress());
userEntity.setPhoneNumber(userReq.getPhoneNumber());
userEntity.setDateOfBirth(userReq.getDateOfBirth());
}
}
return userRepository.save(userEntity);
}
@@ -362,25 +422,83 @@ public class UserDao {
return user;
}
public String initiatePasswordReset(InitiatePasswordResetReq resetReq) {
UserEntity user = userRepository
.findByEmailIgnoreCaseAndHubUniqueUuid(resetReq.getEmail(), resetReq.getHubUuid())
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
public void initiatePasswordReset(InitiatePasswordResetReq resetReq) {
UserEntity user = userRepository.findUserExcludingRoleType(
resetReq.getEmail(),
resetReq.getHubUuid(),
RoleStatusEnum.ROLE_BENEFICIARY.getValue()
).orElseThrow(() -> new ResourceNotFoundException(
Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)
));
UserEntity oldUserEntity = Utils.getClonedEntityForData(user);
String token = Utils.generateSecureToken();
user.setResetPasswordToken(token);
userRepository.save(user);
/** This code is responsible for adding a version history log for the "Initiate password reset request" operation **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserEntity).newData(user).build());
log.info("Password reset token generated for user: {}", resetReq.getEmail());
return token;
sendResetPasswordTokenEmail(user, token);
}
public void sendResetPasswordTokenEmail(UserEntity user, String token) {
SystemEmailTemplateResponse emailTemplate = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.PASSWORD_RESET, user.getHub(), null);
String redirectUrl = feBaseUrl;
if (Boolean.FALSE.equals(StringUtils.isEmpty(user.getHub().getDomainName()))) {
redirectUrl = user.getHub().getDomainName();
}
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(
emailTemplate.getEmailScenario(),
RecipientTypeEnum.USER,
user.getId(),
user.getEmail(),
user.getId(),
null,
null,
null);
redirectUrl = String.format(
user.getHub().getDomainName() + GepafinConstant.RESET_PASSWORD_URL_FORMAT,
token,
user.getEmail()
);
String firstName = user.getFirstName() != null ? user.getFirstName() : "";
String lastName = user.getLastName() != null ? user.getLastName() : "";
String userName = String.join(" ", firstName, lastName).trim();
String subject = Utils.replacePlaceholders(emailTemplate.getSubject(), Map.of(
"{{user_name}}", userName
));
String body = Utils.replacePlaceholders(emailTemplate.getHtmlContent(), Map.of(
"{{user_name}}", userName,
"{{reset_password_link}}", redirectUrl
));
emailNotificationDao.sendMail(
user.getHub().getId(),
subject,
body,
List.of(user.getEmail()),
emailLogRequest
);
log.info("Password reset token email sent to: {}", user.getEmail());
}
public Boolean resetPassword(ResetPasswordReq resetPasswordReq) {
UserEntity user = userRepository
.findByEmailIgnoreCaseAndHubUniqueUuid(resetPasswordReq.getEmail(), resetPasswordReq.getHubUuid())
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
UserEntity user = userRepository.findUserExcludingRoleType(
resetPasswordReq.getEmail(),
resetPasswordReq.getHubUuid(),
RoleStatusEnum.ROLE_BENEFICIARY.getValue()
).orElseThrow(() -> new ResourceNotFoundException(
Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)
));
UserEntity oldUserEntity = Utils.getClonedEntityForData(user);
if (!resetPasswordReq.getNewPassword().equals(resetPasswordReq.getConfirmPassword())) {
log.info("User creation failed: Passwords do not match for email {}", user.getEmail());
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_DOESNT_MATCH));
@@ -395,25 +513,36 @@ public class UserDao {
user.setPassword(passwordEncoder.encode(resetPasswordReq.getNewPassword()));
user.setResetPasswordToken(null);
userRepository.save(user);
/** This code is responsible for adding a version history log for the "Reset Password " operation **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserEntity).newData(user).build());
log.info("Password successfully reset for user: {}", resetPasswordReq.getEmail());
return true;
}
public Boolean changePassword(UserEntity userEntity, ChangePasswordRequest request) {
public Boolean changePassword(UserEntity userEntity, ChangePasswordRequest changePasswordRequest) {
UserEntity user = userRepository
.findByEmailIgnoreCaseAndHubUniqueUuid(request.getEmail(), userEntity.getHub().getUniqueUuid())
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) {
.findUserExcludingRoleType(changePasswordRequest.getEmail(), userEntity.getHub().getUniqueUuid(),RoleStatusEnum.ROLE_BENEFICIARY.getValue())
.orElseThrow(() -> new ResourceNotFoundException(
Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)
));
UserEntity oldUserEntity = Utils.getClonedEntityForData(userEntity);
if (!passwordEncoder.matches(changePasswordRequest.getPassword(), user.getPassword())) {
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CURRENT_PASSWORD_INCORRECT));
}
if (!request.getNewPassword().equals(request.getConfirmPassword())) {
if (!changePasswordRequest.getNewPassword().equals(changePasswordRequest.getConfirmPassword())) {
log.info("User creation failed: Passwords do not match for email {}", user.getEmail());
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_DOESNT_MATCH));
}
user.setPassword(passwordEncoder.encode(request.getNewPassword()));
user.setPassword(passwordEncoder.encode(changePasswordRequest.getNewPassword()));
userRepository.save(user);
/** This code is responsible for adding a version history log for the "Change user password" operation **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserEntity).newData(user).build());
return true;
}
public void logout(HttpServletRequest request, HttpServletResponse response) {

View File

@@ -68,25 +68,46 @@ public class VatCheckDao {
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
log.info("Successfully checked vat number");
Map<String, Object> responseMap = response.getBody();
if (responseMap != null && responseMap.containsKey("data")) {
responseBody = (Map<String, Object>) responseMap.get("data");
responseBody.remove("timestamp_creation");
responseBody.remove("timestamp_last_update");
responseBody.remove("data_iscrizione");
responseBody.remove("id");
Map<String, Object> data = new LinkedHashMap<>();
data.put("data", responseBody);
vatCheckResponseBean.setValid(true);
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.VALID_VATNUMBER_MSG));
vatCheckResponseBean.setVatCheckResponse(data);
}
processValidResponse(responseMap, vatCheckResponseBean);
}
} catch (FeignException ex) {
log.error("Exception occurred while checking vat number: {0}", ex);
Utils.callException(ex.status(), ex);
}
if (ex.status() == 406) {
try {
Map<String, Object> errorResponse = Utils.parseErrorResponse(ex.contentUTF8());
processValidResponse(errorResponse, vatCheckResponseBean);
} catch (Exception parseEx) {
log.error("Failed to parse 406 error response: {0}", parseEx);
}
} else {
log.error("Exception occurred while checking vat number: {0}", ex);
Utils.callException(ex.status(), ex);
}
}
return vatCheckResponseBean;
}
public static void processValidResponse(Map<String, Object> responseMap, VatCheckResponseBean vatCheckResponseBean) {
if (responseMap != null && responseMap.containsKey("data")) {
Map<String, Object> responseBody = (Map<String, Object>) responseMap.get("data");
if (responseBody != null) {
responseBody.remove("timestamp_creation");
responseBody.remove("timestamp_last_update");
responseBody.remove("data_iscrizione");
responseBody.remove("id");
Map<String, Object> data = new LinkedHashMap<>();
data.put("data", responseBody);
vatCheckResponseBean.setValid(true);
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.VALID_VATNUMBER_MSG));
vatCheckResponseBean.setVatCheckResponse(data);
} else {
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
}
} else {
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
}
}
public VatCheckResponseBean checkVatNumber(String vatNumber) {
try {