Resolve Conflicts

This commit is contained in:
rajesh
2025-01-13 16:42:42 +05:30
82 changed files with 1949 additions and 517 deletions

2
mvnw vendored Normal file → Executable file
View File

@@ -8,7 +8,7 @@
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# https://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an

2
mvnw.cmd vendored
View File

@@ -8,7 +8,7 @@
@REM "License"); you may not use this file except in compliance @REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at @REM with the License. You may obtain a copy of the License at
@REM @REM
@REM https://www.apache.org/licenses/LICENSE-2.0 @REM http://www.apache.org/licenses/LICENSE-2.0
@REM @REM
@REM Unless required by applicable law or agreed to in writing, @REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an @REM software distributed under the License is distributed on an

View File

@@ -23,7 +23,8 @@ public class TendermanagementApplication {
@Override @Override
public void addCorsMappings(CorsRegistry registry) { public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("http://localhost:3000").allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD").allowCredentials(true); registry.addMapping("/**").allowedOrigins("http://localhost:3000", "http://127.0.0.1:5500", "https://bandi-staging.memento.credit", "https://bandi.gepafin.it")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD").allowCredentials(true);
} }
} }

View File

@@ -63,7 +63,7 @@ public class SamlSuccessHandler implements AuthenticationSuccessHandler {
Saml2AuthenticatedPrincipal principal = (Saml2AuthenticatedPrincipal) samlAuth.getPrincipal(); Saml2AuthenticatedPrincipal principal = (Saml2AuthenticatedPrincipal) samlAuth.getPrincipal();
Map<String, List<Object>> userAttributes = principal.getAttributes(); Map<String, List<Object>> userAttributes = principal.getAttributes();
String token = Utils.generateSecureToken(); String token = Utils.generateSecureSamlToken();
logger.info("SAML User Attributes: " + userAttributes); logger.info("SAML User Attributes: " + userAttributes);
// Extracting raw SAML response // Extracting raw SAML response

View File

@@ -12,6 +12,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
@@ -97,7 +98,9 @@ public class SecurityConfig {
} }
@Bean @Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.csrf(AbstractHttpConfigurer::disable).authorizeHttpRequests(auth -> auth http.csrf(AbstractHttpConfigurer::disable).headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin)
.contentSecurityPolicy(csp -> csp.policyDirectives("frame-ancestors 'self' https://bandi-staging.memento.credit https://bandi.gepafin.it")))
.authorizeHttpRequests(auth -> auth
// Allow public access to the login endpoints // Allow public access to the login endpoints
.requestMatchers("/v1/user/login").permitAll() // JWT-based login .requestMatchers("/v1/user/login").permitAll() // JWT-based login
.requestMatchers("/v1/user").permitAll() // User registration .requestMatchers("/v1/user").permitAll() // User registration

View File

@@ -33,7 +33,7 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override @Override
public void registerStompEndpoints(StompEndpointRegistry registry) { public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/wss").setAllowedOrigins("http://localhost:3000", "http://127.0.0.1:5500/", "https://bandi-staging.memento.credit/**", "https://bandi.gepafin.it/**") registry.addEndpoint("/wss").setAllowedOrigins("http://localhost:3000", "http://127.0.0.1:5500", "https://bandi-staging.memento.credit", "https://bandi.gepafin.it")
.withSockJS(); .withSockJS();
} }
} }

View File

@@ -305,6 +305,8 @@ public class GepafinConstant {
public static final String USER_ID = "userId"; public static final String USER_ID = "userId";
public static final String LOGIN_ATTEMPT_ID = "loginAttemptId"; public static final String LOGIN_ATTEMPT_ID = "loginAttemptId";
public static final String USER_ACTION_ID = "userActionId"; public static final String USER_ACTION_ID = "userActionId";
public static final String RESET_PASSWORD_URL_FORMAT = "/reset-password?token=%s&email=%s";
public static final String VALID_VATNUMBER_MSG = "valid.vatnumber.message";
public static final String ATLEAST_ONE_ID_REQUIRED="atleast.one.id.required"; public static final String ATLEAST_ONE_ID_REQUIRED="atleast.one.id.required";
//Appointment //Appointment
@@ -355,5 +357,18 @@ public class GepafinConstant {
public static final String USER_WITH_COMPANY_NOT_FOUND = "user.with.company.not.found"; public static final String USER_WITH_COMPANY_NOT_FOUND = "user.with.company.not.found";
public static final String USER_ACTION_FETCHED_SUCCESSFULLY = "user.action.fetched.successfully"; public static final String USER_ACTION_FETCHED_SUCCESSFULLY = "user.action.fetched.successfully";
//action log response
public static final String STATUS_CODE_STRING = "statusCode";
public static final String GET_STATUS_CODE_STRING = "status";
public static final String MESSAGE_STRING = "message";
public static final String AMOUNT_ACCEPTED_REQUIRED_WHILE_APPROVING_APPLICATION="amount.accepted.required";
public static final String CALL_NAME="callName";
public static final String NUMBER_OF_APPLICATIONS="numberOfApplications";
public static final String STATUS="status";
public static final String COUNT="count";
public static final String APPLICATION_PER_CALL="applicationPerCall";
public static final String APPLICATION_PER_STATUS="applicationPerStatus";
} }

View File

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

View File

@@ -47,6 +47,7 @@ import jakarta.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
@@ -172,6 +173,12 @@ public class ApplicationDao {
@Autowired @Autowired
private RoleRepository roleRepository; private RoleRepository roleRepository;
@Autowired
private ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository;
@Autowired
private ApplicationEvaluationRepository applicationEvaluationRepository;
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) { public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
FormEntity formEntity = formService.validateForm(formId); FormEntity formEntity = formService.validateForm(formId);
// callService.validatePublishedCall(formEntity.getCall().getId()); // callService.validatePublishedCall(formEntity.getCall().getId());
@@ -213,7 +220,7 @@ public class ApplicationDao {
} }
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call, UserWithCompanyEntity userWithCompany) { public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call, UserWithCompanyEntity userWithCompany) {
validateDelegation(user,userWithCompany); // validateDelegation(user,userWithCompany);
ApplicationEntity entity = new ApplicationEntity(); ApplicationEntity entity = new ApplicationEntity();
entity.setUserId(user.getId()); entity.setUserId(user.getId());
entity.setCompanyId(userWithCompany.getCompanyId()); entity.setCompanyId(userWithCompany.getCompanyId());
@@ -289,7 +296,12 @@ public class ApplicationDao {
log.info("Deleting application with ID: {}", id); log.info("Deleting application with ID: {}", id);
ApplicationEntity applicationEntity= validateApplication(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); ApplicationEntity oldApplicationDataEntity = Utils.getClonedEntityForData(applicationEntity);
validator.validateUserWithCompany(request, applicationEntity.getCompanyId()); validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
@@ -412,6 +424,10 @@ public class ApplicationDao {
if(applicationEntity.getProtocol() != null) { if(applicationEntity.getProtocol() != null) {
responseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber()); responseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
} }
responseBean.setAmountAccepted(applicationEntity.getAmountAccepted());
responseBean.setAmountRequested(applicationEntity.getAmountRequested());
responseBean.setDateAccepted(applicationEntity.getDateAccepted());
responseBean.setDateRejected(applicationEntity.getDateRejected());
return responseBean; return responseBean;
} }
@@ -431,6 +447,10 @@ public class ApplicationDao {
response.setCallId(entity.getCall().getId()); response.setCallId(entity.getCall().getId());
response.setCreatedDate(entity.getCreatedDate()); response.setCreatedDate(entity.getCreatedDate());
response.setUpdatedDate(entity.getUpdatedDate()); response.setUpdatedDate(entity.getUpdatedDate());
response.setAmountAccepted(entity.getAmountAccepted());
response.setAmountRequested(entity.getAmountRequested());
response.setDateAccepted(entity.getDateAccepted());
response.setDateRejected(entity.getDateRejected());
if(entity.getProtocol() != null) { if(entity.getProtocol() != null) {
response.setProtocolNumber(entity.getProtocol().getProtocolNumber()); response.setProtocolNumber(entity.getProtocol().getProtocolNumber());
} }
@@ -469,6 +489,30 @@ public class ApplicationDao {
List<Long> newDocumentIds = validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity); List<Long> newDocumentIds = validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity); validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
VersionActionTypeEnum actionType = VersionActionTypeEnum.INSERT; 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; ApplicationFormFieldEntity oldApplicationFormFieldData = null;
@@ -800,6 +844,10 @@ public class ApplicationDao {
applicationGetResponseBean.setCallId(applicationEntity.getCall().getId()); applicationGetResponseBean.setCallId(applicationEntity.getCall().getId());
applicationGetResponseBean.setCallTitle(applicationEntity.getCall().getName()); applicationGetResponseBean.setCallTitle(applicationEntity.getCall().getName());
applicationGetResponseBean.setCompanyId(applicationEntity.getCompanyId()); applicationGetResponseBean.setCompanyId(applicationEntity.getCompanyId());
applicationGetResponseBean.setAmountAccepted(applicationEntity.getAmountAccepted());
applicationGetResponseBean.setAmountRequested(applicationEntity.getAmountRequested());
applicationGetResponseBean.setDateAccepted(applicationEntity.getDateAccepted());
applicationGetResponseBean.setDateRejected(applicationEntity.getDateRejected());
if(applicationEntity.getProtocol() != null) { if(applicationEntity.getProtocol() != null) {
applicationGetResponseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber()); applicationGetResponseBean.setProtocolNumber(applicationEntity.getProtocol().getProtocolNumber());
} }
@@ -859,7 +907,7 @@ public class ApplicationDao {
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId(),true); ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId(),true);
applicationEntity.setProtocol(protocolEntity); applicationEntity.setProtocol(protocolEntity);
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue()); applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
applicationEntity.setSubmissionDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); applicationEntity.setSubmissionDate(protocolEntity.getCreatedDate());
applicationEntity = applicationRepository.save(applicationEntity); applicationEntity = applicationRepository.save(applicationEntity);
Map<String ,String> placeHolders=notificationDao.sendNotificationToBeneficiary(applicationEntity,NotificationTypeEnum.APPLICATION_SUBMISSION); Map<String ,String> placeHolders=notificationDao.sendNotificationToBeneficiary(applicationEntity,NotificationTypeEnum.APPLICATION_SUBMISSION);
notificationDao.sendNotificationToSuperUser(applicationEntity,placeHolders,NotificationTypeEnum.APPLICATION_SUBMISSION); notificationDao.sendNotificationToSuperUser(applicationEntity,placeHolders,NotificationTypeEnum.APPLICATION_SUBMISSION);
@@ -975,7 +1023,8 @@ public class ApplicationDao {
private void sendMailToUserAndCompany(UserEntity userEntity, ApplicationEntity applicationEntity) { private void sendMailToUserAndCompany(UserEntity userEntity, ApplicationEntity applicationEntity) {
CallEntity call =applicationEntity.getCall(); CallEntity call =applicationEntity.getCall();
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId()); CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
ProtocolEntity protocol = applicationEntity.getProtocol(); UserWithCompanyEntity userWithCompany=companyService.getUserWithCompany(userEntity.getId(),company.getId());
ProtocolEntity protocol= applicationEntity.getProtocol();
HubEntity hub = hubService.valdateHub(applicationEntity.getHubId()); HubEntity hub = hubService.valdateHub(applicationEntity.getHubId());
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService
.retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_TO_USER_AND_COMPANY, .retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_TO_USER_AND_COMPANY,
@@ -1006,8 +1055,8 @@ public class ApplicationDao {
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest); emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest);
List<String> recipientEmails = new ArrayList<>(); List<String> recipientEmails = new ArrayList<>();
// recipientEmails.add(email); // recipientEmails.add(email);
String companyEmail = company.getEmail(); String companyEmail = userWithCompany.getEmail();
String contactEmail = company.getContactEmail(); String contactEmail = userWithCompany.getContactEmail();
if (companyEmail != null && !companyEmail.isEmpty()) { if (companyEmail != null && !companyEmail.isEmpty()) {
recipientEmails.add(companyEmail); recipientEmails.add(companyEmail);
@@ -1225,47 +1274,43 @@ public class ApplicationDao {
} }
public byte[] downloadApplicationDocumentsAsZip(HttpServletRequest request, Long applicationId) { public byte[] downloadApplicationDocumentsAsZip(HttpServletRequest request, Long applicationId) {
ApplicationEntity applicationEntity = validateApplication(applicationId); ApplicationEntity applicationEntity = validateApplication(applicationId);
validateAssignedUser(request, applicationId); validateAssignedUser(request, applicationId);
Set<Long> documentIds = extractDocumentIdsFromApplicationForms(applicationId); Set<Long> documentIds = extractDocumentIdsFromApplicationForms(applicationId);
List<DocumentEntity> documents = documentRepository.findAllByIdInAndIsDeletedFalse(documentIds); List<DocumentEntity> documents = documentRepository.findAllByIdInAndIsDeletedFalse(documentIds);
ApplicationSignedDocumentEntity signedDocument = applicationSignedDocumentRepository.findByApplicationIdAndStatus(applicationId,
ApplicationSignedDocumentEntity signedDocument = applicationSignedDocumentRepository ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue()); List<DocumentEntity> amendmentDocuments = fetchAmendmentDocuments(applicationId);
if (documents.isEmpty() && signedDocument == null) { List<DocumentEntity> evaluationDocuments = fetchEvaluationDocuments(applicationId);
if (documents.isEmpty() && signedDocument == null && amendmentDocuments.isEmpty() && evaluationDocuments.isEmpty()) {
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)); throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
} }
return createZipWithDocuments(applicationEntity, documents, signedDocument, applicationId); return createZipWithDocuments(applicationEntity, documents, signedDocument, amendmentDocuments, evaluationDocuments, applicationId);
} }
private void validateAssignedUser(HttpServletRequest request, Long applicationId) { private void validateAssignedUser(HttpServletRequest request, Long applicationId) {
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository
.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null); AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null);
if (assignedApplications != null) { if (assignedApplications != null) {
validator.validatePreInstructor(request, assignedApplications.getUserId()); validator.validatePreInstructor(request, assignedApplications.getUserId());
} }
} }
private Set<Long> extractDocumentIdsFromApplicationForms(Long applicationId) { private Set<Long> extractDocumentIdsFromApplicationForms(Long applicationId) {
Set<Long> documentIds = new HashSet<>(); Set<Long> documentIds = new HashSet<>();
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId); List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
applicationForms.forEach(applicationForm -> { applicationForms.forEach(applicationForm -> {
FormEntity formEntity = applicationForm.getForm(); FormEntity formEntity = applicationForm.getForm();
if (formEntity != null) { if (formEntity != null) {
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent(); List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
contentResponseBeans.stream() contentResponseBeans.stream().filter(content -> "fileupload".equals(content.getName())).forEach(content -> {
.filter(content -> "fileupload".equals(content.getName())) Optional<ApplicationFormFieldEntity> formField = applicationFormFieldRepository.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
.forEach(content -> {
Optional<ApplicationFormFieldEntity> formField = applicationFormFieldRepository
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
content.getId(), applicationForm.getId(), applicationId); content.getId(), applicationForm.getId(), applicationId);
formField.ifPresent(field -> { formField.ifPresent(field -> {
if (field.getFieldValue() != null) { if (field.getFieldValue() != null) {
Arrays.stream(field.getFieldValue().split(",")) Arrays.stream(field.getFieldValue().split(",")).map(String::trim).map(Long::valueOf).forEach(documentIds::add);
.map(String::trim)
.map(Long::valueOf)
.forEach(documentIds::add);
} }
}); });
}); });
@@ -1274,41 +1319,76 @@ public class ApplicationDao {
return documentIds; return documentIds;
} }
private void addDocumentToZip(ZipOutputStream zos, String s3Folder, String filePath, String fileName) { private List<DocumentEntity> fetchAmendmentDocuments(Long applicationId) {
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
Set<Long> amendmentIds = amendmentRequests.stream().map(ApplicationAmendmentRequestEntity::getId).collect(Collectors.toSet());
return documentRepository.findBySourceIdInAndSourceAndIsDeletedFalse(amendmentIds, DocumentSourceTypeEnum.AMENDMENT.getValue());
}
private List<DocumentEntity> fetchEvaluationDocuments(Long applicationId) {
Optional<ApplicationEvaluationEntity> evaluationEntity = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
if (evaluationEntity.isPresent()) {
Long evaluationId = evaluationEntity.get().getId();
return documentRepository.findBySourceIdInAndSourceAndIsDeletedFalse(Collections.singleton(evaluationId), DocumentSourceTypeEnum.EVALUATION.getValue());
}
return Collections.emptyList();
}
private String fetchProtocolNumberForAmendment(Long amendmentRequestId) {
ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentRequestId).orElse(null);
if (amendmentRequest != null && amendmentRequest.getProtocol() != null) {
return amendmentRequest.getProtocol().getProtocolNumber().toString();
}
return "unknown";
}
private void addDocumentToZip(ZipOutputStream zos, String s3Folder, String filePath, String fullPath) {
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, filePath)) { try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, filePath)) {
zos.putNextEntry(new ZipEntry(fileName)); zos.putNextEntry(new ZipEntry(fullPath));
IOUtils.copy(fileInputStream, zos); IOUtils.copy(fileInputStream, zos);
zos.closeEntry(); zos.closeEntry();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Error downloading or adding document to ZIP: " + fileName, e); throw new RuntimeException("Error downloading or adding document to ZIP: " + fullPath, e);
} }
} }
private byte[] createZipWithDocuments(ApplicationEntity applicationEntity, List<DocumentEntity> documents, ApplicationSignedDocumentEntity signedDocument,
List<DocumentEntity> amendmentDocuments, List<DocumentEntity> evaluationDocuments, Long applicationId) {
private byte[] createZipWithDocuments(ApplicationEntity applicationEntity, List<DocumentEntity> documents, try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
ApplicationSignedDocumentEntity signedDocument, Long applicationId) { Long callId = applicationEntity.getCall().getId();
try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream(); // Add Application Documents
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) { String appS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, callId, applicationId, 0L);
String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, applicationEntity.getCall().getId(), applicationId,0L);
for (DocumentEntity document : documents) { for (DocumentEntity document : documents) {
String fileName = Utils.extractFileName(document.getFilePath()); String fileName = Utils.extractFileName(document.getFilePath());
addDocumentToZip(zos, s3Folder, document.getFilePath(), fileName); addDocumentToZip(zos, appS3Folder, document.getFilePath(), fileName);
} }
// Add Signed Document
if (signedDocument != null) { if (signedDocument != null) {
String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, applicationEntity.getCall().getId(), applicationId,0L); String signedFolder = "SIGNED_DOCUMENT/";
String signedDocFileName = signedDocument.getFileName(); String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId, 0L);
addDocumentToZip(zos, signedDocS3Folder, signedDocument.getFilePath(), signedDocFileName); String fileName = signedDocument.getFileName();
addDocumentToZip(zos, signedDocS3Folder, signedDocument.getFilePath(), signedFolder + fileName);
}
// Add Amendment (Soccorso) Documents
for (DocumentEntity amendmentDocument : amendmentDocuments) {
String protocolNumber = fetchProtocolNumberForAmendment(amendmentDocument.getSourceId());
String amendmentFolder = "SOCCORSO_" + protocolNumber + "/";
String amendmentS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.AMENDMENT, callId, applicationId, amendmentDocument.getSourceId());
String fileName = Utils.extractFileName(amendmentDocument.getFilePath());
addDocumentToZip(zos, amendmentS3Folder, amendmentDocument.getFilePath(), amendmentFolder + fileName);
}
// Add Evaluation Documents
for (DocumentEntity evaluationDocument : evaluationDocuments) {
String evaluationFolder = "EVALUATION/";
String evaluationS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.EVALUATION, callId, applicationId, evaluationDocument.getSourceId());
String fileName = Utils.extractFileName(evaluationDocument.getFilePath());
addDocumentToZip(zos, evaluationS3Folder, evaluationDocument.getFilePath(), evaluationFolder + fileName);
} }
zos.finish(); zos.finish();
return zipOutputStream.toByteArray(); return zipOutputStream.toByteArray();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Error while creating ZIP file", e); throw new RuntimeException("Error while creating ZIP file", e);
} }
} }
} }

View File

@@ -24,7 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -580,6 +583,10 @@ public class ApplicationEvaluationDao {
CompanyEntity company = companyService.validateCompany(application.getCompanyId()); CompanyEntity company = companyService.validateCompany(application.getCompanyId());
response.setCompanyName(company.getCompanyName()); response.setCompanyName(company.getCompanyName());
} }
response.setAmountAccepted(application.getAmountAccepted());
response.setAmountRequested(application.getAmountRequested());
response.setDateAccepted(application.getDateAccepted());
response.setDateRejected(application.getDateRejected());
} }
@@ -594,6 +601,7 @@ public class ApplicationEvaluationDao {
Optional<AssignedApplicationsEntity> assignedApplications = Optional<AssignedApplicationsEntity> assignedApplications =
assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplicationId); assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplicationId);
ApplicationEvaluationEntity oldApplicationEvaluation = null; ApplicationEvaluationEntity oldApplicationEvaluation = null;
ApplicationEntity application = applicationService.validateApplication(assignedApplications.get().getApplication().getId());
VersionActionTypeEnum actionType = VersionActionTypeEnum.INSERT; VersionActionTypeEnum actionType = VersionActionTypeEnum.INSERT;
if (existingEntityOptional.isPresent()) { if (existingEntityOptional.isPresent()) {
entity = existingEntityOptional.get(); entity = existingEntityOptional.get();
@@ -610,9 +618,15 @@ public class ApplicationEvaluationDao {
entity.setIsDeleted(false); entity.setIsDeleted(false);
setIfUpdated(entity::getNote, entity::setNote, req.getNote()); setIfUpdated(entity::getNote, entity::setNote, req.getNote());
setIfUpdated(entity::getMotivation, entity::setMotivation, req.getMotivation()); 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; actionType = VersionActionTypeEnum.UPDATE;
} else { } else {
ApplicationEntity application=entity.getAssignedApplicationsEntity().getApplication(); AssignedApplicationsEntity assignedApplicationsEntity = assignedApplicationsService.validateAssignedApplication(assignedApplicationId);
entity = convertToEntity(user, req, assignedApplicationId); entity = convertToEntity(user, req, assignedApplicationId);
actionType = VersionActionTypeEnum.INSERT; actionType = VersionActionTypeEnum.INSERT;
@@ -641,7 +655,6 @@ public class ApplicationEvaluationDao {
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(actionType).oldData(oldApplicationEvaluation).newData(entity).build()); loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(actionType).oldData(oldApplicationEvaluation).newData(entity).build());
if (status != null) { if (status != null) {
ApplicationEntity application = applicationService.validateApplication(assignedApplications.get().getApplication().getId());
AssignedApplicationsEntity assignedApplicationsEntity = assignedApplications.get(); AssignedApplicationsEntity assignedApplicationsEntity = assignedApplications.get();
return updateApplicationEvaluationStatus(application, assignedApplicationsEntity, status); return updateApplicationEvaluationStatus(application, assignedApplicationsEntity, status);
} else { } else {
@@ -1799,6 +1812,11 @@ public class ApplicationEvaluationDao {
existingEntity.setClosingDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); existingEntity.setClosingDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.CLOSE.getValue()); 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); entity = applicationEvaluationRepository.save(existingEntity);
assignedApplicationsRepository.save(assignedApplicationsEntity); assignedApplicationsRepository.save(assignedApplicationsEntity);
@@ -1813,9 +1831,15 @@ public class ApplicationEvaluationDao {
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.APPROVED.getValue())))) { 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); emailNotificationDao.sendAdmissibilityNotificationEmailForApprovedApplication(application);
} }
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.REJECTED.getValue())))) { 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); emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity);
} }

View File

@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.dao;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.entities.*; import net.gepafin.tendermanagement.entities.*;
@@ -66,7 +67,7 @@ public class CompanyDao {
if (existingCompany != null) { if (existingCompany != null) {
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()).orElse(null); UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()).orElse(null);
if (existingRelation == null) { if (existingRelation == null) {
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, existingCompany, companyRequest.getIsLegalRepresentant()); userWithCompanyEntity = createUserWithCompanyRelation(userEntity, existingCompany, companyRequest.getIsLegalRepresentant(),companyRequest);
/** This code is responsible for adding a version history log for "adding user with company" operation. **/ /** This code is responsible for adding a version history log for "adding user with company" operation. **/
loggingUtil.addVersionHistory( loggingUtil.addVersionHistory(
@@ -83,7 +84,7 @@ public class CompanyDao {
/** This code is responsible for adding a version history log for "creating company" operation. **/ /** This code is responsible for adding a version history log for "creating company" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(companyData).build()); loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(companyData).build());
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant()); userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant(),companyRequest);
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity); return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
} }
@@ -107,7 +108,7 @@ public class CompanyDao {
} }
} }
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity, Boolean isLegalRepresentant) { private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity, Boolean isLegalRepresentant,CompanyRequest companyRequest) {
UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity(); UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity();
if (userEntity.getBeneficiary() != null) { if (userEntity.getBeneficiary() != null) {
@@ -117,6 +118,11 @@ public class CompanyDao {
userWithCompanyEntity.setCompanyId(companyEntity.getId()); userWithCompanyEntity.setCompanyId(companyEntity.getId());
userWithCompanyEntity.setUserId(userEntity.getId()); userWithCompanyEntity.setUserId(userEntity.getId());
userWithCompanyEntity.setIsLegalRepresentant(isLegalRepresentant); userWithCompanyEntity.setIsLegalRepresentant(isLegalRepresentant);
userWithCompanyEntity.setEmail(companyRequest.getEmail());
userWithCompanyEntity.setPec(companyRequest.getPec());
userWithCompanyEntity.setContactName(companyRequest.getContactName());
userWithCompanyEntity.setContactEmail(companyRequest.getContactEmail());
userWithCompanyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) );
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity); UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity);
/** This code is responsible for adding a version history log for the "adding user with company" operation. **/ /** This code is responsible for adding a version history log for the "adding user with company" operation. **/
@@ -135,12 +141,8 @@ public class CompanyDao {
entity.setProvince(request.getProvince()); entity.setProvince(request.getProvince());
entity.setCap(request.getCap()); entity.setCap(request.getCap());
entity.setCountry(request.getCountry()); entity.setCountry(request.getCountry());
entity.setPec(request.getPec());
entity.setEmail(request.getEmail());
entity.setNumberOfEmployees(request.getNumberOfEmployees()); entity.setNumberOfEmployees(request.getNumberOfEmployees());
entity.setAnnualRevenue(request.getAnnualRevenue()); entity.setAnnualRevenue(request.getAnnualRevenue());
entity.setContactName(request.getContactName());
entity.setContactEmail(request.getContactEmail());
entity.setHub(userEntity.getHub()); entity.setHub(userEntity.getHub());
return entity; return entity;
} }
@@ -157,8 +159,8 @@ public class CompanyDao {
response.setProvince(entity.getProvince()); response.setProvince(entity.getProvince());
response.setCap(entity.getCap()); response.setCap(entity.getCap());
response.setCountry(entity.getCountry()); response.setCountry(entity.getCountry());
response.setPec(entity.getPec()); response.setPec(userWithCompanyEntity.getPec());
response.setEmail(entity.getEmail()); response.setEmail(userWithCompanyEntity.getEmail());
response.setNumberOfEmployees(entity.getNumberOfEmployees()); response.setNumberOfEmployees(entity.getNumberOfEmployees());
response.setAnnualRevenue(entity.getAnnualRevenue()); response.setAnnualRevenue(entity.getAnnualRevenue());
if(userWithCompanyEntity!=null) { if(userWithCompanyEntity!=null) {
@@ -166,8 +168,8 @@ public class CompanyDao {
} }
response.setCreatedDate(entity.getCreatedDate()); response.setCreatedDate(entity.getCreatedDate());
response.setUpdatedDate(entity.getUpdatedDate()); response.setUpdatedDate(entity.getUpdatedDate());
response.setContactName(entity.getContactName()); response.setContactName(userWithCompanyEntity.getContactName());
response.setContactEmail(entity.getContactEmail()); response.setContactEmail(userWithCompanyEntity.getContactEmail());
return response; return response;
} }
@@ -178,7 +180,6 @@ public class CompanyDao {
CompanyEntity oldCompanyData = Utils.getClonedEntityForData(companyEntity); CompanyEntity oldCompanyData = Utils.getClonedEntityForData(companyEntity);
setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName, companyRequest.getCompanyName()); setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName, companyRequest.getCompanyName());
setIfUpdated(companyEntity::getVatNumber, companyEntity::setVatNumber, companyRequest.getVatNumber());
setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale, companyRequest.getCodiceFiscale()); setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale, companyRequest.getCodiceFiscale());
setIfUpdated(companyEntity::getAddress, companyEntity::setAddress, companyRequest.getAddress()); setIfUpdated(companyEntity::getAddress, companyEntity::setAddress, companyRequest.getAddress());
setIfUpdated(companyEntity::getPhoneNumber, companyEntity::setPhoneNumber, companyRequest.getPhoneNumber()); setIfUpdated(companyEntity::getPhoneNumber, companyEntity::setPhoneNumber, companyRequest.getPhoneNumber());
@@ -186,12 +187,17 @@ public class CompanyDao {
setIfUpdated(companyEntity::getProvince, companyEntity::setProvince, companyRequest.getProvince()); setIfUpdated(companyEntity::getProvince, companyEntity::setProvince, companyRequest.getProvince());
setIfUpdated(companyEntity::getCap, companyEntity::setCap, companyRequest.getCap()); setIfUpdated(companyEntity::getCap, companyEntity::setCap, companyRequest.getCap());
setIfUpdated(companyEntity::getCountry, companyEntity::setCountry, companyRequest.getCountry()); setIfUpdated(companyEntity::getCountry, companyEntity::setCountry, companyRequest.getCountry());
setIfUpdated(companyEntity::getPec, companyEntity::setPec, companyRequest.getPec());
setIfUpdated(companyEntity::getEmail, companyEntity::setEmail, companyRequest.getEmail());
setIfUpdated(companyEntity::getNumberOfEmployees, companyEntity::setNumberOfEmployees, companyRequest.getNumberOfEmployees()); setIfUpdated(companyEntity::getNumberOfEmployees, companyEntity::setNumberOfEmployees, companyRequest.getNumberOfEmployees());
setIfUpdated(companyEntity::getAnnualRevenue, companyEntity::setAnnualRevenue, companyRequest.getAnnualRevenue()); setIfUpdated(companyEntity::getAnnualRevenue, companyEntity::setAnnualRevenue, companyRequest.getAnnualRevenue());
setIfUpdated(companyEntity::getContactName, companyEntity::setContactName, companyRequest.getContactName()); //
setIfUpdated(companyEntity::getContactEmail, companyEntity::setContactEmail, companyRequest.getContactEmail()); // 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); companyRepository.save(companyEntity);
/** This code is responsible for adding a version history log for the "Update company" operation. **/ /** This code is responsible for adding a version history log for the "Update company" operation. **/
@@ -201,8 +207,15 @@ public class CompanyDao {
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId); UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
//cloned entity for old data //cloned entity for old data
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity); UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity);
if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant, companyRequest.getIsLegalRepresentant()); String responseJson = companyRequest.getVatCheckResponse() != null ? Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) : null;
setIfUpdated(userWithCompanyEntity::getJson, userWithCompanyEntity::setJson, responseJson);
}
setIfUpdated(userWithCompanyEntity::getPec, userWithCompanyEntity::setPec, userWithCompanyEntity.getPec());
setIfUpdated(userWithCompanyEntity::getEmail, userWithCompanyEntity::setEmail, userWithCompanyEntity.getEmail());
setIfUpdated(userWithCompanyEntity::getContactName, userWithCompanyEntity::setContactName, companyRequest.getContactName());
setIfUpdated(userWithCompanyEntity::getContactEmail, userWithCompanyEntity::setContactEmail, companyRequest.getContactEmail());
setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant, companyRequest.getIsLegalRepresentant());
userWithCompanyEntity = userWithCompanyRepository.save(userWithCompanyEntity); userWithCompanyEntity = userWithCompanyRepository.save(userWithCompanyEntity);
/** This code is responsible for adding a version history log for the "Update company" operation. **/ /** This code is responsible for adding a version history log for the "Update company" operation. **/
@@ -277,36 +290,56 @@ public class CompanyDao {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.CANNOT_DELETE_COMPANY_WITH_APPLICATION_SUBMITT)); throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.CANNOT_DELETE_COMPANY_WITH_APPLICATION_SUBMITT));
} }
for(ApplicationEntity application:userApplications){ userApplications = userApplications.stream()
.peek(application -> {
ApplicationEntity oldApplication = Utils.getClonedEntityForData(application); ApplicationEntity oldApplication = Utils.getClonedEntityForData(application);
application.setIsDeleted(Boolean.TRUE); application.setIsDeleted(Boolean.TRUE);
/** This code is responsible for adding a version history log for the "Soft delete application" operation. **/
loggingUtil.addVersionHistory(
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldApplication).newData(application).build());
}
applicationRepository.saveAll(userApplications);
for(FaqEntity faq:faqs){
FaqEntity oldFaq = Utils.getClonedEntityForData(faq);
faq.setIsDeleted(Boolean.TRUE);
/** This code is responsible for adding a version history log for the "Soft delete Faq" operation. **/ /** This code is responsible for adding a version history log for the "Soft delete Faq" operation. **/
loggingUtil.addVersionHistory( loggingUtil.addVersionHistory(
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldFaq).newData(faq).build()); VersionHistoryRequest.builder()
} .request(request)
.actionType(VersionActionTypeEnum.SOFT_DELETE)
.oldData(oldApplication)
.newData(application)
.build()
);
})
.toList();
applicationRepository.saveAll(userApplications);
faqs = faqs.stream()
.peek(faq -> {
FaqEntity oldFaq = Utils.getClonedEntityForData(faq);
faq.setIsDeleted(Boolean.TRUE);
/** This code is responsible for adding a version history log for the "Soft delete Faq" operation. **/
loggingUtil.addVersionHistory(
VersionHistoryRequest.builder()
.request(request)
.actionType(VersionActionTypeEnum.SOFT_DELETE)
.oldData(oldFaq)
.newData(faq)
.build()
);
})
.toList();
faqRepository.saveAll(faqs); faqRepository.saveAll(faqs);
for(BeneficiaryPreferredCallEntity beneficiaryPreferredCall:preferredCallEntities){ preferredCallEntities = preferredCallEntities.stream()
.peek(beneficiaryPreferredCall -> {
BeneficiaryPreferredCallEntity oldPreferredCall = Utils.getClonedEntityForData(beneficiaryPreferredCall); BeneficiaryPreferredCallEntity oldPreferredCall = Utils.getClonedEntityForData(beneficiaryPreferredCall);
beneficiaryPreferredCall.setIsDeleted(Boolean.TRUE); beneficiaryPreferredCall.setIsDeleted(Boolean.TRUE);
/** This code is responsible for adding a version history log for the "Soft Delete BeneficiaryPreferredCall" operation. **/ /** This code is responsible for adding a version history log for the "Soft Delete BeneficiaryPreferredCall" operation. **/
loggingUtil.addVersionHistory( loggingUtil.addVersionHistory(
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldPreferredCall).newData(beneficiaryPreferredCall).build()); VersionHistoryRequest.builder()
.request(request)
} .actionType(VersionActionTypeEnum.SOFT_DELETE)
.oldData(oldPreferredCall)
.newData(beneficiaryPreferredCall)
.build()
);
})
.toList();
beneficiaryPreferredCallRepository.saveAll(preferredCallEntities); beneficiaryPreferredCallRepository.saveAll(preferredCallEntities);
if(userCompanyDelegationEntity!=null){ if(userCompanyDelegationEntity!=null){

View File

@@ -1,23 +1,36 @@
package net.gepafin.tendermanagement.dao; package net.gepafin.tendermanagement.dao;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.CompanyEntity; import net.gepafin.tendermanagement.entities.CompanyEntity;
import net.gepafin.tendermanagement.entities.UserActionEntity;
import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity; import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.enums.CallStatusEnum; import net.gepafin.tendermanagement.enums.CallStatusEnum;
import net.gepafin.tendermanagement.enums.RoleStatusEnum; import net.gepafin.tendermanagement.enums.RoleStatusEnum;
import net.gepafin.tendermanagement.enums.UserStatusEnum; 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.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.Widget1; import net.gepafin.tendermanagement.model.response.Widget1;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean; import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
import net.gepafin.tendermanagement.repositories.ApplicationRepository; import net.gepafin.tendermanagement.repositories.*;
import net.gepafin.tendermanagement.repositories.CallRepository;
import net.gepafin.tendermanagement.repositories.CompanyRepository;
import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.service.CompanyService; import net.gepafin.tendermanagement.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired; 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 org.springframework.stereotype.Component;
import java.math.BigDecimal; 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 @Component
public class DashboardDao { public class DashboardDao {
@@ -36,12 +49,21 @@ public class DashboardDao {
@Autowired @Autowired
private CompanyService companyService; private CompanyService companyService;
@Autowired
private BeneficiaryPreferredCallRepository beneficiaryPreferredCallRepository;
@Autowired
private ApplicationEvaluationRepository applicationEvaluationRepository;
@Autowired
private UserActionsRepository userActionsRepository;
public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) { public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) {
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean(); SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity)); widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
// List<Object[]> widgetBars = callRepository.findApplicationsPerCall(); Map<String, Object> widgetBars =getStatistics(requestedUserEntity);
// widgetResponseBean.setWidgetBars(widgetBars); widgetResponseBean.setWidgetBars(widgetBars);
return widgetResponseBean; return widgetResponseBean;
} }
@@ -54,7 +76,8 @@ public class DashboardDao {
setSubmittedApplications(widget1, requestedUserEntity); setSubmittedApplications(widget1, requestedUserEntity);
setDraftApplications(widget1, requestedUserEntity); setDraftApplications(widget1, requestedUserEntity);
setNumberOfCompanies(widget1, requestedUserEntity); setNumberOfCompanies(widget1, requestedUserEntity);
setAmountRequested(widget1,requestedUserEntity);
setAmountAccepted(widget1,requestedUserEntity);
return widget1; 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) { private void setRegisteredUsers(Widget1 widget1, UserEntity requestedUserEntity) {
Long activeUsers = userRepository.countByStatusAndRoleEntityRoleTypeAndHubId(UserStatusEnum.ACTIVE.getValue(), Long activeUsers = userRepository.countByStatusAndRoleEntityRoleTypeAndHubId(UserStatusEnum.ACTIVE.getValue(),
RoleStatusEnum.ROLE_BENEFICIARY.getValue(), requestedUserEntity.getHub().getId()); RoleStatusEnum.ROLE_BENEFICIARY.getValue(), requestedUserEntity.getHub().getId());
@@ -109,11 +146,23 @@ public class DashboardDao {
CompanyEntity company) { CompanyEntity company) {
BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder() BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder()
.numberOfApplications(0L).numberOfCalls(0L).numberOfIntegratedDocuments(0L).build(); .numberOfApplications(0L).numberOfCalls(0L).numberOfIntegratedDocuments(0L).build();
Long activeCalls = callRepository.countByStatusAndHubId(CallStatusEnum.PUBLISH.getValue(), userEntity.getHub().getId()); UserWithCompanyEntity userWithCompanyEntity = companyService.getUserWithCompany(userEntity.getId(), company.getId());
if (activeCalls != null) {
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls); 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(), Long activeApplication = applicationRepository.countSubmittedApplicationsByUserId(userEntity.getId(),
userWithCompanyEntity.getId()); userWithCompanyEntity.getId());
if (activeApplication != null) { if (activeApplication != null) {
@@ -121,4 +170,99 @@ public class DashboardDao {
} }
return beneficiaryWidgetResponseBean; 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

@@ -103,8 +103,10 @@ public class EmailNotificationDao {
Optional<ApplicationEvaluationEntity> applicationEvaluationEntity = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationEntity.getId()); Optional<ApplicationEvaluationEntity> applicationEvaluationEntity = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationEntity.getId());
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId()); CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
String companyEmail = company.getEmail();
String contactEmail = company.getContactEmail(); UserWithCompanyEntity userWithCompany=companyService.getUserWithCompany(userEntity.getId(),company.getId());
String companyEmail = userWithCompany.getEmail();
String contactEmail = userWithCompany.getContactEmail();
if (companyEmail != null && !companyEmail.isEmpty()) { if (companyEmail != null && !companyEmail.isEmpty()) {
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY,company.getId() , EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY,company.getId() ,

View File

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

View File

@@ -177,7 +177,7 @@ public class NotificationDao {
ApplicationEntity application = applicationService.validateApplication(applicationEvaluationEntity.getApplicationId()); ApplicationEntity application = applicationService.validateApplication(applicationEvaluationEntity.getApplicationId());
if (instructorId != null) { if (instructorId != null) {
NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, instructorId, application.getUserWithCompany(), NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, instructorId, application.getUserWithCompany(),
listOf(application.getCompanyId())); null);
sendNotification(notificationreq); sendNotification(notificationreq);
} }
} }
@@ -187,7 +187,7 @@ public class NotificationDao {
UserEntity userEntity1 = user.get(0); UserEntity userEntity1 = user.get(0);
if (userEntity1 != null) { if (userEntity1 != null) {
NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, userEntity1.getId(), application.getUserWithCompany(), NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, userEntity1.getId(), application.getUserWithCompany(),
listOf(application.getCompanyId())); null);
sendNotification(notificationreq); sendNotification(notificationreq);
} }
} }
@@ -253,19 +253,26 @@ public class NotificationDao {
notificationRepository.save(notificationEntity); notificationRepository.save(notificationEntity);
} }
public List<NotificationResponse> getNotificationByCompanyIdAndUserId(Long userId, Long companyId) { public List<NotificationResponse> getNotificationByCompanyIdAndUserId(Long userId, Long companyId, List<NotificationEnum> statuses) {
companyDao.validateCompany(companyId); List<NotificationEntity> notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalse(userId);
userDao.validateUser(userId); UserWithCompanyEntity userWithCompany = null;
List<String> statusStrings;
UserWithCompanyEntity userWithCompanyData = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalseForNotification(userId, companyId); if (companyId != null) {
if (userWithCompanyData == null) { userWithCompany = companyDao.validateUserWithCompny(userId, companyId);
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.USER_MUST_BE_ASSOCIATED_WITH_COMPANY);
} }
List<NotificationEntity> notifications = notificationRepository.findByUserWithCompanyIdAndUserIdAndIsDeletedFalse(userWithCompanyData.getId(), if (statuses != null) {
userWithCompanyData.getUserId()); statusStrings = statuses.stream().map(NotificationEnum::name)
return notifications.stream().map(this::convertNotificationEntityToNotificationResponse).toList(); .toList();
notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalseAndStatusIn(userId, statusStrings);
if (userWithCompany != null) {
notificationEntities = notificationRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(userId, userWithCompany.getId(), statusStrings);
}
}
return notificationEntities.stream().map(this::convertNotificationEntityToNotificationResponse).toList();
} }
} }

