Resolved conflicts
This commit is contained in:
@@ -110,6 +110,14 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
@Autowired
|
||||
private DocumentRepository documentRepository;
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
@Autowired
|
||||
private NotificationDao notificationDao;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
|
||||
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
|
||||
@@ -231,7 +239,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
log.info("Submiting application data for amendment Process with details: {}", applicationEvaluationId);
|
||||
|
||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = createApplicationAmendmentRequestEntity(applicationAmendmentRequest, applicationEvaluationId);
|
||||
ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = convertEntityToResponse(applicationAmendmentRequestEntity);
|
||||
ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = convertEntityToResponse(applicationAmendmentRequestEntity,false);
|
||||
log.info("Application submitted successfully for amendment", applicationAmendmentRequestResponse);
|
||||
if (Boolean.TRUE.equals(applicationAmendmentRequestResponse.getIsSendEmail())) {
|
||||
emailNotificationDao.sendMailToNotifyBeneficiaryRegardingNewAmendment(applicationAmendmentRequestEntity);
|
||||
@@ -298,7 +306,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity, null, VersionActionTypeEnum.INSERT);
|
||||
String evaluationStatusType = applicationEvaluationEntity.getStatus();
|
||||
if (Boolean.FALSE.equals(evaluationStatusType.equals((ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue())))){
|
||||
applicationEvaluationEntity.setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
|
||||
// applicationEvaluationEntity.setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
|
||||
|
||||
//Set Status
|
||||
applicationEvaluationEntity.setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
|
||||
@@ -326,6 +334,10 @@ public class ApplicationAmendmentRequestDao {
|
||||
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.SOCCORSO.getValue());
|
||||
assignedApplicationsRepository.save(assignedApplicationsEntity);
|
||||
|
||||
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(applicationEntity, NotificationTypeEnum.AMENDMENT_CREATION);
|
||||
|
||||
notificationDao.sendNotificationToInstructor(placeHolders,applicationAmendmentRequestEntity.getApplicationEvaluationEntity(),NotificationTypeEnum.AMENDMENT_CREATION);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update Assigned Application" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldAssignedApplication).newData(assignedApplicationsEntity).build());
|
||||
}
|
||||
@@ -362,8 +374,8 @@ public class ApplicationAmendmentRequestDao {
|
||||
return applicationAmendmentRequest;
|
||||
}
|
||||
|
||||
public ApplicationAmendmentRequestResponse convertEntityToResponse(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
|
||||
ApplicationAmendmentRequestResponse response = initializeBasicResponse(applicationAmendmentRequestEntity);
|
||||
public ApplicationAmendmentRequestResponse convertEntityToResponse(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity,boolean includeEmailContent) {
|
||||
ApplicationAmendmentRequestResponse response = initializeBasicResponse(applicationAmendmentRequestEntity,includeEmailContent);
|
||||
|
||||
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationAmendmentRequestEntity.getApplicationId());
|
||||
Map<String, String> fieldIdToLabelMap = extractFieldIdToLabelMap(forms);
|
||||
@@ -431,8 +443,12 @@ public class ApplicationAmendmentRequestDao {
|
||||
}
|
||||
|
||||
|
||||
private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity) {
|
||||
private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity,boolean includeEmailContent) {
|
||||
ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse();
|
||||
ApplicationEntity applicationEntity = entity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication();
|
||||
Long hubId = applicationEntity.getHubId();
|
||||
HubEntity hubEntity = hubService.valdateHub(hubId);
|
||||
|
||||
response.setId(entity.getId());
|
||||
response.setApplicationId(entity.getApplicationId());
|
||||
response.setApplicationEvaluationId(entity.getApplicationEvaluationEntity().getId());
|
||||
@@ -454,10 +470,17 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
UserEntity userEntity = userService.validateUser(application.getUserId());
|
||||
response.setBeneficiaryName(buildBeneficiaryName(userEntity));
|
||||
|
||||
CompanyEntity company = companyService.validateCompany(application.getCompanyId());
|
||||
response.setCompanyName(company.getCompanyName());
|
||||
Long protocolNumber = entity.getProtocol() != null ? entity.getProtocol().getProtocolNumber() : null;
|
||||
response.setProtocolNumber(protocolNumber);
|
||||
|
||||
if (includeEmailContent) {
|
||||
Map<String, String> bodyPlaceholders = emailNotificationDao.prepareEmailPlaceholders(applicationEntity, entity);
|
||||
EmailContentResponse emailContent = emailNotificationDao.prepareEmailContent(applicationEntity, SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, hubEntity, bodyPlaceholders);
|
||||
String body = emailContent.getBody();
|
||||
response.setEmailTemplate(body);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -564,7 +587,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
public ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(Long id) {
|
||||
log.info("Fetching application amendment with ID: {}", id);
|
||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validateApplicationAmendmentRequest(id);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(applicationAmendmentRequestEntity);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(applicationAmendmentRequestEntity,true);
|
||||
log.info("Application Amendment fetched successfully by ID: {}", response);
|
||||
return response;
|
||||
}
|
||||
@@ -581,7 +604,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
applicationAmendmentRequestRepository.findAll(spec);
|
||||
|
||||
return applicationAmendmentRequestEntities.stream()
|
||||
.map(this::convertEntityToResponse)
|
||||
.map(entity -> convertEntityToResponse(entity, false))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -641,7 +664,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
setAmendmentDocuments(updateRequest.getAmendmentNotes(),updateRequest.getAmendmentDocuments(), existingApplicationAmendment);
|
||||
}
|
||||
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment,oldApplicationAmendmentEntity,VersionActionTypeEnum.UPDATE);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment,false);
|
||||
log.info("Application Amendment updated successfully: {}", response);
|
||||
return response;
|
||||
}
|
||||
@@ -942,7 +965,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
applicationAmendmentRequestRepository.findByUserId(beneficiaryUserId);
|
||||
|
||||
return entities.stream()
|
||||
.map(this::convertEntityToResponse)
|
||||
.map(entity -> convertEntityToResponse(entity, false))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -952,8 +975,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
||||
//cloned entity for old data and versioning
|
||||
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
|
||||
|
||||
List<ApplicationAmendmentRequestEntity> amendmentRequestList = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
|
||||
List<ApplicationAmendmentRequestEntity> amendmentRequestList = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
|
||||
existingApplicationAmendment.getApplicationEvaluationEntity().getId()
|
||||
);
|
||||
|
||||
@@ -971,7 +993,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment, oldApplicationAmendmentEntity,
|
||||
VersionActionTypeEnum.UPDATE);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment,false);
|
||||
|
||||
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
|
||||
existingApplicationAmendment.getApplicationEvaluationEntity().getId());
|
||||
@@ -998,6 +1020,11 @@ public class ApplicationAmendmentRequestDao {
|
||||
AssignedApplicationsEntity oldAssignedApplicationData = Utils.getClonedEntityForData(assignedApplicationsEntity);
|
||||
assignedApplicationsEntity = assignedApplicationsRepository.save(existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity());
|
||||
|
||||
|
||||
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.AMENDMENT_CLOSED);
|
||||
|
||||
notificationDao.sendNotificationToInstructor(placeHolders,existingApplicationAmendment.getApplicationEvaluationEntity(),NotificationTypeEnum.AMENDMENT_CLOSED);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update Application Evaluation" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity)
|
||||
.newData(existingApplicationEvaluationEntity).build());
|
||||
@@ -1017,6 +1044,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public ApplicationAmendmentRequestResponse extendResponseDays(Long id, Long newResponseDays) {
|
||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validateApplicationAmendmentRequest(id);
|
||||
|
||||
@@ -1030,7 +1058,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationAmendmentEntity).newData(applicationAmendmentRequestEntity).build());
|
||||
}
|
||||
return convertEntityToResponse(applicationAmendmentRequestEntity);
|
||||
return convertEntityToResponse(applicationAmendmentRequestEntity,false);
|
||||
}
|
||||
|
||||
public List<ApplicationAmendmentRequestResponse> getAmendmentByApplicationId(HttpServletRequest request, Long applicationId, List<ApplicationAmendmentRequestEnum> statuses) {
|
||||
@@ -1055,7 +1083,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
List<ApplicationAmendmentRequestResponse> response = new ArrayList<>();
|
||||
if (applicationAmendmentRequestEntity != null) {
|
||||
response = applicationAmendmentRequestEntity.stream()
|
||||
.map(this::convertEntityToResponse)
|
||||
.map(entity -> convertEntityToResponse(entity, false))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return response;
|
||||
@@ -1075,7 +1103,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
/** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationAmendmentEntity).newData(existingApplicationAmendment).build());
|
||||
}
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(existingApplicationAmendment);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(existingApplicationAmendment,false);
|
||||
log.info("Amendment status updated successfully: {}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBea
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
@@ -163,6 +164,21 @@ public class ApplicationDao {
|
||||
@Autowired
|
||||
private ApplicationEvaluationService applicationEvaluationService;
|
||||
|
||||
@Autowired
|
||||
private NotificationDao notificationDao;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private RoleRepository roleRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||
|
||||
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
// callService.validatePublishedCall(formEntity.getCall().getId());
|
||||
@@ -280,7 +296,12 @@ public class ApplicationDao {
|
||||
log.info("Deleting application with ID: {}", id);
|
||||
|
||||
ApplicationEntity applicationEntity= validateApplication(id);
|
||||
|
||||
if (Boolean.FALSE.equals(ApplicationStatusTypeEnum.DRAFT.getValue().equals(applicationEntity.getStatus()))) {
|
||||
throw new CustomValidationException(
|
||||
Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS)
|
||||
);
|
||||
}
|
||||
ApplicationEntity oldApplicationDataEntity = Utils.getClonedEntityForData(applicationEntity);
|
||||
|
||||
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||
@@ -388,6 +409,16 @@ public class ApplicationDao {
|
||||
responseBean.setStatus(applicationEntity.getStatus());
|
||||
responseBean.setComments(applicationEntity.getComments());
|
||||
responseBean.setCompanyId(applicationEntity.getCompanyId());
|
||||
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||
assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationEntity.getId());
|
||||
if(assignedApplicationsOptional.isPresent()){
|
||||
responseBean.setAssignedUserId(assignedApplicationsOptional.get().getUserId());
|
||||
UserEntity user = userService.validateUser(assignedApplicationsOptional.get().getUserId());
|
||||
String firstName = user.getFirstName() != null ? user.getFirstName() : "";
|
||||
String lastName = user.getLastName() != null ? user.getLastName() : "";
|
||||
String userName = String.join(" ", firstName, lastName).trim();
|
||||
responseBean.setAssignedUserName(userName);
|
||||
}
|
||||
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
|
||||
responseBean.setCompanyName(company.getCompanyName());
|
||||
if(applicationEntity.getProtocol() != null) {
|
||||
@@ -857,6 +888,8 @@ public class ApplicationDao {
|
||||
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
|
||||
applicationEntity.setSubmissionDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
applicationEntity = applicationRepository.save(applicationEntity);
|
||||
Map<String ,String> placeHolders=notificationDao.sendNotificationToBeneficiary(applicationEntity,NotificationTypeEnum.APPLICATION_SUBMISSION);
|
||||
notificationDao.sendNotificationToSuperUser(applicationEntity,placeHolders,NotificationTypeEnum.APPLICATION_SUBMISSION);
|
||||
|
||||
/** This code is responsible for adding a version history log for "Update application status" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
@@ -969,7 +1002,8 @@ public class ApplicationDao {
|
||||
private void sendMailToUserAndCompany(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
||||
CallEntity call =applicationEntity.getCall();
|
||||
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());
|
||||
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService
|
||||
.retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_TO_USER_AND_COMPANY,
|
||||
@@ -1000,8 +1034,8 @@ public class ApplicationDao {
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest);
|
||||
List<String> recipientEmails = new ArrayList<>();
|
||||
// recipientEmails.add(email);
|
||||
String companyEmail = company.getEmail();
|
||||
String contactEmail = company.getContactEmail();
|
||||
String companyEmail = userWithCompany.getEmail();
|
||||
String contactEmail = userWithCompany.getContactEmail();
|
||||
|
||||
if (companyEmail != null && !companyEmail.isEmpty()) {
|
||||
recipientEmails.add(companyEmail);
|
||||
@@ -1219,90 +1253,121 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public byte[] downloadApplicationDocumentsAsZip(HttpServletRequest request, Long applicationId) {
|
||||
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
validateAssignedUser(request, applicationId);
|
||||
|
||||
Set<Long> documentIds = extractDocumentIdsFromApplicationForms(applicationId);
|
||||
List<DocumentEntity> documents = documentRepository.findAllByIdInAndIsDeletedFalse(documentIds);
|
||||
|
||||
ApplicationSignedDocumentEntity signedDocument = applicationSignedDocumentRepository
|
||||
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||
if (documents.isEmpty() && signedDocument == null) {
|
||||
ApplicationSignedDocumentEntity signedDocument = applicationSignedDocumentRepository.findByApplicationIdAndStatus(applicationId,
|
||||
ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||
List<DocumentEntity> amendmentDocuments = fetchAmendmentDocuments(applicationId);
|
||||
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));
|
||||
}
|
||||
return createZipWithDocuments(applicationEntity, documents, signedDocument, applicationId);
|
||||
return createZipWithDocuments(applicationEntity, documents, signedDocument, amendmentDocuments, evaluationDocuments, 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) {
|
||||
validator.validatePreInstructor(request, assignedApplications.getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Long> extractDocumentIdsFromApplicationForms(Long applicationId) {
|
||||
|
||||
Set<Long> documentIds = new HashSet<>();
|
||||
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
|
||||
|
||||
applicationForms.forEach(applicationForm -> {
|
||||
FormEntity formEntity = applicationForm.getForm();
|
||||
if (formEntity != null) {
|
||||
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
|
||||
contentResponseBeans.stream()
|
||||
.filter(content -> "fileupload".equals(content.getName()))
|
||||
.forEach(content -> {
|
||||
Optional<ApplicationFormFieldEntity> formField = applicationFormFieldRepository
|
||||
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
||||
content.getId(), applicationForm.getId(), applicationId);
|
||||
formField.ifPresent(field -> {
|
||||
if (field.getFieldValue() != null) {
|
||||
Arrays.stream(field.getFieldValue().split(","))
|
||||
.map(String::trim)
|
||||
.map(Long::valueOf)
|
||||
.forEach(documentIds::add);
|
||||
}
|
||||
});
|
||||
});
|
||||
contentResponseBeans.stream().filter(content -> "fileupload".equals(content.getName())).forEach(content -> {
|
||||
Optional<ApplicationFormFieldEntity> formField = applicationFormFieldRepository.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
||||
content.getId(), applicationForm.getId(), applicationId);
|
||||
formField.ifPresent(field -> {
|
||||
if (field.getFieldValue() != null) {
|
||||
Arrays.stream(field.getFieldValue().split(",")).map(String::trim).map(Long::valueOf).forEach(documentIds::add);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
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)) {
|
||||
zos.putNextEntry(new ZipEntry(fileName));
|
||||
zos.putNextEntry(new ZipEntry(fullPath));
|
||||
IOUtils.copy(fileInputStream, zos);
|
||||
zos.closeEntry();
|
||||
} 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,
|
||||
ApplicationSignedDocumentEntity signedDocument, Long applicationId) {
|
||||
try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
||||
|
||||
String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, applicationEntity.getCall().getId(), applicationId,0L);
|
||||
|
||||
try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
||||
Long callId = applicationEntity.getCall().getId();
|
||||
// Add Application Documents
|
||||
String appS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, callId, applicationId, 0L);
|
||||
for (DocumentEntity document : documents) {
|
||||
String fileName = Utils.extractFileName(document.getFilePath());
|
||||
addDocumentToZip(zos, s3Folder, document.getFilePath(), fileName);
|
||||
addDocumentToZip(zos, appS3Folder, document.getFilePath(), fileName);
|
||||
}
|
||||
|
||||
// Add Signed Document
|
||||
if (signedDocument != null) {
|
||||
String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, applicationEntity.getCall().getId(), applicationId,0L);
|
||||
String signedDocFileName = signedDocument.getFileName();
|
||||
addDocumentToZip(zos, signedDocS3Folder, signedDocument.getFilePath(), signedDocFileName);
|
||||
String signedFolder = "SIGNED_DOCUMENT/";
|
||||
String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId, 0L);
|
||||
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();
|
||||
return zipOutputStream.toByteArray();
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Error while creating ZIP file", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -94,6 +96,12 @@ public class ApplicationEvaluationDao {
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
@Autowired
|
||||
private NotificationDao notificationDao;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
@@ -558,7 +566,16 @@ public class ApplicationEvaluationDao {
|
||||
response.setAssignedAt(assignedApplications.getAssignedAt());
|
||||
}
|
||||
response.setEvaluationEndDate(entity.getEndDate());
|
||||
|
||||
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||
assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(application.getId());
|
||||
if(assignedApplicationsOptional.isPresent()){
|
||||
response.setAssignedUserId(assignedApplicationsOptional.get().getUserId());
|
||||
UserEntity assignedUser = userService.validateUser(assignedApplicationsOptional.get().getUserId());
|
||||
String assignedUserFirstName = assignedUser.getFirstName() != null ? assignedUser.getFirstName() : "";
|
||||
String assignedUserLastName = assignedUser.getLastName() != null ? assignedUser.getLastName() : "";
|
||||
String userName = String.join(" ", assignedUserFirstName, assignedUserLastName).trim();
|
||||
response.setAssignedUserName(userName);
|
||||
}
|
||||
LocalDateTime callEndDate = application.getCall().getEndDate();
|
||||
response.setCallEndDate(callEndDate);
|
||||
if (application.getCompanyId() != null) {
|
||||
@@ -599,8 +616,15 @@ public class ApplicationEvaluationDao {
|
||||
application.setAmountAccepted(req.getAmountAccepted());
|
||||
actionType = VersionActionTypeEnum.UPDATE;
|
||||
} else {
|
||||
AssignedApplicationsEntity assignedApplicationsEntity = assignedApplicationsService.validateAssignedApplication(assignedApplicationId);
|
||||
ApplicationEntity application = applicationService.validateApplication(assignedApplicationsEntity.getApplication().getId());
|
||||
entity = convertToEntity(user, req, assignedApplicationId);
|
||||
actionType = VersionActionTypeEnum.INSERT;
|
||||
|
||||
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_CREATION);
|
||||
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_CREATION);
|
||||
notificationDao.sendNotificationToInstructor(placeHolders,entity,NotificationTypeEnum.EVALUATION_CREATION);
|
||||
|
||||
}
|
||||
ApplicationStatusForEvaluation status = req.getApplicationStatus();
|
||||
// Fetch all amendment request entities associated with the evaluation ID
|
||||
@@ -1776,8 +1800,14 @@ public class ApplicationEvaluationDao {
|
||||
String statusType = application.getStatus();
|
||||
if (application.getStatus().equals(ApplicationStatusTypeEnum.APPROVED.getValue()) || application.getStatus().equals(ApplicationStatusTypeEnum.REJECTED.getValue())) {
|
||||
existingEntity.setStatus(ApplicationEvaluationStatusTypeEnum.CLOSE.getValue());
|
||||
existingEntity.setClosingDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.CLOSE.getValue());
|
||||
}
|
||||
if (existingEntity.getStartDate() != null && existingEntity.getClosingDate() != null) {
|
||||
long activeDays = ChronoUnit.DAYS.between(existingEntity.getStartDate(), existingEntity.getClosingDate());
|
||||
activeDays -= existingEntity.getSuspendedDays() != null ? existingEntity.getSuspendedDays() : 0;
|
||||
existingEntity.setActiveDays(activeDays);
|
||||
}
|
||||
entity = applicationEvaluationRepository.save(existingEntity);
|
||||
assignedApplicationsRepository.save(assignedApplicationsEntity);
|
||||
|
||||
@@ -1804,12 +1834,16 @@ public class ApplicationEvaluationDao {
|
||||
emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity);
|
||||
}
|
||||
|
||||
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_RESULT);
|
||||
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_RESULT);
|
||||
notificationDao.sendNotificationToInstructor(placeHolders,existingEntity,NotificationTypeEnum.EVALUATION_RESULT);
|
||||
|
||||
return convertToResponse(entity);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ApplicationEvaluationEntity validateApplicationEvaluationByApplicationId(Long applicationId) {
|
||||
public ApplicationEvaluationEntity validateApplicationEvaluationByApplicationId(Long applicationId) {
|
||||
return applicationEvaluationRepository
|
||||
.findByApplicationIdAndIsDeletedFalse(applicationId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
|
||||
@@ -16,14 +16,18 @@ import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||
import net.gepafin.tendermanagement.entities.HubEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.AppointmentCreationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.AppointmentNdgRequest;
|
||||
import net.gepafin.tendermanagement.model.request.AppointmentVisuraListRequest;
|
||||
import net.gepafin.tendermanagement.model.request.AppointmentVisuraRequest;
|
||||
import net.gepafin.tendermanagement.model.request.CreateAppointmentRequest;
|
||||
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||
import net.gepafin.tendermanagement.model.request.UploadDocToExternalSystemRequest;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.model.response.AppointmentCreationResponse;
|
||||
@@ -34,6 +38,7 @@ import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.CompanyRepository;
|
||||
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
||||
import net.gepafin.tendermanagement.repositories.HubRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||
import net.gepafin.tendermanagement.service.CompanyService;
|
||||
import net.gepafin.tendermanagement.service.feignClient.AppointmentApiService;
|
||||
@@ -58,6 +63,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -130,6 +136,12 @@ public class AppointmentDao {
|
||||
@Autowired
|
||||
private TokenProvider tokenProvider;
|
||||
|
||||
@Autowired
|
||||
private NotificationDao notificationDao;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
private final Map<Long, ExecutorService> executorMap = new ConcurrentHashMap<>();
|
||||
|
||||
private final ConcurrentHashMap<Long, ExecutorService> threadForDocumentMap = new ConcurrentHashMap<>();
|
||||
@@ -312,6 +324,8 @@ public class AppointmentDao {
|
||||
company.setNdg(ndg);
|
||||
companyRepository.save(company);
|
||||
applicationRepository.save(application);
|
||||
Map<String ,String> placeHolders=notificationDao.sendNotificationToBeneficiary(application,NotificationTypeEnum.NDG_GENERATION);
|
||||
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.NDG_GENERATION);
|
||||
|
||||
// /** This code is responsible for adding a version history log for the "update application ndg code, status, and Id visura" operation. **/
|
||||
// loggingUtil.addVersionHistory(
|
||||
|
||||
@@ -15,7 +15,9 @@ import java.util.zip.ZipOutputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
@@ -49,6 +51,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
|
||||
import static net.gepafin.tendermanagement.enums.RoleStatusEnum.ROLE_SUPER_ADMIN;
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
import static org.hibernate.internal.util.collections.CollectionHelper.listOf;
|
||||
|
||||
@Component
|
||||
public class CallDao {
|
||||
@@ -108,6 +111,15 @@ public class CallDao {
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
private NotificationDao notificationDao;
|
||||
|
||||
@Autowired
|
||||
private BeneficiaryRepository beneficiaryRepository;
|
||||
|
||||
@Autowired
|
||||
private NotificationTypeRepository notificationTypeRepository;
|
||||
|
||||
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) {
|
||||
createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId());
|
||||
CallEntity callEntity = convertToCallEntity(createCallRequest, userEntity);
|
||||
@@ -828,10 +840,20 @@ public class CallDao {
|
||||
validateStatusChange(currentStatus, statusReq);
|
||||
callEntity.setStatus(statusReq.getValue());
|
||||
callEntity = callRepository.save(callEntity);
|
||||
|
||||
|
||||
//Creating notification.
|
||||
List<Long> userIds = beneficiaryRepository.findUserIdsByHubIdAndBeneficiaryId(callEntity.getHub().getId());
|
||||
Map<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("{{call_name}}", callEntity.getName());
|
||||
userIds.forEach(userId -> {
|
||||
List<Long> companyIds = notificationDao.getAllCompanyIdsForUser(userId);
|
||||
NotificationReq notificationReq = notificationDao.createNotificationReq(NotificationTypeEnum.CALL_CREATED.getValue(), placeholders, userId, null, companyIds);
|
||||
notificationDao.sendNotification(notificationReq);
|
||||
});
|
||||
|
||||
/** This code is responsible for adding a version history log for the "update call status" operation **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCallEntity).newData(callEntity).build());
|
||||
|
||||
|
||||
return convertToCallResponseBean(callEntity);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
@@ -66,7 +67,7 @@ public class CompanyDao {
|
||||
if (existingCompany != null) {
|
||||
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()).orElse(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. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
@@ -83,7 +84,7 @@ public class CompanyDao {
|
||||
/** 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());
|
||||
|
||||
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
|
||||
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant(),companyRequest);
|
||||
|
||||
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();
|
||||
if (userEntity.getBeneficiary() != null) {
|
||||
@@ -117,6 +118,11 @@ public class CompanyDao {
|
||||
userWithCompanyEntity.setCompanyId(companyEntity.getId());
|
||||
userWithCompanyEntity.setUserId(userEntity.getId());
|
||||
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);
|
||||
|
||||
/** 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.setCap(request.getCap());
|
||||
entity.setCountry(request.getCountry());
|
||||
entity.setPec(request.getPec());
|
||||
entity.setEmail(request.getEmail());
|
||||
entity.setNumberOfEmployees(request.getNumberOfEmployees());
|
||||
entity.setAnnualRevenue(request.getAnnualRevenue());
|
||||
entity.setContactName(request.getContactName());
|
||||
entity.setContactEmail(request.getContactEmail());
|
||||
entity.setHub(userEntity.getHub());
|
||||
return entity;
|
||||
}
|
||||
@@ -157,8 +159,8 @@ public class CompanyDao {
|
||||
response.setProvince(entity.getProvince());
|
||||
response.setCap(entity.getCap());
|
||||
response.setCountry(entity.getCountry());
|
||||
response.setPec(entity.getPec());
|
||||
response.setEmail(entity.getEmail());
|
||||
response.setPec(userWithCompanyEntity.getPec());
|
||||
response.setEmail(userWithCompanyEntity.getEmail());
|
||||
response.setNumberOfEmployees(entity.getNumberOfEmployees());
|
||||
response.setAnnualRevenue(entity.getAnnualRevenue());
|
||||
if(userWithCompanyEntity!=null) {
|
||||
@@ -166,8 +168,8 @@ public class CompanyDao {
|
||||
}
|
||||
response.setCreatedDate(entity.getCreatedDate());
|
||||
response.setUpdatedDate(entity.getUpdatedDate());
|
||||
response.setContactName(entity.getContactName());
|
||||
response.setContactEmail(entity.getContactEmail());
|
||||
response.setContactName(userWithCompanyEntity.getContactName());
|
||||
response.setContactEmail(userWithCompanyEntity.getContactEmail());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -178,7 +180,6 @@ public class CompanyDao {
|
||||
CompanyEntity oldCompanyData = Utils.getClonedEntityForData(companyEntity);
|
||||
|
||||
setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName, companyRequest.getCompanyName());
|
||||
setIfUpdated(companyEntity::getVatNumber, companyEntity::setVatNumber, companyRequest.getVatNumber());
|
||||
setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale, companyRequest.getCodiceFiscale());
|
||||
setIfUpdated(companyEntity::getAddress, companyEntity::setAddress, companyRequest.getAddress());
|
||||
setIfUpdated(companyEntity::getPhoneNumber, companyEntity::setPhoneNumber, companyRequest.getPhoneNumber());
|
||||
@@ -186,12 +187,17 @@ public class CompanyDao {
|
||||
setIfUpdated(companyEntity::getProvince, companyEntity::setProvince, companyRequest.getProvince());
|
||||
setIfUpdated(companyEntity::getCap, companyEntity::setCap, companyRequest.getCap());
|
||||
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::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);
|
||||
|
||||
/** 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);
|
||||
//cloned entity for old data
|
||||
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity);
|
||||
|
||||
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant, companyRequest.getIsLegalRepresentant());
|
||||
if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
|
||||
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);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update company" operation. **/
|
||||
@@ -254,7 +267,7 @@ public class CompanyDao {
|
||||
return userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userId, companyId).orElseThrow(() -> new ForbiddenAccessException(Status.FORBIDDEN,
|
||||
Translator.toLocale(GepafinConstant.PERMISSION_DENIED)));
|
||||
}
|
||||
|
||||
|
||||
public UserWithCompanyEntity getUserWithCompany(Long userId, Long compnayId) {
|
||||
return userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userId, compnayId).orElseThrow(
|
||||
() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_COMPANY_RELATION_NOT_FOUND)));
|
||||
@@ -277,39 +290,59 @@ public class CompanyDao {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.CANNOT_DELETE_COMPANY_WITH_APPLICATION_SUBMITT));
|
||||
}
|
||||
|
||||
for(ApplicationEntity application:userApplications){
|
||||
ApplicationEntity oldApplication = Utils.getClonedEntityForData(application);
|
||||
application.setIsDeleted(Boolean.TRUE);
|
||||
userApplications = userApplications.stream()
|
||||
.peek(application -> {
|
||||
ApplicationEntity oldApplication = Utils.getClonedEntityForData(application);
|
||||
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());
|
||||
|
||||
}
|
||||
/** 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(oldApplication)
|
||||
.newData(application)
|
||||
.build()
|
||||
);
|
||||
})
|
||||
.toList();
|
||||
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. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldFaq).newData(faq).build());
|
||||
}
|
||||
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);
|
||||
|
||||
for(BeneficiaryPreferredCallEntity beneficiaryPreferredCall:preferredCallEntities){
|
||||
BeneficiaryPreferredCallEntity oldPreferredCall = Utils.getClonedEntityForData(beneficiaryPreferredCall);
|
||||
beneficiaryPreferredCall.setIsDeleted(Boolean.TRUE);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Soft Delete BeneficiaryPreferredCall" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldPreferredCall).newData(beneficiaryPreferredCall).build());
|
||||
|
||||
}
|
||||
preferredCallEntities = preferredCallEntities.stream()
|
||||
.peek(beneficiaryPreferredCall -> {
|
||||
BeneficiaryPreferredCallEntity oldPreferredCall = Utils.getClonedEntityForData(beneficiaryPreferredCall);
|
||||
beneficiaryPreferredCall.setIsDeleted(Boolean.TRUE);
|
||||
/** This code is responsible for adding a version history log for the "Soft Delete BeneficiaryPreferredCall" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder()
|
||||
.request(request)
|
||||
.actionType(VersionActionTypeEnum.SOFT_DELETE)
|
||||
.oldData(oldPreferredCall)
|
||||
.newData(beneficiaryPreferredCall)
|
||||
.build()
|
||||
);
|
||||
})
|
||||
.toList();
|
||||
beneficiaryPreferredCallRepository.saveAll(preferredCallEntities);
|
||||
|
||||
if(userCompanyDelegationEntity!=null){
|
||||
if(userCompanyDelegationEntity!=null){
|
||||
UserCompanyDelegationEntity oldUserWithCompanyDelegation = Utils.getClonedEntityForData(userCompanyDelegationEntity);
|
||||
userCompanyDelegationEntity.setStatus( UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||
|
||||
@@ -4,9 +4,11 @@ import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserActionEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.Widget1;
|
||||
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
|
||||
@@ -22,6 +24,12 @@ import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class DashboardDao {
|
||||
@@ -37,9 +45,15 @@ public class DashboardDao {
|
||||
|
||||
@Autowired
|
||||
private CompanyRepository companyRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
@Autowired
|
||||
private BeneficiaryPreferredCallRepository beneficiaryPreferredCallRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||
|
||||
@Autowired
|
||||
private UserActionsRepository userActionsRepository;
|
||||
@@ -129,14 +143,26 @@ public class DashboardDao {
|
||||
}
|
||||
|
||||
public BeneficiaryWidgetResponseBean getDashboardWidgetForBeneficiary(UserEntity userEntity,
|
||||
CompanyEntity company) {
|
||||
CompanyEntity company) {
|
||||
BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder()
|
||||
.numberOfApplications(0L).numberOfCalls(0L).numberOfIntegratedDocuments(0L).build();
|
||||
Long activeCalls = callRepository.countByStatusAndHubId(CallStatusEnum.PUBLISH.getValue(), userEntity.getHub().getId());
|
||||
if (activeCalls != null) {
|
||||
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls);
|
||||
UserWithCompanyEntity userWithCompanyEntity = companyService.getUserWithCompany(userEntity.getId(), company.getId());
|
||||
|
||||
List<BeneficiaryPreferredCallEntity> preferredCalls = beneficiaryPreferredCallRepository
|
||||
.findByUserIdAndUserWithCompanyIdAndIsDeletedFalse(userEntity.getId(), userWithCompanyEntity.getId());
|
||||
|
||||
if (preferredCalls != null && !preferredCalls.isEmpty()) {
|
||||
List<Long> callIds = preferredCalls.stream()
|
||||
.map(BeneficiaryPreferredCallEntity::getCallId)
|
||||
.collect(Collectors.toList());
|
||||
List<CallEntity> callEntities = callRepository.findByIdIn(callIds);
|
||||
long activeCallsCount = callEntities.stream()
|
||||
.filter(call -> CallStatusEnum.PUBLISH.getValue().equals(call.getStatus())
|
||||
&& userEntity.getHub().getId().equals(call.getHub().getId()))
|
||||
.count();
|
||||
|
||||
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCallsCount);
|
||||
}
|
||||
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),company.getId());
|
||||
Long activeApplication = applicationRepository.countSubmittedApplicationsByUserId(userEntity.getId(),
|
||||
userWithCompanyEntity.getId());
|
||||
if (activeApplication != null) {
|
||||
@@ -174,4 +200,69 @@ public class DashboardDao {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.gepafin.tendermanagement.enums.RecipientTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.model.response.AmendmentFormFieldResponse;
|
||||
import net.gepafin.tendermanagement.model.response.EmailContentResponse;
|
||||
import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.*;
|
||||
@@ -61,9 +62,6 @@ public class EmailNotificationDao {
|
||||
@Autowired
|
||||
private ApplicationFormRepository applicationFormRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationFormFieldRepository applicationFormFieldRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||
|
||||
@@ -77,7 +75,19 @@ public class EmailNotificationDao {
|
||||
// String service = determineService(applicationEntity.getHubId());
|
||||
// String legalMail = service.equals("Gepafin S.p.a.") ? "bandi.gepafin@legalmail.it" : "bandi.sviluppumbria@legalmail.it";
|
||||
|
||||
EmailContentResponse emailContent = prepareEmailContent(applicationEntity, templateType, hubEntity, bodyPlaceholders);
|
||||
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
||||
sendEmails(applicationEntity, userEntity, additionalRecipients,amendmentId,emailContent.getSystemEmailTemplateResponse(),emailContent.getSubject(),emailContent.getBody());
|
||||
}
|
||||
|
||||
public EmailContentResponse prepareEmailContent(
|
||||
ApplicationEntity applicationEntity,
|
||||
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType,
|
||||
HubEntity hubEntity,
|
||||
Map<String, String> bodyPlaceholders
|
||||
) {
|
||||
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(templateType, hubEntity, null);
|
||||
|
||||
Map<String, String> subjectPlaceholders = new HashMap<>();
|
||||
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
|
||||
subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
||||
@@ -85,15 +95,18 @@ public class EmailNotificationDao {
|
||||
// bodyPlaceholders.put("{{legal_mail}}", legalMail);
|
||||
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
||||
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
||||
sendEmails(applicationEntity, userEntity, additionalRecipients,amendmentId,systemEmailTemplateResponse,subject,body);
|
||||
|
||||
return new EmailContentResponse(subject, body, systemEmailTemplateResponse);
|
||||
}
|
||||
|
||||
private void sendEmails(ApplicationEntity applicationEntity, UserEntity userEntity, List<String> additionalRecipients,Long amendmentId,SystemEmailTemplateResponse systemEmailTemplateResponse,String subject,String body) {
|
||||
|
||||
Optional<ApplicationEvaluationEntity> applicationEvaluationEntity = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationEntity.getId());
|
||||
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()) {
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY,company.getId() ,
|
||||
@@ -150,6 +163,11 @@ public class EmailNotificationDao {
|
||||
public void sendMailToNotifyBeneficiaryRegardingNewAmendment(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
|
||||
|
||||
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationAmendmentRequestEntity.getApplicationId());
|
||||
Map<String, String> bodyPlaceholders = prepareEmailPlaceholders(applicationEntity, applicationAmendmentRequestEntity);
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, bodyPlaceholders, null,
|
||||
applicationAmendmentRequestEntity.getId());
|
||||
}
|
||||
public Map<String, String> prepareEmailPlaceholders(ApplicationEntity applicationEntity, ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity){
|
||||
Map<String, String> bodyPlaceholders = new HashMap<>();
|
||||
bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
||||
bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString());
|
||||
@@ -185,8 +203,7 @@ public class EmailNotificationDao {
|
||||
|
||||
|
||||
bodyPlaceholders.put("{{note}}", applicationAmendmentRequestEntity.getNote());
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, bodyPlaceholders, null,
|
||||
applicationAmendmentRequestEntity.getId());
|
||||
return bodyPlaceholders;
|
||||
}
|
||||
|
||||
public List<AmendmentFormFieldResponse> getIdAndLabelFromResult(List<Map<String, Object>> result) {
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
|
||||
import net.gepafin.tendermanagement.entities.NotificationEntity;
|
||||
import net.gepafin.tendermanagement.entities.NotificationTypeEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||
import net.gepafin.tendermanagement.enums.NotificationEnum;
|
||||
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||
import net.gepafin.tendermanagement.model.response.NotificationResponse;
|
||||
import net.gepafin.tendermanagement.repositories.NotificationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.NotificationTypeRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
|
||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hibernate.internal.util.collections.CollectionHelper.listOf;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class NotificationDao {
|
||||
|
||||
@Autowired
|
||||
private SimpMessagingTemplate messagingTemplate;
|
||||
|
||||
@Autowired
|
||||
private NotificationRepository notificationRepository;
|
||||
|
||||
@Autowired
|
||||
private NotificationTypeRepository notificationTypeRepository;
|
||||
|
||||
@Autowired
|
||||
private UserWithCompanyRepository userWithCompanyRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private CompanyDao companyDao;
|
||||
|
||||
@Autowired
|
||||
private ApplicationService applicationService;
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
public NotificationResponse sendNotification(NotificationReq notificationReq) {
|
||||
|
||||
// Ensure userId is properly set in notificationReq if not already
|
||||
Long userId = notificationReq.getUserId();
|
||||
if (userId == null) {
|
||||
log.error("User ID is missing in the notification request.");
|
||||
return null;
|
||||
}
|
||||
NotificationEntity notificationEntity = saveNotification(notificationReq);
|
||||
log.info("Sending notification to user {} with content: {}", userId, notificationReq.getMessage());
|
||||
List<Long> companyIds = notificationReq.getCompanyIds();
|
||||
|
||||
if (companyIds == null || companyIds.isEmpty()) {
|
||||
sendToUser(userId, notificationEntity);
|
||||
} else {
|
||||
sendToCompanies(userId, companyIds, notificationEntity);
|
||||
}
|
||||
|
||||
return convertNotificationEntityToNotificationResponse(notificationEntity);
|
||||
}
|
||||
|
||||
private NotificationEntity saveNotification(NotificationReq notificationReq) {
|
||||
|
||||
return notificationRepository.save(convertNotificationRequestToNotificationEntity(notificationReq));
|
||||
}
|
||||
|
||||
private void sendToUser(Long userId, NotificationEntity notificationEntity) {
|
||||
|
||||
String userChannel = GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId;
|
||||
log.info("Channel for User {}", userChannel);
|
||||
NotificationResponse notificationResponse = convertNotificationEntityToNotificationResponse(notificationEntity);
|
||||
messagingTemplate.convertAndSend(userChannel, notificationResponse);
|
||||
}
|
||||
|
||||
private void sendToCompanies(Long userId, List<Long> companyIds, NotificationEntity notificationEntity) {
|
||||
// Send notification to each company provided in the companyIds list
|
||||
companyIds.forEach(companyId -> {
|
||||
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalseForNotification(userId, companyId);
|
||||
String companyChannel = Utils.createChannelForUserAndCompany(userId, companyId);
|
||||
log.info("Channel for User and Company {}, {}", userId, companyChannel);
|
||||
if (userWithCompany == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.USER_WITH_COMPANY_NOT_FOUND);
|
||||
}
|
||||
notificationEntity.setUserWithCompany(userWithCompany);
|
||||
notificationRepository.save(notificationEntity);
|
||||
NotificationResponse notificationResponse = convertNotificationEntityToNotificationResponse(notificationEntity);
|
||||
messagingTemplate.convertAndSend(companyChannel, notificationResponse);
|
||||
});
|
||||
}
|
||||
|
||||
private NotificationResponse convertNotificationEntityToNotificationResponse(NotificationEntity notificationEntity) {
|
||||
|
||||
NotificationResponse notificationResponse = new NotificationResponse();
|
||||
notificationResponse.setId(notificationEntity.getId());
|
||||
notificationResponse.setUserId(notificationEntity.getUserId());
|
||||
notificationResponse.setStatus(notificationEntity.getStatus());
|
||||
notificationResponse.setMessage(notificationEntity.getMessage());
|
||||
notificationResponse.setCreatedDate(notificationEntity.getCreatedDate());
|
||||
notificationResponse.setUpdatedDate(notificationEntity.getUpdatedDate());
|
||||
notificationResponse.setRedirectUrl(notificationEntity.getNotificationType());
|
||||
notificationResponse.setCompanyId(notificationEntity.getUserWithCompany() != null ? notificationEntity.getUserWithCompany().getCompanyId() : null);
|
||||
notificationResponse.setNotificationType(notificationEntity.getNotificationType());
|
||||
notificationResponse.setTitle(notificationEntity.getTitle());
|
||||
return notificationResponse;
|
||||
}
|
||||
|
||||
private NotificationEntity convertNotificationRequestToNotificationEntity(NotificationReq notificationReq) {
|
||||
|
||||
NotificationEntity notificationEntity = new NotificationEntity();
|
||||
String message = notificationReq.getMessage();
|
||||
notificationEntity.setNotificationType(notificationReq.getNotificationType());
|
||||
notificationEntity.setUserId(notificationReq.getUserId());
|
||||
notificationEntity.setStatus(NotificationEnum.UNREAD.getValue());
|
||||
notificationEntity.setIsDeleted(Boolean.FALSE);
|
||||
notificationEntity.setUserWithCompany(notificationReq.getUserWithCompanyEntity() != null ? notificationReq.getUserWithCompanyEntity() : null);
|
||||
notificationEntity.setMessage(message);
|
||||
notificationEntity.setTitle(notificationReq.getTitle());
|
||||
return notificationEntity;
|
||||
}
|
||||
|
||||
public NotificationReq createNotificationReq(String notificationType, Map<String, String> placeholders, Long userId, UserWithCompanyEntity userWithCompanyEntity,
|
||||
List<Long> companyIds) {
|
||||
// Create NotificationReq object
|
||||
NotificationReq notificationReq = new NotificationReq();
|
||||
NotificationTypeEntity notificationTypeEntity = notificationTypeRepository.findByNotificationNameAndIsDeletedFalse(notificationType);
|
||||
notificationReq.setNotificationType(notificationType);
|
||||
String message = Utils.replacePlaceholders(notificationTypeEntity.getJsonTemplate(), placeholders);
|
||||
notificationReq.setMessage(message);
|
||||
notificationReq.setUserId(userId);
|
||||
notificationReq.setCompanyIds(companyIds);
|
||||
String title = Utils.replacePlaceholders(notificationTypeEntity.getTitle(), placeholders);
|
||||
notificationReq.setTitle(title);
|
||||
notificationReq.setUserWithCompanyEntity(userWithCompanyEntity);
|
||||
return notificationReq;
|
||||
}
|
||||
|
||||
public Map<String, String> sendNotificationToBeneficiary(ApplicationEntity application, NotificationTypeEnum notificationTypeEnum) {
|
||||
|
||||
Map<String, String> placeHolders = new HashMap<>();
|
||||
placeHolders.put("{{call_name}}", application.getCall().getName());
|
||||
placeHolders.put("{{protocol_number}}", String.valueOf(application.getProtocol().getProtocolNumber()));
|
||||
NotificationReq notificationReq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, application.getUserId(), application.getUserWithCompany(),
|
||||
listOf(application.getCompanyId()));
|
||||
sendNotification(notificationReq);
|
||||
return placeHolders;
|
||||
}
|
||||
|
||||
public void sendNotificationToInstructor(Map<String, String> placeHolders, ApplicationEvaluationEntity applicationEvaluationEntity, NotificationTypeEnum notificationTypeEnum) {
|
||||
|
||||
Long instructorId = applicationEvaluationEntity.getUserId();
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationEvaluationEntity.getApplicationId());
|
||||
if (instructorId != null) {
|
||||
NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, instructorId, application.getUserWithCompany(),
|
||||
null);
|
||||
sendNotification(notificationreq);
|
||||
}
|
||||
}
|
||||
public void sendNotificationToSuperUser(ApplicationEntity application, Map<String, String> placeHolders, NotificationTypeEnum notificationTypeEnum) {
|
||||
|
||||
List<UserEntity> user = userRepository.findByRoleEntity_RoleTypeAndHubId(RoleStatusEnum.ROLE_SUPER_ADMIN.getValue(), application.getHubId());
|
||||
UserEntity userEntity1 = user.get(0);
|
||||
if (userEntity1 != null) {
|
||||
NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, userEntity1.getId(), application.getUserWithCompany(),
|
||||
null);
|
||||
sendNotification(notificationreq);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Long> getAllCompanyIdsForUser(Long userId) {
|
||||
|
||||
return userWithCompanyRepository.findActiveCompanyIdsByUserId(userId);
|
||||
}
|
||||
|
||||
public NotificationResponse getNotificationById(Long id) {
|
||||
|
||||
NotificationEntity notificationEntity = validateNotificationEntity(id);
|
||||
return convertNotificationEntityToNotificationResponse(notificationEntity);
|
||||
}
|
||||
|
||||
private NotificationEntity validateNotificationEntity(Long id) {
|
||||
|
||||
NotificationEntity notificationEntity = notificationRepository.findByIdAndIsDeletedFalse(id);
|
||||
if (notificationEntity == null) {
|
||||
throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.NOTIFICATION_NOT_FOUND));
|
||||
}
|
||||
return notificationEntity;
|
||||
}
|
||||
|
||||
public List<NotificationResponse> getNotificationByUserId(Long userId, Long companyId, List<NotificationEnum> statuses) {
|
||||
|
||||
List<NotificationEntity> notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalse(userId);
|
||||
UserWithCompanyEntity userWithCompany = null;
|
||||
List<String> statusStrings = new ArrayList<>();
|
||||
if (companyId != null) {
|
||||
userWithCompany = companyDao.validateUserWithCompny(userId, companyId);
|
||||
}
|
||||
|
||||
if (statuses != null) {
|
||||
statusStrings = statuses.stream().map(NotificationEnum::name) // Convert enum to its name as String
|
||||
.toList();
|
||||
notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalseAndStatusIn(userId, statusStrings);
|
||||
|
||||
if (userWithCompany != null) {
|
||||
notificationEntities = notificationRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(userId, userWithCompany.getId(), statusStrings);
|
||||
}
|
||||
}
|
||||
|
||||
return notificationEntities.stream().map(this::convertNotificationEntityToNotificationResponse).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public NotificationResponse updateNotificationStatus(Long id, NotificationEnum status) {
|
||||
|
||||
NotificationEntity notificationEntity = validateNotificationEntity(id);
|
||||
if (notificationEntity.getStatus().equals(status.getValue())) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.NOTIFICATION_ALREADY_IN_THAT_STATE));
|
||||
}
|
||||
notificationEntity.setStatus(status.getValue());
|
||||
notificationEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
notificationRepository.save(notificationEntity);
|
||||
return convertNotificationEntityToNotificationResponse(notificationEntity);
|
||||
}
|
||||
|
||||
public void deleteNotification(Long id) {
|
||||
|
||||
NotificationEntity notificationEntity = validateNotificationEntity(id);
|
||||
notificationEntity.setIsDeleted(true);
|
||||
notificationRepository.save(notificationEntity);
|
||||
}
|
||||
|
||||
public List<NotificationResponse> getNotificationByCompanyIdAndUserId(Long userId, Long companyId, List<NotificationEnum> statuses) {
|
||||
|
||||
List<NotificationEntity> notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalse(userId);
|
||||
UserWithCompanyEntity userWithCompany = null;
|
||||
List<String> statusStrings;
|
||||
if (companyId != null) {
|
||||
userWithCompany = companyDao.validateUserWithCompny(userId, companyId);
|
||||
}
|
||||
|
||||
if (statuses != null) {
|
||||
statusStrings = statuses.stream().map(NotificationEnum::name)
|
||||
.toList();
|
||||
notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalseAndStatusIn(userId, statusStrings);
|
||||
|
||||
if (userWithCompany != null) {
|
||||
notificationEntities = notificationRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(userId, userWithCompany.getId(), statusStrings);
|
||||
}
|
||||
}
|
||||
|
||||
return notificationEntities.stream().map(this::convertNotificationEntityToNotificationResponse).toList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,21 +6,15 @@ import net.gepafin.tendermanagement.config.SamlSuccessHandler;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.response.CompanyResponse;
|
||||
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.UserSamlResponse;
|
||||
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||
import net.gepafin.tendermanagement.repositories.BeneficiaryRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.service.HubService;
|
||||
import net.gepafin.tendermanagement.service.RoleService;
|
||||
import net.gepafin.tendermanagement.service.SystemEmailTemplatesService;
|
||||
import net.gepafin.tendermanagement.service.impl.AuthenticationService;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
@@ -39,6 +33,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
@@ -90,6 +85,18 @@ public class UserDao {
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
private SystemEmailTemplatesService systemEmailTemplatesService;
|
||||
|
||||
@Autowired
|
||||
private EmailLogDao emailLogDao;
|
||||
|
||||
@Autowired
|
||||
private EmailNotificationDao emailNotificationDao;
|
||||
|
||||
@Value("${fe.base.url}")
|
||||
private String feBaseUrl;
|
||||
|
||||
public JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq) {
|
||||
|
||||
if (StringUtils.isEmpty(userReq.getHubUuid())) {
|
||||
@@ -120,9 +127,35 @@ public class UserDao {
|
||||
/** This code is responsible for adding a version history log for the "Create user" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).newData(userEntity).build());
|
||||
|
||||
if(beneficiary == null){
|
||||
sendEmailToOnboardingUser(userEntity);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
public void sendEmailToOnboardingUser(UserEntity userEntity){
|
||||
SystemEmailTemplateResponse emailTemplate = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(
|
||||
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.USER_ONBOARDING, userEntity.getHub(), null);
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(), RecipientTypeEnum.USER, userEntity.getId(), userEntity.getEmail(),
|
||||
userEntity.getId(), null, null, null);
|
||||
String firstName = userEntity.getFirstName() != null ? userEntity.getFirstName() : "";
|
||||
String lastName = userEntity.getLastName() != null ? userEntity.getLastName() : "";
|
||||
String userName = String.join(" ", firstName, lastName).trim();
|
||||
String subject = Utils.replacePlaceholders(emailTemplate.getSubject(), Map.of(
|
||||
"{{user_name}}", userName
|
||||
));
|
||||
String body = Utils.replacePlaceholders(emailTemplate.getHtmlContent(), Map.of(
|
||||
"{{user_name}}", userName,
|
||||
"{{user_email}}", userEntity.getEmail()
|
||||
));
|
||||
|
||||
emailNotificationDao.sendMail(
|
||||
userEntity.getHub().getId(),
|
||||
subject,
|
||||
body,
|
||||
List.of(userEntity.getEmail()),
|
||||
emailLogRequest
|
||||
);
|
||||
}
|
||||
private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq, HubEntity hub) {
|
||||
BeneficiaryEntity beneficiaryEntity = null;
|
||||
if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) {
|
||||
@@ -157,6 +190,8 @@ public class UserDao {
|
||||
userReq.setHubUuid(userEntity.getHub().getUniqueUuid());
|
||||
}else {
|
||||
samlSuccessHandler.validateToken(tempToken, userReq.getCodiceFiscale(), userReq.getHubUuid());
|
||||
RoleEntity roleEntity = roleDao.getRoleByType(RoleStatusEnum.ROLE_BENEFICIARY);
|
||||
userReq.setRoleId(roleEntity.getId());
|
||||
}
|
||||
|
||||
if (Boolean.FALSE.equals(Utils.isValidEmail(userReq.getEmail()))) {
|
||||
@@ -164,12 +199,10 @@ public class UserDao {
|
||||
Translator.toLocale(GepafinConstant.VALIDATE_EMAIL));
|
||||
}
|
||||
log.info("Creating user with email: {}", userReq.getEmail());
|
||||
if (userRepository.existsByEmailIgnoreCaseAndHubUniqueUuid(userReq.getEmail(), userReq.getHubUuid())) {
|
||||
log.error("User creation failed: Email {} already exists", userReq.getEmail());
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
||||
}
|
||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale()))
|
||||
RoleEntity roleEntity = roleService.validateRole(userReq.getRoleId());
|
||||
validateDuplicateEmail(userReq.getEmail(), userReq.getHubUuid(), roleEntity.getRoleType());
|
||||
|
||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale()))
|
||||
&& userRepository.existsByBeneficiaryCodiceFiscaleAndHubId(userReq.getCodiceFiscale(), hub.getId())) {
|
||||
log.error("User creation failed: CodiceFiscale {} already exists", userReq.getCodiceFiscale());
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
@@ -192,7 +225,30 @@ public class UserDao {
|
||||
}
|
||||
}
|
||||
|
||||
private void validatePassword(String password, String confirmPassword, String tempToken) {
|
||||
private void validateDuplicateEmail(String email, String hubUuid, String roleType) {
|
||||
String beneficiaryRoleType = RoleStatusEnum.ROLE_BENEFICIARY.getValue();
|
||||
|
||||
if (beneficiaryRoleType.equals(roleType)) {
|
||||
Boolean beneficiaryExistsInHub = userRepository.existsByEmailIgnoreCaseForBeneficiaries(
|
||||
email, hubUuid, beneficiaryRoleType);
|
||||
|
||||
if (Boolean.TRUE.equals(beneficiaryExistsInHub)) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
||||
}
|
||||
} else {
|
||||
Boolean existsForNonBeneficiaries = userRepository.existsByEmailIgnoreCaseForNonBeneficiaries(
|
||||
email, hubUuid, beneficiaryRoleType);
|
||||
|
||||
if (Boolean.TRUE.equals(existsForNonBeneficiaries)) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void validatePassword(String password, String confirmPassword, String tempToken) {
|
||||
if (StringUtils.isEmpty(password) || StringUtils.isEmpty(confirmPassword)) {
|
||||
if(tempToken == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.VALIDATE_PASSWORD));
|
||||
@@ -219,7 +275,7 @@ public class UserDao {
|
||||
log.info("Current user details: {}", userEntity);
|
||||
log.info("New user details: {}", userReq);
|
||||
String newStatus = userReq.getStatus() != null ? userReq.getStatus().getValue() : null;
|
||||
if (Boolean.FALSE.equals(userEntity.getStatus().equals(newStatus))) {
|
||||
if (newStatus!=null && Boolean.FALSE.equals(userEntity.getStatus().equals(newStatus))) {
|
||||
userEntity.setStatus(newStatus);
|
||||
}
|
||||
setIfUpdated(userEntity::getFirstName, userEntity::setFirstName, userReq.getFirstName());
|
||||
@@ -228,15 +284,19 @@ public class UserDao {
|
||||
setIfUpdated(userEntity::getAddress, userEntity::setAddress, userReq.getAddress());
|
||||
setIfUpdated(userEntity::getPhoneNumber, userEntity::setPhoneNumber, userReq.getPhoneNumber());
|
||||
setIfUpdated(userEntity::getDateOfBirth, userEntity::setDateOfBirth, userReq.getDateOfBirth());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getCodiceFiscale, userEntity.getBeneficiary()::setCodiceFiscale, userReq.getCodiceFiscale());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getMarketing, userEntity.getBeneficiary()::setMarketing, userReq.getMarketing());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getOffers, userEntity.getBeneficiary()::setOffers, userReq.getOffers());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getThirdParty, userEntity.getBeneficiary()::setThirdParty, userReq.getThirdParty());
|
||||
if (userReq.getRoleId() != null) {
|
||||
RoleEntity roleEntity = roleDao.validateRole(userReq.getRoleId());
|
||||
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
|
||||
if((userEntity.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue()) && roleEntity.getRoleType().equals(RoleStatusEnum.ROLE_PRE_INSTRUCTOR.getValue())) || (userEntity.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_PRE_INSTRUCTOR.getValue()) && roleEntity.getRoleType().equals(RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue()))) {
|
||||
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
|
||||
}
|
||||
}
|
||||
if(userEntity.getBeneficiary()!=null) {
|
||||
setIfUpdated(userEntity.getBeneficiary()::getCodiceFiscale, userEntity.getBeneficiary()::setCodiceFiscale, userReq.getCodiceFiscale());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getMarketing, userEntity.getBeneficiary()::setMarketing, userReq.getMarketing());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getOffers, userEntity.getBeneficiary()::setOffers, userReq.getOffers());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getThirdParty, userEntity.getBeneficiary()::setThirdParty, userReq.getThirdParty());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getEmailPec, userEntity.getBeneficiary()::setEmailPec, userReq.getEmailPec());
|
||||
}
|
||||
setIfUpdated(userEntity.getBeneficiary()::getEmailPec, userEntity.getBeneficiary()::setEmailPec, userReq.getEmailPec());
|
||||
userEntity = userRepository.save(userEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update user details" operation **/
|
||||
@@ -263,7 +323,7 @@ public class UserDao {
|
||||
userEntity.setAddress(userReq.getAddress());
|
||||
userEntity.setPhoneNumber(userReq.getPhoneNumber());
|
||||
userEntity.setDateOfBirth(userReq.getDateOfBirth());
|
||||
}
|
||||
}
|
||||
return userRepository.save(userEntity);
|
||||
}
|
||||
|
||||
@@ -362,25 +422,83 @@ public class UserDao {
|
||||
return user;
|
||||
}
|
||||
|
||||
public String initiatePasswordReset(InitiatePasswordResetReq resetReq) {
|
||||
UserEntity user = userRepository
|
||||
.findByEmailIgnoreCaseAndHubUniqueUuid(resetReq.getEmail(), resetReq.getHubUuid())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||
public void initiatePasswordReset(InitiatePasswordResetReq resetReq) {
|
||||
UserEntity user = userRepository.findUserExcludingRoleType(
|
||||
resetReq.getEmail(),
|
||||
resetReq.getHubUuid(),
|
||||
RoleStatusEnum.ROLE_BENEFICIARY.getValue()
|
||||
).orElseThrow(() -> new ResourceNotFoundException(
|
||||
Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)
|
||||
));
|
||||
|
||||
UserEntity oldUserEntity = Utils.getClonedEntityForData(user);
|
||||
String token = Utils.generateSecureToken();
|
||||
user.setResetPasswordToken(token);
|
||||
userRepository.save(user);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Initiate password reset request" operation **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserEntity).newData(user).build());
|
||||
|
||||
log.info("Password reset token generated for user: {}", resetReq.getEmail());
|
||||
return token;
|
||||
|
||||
sendResetPasswordTokenEmail(user, token);
|
||||
}
|
||||
public void sendResetPasswordTokenEmail(UserEntity user, String token) {
|
||||
|
||||
SystemEmailTemplateResponse emailTemplate = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(
|
||||
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.PASSWORD_RESET, user.getHub(), null);
|
||||
String redirectUrl = feBaseUrl;
|
||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(user.getHub().getDomainName()))) {
|
||||
redirectUrl = user.getHub().getDomainName();
|
||||
}
|
||||
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(
|
||||
emailTemplate.getEmailScenario(),
|
||||
RecipientTypeEnum.USER,
|
||||
user.getId(),
|
||||
user.getEmail(),
|
||||
user.getId(),
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
redirectUrl = String.format(
|
||||
user.getHub().getDomainName() + GepafinConstant.RESET_PASSWORD_URL_FORMAT,
|
||||
token,
|
||||
user.getEmail()
|
||||
);
|
||||
String firstName = user.getFirstName() != null ? user.getFirstName() : "";
|
||||
String lastName = user.getLastName() != null ? user.getLastName() : "";
|
||||
String userName = String.join(" ", firstName, lastName).trim();
|
||||
String subject = Utils.replacePlaceholders(emailTemplate.getSubject(), Map.of(
|
||||
"{{user_name}}", userName
|
||||
));
|
||||
String body = Utils.replacePlaceholders(emailTemplate.getHtmlContent(), Map.of(
|
||||
"{{user_name}}", userName,
|
||||
"{{reset_password_link}}", redirectUrl
|
||||
));
|
||||
emailNotificationDao.sendMail(
|
||||
user.getHub().getId(),
|
||||
subject,
|
||||
body,
|
||||
List.of(user.getEmail()),
|
||||
emailLogRequest
|
||||
);
|
||||
|
||||
log.info("Password reset token email sent to: {}", user.getEmail());
|
||||
}
|
||||
|
||||
public Boolean resetPassword(ResetPasswordReq resetPasswordReq) {
|
||||
UserEntity user = userRepository
|
||||
.findByEmailIgnoreCaseAndHubUniqueUuid(resetPasswordReq.getEmail(), resetPasswordReq.getHubUuid())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||
|
||||
UserEntity user = userRepository.findUserExcludingRoleType(
|
||||
resetPasswordReq.getEmail(),
|
||||
resetPasswordReq.getHubUuid(),
|
||||
RoleStatusEnum.ROLE_BENEFICIARY.getValue()
|
||||
).orElseThrow(() -> new ResourceNotFoundException(
|
||||
Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)
|
||||
));
|
||||
|
||||
UserEntity oldUserEntity = Utils.getClonedEntityForData(user);
|
||||
if (!resetPasswordReq.getNewPassword().equals(resetPasswordReq.getConfirmPassword())) {
|
||||
log.info("User creation failed: Passwords do not match for email {}", user.getEmail());
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_DOESNT_MATCH));
|
||||
@@ -395,25 +513,36 @@ public class UserDao {
|
||||
user.setPassword(passwordEncoder.encode(resetPasswordReq.getNewPassword()));
|
||||
user.setResetPasswordToken(null);
|
||||
userRepository.save(user);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Reset Password " operation **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserEntity).newData(user).build());
|
||||
|
||||
log.info("Password successfully reset for user: {}", resetPasswordReq.getEmail());
|
||||
return true;
|
||||
}
|
||||
|
||||
public Boolean changePassword(UserEntity userEntity, ChangePasswordRequest request) {
|
||||
public Boolean changePassword(UserEntity userEntity, ChangePasswordRequest changePasswordRequest) {
|
||||
UserEntity user = userRepository
|
||||
.findByEmailIgnoreCaseAndHubUniqueUuid(request.getEmail(), userEntity.getHub().getUniqueUuid())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||
|
||||
if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) {
|
||||
.findUserExcludingRoleType(changePasswordRequest.getEmail(), userEntity.getHub().getUniqueUuid(),RoleStatusEnum.ROLE_BENEFICIARY.getValue())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(
|
||||
Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)
|
||||
));
|
||||
UserEntity oldUserEntity = Utils.getClonedEntityForData(userEntity);
|
||||
if (!passwordEncoder.matches(changePasswordRequest.getPassword(), user.getPassword())) {
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CURRENT_PASSWORD_INCORRECT));
|
||||
}
|
||||
if (!request.getNewPassword().equals(request.getConfirmPassword())) {
|
||||
if (!changePasswordRequest.getNewPassword().equals(changePasswordRequest.getConfirmPassword())) {
|
||||
log.info("User creation failed: Passwords do not match for email {}", user.getEmail());
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.PASSWORD_DOESNT_MATCH));
|
||||
}
|
||||
user.setPassword(passwordEncoder.encode(request.getNewPassword()));
|
||||
user.setPassword(passwordEncoder.encode(changePasswordRequest.getNewPassword()));
|
||||
userRepository.save(user);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Change user password" operation **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserEntity).newData(user).build());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
public void logout(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
@@ -4,15 +4,11 @@ import feign.FeignException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
|
||||
import net.gepafin.tendermanagement.model.request.UserActionRequest;
|
||||
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||
import net.gepafin.tendermanagement.model.response.VatCheckResponseBean;
|
||||
import net.gepafin.tendermanagement.service.feignClient.VatCheckService;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
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.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -49,10 +45,13 @@ public class VatCheckDao {
|
||||
@Autowired
|
||||
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))) {
|
||||
return new HashMap<>();
|
||||
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||
return vatCheckResponseBean;
|
||||
}
|
||||
Map<String, Object> responseBody = new HashMap<>();
|
||||
try {
|
||||
@@ -69,30 +68,57 @@ public class VatCheckDao {
|
||||
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
|
||||
log.info("Successfully checked vat number");
|
||||
Map<String, Object> responseMap = response.getBody();
|
||||
if (responseMap != null && responseMap.containsKey("data")) {
|
||||
responseBody = (Map<String, Object>) responseMap.get("data");
|
||||
responseBody.remove("timestamp_creation");
|
||||
responseBody.remove("timestamp_last_update");
|
||||
responseBody.remove("data_iscrizione");
|
||||
responseBody.remove("id");
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("data", responseBody);
|
||||
return data;
|
||||
}
|
||||
processValidResponse(responseMap, vatCheckResponseBean);
|
||||
}
|
||||
} catch (FeignException ex) {
|
||||
log.error("Exception occurred while checking vat number: {0}", ex);
|
||||
Utils.callException(ex.status(), ex);
|
||||
if (ex.status() == 406) {
|
||||
try {
|
||||
Map<String, Object> errorResponse = Utils.parseErrorResponse(ex.contentUTF8());
|
||||
processValidResponse(errorResponse, vatCheckResponseBean);
|
||||
} catch (Exception parseEx) {
|
||||
log.error("Failed to parse 406 error response: {0}", parseEx);
|
||||
}
|
||||
} else {
|
||||
log.error("Exception occurred while checking vat number: {0}", ex);
|
||||
Utils.callException(ex.status(), ex);
|
||||
}
|
||||
}
|
||||
return vatCheckResponseBean;
|
||||
}
|
||||
public static void processValidResponse(Map<String, Object> responseMap, VatCheckResponseBean vatCheckResponseBean) {
|
||||
if (responseMap != null && responseMap.containsKey("data")) {
|
||||
Map<String, Object> responseBody = (Map<String, Object>) responseMap.get("data");
|
||||
|
||||
if (responseBody != null) {
|
||||
responseBody.remove("timestamp_creation");
|
||||
responseBody.remove("timestamp_last_update");
|
||||
responseBody.remove("data_iscrizione");
|
||||
responseBody.remove("id");
|
||||
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("data", responseBody);
|
||||
|
||||
vatCheckResponseBean.setValid(true);
|
||||
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.VALID_VATNUMBER_MSG));
|
||||
vatCheckResponseBean.setVatCheckResponse(data);
|
||||
} else {
|
||||
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||
}
|
||||
} else {
|
||||
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||
}
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
public Map<String, Object> checkVatNumber(String vatNumber) {
|
||||
public VatCheckResponseBean checkVatNumber(String vatNumber) {
|
||||
try {
|
||||
return checkVatNumberApi(vatNumber);
|
||||
} catch (Exception e) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||
log.error("Error in checkVatNumber: {}", e.getMessage());
|
||||
VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean();
|
||||
vatCheckResponseBean.setValid(false);
|
||||
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||
return vatCheckResponseBean;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user