View File

@@ -109,76 +109,7 @@ public class PdfDao {
document.add(new Paragraph(" ")); // Add line break document.add(new Paragraph(" ")); // Add line break
} }
document.add(new Paragraph("\n")); // 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(); document.close();
@@ -488,12 +419,19 @@ public class PdfDao {
.orElse(null); // If no match is found, set label to null .orElse(null); // If no match is found, set label to null
// Find the form field in the response that matches the contentId // Find the form field in the response that matches the contentId
if (name.equals("paragraph")){ 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() String paragraph = content.getSettings().stream()
.filter(setting -> "text".equals(setting.getName())) // Filter settings by name .filter(setting -> "text".equals(setting.getName())) // Filter settings by name
.map(SettingResponseBean::getValue) // Extract the value from the matching setting .map(SettingResponseBean::getValue) // Extract the value from the matching setting
.map(Object::toString) // Convert the value to a string .map(value -> value != null ? value.toString() : " ") // Replace null with an empty string
.findFirst() // Get the first matching value .findFirst() // Get the first matching value
.orElse(null); .orElse(null); // Return null if no value is found
Paragraph labelParagraph = new Paragraph(); Paragraph labelParagraph = new Paragraph();
PdfPCell labelCell = new PdfPCell(PdfUtils.htmlToPdfPCell(paragraph,labelFont)); PdfPCell labelCell = new PdfPCell(PdfUtils.htmlToPdfPCell(paragraph,labelFont));
labelCell.setBorder(Rectangle.NO_BORDER); 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.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.*; import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.enums.RoleStatusEnum; import net.gepafin.tendermanagement.enums.*;
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.model.request.*; import net.gepafin.tendermanagement.model.request.*;
import net.gepafin.tendermanagement.model.response.CompanyResponse; import net.gepafin.tendermanagement.model.response.*;
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.util.JWTToken; import net.gepafin.tendermanagement.model.util.JWTToken;
import net.gepafin.tendermanagement.repositories.BeneficiaryRepository; import net.gepafin.tendermanagement.repositories.BeneficiaryRepository;
import net.gepafin.tendermanagement.repositories.UserRepository; import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.service.HubService; import net.gepafin.tendermanagement.service.HubService;
import net.gepafin.tendermanagement.service.RoleService; import net.gepafin.tendermanagement.service.RoleService;
import net.gepafin.tendermanagement.service.SystemEmailTemplatesService;
import net.gepafin.tendermanagement.service.impl.AuthenticationService; import net.gepafin.tendermanagement.service.impl.AuthenticationService;
import net.gepafin.tendermanagement.util.LoggingUtil; import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Utils; import net.gepafin.tendermanagement.util.Utils;
@@ -39,6 +33,7 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated; import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
@@ -90,6 +85,18 @@ public class UserDao {
@Autowired @Autowired
private HttpServletRequest request; 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) { public JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq) {
if (StringUtils.isEmpty(userReq.getHubUuid())) { 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. **/ /** 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()); loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).newData(userEntity).build());
if(beneficiary == null){
sendEmailToOnboardingUser(userEntity);
}
return token; 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) { private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq, HubEntity hub) {
BeneficiaryEntity beneficiaryEntity = null; BeneficiaryEntity beneficiaryEntity = null;
if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) { if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) {
@@ -157,6 +190,8 @@ public class UserDao {
userReq.setHubUuid(userEntity.getHub().getUniqueUuid()); userReq.setHubUuid(userEntity.getHub().getUniqueUuid());
}else { }else {
samlSuccessHandler.validateToken(tempToken, userReq.getCodiceFiscale(), userReq.getHubUuid()); 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()))) { if (Boolean.FALSE.equals(Utils.isValidEmail(userReq.getEmail()))) {
@@ -164,11 +199,9 @@ public class UserDao {
Translator.toLocale(GepafinConstant.VALIDATE_EMAIL)); Translator.toLocale(GepafinConstant.VALIDATE_EMAIL));
} }
log.info("Creating user with email: {}", userReq.getEmail()); log.info("Creating user with email: {}", userReq.getEmail());
if (userRepository.existsByEmailIgnoreCaseAndHubUniqueUuid(userReq.getEmail(), userReq.getHubUuid())) { RoleEntity roleEntity = roleService.validateRole(userReq.getRoleId());
log.error("User creation failed: Email {} already exists", userReq.getEmail()); validateDuplicateEmail(userReq.getEmail(), userReq.getHubUuid(), roleEntity.getRoleType());
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
}
if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale())) if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale()))
&& userRepository.existsByBeneficiaryCodiceFiscaleAndHubId(userReq.getCodiceFiscale(), hub.getId())) { && userRepository.existsByBeneficiaryCodiceFiscaleAndHubId(userReq.getCodiceFiscale(), hub.getId())) {
log.error("User creation failed: CodiceFiscale {} already exists", userReq.getCodiceFiscale()); log.error("User creation failed: CodiceFiscale {} already exists", userReq.getCodiceFiscale());
@@ -192,6 +225,29 @@ public class UserDao {
} }
} }
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) { private void validatePassword(String password, String confirmPassword, String tempToken) {
if (StringUtils.isEmpty(password) || StringUtils.isEmpty(confirmPassword)) { if (StringUtils.isEmpty(password) || StringUtils.isEmpty(confirmPassword)) {
if(tempToken == null) { if(tempToken == null) {
@@ -219,7 +275,7 @@ public class UserDao {
log.info("Current user details: {}", userEntity); log.info("Current user details: {}", userEntity);
log.info("New user details: {}", userReq); log.info("New user details: {}", userReq);
String newStatus = userReq.getStatus() != null ? userReq.getStatus().getValue() : null; 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); userEntity.setStatus(newStatus);
} }
setIfUpdated(userEntity::getFirstName, userEntity::setFirstName, userReq.getFirstName()); setIfUpdated(userEntity::getFirstName, userEntity::setFirstName, userReq.getFirstName());
@@ -228,15 +284,19 @@ public class UserDao {
setIfUpdated(userEntity::getAddress, userEntity::setAddress, userReq.getAddress()); setIfUpdated(userEntity::getAddress, userEntity::setAddress, userReq.getAddress());
setIfUpdated(userEntity::getPhoneNumber, userEntity::setPhoneNumber, userReq.getPhoneNumber()); setIfUpdated(userEntity::getPhoneNumber, userEntity::setPhoneNumber, userReq.getPhoneNumber());
setIfUpdated(userEntity::getDateOfBirth, userEntity::setDateOfBirth, userReq.getDateOfBirth()); setIfUpdated(userEntity::getDateOfBirth, userEntity::setDateOfBirth, userReq.getDateOfBirth());
if (userReq.getRoleId() != null) {
RoleEntity roleEntity = roleDao.validateRole(userReq.getRoleId());
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()::getCodiceFiscale, userEntity.getBeneficiary()::setCodiceFiscale, userReq.getCodiceFiscale());
setIfUpdated(userEntity.getBeneficiary()::getMarketing, userEntity.getBeneficiary()::setMarketing, userReq.getMarketing()); setIfUpdated(userEntity.getBeneficiary()::getMarketing, userEntity.getBeneficiary()::setMarketing, userReq.getMarketing());
setIfUpdated(userEntity.getBeneficiary()::getOffers, userEntity.getBeneficiary()::setOffers, userReq.getOffers()); setIfUpdated(userEntity.getBeneficiary()::getOffers, userEntity.getBeneficiary()::setOffers, userReq.getOffers());
setIfUpdated(userEntity.getBeneficiary()::getThirdParty, userEntity.getBeneficiary()::setThirdParty, userReq.getThirdParty()); 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);
}
setIfUpdated(userEntity.getBeneficiary()::getEmailPec, userEntity.getBeneficiary()::setEmailPec, userReq.getEmailPec()); setIfUpdated(userEntity.getBeneficiary()::getEmailPec, userEntity.getBeneficiary()::setEmailPec, userReq.getEmailPec());
}
userEntity = userRepository.save(userEntity); userEntity = userRepository.save(userEntity);
/** This code is responsible for adding a version history log for the "Update user details" operation **/ /** This code is responsible for adding a version history log for the "Update user details" operation **/
@@ -362,25 +422,83 @@ public class UserDao {
return user; return user;
} }
public String initiatePasswordReset(InitiatePasswordResetReq resetReq) { public void initiatePasswordReset(InitiatePasswordResetReq resetReq) {
UserEntity user = userRepository UserEntity user = userRepository.findUserExcludingRoleType(
.findByEmailIgnoreCaseAndHubUniqueUuid(resetReq.getEmail(), resetReq.getHubUuid()) resetReq.getEmail(),
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, resetReq.getHubUuid(),
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG))); 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(); String token = Utils.generateSecureToken();
user.setResetPasswordToken(token); user.setResetPasswordToken(token);
userRepository.save(user); 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()); 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) { public Boolean resetPassword(ResetPasswordReq resetPasswordReq) {
UserEntity user = userRepository UserEntity user = userRepository.findUserExcludingRoleType(
.findByEmailIgnoreCaseAndHubUniqueUuid(resetPasswordReq.getEmail(), resetPasswordReq.getHubUuid()) resetPasswordReq.getEmail(),
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, resetPasswordReq.getHubUuid(),
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG))); 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())) { if (!resetPasswordReq.getNewPassword().equals(resetPasswordReq.getConfirmPassword())) {
log.info("User creation failed: Passwords do not match for email {}", user.getEmail()); 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)); 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.setPassword(passwordEncoder.encode(resetPasswordReq.getNewPassword()));
user.setResetPasswordToken(null); user.setResetPasswordToken(null);
userRepository.save(user); 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()); log.info("Password successfully reset for user: {}", resetPasswordReq.getEmail());
return true; return true;
} }
public Boolean changePassword(UserEntity userEntity, ChangePasswordRequest request) { public Boolean changePassword(UserEntity userEntity, ChangePasswordRequest changePasswordRequest) {
UserEntity user = userRepository UserEntity user = userRepository
.findByEmailIgnoreCaseAndHubUniqueUuid(request.getEmail(), userEntity.getHub().getUniqueUuid()) .findUserExcludingRoleType(changePasswordRequest.getEmail(), userEntity.getHub().getUniqueUuid(),RoleStatusEnum.ROLE_BENEFICIARY.getValue())
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, .orElseThrow(() -> new ResourceNotFoundException(
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG))); Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)
if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) { ));
UserEntity oldUserEntity = Utils.getClonedEntityForData(userEntity);
if (!passwordEncoder.matches(changePasswordRequest.getPassword(), user.getPassword())) {
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CURRENT_PASSWORD_INCORRECT)); 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()); 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)); 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); 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; return true;
} }
public void logout(HttpServletRequest request, HttpServletResponse response) { public void logout(HttpServletRequest request, HttpServletResponse response) {

View File

@@ -4,15 +4,11 @@ import feign.FeignException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.enums.UserActionContextEnum; import net.gepafin.tendermanagement.entities.CompanyEntity;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum; import net.gepafin.tendermanagement.model.response.VatCheckResponseBean;
import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.service.feignClient.VatCheckService; import net.gepafin.tendermanagement.service.feignClient.VatCheckService;
import net.gepafin.tendermanagement.util.LoggingUtil; import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Utils; import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -49,10 +45,13 @@ public class VatCheckDao {
@Autowired @Autowired
private HttpServletRequest request; private HttpServletRequest request;
public Map<String, Object> checkVatNumberApi(String vatNumber) { public VatCheckResponseBean checkVatNumberApi(String vatNumber) {
VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean();
vatCheckResponseBean.setValid(false);
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
if (Boolean.TRUE.equals(Boolean.parseBoolean(isVatCheckGloballyDisabled))) { if (Boolean.TRUE.equals(Boolean.parseBoolean(isVatCheckGloballyDisabled))) {
return new HashMap<>(); vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
return vatCheckResponseBean;
} }
Map<String, Object> responseBody = new HashMap<>(); Map<String, Object> responseBody = new HashMap<>();
try { try {
@@ -69,30 +68,57 @@ public class VatCheckDao {
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) { if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
log.info("Successfully checked vat number"); log.info("Successfully checked vat number");
Map<String, Object> responseMap = response.getBody(); Map<String, Object> responseMap = response.getBody();
processValidResponse(responseMap, vatCheckResponseBean);
}
} catch (FeignException 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")) { if (responseMap != null && responseMap.containsKey("data")) {
responseBody = (Map<String, Object>) responseMap.get("data"); Map<String, Object> responseBody = (Map<String, Object>) responseMap.get("data");
if (responseBody != null) {
responseBody.remove("timestamp_creation"); responseBody.remove("timestamp_creation");
responseBody.remove("timestamp_last_update"); responseBody.remove("timestamp_last_update");
responseBody.remove("data_iscrizione"); responseBody.remove("data_iscrizione");
responseBody.remove("id"); responseBody.remove("id");
Map<String, Object> data = new LinkedHashMap<>(); Map<String, Object> data = new LinkedHashMap<>();
data.put("data", responseBody); data.put("data", responseBody);
return data;
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));
} }
} catch (FeignException ex) {
log.error("Exception occurred while checking vat number: {0}", ex);
Utils.callException(ex.status(), ex);
}
return responseBody;
} }
public Map<String, Object> checkVatNumber(String vatNumber) { public VatCheckResponseBean checkVatNumber(String vatNumber) {
try { try {
return checkVatNumberApi(vatNumber); return checkVatNumberApi(vatNumber);
} catch (Exception e) { } catch (Exception e) {
throw new CustomValidationException(Status.VALIDATION_ERROR, log.error("Error in checkVatNumber: {}", e.getMessage());
Translator.toLocale(GepafinConstant.INVALID_VATNUMBER)); VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean();
vatCheckResponseBean.setValid(false);
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
return vatCheckResponseBean;
} }
} }
} }

View File

@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.entities;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.*; import lombok.*;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@Entity @Entity
@@ -55,4 +56,16 @@ public class ApplicationEntity extends BaseEntity {
@Column(name = "APPOINTMENT_ID") @Column(name = "APPOINTMENT_ID")
private String appointmentId; private String appointmentId;
} @Column(name="AMOUNT_REQUESTED")
private BigDecimal amountRequested;
@Column(name="AMOUNT_ACCEPTED")
private BigDecimal amountAccepted;
@Column(name="DATE_ACCEPTED")
private LocalDateTime dateAccepted;
@Column(name="DATE_REJECTED")
private LocalDateTime dateRejected;
}

View File

@@ -65,4 +65,7 @@ public class ApplicationEvaluationEntity extends BaseEntity{
@Column(name = "CLOSING_DATE") @Column(name = "CLOSING_DATE")
private LocalDateTime closingDate; private LocalDateTime closingDate;
@Column(name = "ACTIVE_DAYS")
private Long activeDays;
} }

View File

@@ -41,28 +41,19 @@ public class CompanyEntity extends BaseEntity{
@Column(name = "COUNTRY") @Column(name = "COUNTRY")
private String country; private String country;
@Column(name = "PEC")
private String pec;
@Column(name = "EMAIL")
private String email;
@Column(name = "NUMBER_OF_EMPLOYEES") @Column(name = "NUMBER_OF_EMPLOYEES")
private String numberOfEmployees; private String numberOfEmployees;
@Column(name = "ANNUAL_REVENUE") @Column(name = "ANNUAL_REVENUE")
private BigDecimal annualRevenue; private BigDecimal annualRevenue;
@Column(name = "CONTACT_NAME")
private String contactName;
@Column(name = "CONTACT_EMAIL")
private String contactEmail;
@ManyToOne @ManyToOne
@JoinColumn(name = "HUB_ID") @JoinColumn(name = "HUB_ID")
private HubEntity hub; private HubEntity hub;
// @Column(name = "JSON")
// private String json;
@Column(name = "NDG") @Column(name = "NDG")
private String ndg; private String ndg;
} }

View File

@@ -0,0 +1,21 @@
package net.gepafin.tendermanagement.entities;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data;
@Entity
@Table(name = "expiration_config")
@Data
public class ExpirationConfigEntity extends BaseEntity {
@Column(name="INTERVAL_DAYS")
private Long intervalDays;
@Column(name="TYPE")
private String type;
@Column(name="IS_DELETED")
private Boolean isDeleted;
}

View File

@@ -47,6 +47,8 @@ public class SystemEmailTemplatesEntity extends BaseEntity {
INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE("INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE"), INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE("INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE"),
ADMISSIBILITY_NOTIFICATION("ADMISSIBILITY_NOTIFICATION"), ADMISSIBILITY_NOTIFICATION("ADMISSIBILITY_NOTIFICATION"),
AMENDMENT_REMINDER("AMENDMENT_REMINDER"), AMENDMENT_REMINDER("AMENDMENT_REMINDER"),
USER_ONBOARDING("USER_ONBOARDING"),
PASSWORD_RESET("PASSWORD_RESET"),
INADMISSIBILITY_TEMPLATE("INADMISSIBILITY_NOTIFICATION"); INADMISSIBILITY_TEMPLATE("INADMISSIBILITY_NOTIFICATION");
private String value; private String value;

View File

@@ -22,6 +22,22 @@ public class UserWithCompanyEntity extends BaseEntity{
@Column(name = "IS_LEGAL_REPRESENTANT") @Column(name = "IS_LEGAL_REPRESENTANT")
private Boolean isLegalRepresentant; private Boolean isLegalRepresentant;
@Column(name = "CONTACT_NAME")
private String contactName;
@Column(name = "CONTACT_EMAIL")
private String contactEmail;
@Column(name = "PEC")
private String pec;
@Column(name = "EMAIL")
private String email;
@Column(name = "JSON")
private String json;
@Column(name = "IS_DELETED") @Column(name = "IS_DELETED")
private Boolean isDeleted = false; private Boolean isDeleted = false;

View File

@@ -9,6 +9,8 @@ public enum EmailScenarioTypeEnum {
APPLICATION_AMENDMENT_EXPIRED("APPLICATION_AMENDMENT_EXPIRED"), APPLICATION_AMENDMENT_EXPIRED("APPLICATION_AMENDMENT_EXPIRED"),
APPLICATION_AMENDMENT_REMINDER("APPLICATION_AMENDMENT_REMINDER"), APPLICATION_AMENDMENT_REMINDER("APPLICATION_AMENDMENT_REMINDER"),
APPLICATION_APPROVED("APPLICATION_APPROVED"), APPLICATION_APPROVED("APPLICATION_APPROVED"),
USER_CREATION("USER_CREATION"),
PASSWORD_RESET_REQUEST("PASSWORD_RESET_REQUEST"),
APPLICATION_REJECTED("APPLICATION_REJECTED"); APPLICATION_REJECTED("APPLICATION_REJECTED");
private final String value; private final String value;

View File

@@ -0,0 +1,20 @@
package net.gepafin.tendermanagement.enums;
import com.fasterxml.jackson.annotation.JsonValue;
public enum ExpirationTypeEnum {
AMENDMENT("AMENDMENT"),
EVALUATION("EVALUATION");
private String value;
ExpirationTypeEnum(String value) {
this.value = value;
}
@JsonValue
public String getValue() {
return value;
}
}

View File

@@ -11,7 +11,9 @@ public enum NotificationTypeEnum {
AMENDMENT_CLOSED("AMENDMENT_CLOSED"), AMENDMENT_CLOSED("AMENDMENT_CLOSED"),
NDG_GENERATION("NDG_GENERATION"), NDG_GENERATION("NDG_GENERATION"),
EVALUATION_CREATION("EVALUATION_CREATION"), EVALUATION_CREATION("EVALUATION_CREATION"),
EVALUATION_EXPIRED("EVALUATION_EXPIRED"); EVALUATION_EXPIRED("EVALUATION_EXPIRED"),
AMENDMENT_EXPIRATION_REMINDER("AMENDMENT_EXPIRATION_REMINDER"),
EVALUATION_EXPIRATION_REMINDER("EVALUATION_EXPIRATION_REMINDER");
private final String value; private final String value;

View File

@@ -24,7 +24,9 @@ public enum UserActionContextEnum {
VALIDATE_EXISTING_USER_WITH_SPID_TOKEN("VALIDATE_EXISTING_USER_WITH_SPID_TOKEN"), VALIDATE_EXISTING_USER_WITH_SPID_TOKEN("VALIDATE_EXISTING_USER_WITH_SPID_TOKEN"),
GET_VALID_USER_DETAILS("GET_VALID_USER_DETAILS"), GET_VALID_USER_DETAILS("GET_VALID_USER_DETAILS"),
GET_ALL_USERS_BY_ROLE("GET_ALL_USERS_BY_ROLE"), GET_ALL_USERS_BY_ROLE("GET_ALL_USERS_BY_ROLE"),
CHANGE_USER_PASSWORD("CHANGE_USER_PASSWORD"),
INITIATE_PASSWORD_RESET_REQUEST("INITIATE_PASSWORD_RESET_REQUEST"),
RESET_USER_PASSWORD("RESET_USER_PASSWORD"),
/** application action context **/ /** application action context **/
GET_APPLICATION("GET_APPLICATION"), GET_APPLICATION("GET_APPLICATION"),
CREATE_UPDATE_APPLICATION_FORM("CREATE_UPDATE_APPLICATION_FORM"), CREATE_UPDATE_APPLICATION_FORM("CREATE_UPDATE_APPLICATION_FORM"),
@@ -134,6 +136,7 @@ public enum UserActionContextEnum {
/** Dashboard action context **/ /** Dashboard action context **/
GET_DASHBOARD_WIDGET_FOR_SUPER_ADMIN("GET_DASHBOARD_WIDGET_FOR_SUPER_ADMIN"), GET_DASHBOARD_WIDGET_FOR_SUPER_ADMIN("GET_DASHBOARD_WIDGET_FOR_SUPER_ADMIN"),
GET_DASHBOARD_WIDGET_FOR_BENEFICIARY("GET_DASHBOARD_WIDGET_FOR_BENEFICIARY"), GET_DASHBOARD_WIDGET_FOR_BENEFICIARY("GET_DASHBOARD_WIDGET_FOR_BENEFICIARY"),
GET_APPLICATION_DETAILS("GET_APPLICATION_DETAILS"),
/** Evaluation criteria action context **/ /** Evaluation criteria action context **/
GET_EVALUATION_CRITERIA("GET_EVALUATION_CRITERIA"), GET_EVALUATION_CRITERIA("GET_EVALUATION_CRITERIA"),

View File

@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.model.request;
import lombok.Data; import lombok.Data;
import net.gepafin.tendermanagement.enums.ApplicationStatusForEvaluation; import net.gepafin.tendermanagement.enums.ApplicationStatusForEvaluation;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
@Data @Data
public class ApplicationEvaluationRequest { public class ApplicationEvaluationRequest {
@@ -15,4 +16,5 @@ public class ApplicationEvaluationRequest {
private String note; private String note;
private ApplicationStatusForEvaluation applicationStatus; private ApplicationStatusForEvaluation applicationStatus;
private String motivation; private String motivation;
private BigDecimal amountAccepted;
} }

View File

@@ -1,6 +1,7 @@
package net.gepafin.tendermanagement.model.request; package net.gepafin.tendermanagement.model.request;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Map;
import lombok.Data; import lombok.Data;
@@ -23,4 +24,5 @@ public class CompanyRequest {
private Boolean isLegalRepresentant; private Boolean isLegalRepresentant;
private String contactName; private String contactName;
private String contactEmail; private String contactEmail;
private Map<String, Object> vatCheckResponse;
} }

View File

@@ -4,6 +4,7 @@ import lombok.Data;
import net.gepafin.tendermanagement.enums.ApplicationEvaluationStatusTypeEnum; import net.gepafin.tendermanagement.enums.ApplicationEvaluationStatusTypeEnum;
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum; import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@@ -38,4 +39,8 @@ public class ApplicationEvaluationResponse {
private LocalDateTime assignedAt; private LocalDateTime assignedAt;
private String ndg; private String ndg;
private String appointmentId; private String appointmentId;
private BigDecimal amountRequested;
private BigDecimal amountAccepted;
private LocalDateTime dateAccepted;
private LocalDateTime dateRejected;
} }

View File

@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.model.response;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@@ -26,6 +27,15 @@ public class ApplicationGetResponseBean {
private Long protocolNumber; private Long protocolNumber;
private BigDecimal amountRequested;
private BigDecimal amountAccepted;
private LocalDateTime dateAccepted;
private LocalDateTime dateRejected;
private List<FormApplicationResponse> form; private List<FormApplicationResponse> form;
} }

View File

@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.model.response;
import lombok.Data; import lombok.Data;
import net.gepafin.tendermanagement.model.response.ApplicationFormFieldResponseBean; import net.gepafin.tendermanagement.model.response.ApplicationFormFieldResponseBean;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@@ -37,4 +38,12 @@ public class ApplicationResponse{
private String assignedUserName; private String assignedUserName;
private BigDecimal amountRequested;
private BigDecimal amountAccepted;
private LocalDateTime dateAccepted;
private LocalDateTime dateRejected;
} }

View File

@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.model.response;
import lombok.Data; import lombok.Data;
import net.gepafin.tendermanagement.model.BaseBean; import net.gepafin.tendermanagement.model.BaseBean;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@@ -19,6 +20,14 @@ public class ApplicationResponseBean extends BaseBean {
private Long protocolNumber; private Long protocolNumber;
private BigDecimal amountRequested;
private BigDecimal amountAccepted;
private LocalDateTime dateAccepted;
private LocalDateTime dateRejected;
private List<ApplicationFormFieldResponseBean> formFields; private List<ApplicationFormFieldResponseBean> formFields;
} }

View File

@@ -0,0 +1,23 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Builder;
import lombok.Data;
import java.math.BigDecimal;
@Builder
@Data
public class ApplicationWidgetResponseBean {
private Long numberOfApplication;
private Long numberOfAssignedApplication;
private Long numberOfAcceptedApplication;
private Long numberOfApplicationInAmendmentState;
private Long numberOfDueApplication;
private BigDecimal evaluationAverageTime;
}

View File

@@ -3,6 +3,9 @@ package net.gepafin.tendermanagement.model.response;
import lombok.Data; import lombok.Data;
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum; import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data @Data
public class NextOrPreviousFormResponse { public class NextOrPreviousFormResponse {
@@ -26,6 +29,14 @@ public class NextOrPreviousFormResponse {
private ApplicationStatusTypeEnum applicationStatus; private ApplicationStatusTypeEnum applicationStatus;
private BigDecimal amountRequested;
private BigDecimal amountAccepted;
private LocalDateTime dateAccepted;
private LocalDateTime dateRejected;
private FormApplicationResponse applicationFormResponse; private FormApplicationResponse applicationFormResponse;
} }

View File

@@ -1,14 +1,17 @@
package net.gepafin.tendermanagement.model.response; package net.gepafin.tendermanagement.model.response;
import lombok.Data; import lombok.Data;
import net.gepafin.tendermanagement.entities.UserActionEntity;
import org.springframework.data.domain.Page;
import java.util.List; import java.util.List;
import java.util.Map;
@Data @Data
public class SuperAdminWidgetResponseBean { public class SuperAdminWidgetResponseBean {
private Widget1 widget1; private Widget1 widget1;
// private List<Object[]> widgetBars; private Map<String, Object> widgetBars;
} }

View File

@@ -0,0 +1,12 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Getter;
import lombok.Setter;
import java.util.Map;
@Getter
@Setter
public class VatCheckResponseBean {
private Boolean valid;
private Map<String, Object> vatCheckResponse;
private String message;
}

View File

@@ -23,4 +23,8 @@ public class Widget1 {
private BigDecimal totalActiveFinancing; private BigDecimal totalActiveFinancing;
private BigDecimal totalAmountRequested;
private BigDecimal totalAmountAccepted;
} }

View File

@@ -74,4 +74,10 @@ public interface ApplicationAmendmentRequestRepository extends JpaRepository<App
" AND activeAmendment.isDeleted = false) ") " AND activeAmendment.isDeleted = false) ")
Set<ApplicationEvaluationEntity> findEvaluationsWithoutActiveAmendmentsByIds(@Param("applicationEvaluationIds") Set<Long> applicationEvaluationIds); Set<ApplicationEvaluationEntity> findEvaluationsWithoutActiveAmendmentsByIds(@Param("applicationEvaluationIds") Set<Long> applicationEvaluationIds);
@Query("SELECT a FROM ApplicationAmendmentRequestEntity a " +
"WHERE a.isDeleted = false " +
"AND a.status NOT IN ('CLOSE', 'EXPIRED') " +
"AND a.endDate BETWEEN :startTime AND :endTime")
List<ApplicationAmendmentRequestEntity> findExpiringBetween(LocalDateTime startTime, LocalDateTime endTime);
} }

View File

@@ -1,12 +1,15 @@
package net.gepafin.tendermanagement.repositories; package net.gepafin.tendermanagement.repositories;
import net.gepafin.tendermanagement.entities.ApplicationEntity; import net.gepafin.tendermanagement.entities.ApplicationEntity;
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity; import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@@ -31,4 +34,33 @@ public interface ApplicationEvaluationRepository extends JpaRepository<Applicati
@Query("SELECT a FROM ApplicationEvaluationEntity a WHERE a.isDeleted = false AND a.endDate < :currentDate") @Query("SELECT a FROM ApplicationEvaluationEntity a WHERE a.isDeleted = false AND a.endDate < :currentDate")
List<ApplicationEvaluationEntity> findAllByIsDeletedFalseAndEndDateBefore(@Param("currentDate") LocalDateTime currentDate); List<ApplicationEvaluationEntity> findAllByIsDeletedFalseAndEndDateBefore(@Param("currentDate") LocalDateTime currentDate);
@Query("SELECT a FROM ApplicationEvaluationEntity a " +
"WHERE a.isDeleted = false " +
"AND a.status NOT IN ('CLOSE', 'EXPIRED') " +
"AND a.endDate BETWEEN :startTime AND :endTime")
List<ApplicationEvaluationEntity> findExpiringBetween(LocalDateTime startTime, LocalDateTime endTime);
// @Query("SELECT AVG(DATEDIFF(DAY, e.startDate, e.endDate)) FROM ApplicationEvaluationEntity e WHERE e.applicationId IN :applicationIds AND e.startDate IS NOT NULL AND e.endDate IS NOT NULL AND e.isDeleted = false ")
@Query("""
SELECT AVG(e.activeDays)
FROM ApplicationEvaluationEntity e
WHERE e.applicationId IN :applicationIds
AND e.activeDays IS NOT NULL
AND e.isDeleted = false
""")
BigDecimal findAverageEvaluationTimeByApplicationIds(@Param("applicationIds") List<Long> applicationIds);
@Query("""
SELECT COUNT(e)
FROM ApplicationEvaluationEntity e
WHERE e.applicationId IN :applicationIds
AND FUNCTION('DATE', e.endDate) BETWEEN :startDate AND :endDate
AND e.isDeleted = false
""")
Long countDueApplicationsBetween(
@Param("applicationIds") List<Long> applicationIds,
@Param("startDate") LocalDate startDate,
@Param("endDate") LocalDate endDate
);
} }

View File

@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@@ -24,7 +25,6 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
public Optional<ApplicationEntity> findByIdAndUserIdAndIsDeletedFalse(Long id,Long userId); public Optional<ApplicationEntity> findByIdAndUserIdAndIsDeletedFalse(Long id,Long userId);
Optional<ApplicationEntity> findByUserIdAndUserWithCompanyIdAndCallIdAndIsDeletedFalse(Long userId, Long userWithCompanyId, Long callId);
public Optional<ApplicationEntity> findByIdAndUserIdAndCallIdAndIsDeletedFalse(Long applicationId, Long userId, public Optional<ApplicationEntity> findByIdAndUserIdAndCallIdAndIsDeletedFalse(Long applicationId, Long userId,
Long callId); Long callId);
@@ -44,4 +44,37 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
@Query("SELECT a.call.id FROM ApplicationEntity a WHERE a.id = :id AND a.isDeleted = false") @Query("SELECT a.call.id FROM ApplicationEntity a WHERE a.id = :id AND a.isDeleted = false")
Long findCallIdById(@Param("id") Long id); Long findCallIdById(@Param("id") Long id);
@Query("SELECT a.call.name, COUNT(a.id) FROM ApplicationEntity a WHERE a.isDeleted = false AND a.call.hub.id = :hubId GROUP BY a.call.name")
List<Object[]> findApplicationsPerCallWithName(@Param("hubId") Long hubId);
// Count Applications by Status by Hub ID
@Query("SELECT a.status, COUNT(a.id) FROM ApplicationEntity a WHERE a.isDeleted = false AND a.call.hub.id = :hubId GROUP BY a.status")
List<Object[]> findApplicationsByStatus(@Param("hubId") Long hubId);
@Query("SELECT SUM(a.amountRequested) " +
"FROM ApplicationEntity a " +
"WHERE a.hubId = :hubId AND a.status IN ('SUBMIT', 'SOCCORSO', 'APPROVED', 'EVALUATION', 'APPOINTMENT', 'NDG', 'ADMISSIBLE','REJECTED')")
BigDecimal findTotalAmountRequestedOfApplication(@Param("hubId") Long hubId);
@Query("SELECT SUM(a.amountAccepted) " +
"FROM ApplicationEntity a " +
"WHERE a.hubId = :hubId AND a.status = 'APPROVED'")
BigDecimal findTotalAmountAcceptedOfApplication(@Param("hubId") Long hubId);
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.hubId = :hubId AND a.status = 'SUBMIT' AND a.isDeleted = false")
public Long countApplicationsByHubId(@Param("hubId") Long hubId);
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.hubId = :hubId AND a.status = 'EVALUATION' AND a.isDeleted = false")
Long countAssignedApplicationsByHubId(@Param("hubId") Long hubId);
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.hubId = :hubId AND a.status = 'APPROVED' AND a.isDeleted = false")
Long countApprovedApplicationsByHubId(@Param("hubId") Long hubId);
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.hubId = :hubId AND a.status = 'SOCCORSO' AND a.isDeleted = false")
Long countSoccorsoApplicationsByHubId(@Param("hubId") Long hubId);
@Query("SELECT a.id FROM ApplicationEntity a WHERE a.hubId = :hubId AND a.isDeleted = false")
List<Long> findApplicationIdsByHubId(@Param("hubId") Long hubId);
} }

View File

@@ -47,4 +47,10 @@ public interface CallRepository extends JpaRepository<CallEntity, Long> {
BigDecimal findTotalAmountOfPublishedCallsAndHubId(@Param("hubId") Long hubId); BigDecimal findTotalAmountOfPublishedCallsAndHubId(@Param("hubId") Long hubId);
@Query("SELECT c FROM CallEntity c WHERE c.id IN :ids AND c.status IN :status") @Query("SELECT c FROM CallEntity c WHERE c.id IN :ids AND c.status IN :status")
List<CallEntity> findByIdInAndStatusIn(@Param("ids") List<Long> ids, @Param("status") List<String> status); List<CallEntity> findByIdInAndStatusIn(@Param("ids") List<Long> ids, @Param("status") List<String> status);
@Query("SELECT SUM(c.amount) FROM CallEntity c WHERE c.hub.id = :hubId AND c.status = 'PUBLISH'")
BigDecimal findTotalAmountOfPublishedCalls(@Param("hubId") Long hubId);
List<CallEntity> findByIdIn(@Param("ids") List<Long> ids);
} }

View File

@@ -33,5 +33,7 @@ public interface DocumentRepository extends JpaRepository<DocumentEntity, Long>
List<DocumentEntity> findAllByIsDeleteTrue(); List<DocumentEntity> findAllByIsDeleteTrue();
List<DocumentEntity> findAllByIdInAndIsDeletedFalse(Set<Long> documentIds); List<DocumentEntity> findAllByIdInAndIsDeletedFalse(Set<Long> documentIds);
List<DocumentEntity> findBySourceIdInAndSourceAndIsDeletedFalse(Set<Long> sourceId, String type);
} }

View File

@@ -0,0 +1,13 @@
package net.gepafin.tendermanagement.repositories;
import net.gepafin.tendermanagement.entities.ExpirationConfigEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ExpirationConfigRepository extends JpaRepository<ExpirationConfigEntity, Long> {
List<ExpirationConfigEntity> findByTypeAndIsDeletedFalse(String type);
}

View File

@@ -6,9 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.data.domain.Pageable;
import java.time.LocalDateTime;
import java.util.List;
@Repository @Repository
public interface UserActionsRepository extends JpaRepository<UserActionEntity, Long> , JpaSpecificationExecutor<UserActionEntity> { public interface UserActionsRepository extends JpaRepository<UserActionEntity, Long> , JpaSpecificationExecutor<UserActionEntity> {
@@ -20,5 +18,5 @@ public interface UserActionsRepository extends JpaRepository<UserActionEntity, L
"AND u.isDeleted = false") "AND u.isDeleted = false")
Long countUserLoginAttempts(@Param("userId") Long userId); Long countUserLoginAttempts(@Param("userId") Long userId);
UserActionEntity findUserActionByIdAndIsDeletedFalse(Long id);
} }

View File

@@ -2,6 +2,8 @@ package net.gepafin.tendermanagement.repositories;
import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.entities.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@@ -12,9 +14,16 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
UserEntity findByBeneficiaryId(Long beneficiaryId); UserEntity findByBeneficiaryId(Long beneficiaryId);
Optional<UserEntity> findByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid); // Optional<UserEntity> findByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
boolean existsByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid); @Query("SELECT u FROM UserEntity u WHERE LOWER(u.email) = LOWER(:email) AND u.hub.uniqueUuid = :hubUuid AND u.roleEntity.roleType <> :roleType")
Optional<UserEntity> findUserExcludingRoleType(
@Param("email") String email,
@Param("hubUuid") String hubUuid,
@Param("roleType") String roleType
);
// boolean existsByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
List<UserEntity> findByRoleEntityIdInAndHubId(List<Long> roleIds, Long hubId); List<UserEntity> findByRoleEntityIdInAndHubId(List<Long> roleIds, Long hubId);
@@ -24,6 +33,27 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
Optional<UserEntity> findByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); Optional<UserEntity> findByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
// Boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
@Query("SELECT COUNT(u) > 0 " +
"FROM UserEntity u " +
"WHERE LOWER(u.email) = LOWER(:email) " +
"AND u.hub.uniqueUuid = :hubUuid " +
"AND u.roleEntity.roleType <> :beneficiaryRoleType")
Boolean existsByEmailIgnoreCaseForNonBeneficiaries(@Param("email") String email,
@Param("hubUuid") String hubUuid,
@Param("beneficiaryRoleType") String beneficiaryRoleType);
@Query("SELECT COUNT(u) > 0 " +
"FROM UserEntity u " +
"WHERE LOWER(u.email) = LOWER(:email) " +
"AND u.hub.uniqueUuid = :hubUuid " +
"AND u.roleEntity.roleType = :beneficiaryRoleType")
Boolean existsByEmailIgnoreCaseForBeneficiaries(@Param("email") String email,
@Param("hubUuid") String hubUuid,
@Param("beneficiaryRoleType") String beneficiaryRoleType);
boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
List<UserEntity> findByRoleEntity_RoleTypeAndHubId(String roleType, Long hubId); List<UserEntity> findByRoleEntity_RoleTypeAndHubId(String roleType, Long hubId);

View File

@@ -3,10 +3,26 @@ package net.gepafin.tendermanagement.scheduler;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao; import net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao;
import net.gepafin.tendermanagement.dao.NotificationDao; import net.gepafin.tendermanagement.dao.NotificationDao;
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import net.gepafin.tendermanagement.entities.ApplicationEntity; import net.gepafin.tendermanagement.entities.ApplicationEntity;
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
import net.gepafin.tendermanagement.entities.AssignedApplicationsEntity; import net.gepafin.tendermanagement.entities.AssignedApplicationsEntity;
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum; import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum;
import net.gepafin.tendermanagement.enums.ApplicationEvaluationStatusTypeEnum; import net.gepafin.tendermanagement.enums.ApplicationEvaluationStatusTypeEnum;
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum; import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
@@ -18,25 +34,9 @@ import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
import net.gepafin.tendermanagement.model.request.UserActionRequest; import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest; import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository; import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository;
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository;
import net.gepafin.tendermanagement.service.ApplicationService;
import net.gepafin.tendermanagement.util.DateTimeUtil; import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.LoggingUtil; import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Utils; import net.gepafin.tendermanagement.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@Component @Component
public class ApplicationAmendmentScheduler { public class ApplicationAmendmentScheduler {
@@ -60,9 +60,6 @@ public class ApplicationAmendmentScheduler {
@Autowired @Autowired
private AssignedApplicationsRepository assignedApplicationsRepository; private AssignedApplicationsRepository assignedApplicationsRepository;
@Autowired
private ApplicationService applicationService;
@Autowired @Autowired
private ApplicationRepository applicationRepository; private ApplicationRepository applicationRepository;

View File

@@ -0,0 +1,125 @@
package net.gepafin.tendermanagement.scheduler;
import net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao;
import net.gepafin.tendermanagement.dao.ApplicationEvaluationDao;
import net.gepafin.tendermanagement.dao.NotificationDao;
import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.enums.ExpirationTypeEnum;
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository;
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
import net.gepafin.tendermanagement.repositories.ExpirationConfigRepository;
import net.gepafin.tendermanagement.service.ApplicationService;
import net.gepafin.tendermanagement.service.CompanyService;
import net.gepafin.tendermanagement.service.UserService;
import net.gepafin.tendermanagement.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class ExpirationScheduler {
@Autowired
private ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository;
@Autowired
private ApplicationEvaluationRepository applicationEvaluationRepository;
@Autowired
private ExpirationConfigRepository expirationNotificationConfigRepository;
@Autowired
private ApplicationEvaluationDao applicationEvaluationDao;
@Autowired
private ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
@Autowired
private UserService userService;
@Autowired
private ApplicationService applicationService;
@Autowired
private NotificationDao notificationDao;
@Autowired
private CompanyService companyService;
private static final Logger log = LoggerFactory.getLogger(ExpirationScheduler.class);
@Scheduled(cron = "0 0 3 * * ?")
public void processExpiration(){
log.info("Starting the Expiration scheduler...");
try {
Utils.setHttpServletRequestForScheduler();
log.info("Starting processing expiration notifications for Amendment");
processExpiration(ExpirationTypeEnum.AMENDMENT);
log.info("Starting processing expiration notifications for Evaluation");
processExpiration(ExpirationTypeEnum.EVALUATION);
log.info("Expiration scheduler completed successfully.");
}
catch (Exception e){
log.error("An error occurred during the Notification Expiration Scheduler: {}", e.getMessage(), e);
}
}
private void processExpiration(ExpirationTypeEnum type) {
List<ExpirationConfigEntity> configEntities = expirationNotificationConfigRepository.findByTypeAndIsDeletedFalse(type.getValue());
for (ExpirationConfigEntity config : configEntities) {
Long daysBefore = config.getIntervalDays();
LocalDateTime now = LocalDateTime.now();
LocalDateTime startDate = now.plusDays(daysBefore).withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime endDate = startDate.plusDays(1).minusNanos(1).withNano(0);
if (ExpirationTypeEnum.AMENDMENT.equals(type)) {
processAmendmentExpiration(startDate, endDate, daysBefore);
} else if (ExpirationTypeEnum.EVALUATION.equals(type)) {
processEvaluationExpiration(startDate, endDate, daysBefore);
}
}
}
private void processAmendmentExpiration(LocalDateTime startDate, LocalDateTime endDate, Long daysBefore) {
List<ApplicationAmendmentRequestEntity> amendmentEntities = applicationAmendmentRequestRepository.findExpiringBetween(startDate, endDate);
for (ApplicationAmendmentRequestEntity entity : amendmentEntities) {
ApplicationEntity application = entity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication();
Map<String, String> placeHolders = replacePlaceholders(application,daysBefore);
notificationDao.sendNotificationToInstructor(placeHolders,entity.getApplicationEvaluationEntity(), NotificationTypeEnum.AMENDMENT_EXPIRATION_REMINDER);
}
}
private Map<String, String> replacePlaceholders (ApplicationEntity application, Long daysBefore){
Long companyId = application.getCompanyId();
CompanyEntity company = companyService.validateCompany(companyId);
Map<String, String> placeHolders = new HashMap<>();
placeHolders.put("{{call_name}}",application.getCall().getName());
placeHolders.put("{{company_name}}", company.getCompanyName());
placeHolders.put("{{days_before}}", daysBefore.toString());
return placeHolders;
}
private void processEvaluationExpiration(LocalDateTime startDate, LocalDateTime endDate, Long daysBefore) {
List<ApplicationEvaluationEntity> evaluationEntities = applicationEvaluationRepository.findExpiringBetween(startDate, endDate);
for (ApplicationEvaluationEntity entity : evaluationEntities) {
ApplicationEntity application = entity.getAssignedApplicationsEntity().getApplication();
Map<String, String> placeHolders = replacePlaceholders(application,daysBefore);
notificationDao.sendNotificationToInstructor(placeHolders,entity,NotificationTypeEnum.EVALUATION_EXPIRATION_REMINDER);
}
}
}

View File

@@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.gepafin.tendermanagement.model.response.VatCheckResponseBean;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@@ -26,7 +27,7 @@ public interface CompanyService {
List<CompanyResponse> getCompanyByUserId(HttpServletRequest request, Long userId); List<CompanyResponse> getCompanyByUserId(HttpServletRequest request, Long userId);
Map<String, Object> checkVatNumber(HttpServletRequest request, String vatNumber); VatCheckResponseBean checkVatNumber(HttpServletRequest request, String vatNumber);
CompanyEntity validateCompany(Long companyId); CompanyEntity validateCompany(Long companyId);
@@ -44,5 +45,4 @@ public interface CompanyService {
UserWithCompanyEntity getUserWithCompanyEntity(Long userId,Long companyId); UserWithCompanyEntity getUserWithCompanyEntity(Long userId,Long companyId);
void removeCompanyFromList(HttpServletRequest request, Long companyId); void removeCompanyFromList(HttpServletRequest request, Long companyId);
} }

View File

@@ -1,6 +1,7 @@
package net.gepafin.tendermanagement.service; package net.gepafin.tendermanagement.service;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean; import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean; import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
@@ -9,5 +10,5 @@ public interface DashboardService {
public SuperAdminWidgetResponseBean getDashboardWidgetForSuperAdmin(HttpServletRequest request); public SuperAdminWidgetResponseBean getDashboardWidgetForSuperAdmin(HttpServletRequest request);
public BeneficiaryWidgetResponseBean getDashboardWidgetForBeneficiary(HttpServletRequest request, Long companyId); public BeneficiaryWidgetResponseBean getDashboardWidgetForBeneficiary(HttpServletRequest request, Long companyId);
public ApplicationWidgetResponseBean getApplicationDetails(HttpServletRequest request);
} }

View File

@@ -18,6 +18,6 @@ public interface NotificationService {
public void deleteNotification(HttpServletRequest request, Long id); public void deleteNotification(HttpServletRequest request, Long id);
public List<NotificationResponse> getNotificationsByCompanyIdAndUserId(Long userId, Long companyId); public List<NotificationResponse> getNotificationsByCompanyIdAndUserId(Long userId, Long companyId, List<NotificationEnum> statuses);
} }

View File

@@ -27,7 +27,7 @@ public interface UserService {
UserEntity validateUser(Long userId); UserEntity validateUser(Long userId);
String initiatePasswordReset(InitiatePasswordResetReq resetReq); void initiatePasswordReset(InitiatePasswordResetReq resetReq);
Boolean resetPassword(ResetPasswordReq resetPasswordReq); Boolean resetPassword(ResetPasswordReq resetPasswordReq);

View File

@@ -12,10 +12,7 @@ import net.gepafin.tendermanagement.entities.HubEntity;
import net.gepafin.tendermanagement.entities.LoginAttemptEntity; import net.gepafin.tendermanagement.entities.LoginAttemptEntity;
import net.gepafin.tendermanagement.entities.SamlResponseEntity; import net.gepafin.tendermanagement.entities.SamlResponseEntity;
import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.LoginAttemptResultEnum; import net.gepafin.tendermanagement.enums.*;
import net.gepafin.tendermanagement.enums.LoginAttemptTypeEnum;
import net.gepafin.tendermanagement.enums.UserStatusEnum;
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
import net.gepafin.tendermanagement.model.request.LoginReq; import net.gepafin.tendermanagement.model.request.LoginReq;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest; import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.model.response.CompanyResponse; import net.gepafin.tendermanagement.model.response.CompanyResponse;
@@ -40,6 +37,7 @@ import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -95,15 +93,22 @@ public class AuthenticationService {
LoginAttemptEntity loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request); LoginAttemptEntity loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request);
try { try {
log.info("Attempting login for email: {}", loginReq.getEmail()); log.info("Attempting login for email: {}", loginReq.getEmail());
user = userRepository.findUserExcludingRoleType(
loginReq.getEmail(),
loginReq.getHubUuid(),
RoleStatusEnum.ROLE_BENEFICIARY.getValue()
).orElseThrow(() -> new ResourceNotFoundException(
Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)
));
String emailWithHubId = loginReq.getEmail()+":"+loginReq.getHubUuid(); String emailWithHubId = loginReq.getEmail()+":"+loginReq.getHubUuid();
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken( UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
emailWithHubId, loginReq.getPassword()); emailWithHubId, loginReq.getPassword());
Authentication authentication = this.authenticationManager.authenticate(authenticationToken); Authentication authentication = this.authenticationManager.authenticate(authenticationToken);
SecurityContextHolder.getContext().setAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication);
log.info("Authentication successful for email: {}", loginReq.getEmail()); log.info("Authentication successful for email: {}", loginReq.getEmail());
user = userRepository.findByEmailIgnoreCaseAndHubUniqueUuid(loginReq.getEmail(), loginReq.getHubUuid())
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
loginAttemptEntity.setUserId(user.getId()); loginAttemptEntity.setUserId(user.getId());
if (Boolean.FALSE.equals(UserStatusEnum.ACTIVE.getValue().equals(user.getStatus()))) { if (Boolean.FALSE.equals(UserStatusEnum.ACTIVE.getValue().equals(user.getStatus()))) {
throw new ResourceNotFoundException(Status.NOT_FOUND, throw new ResourceNotFoundException(Status.NOT_FOUND,

View File

@@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.gepafin.tendermanagement.model.response.VatCheckResponseBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -78,7 +79,7 @@ public class CompanyServiceImpl implements CompanyService {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Map<String, Object> checkVatNumber(HttpServletRequest request, String vatNumber) { public VatCheckResponseBean checkVatNumber(HttpServletRequest request, String vatNumber) {
return vatCheckDao.checkVatNumber(vatNumber); return vatCheckDao.checkVatNumber(vatNumber);
} }
@Override @Override

View File

@@ -4,6 +4,7 @@ import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.dao.DashboardDao; import net.gepafin.tendermanagement.dao.DashboardDao;
import net.gepafin.tendermanagement.entities.CompanyEntity; import net.gepafin.tendermanagement.entities.CompanyEntity;
import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean; import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean; import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
import net.gepafin.tendermanagement.service.DashboardService; import net.gepafin.tendermanagement.service.DashboardService;
@@ -32,4 +33,10 @@ public class DashboardServiceImpl implements DashboardService {
CompanyEntity company = validator.validateUserWithCompany(request, companyId); CompanyEntity company = validator.validateUserWithCompany(request, companyId);
return dashboardDao.getDashboardWidgetForBeneficiary(userEntity, company); return dashboardDao.getDashboardWidgetForBeneficiary(userEntity, company);
} }
@Override
public ApplicationWidgetResponseBean getApplicationDetails(HttpServletRequest request) {
UserEntity userEntity=validator.validateUser(request);
return dashboardDao.getApplicationDetails(userEntity);
}
} }

View File

@@ -56,7 +56,7 @@ public class NotificationServiceImpl implements NotificationService {
} }
@Override @Override
public List<NotificationResponse> getNotificationsByCompanyIdAndUserId(Long userId, Long companyId) { public List<NotificationResponse> getNotificationsByCompanyIdAndUserId(Long userId, Long companyId, List<NotificationEnum> statuses) {
return notificationDao.getNotificationByCompanyIdAndUserId(userId, companyId); return notificationDao.getNotificationByCompanyIdAndUserId(userId, companyId, statuses);
} }
} }

View File

@@ -77,8 +77,8 @@ public class UserServiceImpl implements UserService {
} }
@Override @Override
public String initiatePasswordReset(InitiatePasswordResetReq resetReq) { public void initiatePasswordReset(InitiatePasswordResetReq resetReq) {
return userDao.initiatePasswordReset(resetReq); userDao.initiatePasswordReset(resetReq);
} }
@Override @Override

View File

@@ -41,6 +41,8 @@ public class LoggingUtil {
@Autowired @Autowired
private TokenProvider tokenProvider; private TokenProvider tokenProvider;
private static final ThreadLocal<Long> userActionIdHolder = new ThreadLocal<>();
public UserActionEntity logUserAction(UserActionRequest userActionRequest) { public UserActionEntity logUserAction(UserActionRequest userActionRequest) {
UserActionEntity userAction = new UserActionEntity(); UserActionEntity userAction = new UserActionEntity();
try { try {
@@ -83,12 +85,22 @@ public class LoggingUtil {
userAction.setResponse(response); userAction.setResponse(response);
userActionsRepository.save(userAction); userActionsRepository.save(userAction);
userActionRequest.getRequest().setAttribute(GepafinConstant.USER_ACTION_ID, userAction.getId()); userActionRequest.getRequest().setAttribute(GepafinConstant.USER_ACTION_ID, userAction.getId());
userActionIdHolder.set(userAction.getId());
} catch (Exception e) { } catch (Exception e) {
log.error("Error logging user action: {}", e.getMessage(), e); log.error("Error logging user action: {}", e.getMessage(), e);
} }
return userAction; return userAction;
} }
public Long getUserActionId() {
return userActionIdHolder.get();
}
public void clearUserActionId() {
userActionIdHolder.remove();
log.info("UserActionId cleared from ThreadLocal");
}
private String normalizeUrl(String url) { private String normalizeUrl(String url) {
url = url.replaceAll("(?<!:)//+", "/"); url = url.replaceAll("(?<!:)//+", "/");
@@ -263,6 +275,7 @@ public class LoggingUtil {
userAction.setResponse(response); userAction.setResponse(response);
userActionsRepository.save(userAction); userActionsRepository.save(userAction);
userActionRequest.getRequest().setAttribute(GepafinConstant.USER_ACTION_ID, userAction.getId()); userActionRequest.getRequest().setAttribute(GepafinConstant.USER_ACTION_ID, userAction.getId());
} catch (Exception e) { } catch (Exception e) {
log.error("Error logging user action: {}", e.getMessage(), e); log.error("Error logging user action: {}", e.getMessage(), e);
} }
@@ -323,10 +336,35 @@ public class LoggingUtil {
public UserActionEntity getUserActionLogById(Long id) { public UserActionEntity getUserActionLogById(Long id) {
return userActionsRepository.findUserActionById(id); return userActionsRepository.findUserActionByIdAndIsDeletedFalse(id);
} }
public List<VersionHistoryEntity> getVersionHistoryLogById(Long id) { public List<VersionHistoryEntity> getVersionHistoryLogById(Long id) {
return versionHistoryRepository.findVersionHistoryByUserActionId(id); return versionHistoryRepository.findVersionHistoryByUserActionId(id);
} }
public void updateUserActionWithError(Long userActionId, String errorDetails) {
if (userActionId == null) {
return;
}
UserActionEntity userAction = userActionsRepository.findUserActionByIdAndIsDeletedFalse(userActionId);
if (userAction != null) {
userAction.setResponse(errorDetails);
userActionsRepository.save(userAction);
}
}
public void updateUserActionWithResponse(Long userActionId, String response) {
if (userActionId == null) {
return;
}
UserActionEntity userAction = userActionsRepository.findUserActionByIdAndIsDeletedFalse(userActionId);
if (userAction != null) {
userAction.setResponse(response);
userActionsRepository.save(userAction);
}
}
} }

View File

@@ -0,0 +1,148 @@
package net.gepafin.tendermanagement.util;
import com.amazonaws.services.alexaforbusiness.model.UnauthorizedException;
import jakarta.persistence.EntityNotFoundException;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.server.ResponseStatusException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.AccessDeniedException;
import java.util.LinkedHashMap;
import java.util.Map;
@Aspect
@Component
@Slf4j
public class UserActionAspect {
@Autowired
private LoggingUtil loggingUtil;
@Around("execution(public * net.gepafin.tendermanagement.web.rest.api.impl..*(..))")
public Object logApiResponse(ProceedingJoinPoint joinPoint) throws Throwable {
Object result;
HttpServletRequest request = getRequestFromContext();
try {
Long userActionId = getUserActionIdFromRequest(request);
if (userActionId != null) {
request.setAttribute(GepafinConstant.USER_ACTION_ID, userActionId);
log.info("Stored userActionId in RequestContext: {}", userActionId);
} else {
userActionId = loggingUtil.getUserActionId();
if (userActionId != null) {
request.setAttribute(GepafinConstant.USER_ACTION_ID, userActionId);
}
}
result = joinPoint.proceed();
if (result instanceof ResponseEntity<?>) {
Long storedUserActionId = (Long) request.getAttribute(GepafinConstant.USER_ACTION_ID);
handleSuccessResponse((ResponseEntity<?>) result, storedUserActionId == null ? userActionId : storedUserActionId);
}
} catch (Exception ex) {
log.error("Exception occurred: ", ex);
handleError(ex, getUserActionIdFromRequest(request));
throw ex;
} finally {
loggingUtil.clearUserActionId();
}
return result;
}
private void handleSuccessResponse(ResponseEntity<?> responseEntity, Long userActionId) {
if (userActionId != null) {
Map<String, Object> responseWithUserAction = new LinkedHashMap<>();
responseWithUserAction.put(GepafinConstant.STATUS_CODE_STRING, responseEntity.getStatusCode().value());
// Log and update user action
loggingUtil.updateUserActionWithResponse(userActionId, Utils.convertMapIntoJsonString(responseWithUserAction));
log.info("Updated userActionId with response: {}", userActionId);
}
}
private void handleError(Throwable ex, Long userActionId) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
HttpStatus status = getStatusCodeFromException(ex);
log.info("Status Code received from exception : {}", status);
String errorMessage = ex.getMessage();
Map<String, Object> errorResponse = new LinkedHashMap<>();
errorResponse.put(GepafinConstant.STATUS_CODE_STRING, status.value());
errorResponse.put(GepafinConstant.GET_STATUS_CODE_STRING, status);
errorResponse.put(GepafinConstant.MESSAGE_STRING, errorMessage);
if (userActionId != null) {
String errorDetails = Utils.convertMapIntoJsonString(errorResponse);
loggingUtil.updateUserActionWithError(userActionId, errorDetails);
log.info("Updated userActionId with error details: {}", userActionId);
}
}
private HttpServletRequest getRequestFromContext() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attributes != null ? attributes.getRequest() : null;
}
private Long getUserActionIdFromRequest(HttpServletRequest request) {
if (request != null) {
Object userActionIdAttr = request.getAttribute(GepafinConstant.USER_ACTION_ID);
return userActionIdAttr != null ? Long.valueOf(userActionIdAttr.toString()) : null;
}
return null;
}
private HttpStatus getStatusCodeFromException(Throwable ex) {
if (ex instanceof ResourceNotFoundException) {
return HttpStatus.NOT_FOUND;
}
if (ex instanceof ResponseStatusException responseStatusException) {
return (HttpStatus) responseStatusException.getStatusCode();
}
if (ex instanceof CustomValidationException) {
return HttpStatus.BAD_REQUEST;
}
if (ex instanceof EntityNotFoundException) {
return HttpStatus.NOT_FOUND;
}
if (ex instanceof IllegalArgumentException || ex instanceof MissingServletRequestParameterException || ex instanceof MethodArgumentNotValidException) {
return HttpStatus.BAD_REQUEST;
}
if (ex instanceof AccessDeniedException) {
return HttpStatus.FORBIDDEN;
}
if (ex instanceof UnauthorizedException) {
return HttpStatus.UNAUTHORIZED;
}
return HttpStatus.INTERNAL_SERVER_ERROR;
}
}

View File

@@ -24,6 +24,7 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.constants.GepafinConstant;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -153,6 +154,9 @@ public class Utils {
public static String convertMapIntoJsonString(Map<String, Object> map) { public static String convertMapIntoJsonString(Map<String, Object> map) {
try { try {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
if (MapUtils.isNotEmpty(map)) { if (MapUtils.isNotEmpty(map)) {
return mapper.writeValueAsString(map); return mapper.writeValueAsString(map);
} }
@@ -206,7 +210,7 @@ public class Utils {
return new String(decodedBytes, StandardCharsets.UTF_8); return new String(decodedBytes, StandardCharsets.UTF_8);
} }
public static String generateSecureToken() { public static String generateSecureSamlToken() {
SecureRandom secureRandom = new SecureRandom(); SecureRandom secureRandom = new SecureRandom();
byte[] tokenBytes = new byte[24]; byte[] tokenBytes = new byte[24];
secureRandom.nextBytes(tokenBytes); secureRandom.nextBytes(tokenBytes);
@@ -214,7 +218,14 @@ public class Utils {
log.debug("Generated secure token: {}", token); log.debug("Generated secure token: {}", token);
return token; return token;
} }
public static String generateSecureToken() {
SecureRandom secureRandom = new SecureRandom();
byte[] tokenBytes = new byte[5];
secureRandom.nextBytes(tokenBytes);
String token = Base64.getUrlEncoder().withoutPadding().encodeToString(tokenBytes);
log.debug("Generated secure token: {}", token);
return token;
}
public static Map<String, List<Object>> convertStringIntoMap(String jsonString) { public static Map<String, List<Object>> convertStringIntoMap(String jsonString) {
try { try {
return mapper.readValue(jsonString, new TypeReference<Map<String, List<Object>>>() { return mapper.readValue(jsonString, new TypeReference<Map<String, List<Object>>>() {
@@ -690,4 +701,22 @@ public class Utils {
public static String createChannelForUserAndCompany(Long userId, Long companyId) { public static String createChannelForUserAndCompany(Long userId, Long companyId) {
return GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId + GepafinConstant.COMPANY_PREFIX + companyId; return GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId + GepafinConstant.COMPANY_PREFIX + companyId;
} }
public static Map<String, Object> parseErrorResponse(String responseBody) {
if (StringUtils.isBlank(responseBody)) {
return defaultErrorResponse();
}
try {
return mapper.readValue(responseBody, Map.class);
} catch (Exception e) {
log.error("Failed to parse error response: {}", e.getMessage(), e);
return defaultErrorResponse();
}
}
private static Map<String, Object> defaultErrorResponse() {
return Collections.singletonMap("message", Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
}
} }

View File

@@ -33,7 +33,7 @@ public interface CommunicationApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@PostMapping(value = "/{amendmentId}", produces = { "application/json" }) @PostMapping(value = "/{amendmentId}", produces = { "application/json" })
@PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY')") @PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY') || hasRole('ROLE_INSTRUCTOR_MANAGER')")
ResponseEntity<Response<CommunicationResponseBean>> addCommentToAmendmentRequest(HttpServletRequest request, ResponseEntity<Response<CommunicationResponseBean>> addCommentToAmendmentRequest(HttpServletRequest request,
@RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId); @RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId);
@@ -55,7 +55,7 @@ public interface CommunicationApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@PutMapping(value = "/{amendmentId}/{commentId}", produces = { "application/json" }) @PutMapping(value = "/{amendmentId}/{commentId}", produces = { "application/json" })
@PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY')") @PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY') || hasRole('ROLE_INSTRUCTOR_MANAGER')")
ResponseEntity<Response<CommunicationResponseBean>> updateCommunicationAmendment(HttpServletRequest request, ResponseEntity<Response<CommunicationResponseBean>> updateCommunicationAmendment(HttpServletRequest request,
@RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId, @PathVariable(value = "commentId") Long commentId); @RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId, @PathVariable(value = "commentId") Long commentId);

View File

@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.web.rest.api;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.gepafin.tendermanagement.model.response.VatCheckResponseBean;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
@@ -94,7 +95,7 @@ public interface CompanyApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "/vatNumber", produces = { "application/json" }) @GetMapping(value = "/vatNumber", produces = { "application/json" })
ResponseEntity<Response<Map<String,Object>>> checkVatNumber(HttpServletRequest request, ResponseEntity<Response<VatCheckResponseBean>> checkVatNumber(HttpServletRequest request,
@Parameter(description = "The vatNumber of company", required = true) @RequestParam("vatNumber") String vatNumber); @Parameter(description = "The vatNumber of company", required = true) @RequestParam("vatNumber") String vatNumber);
@Operation(summary = "Api to download company delegation template", responses = { @ApiResponse(responseCode = "200", description = "OK"), @Operation(summary = "Api to download company delegation template", responses = { @ApiResponse(responseCode = "200", description = "OK"),

View File

@@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean; import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean; import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.model.util.Response;
@@ -47,6 +48,18 @@ public interface DashboardApi {
ResponseEntity<Response<BeneficiaryWidgetResponseBean>> getDashboardWidgetForBeneficiary(HttpServletRequest request, ResponseEntity<Response<BeneficiaryWidgetResponseBean>> getDashboardWidgetForBeneficiary(HttpServletRequest request,
@Parameter(description = "The company id", required = true) @PathVariable(value = "companyId", required = true) Long companyId); @Parameter(description = "The company id", required = true) @PathVariable(value = "companyId", required = true) Long companyId);
@Operation(summary = "Api to get Application details",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "/application",
produces = { "application/json" })
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN') || hasRole('ROLE_INSTRUCTOR_MANAGER')")
ResponseEntity<Response<ApplicationWidgetResponseBean>> getApplicationDetails(HttpServletRequest request);
} }

View File

@@ -33,8 +33,8 @@ public interface NotificationApi {
ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) }) ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) })
@PostMapping(value = "/user/{userId}/sent", consumes = "application/json", produces = "application/json") @PostMapping(value = "/user/{userId}/sent", consumes = "application/json", produces = "application/json")
ResponseEntity<Response<NotificationResponse>> sendNotification(HttpServletRequest request, @RequestBody NotificationReq notificationReq, ResponseEntity<Response<NotificationResponse>> sendNotification(HttpServletRequest request, @RequestBody NotificationReq notificationReq,
@Parameter(description = "The company id", required = false) @RequestParam(value = "companyId", required = false) Long companyId, @Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId,
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId); @Parameter(description = "The company id", required = false) @RequestParam(value = "companyId", required = false) Long companyId);
@Operation(summary = "Api to get notification by id", responses = { @ApiResponse(responseCode = "200", description = "OK"), @Operation(summary = "Api to get notification by id", responses = { @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@@ -93,7 +93,8 @@ public interface NotificationApi {
@GetMapping(value = "/user/{userId}/company/{companyId}/notifications", produces = "application/json") @GetMapping(value = "/user/{userId}/company/{companyId}/notifications", produces = "application/json")
ResponseEntity<Response<List<NotificationResponse>>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request, ResponseEntity<Response<List<NotificationResponse>>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request,
@Parameter(description = "The user id", required = true) @PathVariable(value = "userId") Long userId, @Parameter(description = "The user id", required = true) @PathVariable(value = "userId") Long userId,
@Parameter(description = "The company ID", required = true) @PathVariable(value = "companyId") Long companyId); @Parameter(description = "The company ID", required = true) @PathVariable(value = "companyId") Long companyId,
@Parameter(description = "The notification status", required = false) @RequestParam(value = "status", required = false) List<NotificationEnum> statuses);
} }

View File

@@ -59,6 +59,7 @@ public interface UserApi {
@RequestMapping(value = "/{userId}", @RequestMapping(value = "/{userId}",
produces = {"application/json"}, produces = {"application/json"},
method = RequestMethod.PUT) method = RequestMethod.PUT)
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
default ResponseEntity<Response<UserResponseBean>> updateUser(HttpServletRequest request, default ResponseEntity<Response<UserResponseBean>> updateUser(HttpServletRequest request,
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId, @Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId,
@Parameter(description = "User request object", required = true) @Valid @RequestBody UpdateUserReq userReq) { @Parameter(description = "User request object", required = true) @Valid @RequestBody UpdateUserReq userReq) {
@@ -118,7 +119,7 @@ public interface UserApi {
@RequestMapping(value = "/reset-password/initiate", @RequestMapping(value = "/reset-password/initiate",
produces = {"application/json"}, produces = {"application/json"},
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<Response<String>> initiatePasswordReset( ResponseEntity<Response<Void>> initiatePasswordReset(HttpServletRequest request,
@Parameter(description = "Initiate password reset request object", required = true) @Valid @RequestBody InitiatePasswordResetReq initiatePasswordResetReq); @Parameter(description = "Initiate password reset request object", required = true) @Valid @RequestBody InitiatePasswordResetReq initiatePasswordResetReq);
@Operation(summary = "Api to reset password", @Operation(summary = "Api to reset password",
@@ -131,7 +132,7 @@ public interface UserApi {
@RequestMapping(value = "/reset-password", @RequestMapping(value = "/reset-password",
produces = {"application/json"}, produces = {"application/json"},
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<Response<Boolean>> resetPassword( ResponseEntity<Response<Boolean>> resetPassword(HttpServletRequest request,
@Parameter(description = "Reset password request object", required = true) @Valid @RequestBody ResetPasswordReq resetPasswordReq); @Parameter(description = "Reset password request object", required = true) @Valid @RequestBody ResetPasswordReq resetPasswordReq);
@Operation(summary = "Api to change user password", @Operation(summary = "Api to change user password",
responses = { responses = {

View File

@@ -7,6 +7,7 @@ import java.util.Map;
import net.gepafin.tendermanagement.enums.UserActionContextEnum; import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum; import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.UserActionRequest; import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.model.response.VatCheckResponseBean;
import net.gepafin.tendermanagement.util.LoggingUtil; import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -112,15 +113,15 @@ public class CompanyApiController implements CompanyApi{
} }
@Override @Override
public ResponseEntity<Response<Map<String,Object>>> checkVatNumber(HttpServletRequest request, String vatNumber) { public ResponseEntity<Response<VatCheckResponseBean>> checkVatNumber(HttpServletRequest request, String vatNumber) {
log.info("check VatNumber with: {}", vatNumber); log.info("check VatNumber with: {}", vatNumber);
/** This code is responsible for creating user action logs for the "Check vat number" operation. **/ /** This code is responsible for creating user action logs for the "Check vat number" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.CHECK_COMPANY_VAT_NUMBER).build()); loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.CHECK_COMPANY_VAT_NUMBER).build());
Map<String,Object> data = companyService.checkVatNumber(request, vatNumber); VatCheckResponseBean vatCheckResponseBean = companyService.checkVatNumber(request, vatNumber);
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.CHECK_VATNUMBER_SUCCESS_MSG))); .body(new Response<>(vatCheckResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.CHECK_VATNUMBER_SUCCESS_MSG)));
} }
@Override @Override

View File

@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.web.rest.api.impl;
import net.gepafin.tendermanagement.entities.RoleEntity; import net.gepafin.tendermanagement.entities.RoleEntity;
import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
import net.gepafin.tendermanagement.repositories.UserRepository; import net.gepafin.tendermanagement.repositories.UserRepository;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -35,7 +36,10 @@ public class CustomUserDetailsService implements UserDetailsService {
String email = loginParts[0]; String email = loginParts[0];
String hubId = loginParts[1]; String hubId = loginParts[1];
UserEntity user = userRepository.findByEmailIgnoreCaseAndHubUniqueUuid(email, hubId) UserEntity user = userRepository.findUserExcludingRoleType(
email,
hubId,
RoleStatusEnum.ROLE_BENEFICIARY.getValue())
.orElseThrow( .orElseThrow(
() -> new UsernameNotFoundException("User " + email + " was not found in the database")); () -> new UsernameNotFoundException("User " + email + " was not found in the database"));
return createSpringSecurityUser(user); return createSpringSecurityUser(user);

View File

@@ -6,6 +6,7 @@ import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.enums.UserActionContextEnum; import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum; import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.UserActionRequest; import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean; import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean; import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.model.util.Response;
@@ -49,5 +50,14 @@ public class DashboardApiController implements DashboardApi {
return ResponseEntity.status(HttpStatus.CREATED) return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(widgetResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.DASHBOARD_WIDGET_FETCHED_SUCCESSFULLY))); .body(new Response<>(widgetResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.DASHBOARD_WIDGET_FETCHED_SUCCESSFULLY)));
} }
@Override
public ResponseEntity<Response<ApplicationWidgetResponseBean>> getApplicationDetails(HttpServletRequest request) {
/** This code is responsible for creating user action logs for the "Get complete application page" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_APPLICATION_DETAILS).build());
ApplicationWidgetResponseBean widgetResponseBean= dashboardService.getApplicationDetails(request);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(widgetResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.DASHBOARD_WIDGET_FETCHED_SUCCESSFULLY)));
}
} }

View File

@@ -65,8 +65,8 @@ public class NotificationApiController implements NotificationApi {
} }
@Override @Override
public ResponseEntity<Response<List<NotificationResponse>>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request,Long userId, Long companyId) { public ResponseEntity<Response<List<NotificationResponse>>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request,Long userId, Long companyId, List<NotificationEnum> statuses) {
List<NotificationResponse> notificationResponses = notificationService.getNotificationsByCompanyIdAndUserId(userId, companyId); List<NotificationResponse> notificationResponses = notificationService.getNotificationsByCompanyIdAndUserId(userId, companyId, statuses);
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(notificationResponses, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_FETCHED_SUCCESSFULLY))); .body(new Response<>(notificationResponses, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_FETCHED_SUCCESSFULLY)));
} }

View File

@@ -125,20 +125,35 @@ public class UserApiController implements UserApi {
@Override @Override
public ResponseEntity<Response<Boolean>> changePassword(HttpServletRequest httpServletRequest, @Valid @RequestBody ChangePasswordRequest request) { public ResponseEntity<Response<Boolean>> changePassword(HttpServletRequest httpServletRequest, @Valid @RequestBody ChangePasswordRequest request) {
log.info("Change Password attempt for email: {}", request.getEmail()); log.info("Change Password attempt for email: {}", request.getEmail());
/** This code is responsible for "Change user password" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(httpServletRequest).actionType(UserActionLogsEnum.UPDATE)
.actionContext(UserActionContextEnum.CHANGE_USER_PASSWORD).build());
userService.changePassword(httpServletRequest, request); userService.changePassword(httpServletRequest, request);
return ResponseEntity.ok(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.SUCCESS_PASSWORD_CHANGED))); return ResponseEntity.ok(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.SUCCESS_PASSWORD_CHANGED)));
} }
@Override @Override
public ResponseEntity<Response<String>> initiatePasswordReset(InitiatePasswordResetReq request) { public ResponseEntity<Response<Void>> initiatePasswordReset(HttpServletRequest httpServletRequest,InitiatePasswordResetReq request) {
log.info("Initiating password reset for email: {}", request.getEmail()); log.info("Initiating password reset for email: {}", request.getEmail());
String resetToken = userService.initiatePasswordReset(request);
/** This code is responsible for "Initiating Password Reset Request" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(httpServletRequest).actionType(UserActionLogsEnum.UPDATE)
.actionContext(UserActionContextEnum.INITIATE_PASSWORD_RESET_REQUEST).build());
userService.initiatePasswordReset(request);
log.info("Password reset token generated for email: {}", request.getEmail()); log.info("Password reset token generated for email: {}", request.getEmail());
return ResponseEntity.ok(new Response<>(resetToken, Status.SUCCESS, Translator.toLocale(GepafinConstant.RESET_PASSWORD_INITIATED))); return ResponseEntity.ok(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.RESET_PASSWORD_INITIATED)));
} }
@Override @Override
public ResponseEntity<Response<Boolean>> resetPassword(ResetPasswordReq request) { public ResponseEntity<Response<Boolean>> resetPassword(HttpServletRequest httpServletRequest,ResetPasswordReq request) {
log.info("Resetting password for username: {}", request.getEmail()); log.info("Resetting password for username: {}", request.getEmail());
/** This code is responsible for "Resest user password" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(httpServletRequest).actionType(UserActionLogsEnum.UPDATE)
.actionContext(UserActionContextEnum.RESET_USER_PASSWORD).build());
Boolean success = userService.resetPassword(request); Boolean success = userService.resetPassword(request);
if (success) { if (success) {
log.info("Password reset successfully for username: {}", request.getEmail()); log.info("Password reset successfully for username: {}", request.getEmail());

View File

@@ -25,7 +25,8 @@ appointment.portal.context=GEPAFINPORTAL
flagDaFirmare=false flagDaFirmare=false
# RabbitMQ properties for STOMP broker relay for Notification # RabbitMQ properties for STOMP broker relay for Notification
spring.rabbitmq.host=rabbitmq.bflows.ai #spring.rabbitmq.host=rabbitmq.bflows.ai
spring.rabbitmq.host=172.18.0.7
spring.rabbitmq.port=61613 spring.rabbitmq.port=61613
spring.rabbitmq.username=guest spring.rabbitmq.username=guest
spring.rabbitmq.password=guest spring.rabbitmq.password=guest

View File

@@ -24,7 +24,7 @@ default.hub.uuid=p4lk3bcx1RStqTaIVVbXs
# TEST DEPLOY Configuration # TEST DEPLOY Configuration
#Login to Odessa, Appointment Creation, Upload document Configuration #Login to Odessa, Appointment Creation, Upload document Configuration
appointment.base.url=https://demo.galileonetwork.it/gateway/rest appointment.base.url=https://prd.galileonetwork.it/gateway/rest
appointment.portal.user=UtenzaAPIPortal@621 appointment.portal.user=UtenzaAPIPortal@621
appointment.portal.password=u13nzaAP1P0rtal appointment.portal.password=u13nzaAP1P0rtal
appointment.portal.source=GEPAFINPORTAL appointment.portal.source=GEPAFINPORTAL
@@ -32,7 +32,8 @@ appointment.portal.context=GEPAFINPORTAL
flagDaFirmare=true flagDaFirmare=true
# RabbitMQ properties for STOMP broker relay for Notification # RabbitMQ properties for STOMP broker relay for Notification
spring.rabbitmq.host=rabbitmq.bflows.ai #spring.rabbitmq.host=rabbitmq.bflows.ai
spring.rabbitmq.host=172.18.0.5
spring.rabbitmq.port=61613 spring.rabbitmq.port=61613
spring.rabbitmq.username=guest spring.rabbitmq.username=guest
spring.rabbitmq.password=guest spring.rabbitmq.password=guest

View File

@@ -1961,7 +1961,17 @@
</column> </column>
</addColumn> </addColumn>
</changeSet> </changeSet>
<changeSet id="02-12-2024_1" author="Rajesh Khore">
<sql dbms="postgresql">select
setval('gepafin_schema.system_email_template_id_seq', (select
max(id)+1
from gepafin_schema.system_email_template), false)
</sql>
<sqlFile dbms="postgresql"
path="db/dump/insert_system_email_template_for_user_28_11_2024.sql"/>
<sqlFile dbms="postgresql"
path="db/dump/insert_system_email_template_for_reset_password_28_11_2024.sql"/>
</changeSet>
<changeSet id="03-12-2024_1" author="Piyush"> <changeSet id="03-12-2024_1" author="Piyush">
<sqlFile dbms="postgresql" <sqlFile dbms="postgresql"
path="db/dump/update_system_email_template_for_updating_amendment_mail_notification_mail_03_12_2024_1.sql"/> path="db/dump/update_system_email_template_for_updating_amendment_mail_notification_mail_03_12_2024_1.sql"/>
@@ -1972,6 +1982,20 @@
path="db/dump/update_system_email_template_for_updating_amendment_mail_notification_mail_04_12_2024_1.sql"/> path="db/dump/update_system_email_template_for_updating_amendment_mail_notification_mail_04_12_2024_1.sql"/>
</changeSet> </changeSet>
<changeSet id="19-12-2024_4" author="Nisha Kashyap">
<addColumn tableName="USER_WITH_COMPANY">
<column name="contact_name" type="VARCHAR(255)"/>
<column name="contact_email" type="VARCHAR(255)"/>
<column name="PEC" type="VARCHAR(255)"/>
<column name="EMAIL" type="VARCHAR(255)"/>
<column name="JSON" type="TEXT"/>
</addColumn>
<dropColumn tableName="COMPANY" columnName="contact_name"/>
<dropColumn tableName="COMPANY" columnName="contact_email"/>
<dropColumn tableName="COMPANY" columnName="PEC"/>
<dropColumn tableName="COMPANY" columnName="EMAIL"/>
</changeSet>
<changeSet id="04-12-2024_3" author="Piyush"> <changeSet id="04-12-2024_3" author="Piyush">
<addColumn tableName="hub"> <addColumn tableName="hub">
<column name="auth_token" type="TEXT"/> <column name="auth_token" type="TEXT"/>
@@ -2030,7 +2054,7 @@
</addColumn> </addColumn>
</changeSet> </changeSet>
<changeSet id="19-12-2024_1" author="Nisha kashyap"> <changeSet id="19-12-2024_1" author="Nisha Kashyap">
<!-- Insert data for Intructor manager role --> <!-- Insert data for Intructor manager role -->
<insert tableName="role"> <insert tableName="role">
<column name="role_name" value="instructor manager"/> <column name="role_name" value="instructor manager"/>
@@ -2069,6 +2093,11 @@
<column name="closing_date" type="TIMESTAMP WITHOUT TIME ZONE"></column> <column name="closing_date" type="TIMESTAMP WITHOUT TIME ZONE"></column>
</addColumn> </addColumn>
</changeSet> </changeSet>
<changeSet id="03-01-2025_RK_191100" author="Rajesh Khore">
<addColumn tableName="application_evaluation">
<column name="ACTIVE_DAYS" type="INTEGER"></column>
</addColumn>
</changeSet>
<changeSet id="13-12-2024_1" author="Piyush Kag"> <changeSet id="13-12-2024_1" author="Piyush Kag">
<createTable tableName="notification"> <createTable tableName="notification">
@@ -2123,7 +2152,7 @@
</addColumn> </addColumn>
</changeSet> </changeSet>
<changeSet id="13-01-2025_NK_142215" author="Rajesh Khore"> <changeSet id="13-01-2025_RK_142215" author="Rajesh Khore">
<createTable tableName="role_action_context"> <createTable tableName="role_action_context">
<column autoIncrement="true" name="id" type="BIGINT"> <column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" <constraints nullable="false" primaryKey="true"
@@ -2143,10 +2172,55 @@
</createTable> </createTable>
</changeSet> </changeSet>
<changeSet id="13-01-2025_NK_164615" author="Rajesh Khore"> <changeSet id="13-01-2025_RK_164615" author="Rajesh Khore">
<sqlFile dbms="postgresql" <sqlFile dbms="postgresql"
path="db/dump/insert_action_context_data_09_01_2025.sql"/> path="db/dump/insert_action_context_data_09_01_2025.sql"/>
</changeSet> </changeSet>
<changeSet id="31-12-2024" author="Piyush Kag">
<sqlFile dbms="postgresql"
path="db/dump/update_json_template_for_notification_31_12_2024.sql"/>
</changeSet>
<changeSet id="03-01-2024_NK_125210" author="Nisha Kashyap">
<sql>
TRUNCATE TABLE FORM_FIELD RESTART IDENTITY;
</sql>
<sqlFile dbms="postgresql"
path="db/dump/update_form_field_data_03_01_2025.sql"/>
</changeSet>
<changeSet id="07-01-2025_NK_063910" author="Nisha Kashyap">
<createTable tableName="expiration_config">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="expiration_config_pkey"/>
</column>
<column name="INTERVAL_DAYS" type="INTEGER"></column>
<column name="TYPE" type="VARCHAR(255)"></column>
<column name="is_deleted" type="BOOLEAN" defaultValueBoolean="false">
<constraints nullable="false"/>
</column>
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE"></column>
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE"></column>
</createTable>
</changeSet>
<changeSet id="07-01-2025_NK_064515" author="Nisha kashyap">
<sqlFile dbms="postgresql"
path="db/dump/update_json_template_for_notification_03_01_2025.sql"/>
</changeSet>
<changeSet id="07-01-2025_NK_064516" author="Nisha kashyap">
<sqlFile dbms="postgresql"
path="db/dump/insert_expiration_scheduler_data_07_01_2025.sql"/>
</changeSet>
<changeSet id="08-01-2025_NK_075410" author="Nisha kashyap">
<addColumn tableName="application">
<column name="amount_requested" type="numeric"></column>
<column name="amount_accepted" type="numeric"></column>
<column name="date_accepted" type="TIMESTAMP WITHOUT TIME ZONE"></column>
<column name="date_rejected" type="TIMESTAMP WITHOUT TIME ZONE"></column>
</addColumn>
</changeSet>
</databaseChangeLog> </databaseChangeLog>

View File

@@ -0,0 +1,9 @@
INSERT INTO expiration_config (interval_days, type, created_date, updated_date)
VALUES
(5, 'AMENDMENT', '2024-12-03T11:00:51', '2024-12-03T11:00:51'),
(2, 'AMENDMENT', '2024-12-03T11:00:51', '2024-12-03T11:00:51'),
(0, 'AMENDMENT', '2024-12-03T11:00:51', '2024-12-03T11:00:51'),
(5, 'EVALUATION', '2024-12-03T11:00:51', '2024-12-03T11:00:51'),
(2, 'EVALUATION', '2024-12-03T11:00:51', '2024-12-03T11:00:51'),
(0, 'EVALUATION', '2024-12-03T11:00:51', '2024-12-03T11:00:51');

View File

@@ -0,0 +1,60 @@
INSERT INTO gepafin_schema.system_email_template
(template_name, "type", html_content, subject, "json", "system", is_deleted, created_date, updated_date,email_scenario)
VALUES
(
'Password Reset Link Email (Italian)',
'PASSWORD_RESET',
'<table border="0" style="background: #f5f5f5; text-align: center; width: 100%; max-width: 600px; padding: 20px;" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>
<table>
<thead>
<tr>
<th>
<p style="font-weight: 600; color: #000; font-family: open sans; font-size: 26px; margin: 0; padding-bottom: 20px;">Richiesta di Reimpostazione Password</p>
</th>
</tr>
</thead>
<tbody align="left">
<tr>
<td>
<p style="margin: 8px 0px;">Gentile {{user_name}},</p>
<p style="margin: 8px 0px;">Hai richiesto di reimpostare la tua password.</p>
</td>
</tr>
<tr>
<td>
<p style="margin: 8px 0px;">Cordiali saluti,</p>
<p style="margin: 8px 0px;"><strong>{{email_signature}}</strong></p>
</td>
</tr>
<tr>
<td style="padding-top: 20px;">
<!-- Button added here -->
<a href="{{reset_password_link}}" style="background-color: #007bff;
color: #fff;
font-family: open sans;
border-radius: 5px;
box-sizing: border-box;
cursor: pointer;
font-size: 14px;
font-weight: bold;
width: 100%;
max-width: 280px;
padding: 12px 25px;">Reimposta la Password</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>',
'Richiesta di Reimpostazione Password',
NULL,
true,
false,
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
'PASSWORD_RESET_REQUEST');

View File

@@ -0,0 +1,29 @@
INSERT INTO gepafin_schema.system_email_template
(template_name, "type", html_content, subject, "json", "system", is_deleted, created_date, updated_date, email_scenario)
VALUES
(
'Welcome Email for New User',
'USER_ONBOARDING',
'<html>
<body style="font-family: Arial, sans-serif; color: #000; line-height: 1.6;">
<div style="padding: 20px; border: 1px solid #ddd; border-radius: 8px; max-width: 600px; margin: auto;">
<p><strong>Benvenuto!</strong></p>
<p>Ciao {{user_name}},</p>
<p>Siamo lieti di averti con noi. Di seguito trovi alcune informazioni utili:</p>
<ul>
<li><strong>Nome Utente:</strong> {{user_email}}</li>
</ul>
<p>Per accedere, utilizza il tuo indirizzo email registrato. Se hai bisogno di supporto, non esitare a contattarci.</p>
<p>Distinti saluti,</p>
<p><strong>{{email_signature}}</strong></p>
</div>
</body>
</html>',
'Welcome - {{user_name}}',
NULL,
true,
false,
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
'USER_CREATION'
);

View File

@@ -0,0 +1,101 @@
INSERT INTO FORM_FIELD (SORT_ORDER, NAME, LABEL, DESCRIPTION, SETTINGS, VALIDATORS, CREATED_DATE, UPDATED_DATE)
VALUES
(1, 'textinput', 'Testo Breve', 'Per risposte concise (nomi, titoli, brevi descrizioni)',
'[{"name": "label", "value": "Testo Breve"}, {"name": "placeholder", "value": ""}]',
'{"isRequired": false, "minLength": null, "maxLength": null, "pattern": null, "custom": null}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(2, 'textarea', 'Testo Lungo', 'Campo di testo esteso per paragrafi, descrizioni, proposte',
'[{"name": "label", "value": "Testo Lungo"}, {"name": "placeholder", "value": ""}]',
'{"isRequired": false, "minLength": null, "maxLength": null, "pattern": null, "custom": null}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(3, 'wysiwyg', 'Campo di Testo Formattato', 'Editor avanzato per testo con formattazione',
'[{"name": "label", "value": "Testo Formattato"}, {"name": "placeholder", "value": ""}]',
'{"isRequired": false, "minLength": null, "maxLength": null, "pattern": null, "custom": null}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(4, 'numberinput', 'Campo Numerico', 'Per l''inserimento di valori numerici (quantità, importi, percentuali)',
'[{"name": "label", "value": "Numero"}, {"name": "placeholder", "value": "0"}, {"name": "step", "value": "0"},{"name": "isRequestedAmount","value": false}]',
'{"isRequired": false, "min": null, "max": null, "pattern": null, "custom": null}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(5, 'radio', 'Scelta Singola', 'Gruppo di opzioni per selezione singola',
'[{"name": "label", "value": "Scelta Singola"}, {"name": "options", "value": []}]',
'{"isRequired": false, "custom": null}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(6, 'select', 'Menu a Tendina', 'Selezione da opzioni predefinite',
'[{"name": "label", "value": "Menu a Tendina"}, {"name": "options", "value": []}]',
'{"isRequired": false, "custom": null}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(7, 'checkboxes', 'Scelta Multipla', 'Gruppo di opzioni per selezione singola o multipla',
'[{"name": "label", "value": "Scelta Multipla"}, {"name": "options", "value": []}]',
'{"isRequired": false, "min": null, "max": null, "custom": null}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(8, 'switch', 'Casella di Spunta', 'Per selezioni binarie, accettazioni, conferme',
'[{"name": "label", "value": "Casella di Spunta"}]',
'{"isRequired": false}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(9, 'datepicker', 'Data', 'Selezione di data',
'[{"name": "label", "value": "Data"}]',
'{"isRequired": false}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(10, 'fileupload', 'Caricamento File', 'Per l''upload di documenti o immagini',
'[{"name": "label", "value": "Caricamento File"}, {"name": "mime", "value": []}]',
'{"isRequired": false, "maxSize": 100000}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(11, 'textinput', 'Campo Partita IVA', 'Specifico per l''inserimento del numero di Partita IVA',
'[{"name": "label", "value": "Partita IVA"}, {"name": "placeholder", "value": ""}]',
'{"isRequired": true, "custom": "isPIVA"}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(12, 'textinput', 'Campo Codice Fiscale','Specifico per l''inserimento del Codice Fiscale italiano per persone fisiche e giuridiche',
'[{"name": "label", "value": "Codice Fiscale"}, {"name": "placeholder", "value": ""}]',
'{"isRequired": true, "custom": "isCodiceFiscale"}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(13, 'textinput', 'Campo CAP','Per l''inserimento del Codice di Avviamento Postale',
'[{"name": "label", "value": "CAP"}, {"name": "placeholder", "value": ""}]',
'{"isRequired": true, "custom": "isCAP"}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(14, 'textinput', 'Campo IBAN', 'Per l''inserimento del codice IBAN',
'[{"name": "label", "value": "IBAN"}, {"name": "placeholder", "value": ""}]',
'{"isRequired": true, "custom": "isIBAN"}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(15, 'textinput', 'Campo Email', 'Per l''inserimento di indirizzi email standard (non PEC)',
'[{"name": "label", "value": "Campo Email"}, {"name": "placeholder", "value": "nome@esempio.it"}]',
'{"isRequired": false, "custom": "isEmail"}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(16, 'textinput', 'Campo PEC', 'Specifico per l''inserimento di un indirizzo di Posta Elettronica Certificata',
'[{"name": "label", "value": "Campo PEC"}, {"name": "placeholder", "value": "nome@pec.it"}]',
'{"isRequired": false, "custom": "isEmailPEC"}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(17, 'textinput', 'Campo URL', 'Per l''inserimento di indirizzi web',
'[{"name": "label", "value": "Indirizzo URL"}, {"name": "placeholder", "value": ""}]',
'{"isRequired": false, "custom": "isUrl"}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(18, 'textinput', 'Marca da bollo', 'Per inserire codice di marca da bollo',
'[{"name": "label", "value": "Marca da bollo"}, {"name": "placeholder", "value": "Numero identificativo"}]',
'{"isRequired": false, "custom": "isMarcaDaBollo"}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(19, 'paragraph', 'Paragrafo', 'Semplice testo formattato',
'[{"name": "text", "value": ""}]',
'{}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(20, 'table', 'Tabella', 'Tabella',
'[{"name": "label", "value": "Tabella"}, {"name": "table_columns", "value": []}]',
'{}',
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

View File

@@ -0,0 +1,3 @@
INSERT INTO notification_type (notification_name,title, json_template,created_date,updated_date,is_deleted) VALUES
('AMENDMENT_EXPIRATION_REMINDER','Lemendamento sta per scadere','Lemendamento per {{call_name}} - {{company_name}} scadrà tra {{days_before}} giorni. Assicurati che tutte le azioni necessarie siano completate prima della scadenza.','2025-01-03T10:16:26.472Z','2025-01-03T10:16:26.472Z','false'),
('EVALUATION_EXPIRATION_REMINDER','La valutazione sta per scadere','Lemendamento per {{call_name}} - {{company_name}} scadrà tra {{days_before}} giorni. Assicurati che tutte le azioni necessarie siano completate prima della scadenza.','2025-01-03T10:16:26.472Z','2025-01-03T10:16:26.472Z','false');

View File

@@ -0,0 +1,62 @@
UPDATE notification_type
SET
title = 'Un Nuovo Bando È Stato Pubblicato',
json_template = 'Un nuovo bando intitolato {{call_name}} è stato pubblicato. Controllalo e invia le candidature prima della scadenza.'
WHERE
notification_name = 'CALL_CREATED';
UPDATE notification_type
SET
title = 'Richiesta Finanziamento Inviata con Successo per la Valutazione',
json_template = 'La richiesta per {{call_name}} ai sensi del protocollo n. {{protocol_number}} è stata presentata con successo. È ora in fase di valutazione.'
WHERE
notification_name = 'APPLICATION_SUBMISSION';
UPDATE notification_type
SET
title = 'È Stato Creato un Soccorso Istruttorio per la Richiesta',
json_template = 'È stato creato un soccorso istruttorio per la richiesta in {{call_name}} ai sensi del protocollo n. {{protocol_number}}. Esamina le richieste e procedi di conseguenza.'
WHERE
notification_name = 'AMENDMENT_CREATION';
UPDATE notification_type
SET
title = 'Il Risultato della Valutazione per la Richiesta È Disponibile',
json_template = 'Il risultato della valutazione per la richiesta ai sensi del protocollo n. {{protocol_number}} è ora disponibile.'
WHERE
notification_name = 'EVALUATION_RESULT';
UPDATE notification_type
SET
title = 'Soccorso Scaduto',
json_template = 'Il soccorso istruttorio per la richiesta in {{call_name}} ai sensi del protocollo n. {{protocol_number}} è scaduto.'
WHERE
notification_name = 'AMENDMENT_EXPIRED';
UPDATE notification_type
SET
title = 'Scorso Chiuso ed È Ora Inattivo',
json_template = 'Il soccorso istruttorio per {{call_name}} ai sensi del protocollo n. {{protocol_number}} è stato chiuso ed è ora inattivo.'
WHERE
notification_name = 'AMENDMENT_CLOSED';
UPDATE notification_type
SET
title = 'NDG creato per la Richiesta',
json_template = 'È stato generato un nuovo NDG per {{call_name}} ai sensi del protocollo n. {{protocol_number}}.'
WHERE
notification_name = 'NDG_GENERATION';
UPDATE notification_type
SET
title = 'La domanda è stata assegnata per la Valutazione',
json_template = 'La richiesta in {{call_name}} ai sensi del protocollo n. {{protocol_number}} è stata assegnata alla fase di valutazione.'
WHERE
notification_name = 'EVALUATION_CREATION';
UPDATE notification_type
SET
title = 'La Valutazione per la Richiesta È Scaduta',
json_template = 'La valutazione per la richiesta in {{call_name}} ai sensi del protocollo n. {{protocol_number}} è scaduta.'
WHERE
notification_name = 'EVALUATION_EXPIRED';

View File

@@ -313,6 +313,7 @@ company.id.required.for.preferred.call=Company ID is required when requesting on
response.days.not.null=Response days should not be null and greater than zero. response.days.not.null=Response days should not be null and greater than zero.
application.cannot.approved.or.rejected=Application cannot be approved and rejected because amendment is active. application.cannot.approved.or.rejected=Application cannot be approved and rejected because amendment is active.
valid.vatnumber.message=The VAT number is valid.
atleast.one.id.required=At least one of companyId or applicationId must be provided atleast.one.id.required=At least one of companyId or applicationId must be provided
@@ -347,3 +348,4 @@ notification.updated.successfully=Notification updated successfully.
user.with.company.not.found = User with company not found for user or company. user.with.company.not.found = User with company not found for user or company.
user.action.fetched.successfully = User action details fetched successfully. user.action.fetched.successfully = User action details fetched successfully.
amount.accepted.required=Amount accepted is required while approving the application.

View File

@@ -70,7 +70,7 @@ email.already.exists=Esiste gi? un utente con questa email.
invalid_user=Validazione utente fallita. Controlla le informazioni, lo stato dell'account e la scadenza del token. invalid_user=Validazione utente fallita. Controlla le informazioni, lo stato dell'account e la scadenza del token.
#Global messages #Global messages
common_message=qualcosa é andato storto. Per favore riprova common_message=qualcosa <EFBFBD> andato storto. Per favore riprova
invalid_signature=Gettone non valido. invalid_signature=Gettone non valido.
invalid_login=Nome utente o password errati invalid_login=Nome utente o password errati
req_validation_er=Errore di convalida req_validation_er=Errore di convalida
@@ -304,7 +304,10 @@ beneficiary.call.duplicate = Una chiamata preferita con questo ID di chiamata e
user.must.be.associated.with.company.to.create.application=Devi essere associato a un'azienda per poter presentare domanda per questa applicazione. user.must.be.associated.with.company.to.create.application=Devi essere associato a un'azienda per poter presentare domanda per questa applicazione.
company.id.required.for.preferred.call=ID azienda obbligatorio quando si richiedono solo chiamate preferite. company.id.required.for.preferred.call=ID azienda obbligatorio quando si richiedono solo chiamate preferite.
response.days.not.null=I giorni di risposta non devono essere nulli e maggiori di zero. response.days.not.null=I giorni di risposta non devono essere nulli e maggiori di zero.
application.cannot.approved.or.rejected=La domanda non pu<70> essere approvata o rifiutata perch<63> l'emendamento <20> attivo.
valid.vatnumber.message=Il numero di partita IVA <20> valido.
application.cannot.approved.or.rejected=La domanda non pu? essere approvata o rifiutata perch? l'emendamento ? attivo. application.cannot.approved.or.rejected=La domanda non pu? essere approvata o rifiutata perch? l'emendamento ? attivo.
atleast.one.id.required=Almeno uno tra companyId o applicationId deve essere fornito. atleast.one.id.required=Almeno uno tra companyId o applicationId deve essere fornito.
#Appointment flow messages #Appointment flow messages
@@ -328,7 +331,7 @@ document.uploading.is.in.progress = Il documento ? in fase di caricamento.
all.document.checked.and.one.checklist.checked=Tutti i documenti devono essere controllati e almeno una checklist deve essere controllata. all.document.checked.and.one.checklist.checked=Tutti i documenti devono essere controllati e almeno una checklist deve essere controllata.
#notification messsages #notification messsages
notification.already.in.state=La notifica è già nello stato fornito. notification.already.in.state=La notifica <EFBFBD> gi<EFBFBD> nello stato fornito.
notification.fetched.successfully=Notifica recuperata con successo. notification.fetched.successfully=Notifica recuperata con successo.
notification.not.found=Notifica non trovata. notification.not.found=Notifica non trovata.
notification.sent.successfully=Notifica inviata con successo. notification.sent.successfully=Notifica inviata con successo.
@@ -337,3 +340,4 @@ notification.updated.successfully=Notifica aggiornata con successo.
user.with.company.not.found = Utente con azienda non trovato per utente o azienda. user.with.company.not.found = Utente con azienda non trovato per utente o azienda.
user.action.fetched.successfully = Dettagli sull'azione dell'utente recuperati correttamente. user.action.fetched.successfully = Dettagli sull'azione dell'utente recuperati correttamente.
amount.accepted.required=L'importo accettato <20> obbligatorio durante l'approvazione della domanda.