Resolved Conflicts.
This commit is contained in:
@@ -105,6 +105,12 @@ public class ApplicationAmendmentRequestDao {
|
||||
@Autowired
|
||||
private AssignedApplicationsDao assignedApplicationsDao;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationDao applicationEvaluationDao;
|
||||
|
||||
@Autowired
|
||||
private DocumentRepository documentRepository;
|
||||
|
||||
@Autowired
|
||||
private NotificationDao notificationDao;
|
||||
|
||||
@@ -115,8 +121,26 @@ public class ApplicationAmendmentRequestDao {
|
||||
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
|
||||
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
|
||||
Long applicationId = applicationEvaluationEntity.getApplicationId();
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
List<FieldRequest> evaluationFileRequests=new ArrayList<>();
|
||||
List<ChecklistRequest> checklistRequests=new ArrayList<>();
|
||||
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
String file=applicationEvaluationEntity.getFile();
|
||||
String checkList=applicationEvaluationEntity.getChecklist();
|
||||
if(file != null){
|
||||
evaluationFileRequests=Utils.convertJsonStringToList(file,FieldRequest.class);
|
||||
}
|
||||
Boolean allValid = evaluationFileRequests.stream()
|
||||
.anyMatch(fieldRequest -> fieldRequest.getValid() == null);
|
||||
if(checkList != null) {
|
||||
checklistRequests=Utils.convertJsonStringToList(checkList,ChecklistRequest.class);
|
||||
}
|
||||
boolean resultCheckList = checklistRequests.stream()
|
||||
.anyMatch(checklistRequest -> Boolean.TRUE.equals(checklistRequest.getValid())) ? false : true;
|
||||
|
||||
if(Boolean.TRUE.equals(allValid) || Boolean.TRUE.equals(resultCheckList)){
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.All_DOCUMENT_CHECKED_AND_ONE_CHECKLIST_CHECKED));
|
||||
}
|
||||
// Set common application-level details
|
||||
String callName = application.getCall().getName();
|
||||
Long protocolNumber = (application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null)
|
||||
@@ -141,11 +165,18 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationId);
|
||||
List<AmendmentFormFieldResponse> allFormFields = new ArrayList<>();
|
||||
|
||||
Map<String, FieldRequest> fieldRequestMap = evaluationFileRequests.stream()
|
||||
.collect(Collectors.toMap(FieldRequest::getId, fieldRequest -> fieldRequest));
|
||||
for (ApplicationFormEntity form : forms) {
|
||||
String content = form.getForm().getContent();
|
||||
List<Map<String, Object>> result = filterByName(content, "fileupload");
|
||||
allFormFields.addAll(getIdAndLabelFromResult(result));
|
||||
List<AmendmentFormFieldResponse> amendmentFormFieldResponses= getIdAndLabelFromResult(result);
|
||||
amendmentFormFieldResponses.removeIf(amendmentFormFieldResponse -> {
|
||||
FieldRequest matchingRequest = fieldRequestMap.get(amendmentFormFieldResponse.getFieldId());
|
||||
// Remove if no matching FieldRequest exists or if valid is true
|
||||
return matchingRequest == null || Boolean.TRUE.equals(matchingRequest.getValid());
|
||||
});
|
||||
allFormFields.addAll(amendmentFormFieldResponses);
|
||||
}
|
||||
|
||||
response.setFormFields(allFormFields);
|
||||
@@ -243,6 +274,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
AmendmentFormField formField = new AmendmentFormField();
|
||||
formField.setFieldId(amendmentFormFieldRequest.getFieldId());
|
||||
formField.setFieldValue(null);
|
||||
formField.setLabel(amendmentFormFieldRequest.getLabel());
|
||||
return formField;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
@@ -267,7 +299,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub());
|
||||
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(
|
||||
applicationEvaluationEntity.getAssignedApplicationsEntity().getApplication(), protocolNumber,
|
||||
userEntity.getHub().getId());
|
||||
userEntity.getHub().getId(),false);
|
||||
applicationAmendmentRequestEntity.setProtocol(protocolEntity);
|
||||
ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity, null, VersionActionTypeEnum.INSERT);
|
||||
String evaluationStatusType = applicationEvaluationEntity.getStatus();
|
||||
@@ -311,6 +343,25 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
return applicationAmendment;
|
||||
}
|
||||
private void setAmendmentDocuments(String amendmentNotes, String amendmentFieldRequest,
|
||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
|
||||
AmendmentDetailsResponseBean amendmentDetails = new AmendmentDetailsResponseBean();
|
||||
if (amendmentFieldRequest != null && !amendmentFieldRequest.trim().isEmpty()) {
|
||||
String[] documentIds = amendmentFieldRequest.split(",");
|
||||
String validDocumentIds = Arrays.stream(documentIds)
|
||||
.map(String::trim)
|
||||
.filter(id -> !id.isEmpty())
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
amendmentDetails.setAmendmentDocuments(validDocumentIds);
|
||||
}
|
||||
if (amendmentNotes != null && !amendmentNotes.trim().isEmpty()) {
|
||||
amendmentDetails.setAmendmentNotes(amendmentNotes.trim());
|
||||
}
|
||||
amendmentDetails.setValid(null);
|
||||
String amendmentDetailsJson = Utils.convertObjectToString(amendmentDetails);
|
||||
applicationAmendmentRequestEntity.setAmendmentDocument(amendmentDetailsJson);
|
||||
}
|
||||
|
||||
public ApplicationAmendmentRequestEntity saveApplicationAmendmentRequestEntity(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity,ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity,VersionActionTypeEnum actionTypeEnum) {
|
||||
ApplicationAmendmentRequestEntity applicationAmendmentRequest = applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||
@@ -326,16 +377,70 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationAmendmentRequestEntity.getApplicationId());
|
||||
Map<String, String> fieldIdToLabelMap = extractFieldIdToLabelMap(forms);
|
||||
|
||||
// List<AmendmentFieldRequest> amendmentFieldRequests= new ArrayList<>();
|
||||
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(
|
||||
applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
|
||||
Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields);
|
||||
if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
|
||||
|
||||
// List<AmendmentDetailsResponseBean> amendmentDetailsList =
|
||||
// Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(),
|
||||
// AmendmentDetailsResponseBean.class);
|
||||
AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(applicationAmendmentRequestEntity.getAmendmentDocument() ,AmendmentDetailsResponseBean.class);
|
||||
if(amendmentDetails!=null) {
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
if (amendmentDetails.getAmendmentDocuments() != null) {
|
||||
// Extract the comma-separated document IDs as a string
|
||||
String documentIdsString = amendmentDetails.getAmendmentDocuments();
|
||||
|
||||
if (documentIdsString != null && !documentIdsString.trim().isEmpty()) {
|
||||
// Split the comma-separated values and process them
|
||||
List<String> documentIds = Arrays.stream(documentIdsString.split(","))
|
||||
.map(String::trim)
|
||||
.filter(id -> !id.isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
documentResponseBeans.addAll(
|
||||
documentIds.stream()
|
||||
.map(id -> {
|
||||
try {
|
||||
return createDocumentResponseBean(id); // Convert to Long
|
||||
} catch (NumberFormatException e) {
|
||||
// Handle invalid document IDs gracefully
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull) // Skip null responses
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
response.setAmendmentNotes(amendmentDetails.getAmendmentNotes());
|
||||
response.setValid(amendmentDetails.getValid());
|
||||
}
|
||||
}
|
||||
response.setAmendmentDocuments(documentResponseBeans);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
processFormFields(amendmentFormFields, fieldIdToLabelMap, formFieldEntityMap, response);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public DocumentResponseBean createDocumentResponseBean(String documentId) {
|
||||
|
||||
if (!StringUtils.isEmpty(documentId)) {
|
||||
Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(documentId));
|
||||
if(documentEntity.isPresent()){
|
||||
return applicationEvaluationDao.createDocumentResponseBean(documentEntity.get());
|
||||
}}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity) {
|
||||
ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse();
|
||||
response.setId(entity.getId());
|
||||
@@ -509,6 +614,20 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
log.info("Updating application amendement with ID: {}", id);
|
||||
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
||||
Boolean isBeneficiary=false;
|
||||
if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) {
|
||||
validator.validatePreInstructor(request, existingApplicationAmendment.getApplicationEvaluationEntity().getUserId());
|
||||
isBeneficiary=false;
|
||||
} else {
|
||||
validator.validateUserId(request, existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
|
||||
isBeneficiary=true;
|
||||
}
|
||||
if(Boolean.TRUE.equals(isBeneficiary) && existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue())){
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||
}
|
||||
if(Boolean.FALSE.equals(isBeneficiary) && existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())){
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||
}
|
||||
|
||||
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
|
||||
setIfUpdated(existingApplicationAmendment::getNote, existingApplicationAmendment::setNote, updateRequest.getNote());
|
||||
@@ -521,14 +640,16 @@ public class ApplicationAmendmentRequestDao {
|
||||
if(updateRequest.getApplicationFormFields() != null) {
|
||||
updateRequest.getApplicationFormFields().stream().forEach(applicationFormFieldRequest->{
|
||||
AmendmentFormField amendmentFormField = getAmendmentFormField(amendmentFormFieldMap,applicationFormFieldRequest.getFieldId());
|
||||
ApplicationFormFieldEntity applicationFormFieldEntity = getApplicationFormField(applicationFormFieldMap, applicationFormFieldRequest.getFieldId());
|
||||
updateApplicationFormField(applicationFormFieldEntity,applicationFormFieldRequest, amendmentFormField);
|
||||
// ApplicationFormFieldEntity applicationFormFieldEntity = getApplicationFormField(applicationFormFieldMap, applicationFormFieldRequest.getFieldId());
|
||||
// updateApplicationFormField(applicationFormFieldEntity,applicationFormFieldRequest, amendmentFormField);
|
||||
updateFormField(applicationFormFieldRequest, amendmentFormField);
|
||||
});
|
||||
existingApplicationAmendment.setFormFields(Utils.convertListToJsonString(amendmentFormFieldMap.values().stream().toList()));
|
||||
}
|
||||
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
|
||||
if(updateRequest.getAmendmentDocuments()!=null && Boolean.FALSE.equals(updateRequest.getAmendmentDocuments().isEmpty())) {
|
||||
setAmendmentDocuments(updateRequest.getAmendmentNotes(),updateRequest.getAmendmentDocuments(), existingApplicationAmendment);
|
||||
}
|
||||
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment,oldApplicationAmendmentEntity,VersionActionTypeEnum.UPDATE);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);
|
||||
log.info("Application Amendment updated successfully: {}", response);
|
||||
@@ -595,13 +716,13 @@ public class ApplicationAmendmentRequestDao {
|
||||
String fieldId) {
|
||||
AmendmentFormField amendmentFormField = amendmentFormFieldMap.get(fieldId);
|
||||
if (amendmentFormField == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND);
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND));
|
||||
}
|
||||
return amendmentFormField;
|
||||
}
|
||||
|
||||
|
||||
private void updateFormField(ApplicationFormFieldRequestBean applicationFormFieldRequest,
|
||||
private void updateFormField(AmendmentFormFieldRequest applicationFormFieldRequest,
|
||||
AmendmentFormField amendmentFormField) {
|
||||
List<Long> requestedDocumentIds = extractIds(applicationFormFieldRequest.getFieldValue());
|
||||
List<Long> existingDocumentIds = extractIds(amendmentFormField.getFieldValue());
|
||||
@@ -610,7 +731,8 @@ public class ApplicationAmendmentRequestDao {
|
||||
if (!existingDocumentIds.isEmpty()) {
|
||||
existingDocumentIds.forEach(this::softDeleteDocument);
|
||||
amendmentFormField.setFieldValue(null);
|
||||
setIsUploadedBy(amendmentFormField);
|
||||
amendmentFormField.setValid(applicationFormFieldRequest.getValid());
|
||||
// setIsUploadedBy(amendmentFormField);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -624,11 +746,12 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
if (!newFieldValue.equals(amendmentFormField.getFieldValue())) {
|
||||
amendmentFormField.setFieldValue(newFieldValue);
|
||||
setIsUploadedBy(amendmentFormField);
|
||||
amendmentFormField.setValid(applicationFormFieldRequest.getValid());
|
||||
// setIsUploadedBy(amendmentFormField);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Long> extractIds(Object fieldValue) {
|
||||
public List<Long> extractIds(Object fieldValue) {
|
||||
if (fieldValue instanceof String && !StringUtils.isEmpty((String) fieldValue)) {
|
||||
return Arrays.stream(((String) fieldValue).split(","))
|
||||
.map(Long::valueOf)
|
||||
@@ -639,14 +762,14 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
|
||||
|
||||
private void setIsUploadedBy(AmendmentFormField amendmentFormField) {
|
||||
if(validator.checkIsBeneficiary()) {
|
||||
amendmentFormField.setIsUploadedBy(AmendmentFormField.AmendmentIsUploadedByEnum.BENEFICIARY.getValue());
|
||||
}else {
|
||||
amendmentFormField.setIsUploadedBy(AmendmentFormField.AmendmentIsUploadedByEnum.PRE_INSTRUCTOR.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
// private void setIsUploadedBy(AmendmentFormField amendmentFormField) {
|
||||
// if(validator.checkIsBeneficiary()) {
|
||||
// amendmentFormField.setIsUploadedBy(AmendmentFormField.AmendmentIsUploadedByEnum.BENEFICIARY.getValue());
|
||||
// }else {
|
||||
// amendmentFormField.setIsUploadedBy(AmendmentFormField.AmendmentIsUploadedByEnum.PRE_INSTRUCTOR.getValue());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
// private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
|
||||
@@ -959,7 +1082,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
log.info("Updating application amendment with status: {}", id);
|
||||
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
||||
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
|
||||
if (Boolean.TRUE.equals(existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())) || Boolean.TRUE.equals(statusTypeEnum.equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED))) {
|
||||
if (Boolean.TRUE.equals(existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())) && Boolean.TRUE.equals(statusTypeEnum.equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED))) {
|
||||
existingApplicationAmendment.setStatus(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
|
||||
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
applicationAmendmentRequestRepository.save(existingApplicationAmendment);
|
||||
@@ -1043,12 +1166,6 @@ public class ApplicationAmendmentRequestDao {
|
||||
|
||||
|
||||
}
|
||||
public List<ApplicationAmendmentRequestEntity> getApplicationAmendmentRequestEntitiesByApplicationEvaluationId(Long applicationEvaluationId){
|
||||
List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities=new ArrayList<>();
|
||||
applicationAmendmentRequestEntities=applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndStatusAndIsDeletedFalse(applicationEvaluationId,ApplicationAmendmentRequestEnum.CLOSE.getValue());
|
||||
return applicationAmendmentRequestEntities;
|
||||
}
|
||||
|
||||
private void softDeleteDocument(Long documentId) {
|
||||
documentService.deleteFile(documentId);
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ public class ApplicationDao {
|
||||
if (applicationFormFieldEntity1.getFieldId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
||||
applicationFormFieldEntity = applicationFormFieldEntity1;
|
||||
oldApplicationFormFieldData = Utils.getClonedEntityForData(applicationFormFieldEntity);
|
||||
if (applicationFormEntity.getForm().getId().equals(applicationFormEntity.getApplication().getCall().getInitialForm())) {
|
||||
if (applicationFormEntity.getForm().getId().equals(applicationFormEntity.getApplication().getCall().getInitialForm()) && checkIfRequestFieldIsDifferent(applicationFormFieldEntity1, applicationFormFieldRequestBean)) {
|
||||
validateRequiredFields(applicationFormEntity.getForm(), applicationFormEntity.getApplication(), applicationFormFieldRequestBean.getFieldId());
|
||||
}
|
||||
actionType = VersionActionTypeEnum.UPDATE;
|
||||
@@ -505,7 +505,30 @@ public class ApplicationDao {
|
||||
return applicationFormField;
|
||||
}
|
||||
|
||||
void updateDocumentDeletionStatus(ApplicationFormFieldEntity applicationFormFieldEntity, ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity, List<Long> newDocumentIds,
|
||||
private Boolean checkIfRequestFieldIsDifferent(ApplicationFormFieldEntity applicationFormFieldEntity,
|
||||
ApplicationFormFieldRequestBean applicationFormFieldRequestBean) {
|
||||
|
||||
// Retrieve the field values from both objects
|
||||
String entityFieldValue = applicationFormFieldEntity.getFieldValue();
|
||||
Object requestFieldValue = applicationFormFieldRequestBean.getFieldValue();
|
||||
|
||||
// Check if both are null
|
||||
if (entityFieldValue == null && requestFieldValue == null) {
|
||||
return false; // No difference if both are null
|
||||
}
|
||||
|
||||
// Compare values
|
||||
Boolean check = !Objects.equals(entityFieldValue, requestFieldValue);
|
||||
|
||||
// Additional comparison if both are non-null
|
||||
if (Boolean.TRUE.equals(check) && entityFieldValue != null && requestFieldValue != null) {
|
||||
check = !entityFieldValue.equals(requestFieldValue.toString());
|
||||
}
|
||||
|
||||
return check;
|
||||
}
|
||||
|
||||
void updateDocumentDeletionStatus(ApplicationFormFieldEntity applicationFormFieldEntity, ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity, List<Long> newDocumentIds,
|
||||
List<String> preInstructorDocumentId,boolean isPreInstructor) {
|
||||
if (newDocumentIds == null) {
|
||||
newDocumentIds = Collections.emptyList();
|
||||
@@ -791,18 +814,18 @@ public class ApplicationDao {
|
||||
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyEntity.getId());
|
||||
|
||||
// call = callService.validatePublishedCall(call.getId());
|
||||
checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
|
||||
// checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
|
||||
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, userWithCompanyEntity);
|
||||
applicationEntity.setComments(applicationRequest.getComments());
|
||||
applicationEntity = saveApplicationEntity(applicationEntity);
|
||||
return getApplicationResponse(applicationEntity);
|
||||
}
|
||||
public void checkIfApplicationExists(CallEntity call, UserWithCompanyEntity userWithCompanyEntity, UserEntity userEntity){
|
||||
Optional<ApplicationEntity> applicationEntity=applicationRepository.findByUserIdAndUserWithCompanyIdAndCallIdAndIsDeletedFalse(userEntity.getId(), userWithCompanyEntity.getId(),call.getId());
|
||||
if(applicationEntity.isPresent()){
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_EXISTS));
|
||||
}
|
||||
}
|
||||
// public void checkIfApplicationExists(CallEntity call, UserWithCompanyEntity userWithCompanyEntity, UserEntity userEntity){
|
||||
// Optional<ApplicationEntity> applicationEntity=applicationRepository.findByUserIdAndUserWithCompanyIdAndCallIdAndIsDeletedFalse(userEntity.getId(), userWithCompanyEntity.getId(),call.getId());
|
||||
// if(applicationEntity.isPresent()){
|
||||
// throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_EXISTS));
|
||||
// }
|
||||
// }
|
||||
|
||||
public ApplicationResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) {
|
||||
|
||||
@@ -823,7 +846,7 @@ public class ApplicationDao {
|
||||
if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) {
|
||||
callService.validatePublishedCall(applicationEntity.getCall().getId(), userEntity.getHub().getId());
|
||||
Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub());
|
||||
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId());
|
||||
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId(),true);
|
||||
applicationEntity.setProtocol(protocolEntity);
|
||||
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
|
||||
applicationEntity.setSubmissionDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
@@ -16,18 +15,21 @@ import net.gepafin.tendermanagement.service.*;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
import static org.apache.commons.lang3.StringUtils.isNumeric;
|
||||
|
||||
@Component
|
||||
public class ApplicationEvaluationDao {
|
||||
@@ -99,6 +101,15 @@ public class ApplicationEvaluationDao {
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private DocumentService documentService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
|
||||
|
||||
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
|
||||
|
||||
ApplicationEvaluationEntity entity = new ApplicationEvaluationEntity();
|
||||
@@ -134,16 +145,103 @@ public class ApplicationEvaluationDao {
|
||||
List<CallTargetAudienceChecklistEntity> checklistEntities = callTargetAudienceChecklistRepository
|
||||
.findByCallIdAndLookupDataTypeAndIsDeletedFalse(call.getId(), LookUpDataEntity.LookUpDataTypeEnum.CHECKLIST.getValue());
|
||||
List<ApplicationFormEntity> applicationFormEntities = applicationFormRepository.findByApplicationId(entity.getApplicationId());
|
||||
setAmendmentDetails(entity,response);
|
||||
|
||||
setCriteriaResponses(entity, response, evaluationCriterias);
|
||||
setChecklistResponses(entity, response, checklistEntities);
|
||||
setFieldResponses(entity, response, applicationFormEntities);
|
||||
|
||||
List<EvaluationDocumentRequest> allDocs = prepareEvaluationDocumentBeanList(entity);
|
||||
setEvaluationDocResponse(response, allDocs);
|
||||
setApplicationDetails(response, entity);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private void setAmendmentDetails(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response) {
|
||||
List<ApplicationAmendmentRequestEntity> amendmentRequests=applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(entity.getId());
|
||||
List<AmendmentDocumentResponseBean> amendmentDocumentResponseBeans=new ArrayList<>();
|
||||
for(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity:amendmentRequests){
|
||||
AmendmentDocumentResponseBean amendmentDocumentResponseBean=new AmendmentDocumentResponseBean();
|
||||
amendmentDocumentResponseBean.setAmendmentId(applicationAmendmentRequestEntity.getId());
|
||||
String amendmentDocument=applicationAmendmentRequestEntity.getAmendmentDocument();
|
||||
String formField=applicationAmendmentRequestEntity.getFormFields();
|
||||
AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(amendmentDocument, AmendmentDetailsResponseBean.class);
|
||||
if (amendmentDetails != null) {
|
||||
if (amendmentDetails.getAmendmentDocuments() != null) {
|
||||
List<DocumentResponseBean> documentResponseBeans = Arrays.stream(amendmentDetails.getAmendmentDocuments().split(","))
|
||||
.map(String::trim)
|
||||
.filter(id -> !id.isEmpty())
|
||||
.map(documentId -> applicationAmendmentRequestDao.createDocumentResponseBean(documentId))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
amendmentDocumentResponseBean.setFileDetail(documentResponseBeans);
|
||||
}
|
||||
amendmentDocumentResponseBean.setFieldId("amend_" + applicationAmendmentRequestEntity.getId());
|
||||
amendmentDocumentResponseBean.setLabel(amendmentDetails.getAmendmentNotes());
|
||||
amendmentDocumentResponseBean.setValid(amendmentDetails.getValid());
|
||||
amendmentDocumentResponseBeans.add(amendmentDocumentResponseBean);
|
||||
}
|
||||
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(formField, AmendmentFormField.class);
|
||||
if (amendmentFormFields != null) {
|
||||
for (AmendmentFormField amendmentFormField : amendmentFormFields) {
|
||||
// Skip fields with null or empty fieldValue
|
||||
if (StringUtils.isEmpty(amendmentFormField.getFieldValue())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
AmendmentDocumentResponseBean formFieldResponseBean = new AmendmentDocumentResponseBean();
|
||||
formFieldResponseBean.setAmendmentId(applicationAmendmentRequestEntity.getId());
|
||||
formFieldResponseBean.setFieldId(amendmentFormField.getFieldId());
|
||||
formFieldResponseBean.setLabel(amendmentFormField.getLabel());
|
||||
formFieldResponseBean.setValid(amendmentFormField.getValid());
|
||||
|
||||
List<Long> fileIds = applicationAmendmentRequestDao.extractIds(amendmentFormField.getFieldValue());
|
||||
List<DocumentResponseBean> documentResponseBeans = fileIds.stream()
|
||||
.map(fileId -> createDocumentResponseBean(documentService.validateDocument(fileId)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
formFieldResponseBean.setFileDetail(documentResponseBeans);
|
||||
amendmentDocumentResponseBeans.add(formFieldResponseBean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response.setAmendmentDetails(amendmentDocumentResponseBeans);
|
||||
}
|
||||
|
||||
private void setEvaluationDocResponse(ApplicationEvaluationResponse response, List<EvaluationDocumentRequest> docRequest) {
|
||||
List<EvaluationDocumentResponse> evaluationDocResponses = new ArrayList<>();
|
||||
|
||||
for (EvaluationDocumentRequest doc : docRequest) {
|
||||
EvaluationDocumentResponse evaluationDocResponse = new EvaluationDocumentResponse();
|
||||
if (doc.getFileValue() != null) {
|
||||
Long fileId = Long.valueOf(doc.getFileValue().toString());
|
||||
documentRepository.findByIdAndNotDeleted(fileId).ifPresent(documentEntity -> {
|
||||
DocumentResponseBean documentResponseBean = new DocumentResponseBean();
|
||||
documentResponseBean.setId(documentEntity.getId());
|
||||
documentResponseBean.setName(documentEntity.getFileName());
|
||||
documentResponseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
|
||||
documentResponseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
|
||||
documentResponseBean.setSourceId(documentEntity.getSourceId());
|
||||
documentResponseBean.setFilePath(documentEntity.getFilePath());
|
||||
documentResponseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||
documentResponseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||
documentResponseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
|
||||
evaluationDocResponse.setFileValue(List.of(documentResponseBean));
|
||||
evaluationDocResponse.setNameValue(doc.getNameValue());
|
||||
evaluationDocResponse.setValid(doc.getValid());
|
||||
evaluationDocResponse.setFieldId(doc.getFieldId());
|
||||
});
|
||||
}
|
||||
if (evaluationDocResponse.getFileValue() == null) {
|
||||
continue;
|
||||
}
|
||||
evaluationDocResponses.add(evaluationDocResponse);
|
||||
}
|
||||
response.setEvaluationDocument(evaluationDocResponses);
|
||||
}
|
||||
|
||||
private void populateBasicDetails(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response) {
|
||||
|
||||
response.setId(entity.getId());
|
||||
@@ -491,9 +589,15 @@ public class ApplicationEvaluationDao {
|
||||
if (existingEntityOptional.isPresent()) {
|
||||
entity = existingEntityOptional.get();
|
||||
oldApplicationEvaluation = Utils.getClonedEntityForData(entity);
|
||||
entity.setCriteria(Utils.convertObjectToJson(filterNonNullCriteria(processCriteria(entity, req))));
|
||||
entity.setChecklist(Utils.convertObjectToJson(filterNonNullChecklist(processChecklist(entity, req))));
|
||||
entity.setFile(Utils.convertObjectToJson(filterNonNullFields(processField(entity, req))));
|
||||
if(req.getCriteria()!=null) {
|
||||
entity.setCriteria(Utils.convertObjectToJson(processCriteria(entity, req)));
|
||||
}
|
||||
if(req.getChecklist()!=null) {
|
||||
entity.setChecklist(Utils.convertObjectToJson(processChecklist(entity, req)));
|
||||
}
|
||||
if(req.getFiles()!=null) {
|
||||
entity.setFile(Utils.convertObjectToJson(processField(entity, req)));
|
||||
}
|
||||
entity.setIsDeleted(false);
|
||||
setIfUpdated(entity::getNote, entity::setNote, req.getNote());
|
||||
setIfUpdated(entity::getMotivation, entity::setMotivation, req.getMotivation());
|
||||
@@ -509,6 +613,18 @@ public class ApplicationEvaluationDao {
|
||||
|
||||
}
|
||||
ApplicationStatusForEvaluation status = req.getApplicationStatus();
|
||||
// Fetch all amendment request entities associated with the evaluation ID
|
||||
List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities =
|
||||
applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(entity.getId());
|
||||
if(req.getEvaluationDocument()!=null) {
|
||||
updateApplicationEvaluation(assignedApplicationId, req.getEvaluationDocument());
|
||||
}
|
||||
// Fetch amendment details from the request
|
||||
if(req.getAmendmentDetails()!=null) {
|
||||
List<AmendmentDetailsRequest> amendmentDetailsRequests = req.getAmendmentDetails();
|
||||
|
||||
updateAmendmentDocumentsAndFormFields(applicationAmendmentRequestEntities, amendmentDetailsRequests);
|
||||
}
|
||||
|
||||
ApplicationEvaluationEntity savedEntity = applicationEvaluationRepository.save(entity);
|
||||
|
||||
@@ -524,22 +640,212 @@ public class ApplicationEvaluationDao {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAmendmentDocumentsAndFormFields(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
|
||||
// Iterate through amendment request entities
|
||||
|
||||
private List<ChecklistRequest> filterNonNullChecklist(List<ChecklistRequest> checklistRequests) {
|
||||
//
|
||||
Map<Long,List<AmendmentDetailsRequest>> amendmentFormFieldsMap = amendmentFormFields.stream().collect(Collectors.groupingBy(AmendmentDetailsRequest::getAmendmentId,HashMap::new,Collectors.toCollection(ArrayList::new)));
|
||||
// amendmentFormFields.forEach(data->{
|
||||
// ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestMap.get(data.getAmendmentId());
|
||||
// if (data.getFieldId().contains("amend_")){
|
||||
// updateAmendmentDocument(applicationAmendmentRequestEntity, data);
|
||||
// }
|
||||
// });
|
||||
applicationAmendmentRequestEntities.forEach(applicationAmendmentRequestEntity->{
|
||||
ApplicationAmendmentRequestEntity oldEntity = Utils.getClonedEntityForData(applicationAmendmentRequestEntity);
|
||||
updateAmendment(applicationAmendmentRequestEntity, amendmentFormFieldsMap.get(applicationAmendmentRequestEntity.getId()));
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().actionType(VersionActionTypeEnum.UPDATE).oldData(oldEntity).newData(applicationAmendmentRequestEntity).build());
|
||||
});
|
||||
applicationAmendmentRequestRepository.saveAll(applicationAmendmentRequestEntities);
|
||||
|
||||
return checklistRequests.stream().filter(request -> request.getValid() != null).collect(Collectors.toList());
|
||||
|
||||
// for (ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity : applicationAmendmentRequestEntities) {
|
||||
// // Process form fields if present
|
||||
// if (applicationAmendmentRequestEntity.getFormFields() != null) {
|
||||
// // Parse existing form fields from JSON
|
||||
// List<AmendmentFormFieldRequest> existingFormFields =
|
||||
// Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getFormFields(), AmendmentFormFieldRequest.class);
|
||||
//
|
||||
// // Prepare a new list to hold updated form fields
|
||||
// List<AmendmentFormFieldRequest> updatedFormFields = new ArrayList<>();
|
||||
//
|
||||
// // Map amendment details for quick lookup by amendment ID
|
||||
// Map<Long, Object> amendmentDetailsMap = amendmentFormFields.stream()
|
||||
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
||||
// .filter(details -> details.getFieldValue() != null) // Null check for getFormFieldDocuments
|
||||
// .collect(Collectors.toMap(
|
||||
// AmendmentDetailsRequest::getAmendmentId,
|
||||
// AmendmentDetailsRequest::getFieldValue
|
||||
// ));
|
||||
// // Get corresponding amendment documents for the current entity
|
||||
// List<AmendmentFormFieldRequest> amendmentDocuments = (List<AmendmentFormFieldRequest>) amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
|
||||
// if (amendmentDocuments != null) {
|
||||
// // Update existing form fields with new values
|
||||
// for (AmendmentFormFieldRequest existingField : existingFormFields) {
|
||||
// for (AmendmentFormFieldRequest newField : amendmentDocuments) {
|
||||
// if (existingField.getFieldId().equals(newField.getFieldId())) {
|
||||
// // Update fields if there are changes
|
||||
// Utils.setIfUpdated(existingField::getValid, existingField::setValid, newField.getValid());
|
||||
// Utils.setIfUpdated(existingField::getFieldValue, existingField::setFieldValue, newField.getFieldValue());
|
||||
//
|
||||
// updatedFormFields.add(existingField);
|
||||
// break; // Move to the next existing field
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Convert updated form fields back to JSON and save to the database
|
||||
// applicationAmendmentRequestEntity.setFormFields(Utils.convertListToJsonString(updatedFormFields));
|
||||
// applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Process amendment documents if present
|
||||
// if (applicationAmendmentRequestEntity.getAmendmentDocument() != null) {
|
||||
// String existingDocumentIds = applicationAmendmentRequestEntity.getAmendmentDocument();
|
||||
//
|
||||
// // Split comma-separated document IDs into a list
|
||||
// List<String> existingDocumentIdList = Arrays.stream(existingDocumentIds.split(","))
|
||||
// .map(String::trim)
|
||||
// .filter(id -> !id.isEmpty())
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
// List<String> updatedDocumentIdList = new ArrayList<>();
|
||||
// Map<Long, Object> amendmentDetailsMap = amendmentFormFields.stream()
|
||||
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
||||
// .collect(Collectors.toMap(
|
||||
// AmendmentDetailsRequest::getAmendmentId,
|
||||
// AmendmentDetailsRequest::getFieldValue
|
||||
// ));
|
||||
//
|
||||
// String amendmentDocumentIds = (String) amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
|
||||
// if (amendmentDocumentIds != null) {
|
||||
// // Split and validate new document IDs
|
||||
// List<String> newDocumentIdList = Arrays.stream(amendmentDocumentIds.split(","))
|
||||
// .map(String::trim)
|
||||
// .filter(id -> !id.isEmpty())
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
// for (String existingId : existingDocumentIdList) {
|
||||
// for (String newId : newDocumentIdList) {
|
||||
// if (existingId.equals(newId)) {
|
||||
// Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(newId));
|
||||
// if(documentEntity.isPresent()) {
|
||||
// updatedDocumentIdList.add(newId);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Add any new IDs not in the existing list
|
||||
// for (String newId : newDocumentIdList) {
|
||||
// if (!existingDocumentIdList.contains(newId)) {
|
||||
// Optional<DocumentEntity> documentEntity = documentRepository.findByIdAndNotDeleted(Long.valueOf(newId));
|
||||
// if(documentEntity.isPresent()) {
|
||||
// updatedDocumentIdList.add(newId);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// String updatedDocumentIds = String.join(",", updatedDocumentIdList);
|
||||
//
|
||||
// // Create the AmendmentDetailsResponseBean for structured data
|
||||
// AmendmentDetailsResponseBean amendmentDetails = new AmendmentDetailsResponseBean();
|
||||
// amendmentDetails.setAmendmentDocuments(updatedDocumentIds);
|
||||
// AmendmentDetailsRequest amendmentDetailsRequest = amendmentFormFields.stream()
|
||||
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
||||
// .findFirst()
|
||||
// .orElse(null);
|
||||
//
|
||||
// if (amendmentDetailsRequest != null) {
|
||||
// amendmentDetails.setValid(amendmentDetailsRequest.getValid());
|
||||
// } else {
|
||||
// amendmentDetails.setValid(false);
|
||||
// }
|
||||
// String amendmentDetailsJson = Utils.convertListToJsonString(Collections.singletonList(amendmentDetails));
|
||||
// applicationAmendmentRequestEntity.setAmendmentDocument(amendmentDetailsJson);
|
||||
// applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private List<CriteriaRequest> filterNonNullCriteria(List<CriteriaRequest> criteriaRequests) {
|
||||
private void updateAmendment(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity, List<AmendmentDetailsRequest> amendmentDetailsRequestList) {
|
||||
if (CollectionUtils.isEmpty(amendmentDetailsRequestList)) {
|
||||
return;
|
||||
}
|
||||
Map<String, AmendmentFormField> formFieldsMap = null;
|
||||
List<AmendmentFormField> formFieldList = Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
|
||||
if(Boolean.FALSE.equals(CollectionUtils.isEmpty(formFieldList))){
|
||||
formFieldsMap = formFieldList.stream().collect(Collectors.toMap(AmendmentFormField::getFieldId, Function.identity()));
|
||||
}
|
||||
updateAmendmentData(applicationAmendmentRequestEntity, amendmentDetailsRequestList, formFieldsMap);
|
||||
|
||||
return criteriaRequests.stream().filter(request -> request.getScore() != null && request.getValid() != null).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<FieldRequest> filterNonNullFields(List<FieldRequest> fieldRequests) {
|
||||
|
||||
return fieldRequests.stream().filter(request -> request.getValid() != null).collect(Collectors.toList());
|
||||
private static void updateAmendmentData(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity, List<AmendmentDetailsRequest> amendmentDetailsRequestList, Map<String, AmendmentFormField> formFieldsMap) {
|
||||
amendmentDetailsRequestList.forEach(amendmentDetailsRequest -> {
|
||||
if (amendmentDetailsRequest.getFieldId().contains("amend_")) {
|
||||
AmendmentDetailsResponseBean amendmentDetails = Utils.convertStringToObject(applicationAmendmentRequestEntity.getAmendmentDocument(), AmendmentDetailsResponseBean.class);
|
||||
if(amendmentDetails!=null) {
|
||||
amendmentDetails.setValid(amendmentDetailsRequest.getValid());
|
||||
applicationAmendmentRequestEntity.setAmendmentDocument(Utils.convertObjectToString(amendmentDetails));
|
||||
}
|
||||
} else if(Boolean.FALSE.equals(CollectionUtils.isEmpty(formFieldsMap))){
|
||||
AmendmentFormField amendmentFormField = formFieldsMap.get(amendmentDetailsRequest.getFieldId());
|
||||
amendmentFormField.setValid(amendmentDetailsRequest.getValid());
|
||||
}
|
||||
});
|
||||
applicationAmendmentRequestEntity.setFormFields(Utils.convertListToJsonString(formFieldsMap.values().stream().toList()));
|
||||
}
|
||||
|
||||
|
||||
// private void updateAmendmentDocuments(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
|
||||
// for (ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity : applicationAmendmentRequestEntities) {
|
||||
// // Skip if there are no amendment documents
|
||||
// if (applicationAmendmentRequestEntity.getAmendmentDocument() == null) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// // Parse existing amendment fields from JSON
|
||||
// List<AmendmentFieldRequest> existingAmendmentFields =
|
||||
// Utils.convertJsonStringToList(applicationAmendmentRequestEntity.getAmendmentDocument(), AmendmentFieldRequest.class);
|
||||
//
|
||||
// // Prepare a new list to hold updated amendment fields
|
||||
// List<AmendmentFieldRequest> updatedAmendmentFields = new ArrayList<>();
|
||||
//
|
||||
// // Map amendment details for quick lookup by amendment ID
|
||||
// Map<Long, List<AmendmentFieldRequest>> amendmentDetailsMap = amendmentFormFields.stream()
|
||||
// .filter(details -> applicationAmendmentRequestEntity.getId().equals(details.getAmendmentId()))
|
||||
// .collect(Collectors.toMap(AmendmentDetailsRequest::getAmendmentId, AmendmentDetailsRequest::getAmendmentDocuments));
|
||||
//
|
||||
// // Get corresponding amendment documents for the current entity
|
||||
// List<AmendmentFieldRequest> amendmentDocuments = amendmentDetailsMap.get(applicationAmendmentRequestEntity.getId());
|
||||
// if (amendmentDocuments == null) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// // Update existing amendment fields with new values
|
||||
// for (AmendmentFieldRequest existingField : existingAmendmentFields) {
|
||||
// for (AmendmentFieldRequest newField : amendmentDocuments) {
|
||||
// if (existingField.getFieldId().equals(newField.getFieldId())) {
|
||||
// // Update fields if there are changes
|
||||
// Utils.setIfUpdated(existingField::getIsValid, existingField::setIsValid, newField.getIsValid());
|
||||
// Utils.setIfUpdated(existingField::getFileValue, existingField::setFileValue, newField.getFileValue());
|
||||
// Utils.setIfUpdated(existingField::getNameValue, existingField::setNameValue, newField.getNameValue());
|
||||
//
|
||||
// updatedAmendmentFields.add(existingField);
|
||||
// break; // Move to the next existing field
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Convert updated fields back to JSON and save to the database
|
||||
// applicationAmendmentRequestEntity.setAmendmentDocument(Utils.convertListToJsonString(updatedAmendmentFields));
|
||||
// applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity);
|
||||
// }
|
||||
// }
|
||||
|
||||
private List<CriteriaRequest> processCriteria(ApplicationEvaluationEntity entity, ApplicationEvaluationRequest req) {
|
||||
|
||||
List<CriteriaRequest> incomingCriteriaList = Optional.ofNullable(req.getCriteria()).orElse(new ArrayList<>());
|
||||
@@ -659,11 +965,52 @@ public class ApplicationEvaluationDao {
|
||||
return entityOptional.get();
|
||||
}
|
||||
|
||||
public void validatePreinstructor(HttpServletRequest request,Long applicationId,Long assignedApplicationId){
|
||||
if (applicationId == null && assignedApplicationId == null) {
|
||||
throw new CustomValidationException(
|
||||
Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.EITHER_APPLICATION_OR_ASSIGNED_APPLICATION_ID_REQUIRED_MSG)
|
||||
);
|
||||
}
|
||||
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||
assignedApplicationsRepository.findByApplicationIdOrIdAndIsDeletedFalse(applicationId,assignedApplicationId);
|
||||
|
||||
public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(UserEntity user, Long applicationId, Long assignedApplicationId) {
|
||||
if (assignedApplicationId != null) {
|
||||
assignedApplicationsOptional = assignedApplicationsOptional.filter(a -> a.getId().equals(assignedApplicationId));
|
||||
}
|
||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsOptional
|
||||
.orElseThrow(() -> new CustomValidationException(
|
||||
Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.ASSIGNED_APPLICATION_NOT_FOUND_WITH_ID_MSG)
|
||||
));
|
||||
if (applicationId == null) {
|
||||
applicationId = assignedApplications.getApplication().getId();
|
||||
}
|
||||
validator.validatePreInstructor(request, assignedApplications.getUserId());
|
||||
}
|
||||
public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(HttpServletRequest request, UserEntity user, Long applicationID, Long assignedApplicationID) {
|
||||
Long applicationId;
|
||||
Long assignedApplicationId;
|
||||
validatePreinstructor(request, applicationID, assignedApplicationID);
|
||||
|
||||
if (applicationID == null && assignedApplicationID != null) {
|
||||
assignedApplicationId = assignedApplicationID;
|
||||
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||
assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplicationId);
|
||||
|
||||
applicationId = assignedApplicationsOptional.map(a -> a.getApplication().getId()).orElse(null);
|
||||
} else {
|
||||
applicationId = applicationID;
|
||||
if (assignedApplicationID == null && applicationID != null) {
|
||||
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||
assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
|
||||
|
||||
assignedApplicationId = assignedApplicationsOptional.map(AssignedApplicationsEntity::getId).orElse(null);
|
||||
} else {
|
||||
assignedApplicationId = assignedApplicationID;
|
||||
}
|
||||
}
|
||||
applicationService.validateApplication(applicationId);
|
||||
|
||||
Optional<ApplicationEvaluationEntity> entityOptional;
|
||||
|
||||
if (applicationId != null && assignedApplicationId != null) {
|
||||
@@ -675,11 +1022,19 @@ public class ApplicationEvaluationDao {
|
||||
} else {
|
||||
entityOptional = applicationEvaluationRepository.findFirstByIsDeletedFalseOrderByCreatedDateDesc();
|
||||
}
|
||||
return entityOptional.map(this::convertToResponse)
|
||||
return entityOptional.map(this::convertToResponse)
|
||||
.orElseGet(() -> {
|
||||
return getEvaluationResponseByApplicationid(user, applicationId, assignedApplicationId);
|
||||
});
|
||||
}
|
||||
private List<EvaluationDocumentRequest> prepareEvaluationDocumentBeanList(ApplicationEvaluationEntity entity) {
|
||||
List<EvaluationDocumentRequest> docRequest = new ArrayList<>();
|
||||
|
||||
if (entity != null && entity.getEvaluationDocument() != null) {
|
||||
docRequest = Utils.convertJsonToList(entity.getEvaluationDocument(), new TypeReference<List<EvaluationDocumentRequest>>() {});
|
||||
}
|
||||
return docRequest;
|
||||
}
|
||||
|
||||
public ApplicationEvaluationResponse getEvaluationResponseByApplicationid(UserEntity user, Long applicationId, Long assignedApplicationId) {
|
||||
|
||||
@@ -777,7 +1132,7 @@ public class ApplicationEvaluationDao {
|
||||
if (!mappedFieldMap.containsKey(formFieldId)) {
|
||||
// CriteriaMappedField mappedField = new CriteriaMappedField();
|
||||
CriteriaMappedField mappedField = populateMappedField(formFieldId, criteriaFormField, applicationForm, applicationId);
|
||||
if(mappedField != null) {
|
||||
if(mappedField != null) {
|
||||
mappedFieldMap.put(formFieldId, mappedField);
|
||||
}
|
||||
}
|
||||
@@ -906,7 +1261,7 @@ public class ApplicationEvaluationDao {
|
||||
}
|
||||
|
||||
|
||||
private DocumentResponseBean createDocumentResponseBean(DocumentEntity documentEntity) {
|
||||
public DocumentResponseBean createDocumentResponseBean(DocumentEntity documentEntity) {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
responseBean.setId(documentEntity.getId());
|
||||
responseBean.setName(documentEntity.getFileName());
|
||||
@@ -1425,9 +1780,14 @@ public class ApplicationEvaluationDao {
|
||||
ApplicationEvaluationEntity oldApplicationEvaluation = Utils.getClonedEntityForData(existingEntity);
|
||||
AssignedApplicationsEntity oldAssignedApplication = Utils.getClonedEntityForData(assignedApplicationsEntity);
|
||||
|
||||
List<ApplicationAmendmentRequestEntity> amendmentRequest = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndStatusAndIsDeletedFalse(existingEntity.getId(),List.of(ApplicationAmendmentRequestEnum.AWAITING.getValue(),ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue()));
|
||||
if(amendmentRequest !=null && Boolean.FALSE.equals(amendmentRequest.isEmpty())){
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_CANNOT_APPROVED_OR_REJECTED));
|
||||
}
|
||||
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());
|
||||
}
|
||||
entity = applicationEvaluationRepository.save(existingEntity);
|
||||
@@ -1443,11 +1803,6 @@ public class ApplicationEvaluationDao {
|
||||
}
|
||||
|
||||
|
||||
List<ApplicationAmendmentRequestEntity> amendmentRequest = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndStatusAndIsDeletedFalse(existingEntity.getId(),ApplicationAmendmentRequestEnum.AWAITING.getValue());
|
||||
if(amendmentRequest !=null && Boolean.FALSE.equals(amendmentRequest.isEmpty())){
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_CANNOT_APPROVED_OR_REJECTED));
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.APPROVED.getValue())))) {
|
||||
emailNotificationDao.sendAdmissibilityNotificationEmailForApprovedApplication(application);
|
||||
}
|
||||
@@ -1470,5 +1825,33 @@ public class ApplicationEvaluationDao {
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_EVALUATION_NOT_FOUND)));
|
||||
}
|
||||
|
||||
public ApplicationEvaluationResponse updateApplicationEvaluation(
|
||||
Long assignedApplicationId,
|
||||
List<EvaluationDocumentRequest> docRequest) {
|
||||
Optional<ApplicationEvaluationEntity> entityOptional=applicationEvaluationRepository.findByAssignedApplicationsEntity_IdAndIsDeletedFalse(assignedApplicationId);
|
||||
ApplicationEvaluationEntity applicationEvaluationEntity =null;
|
||||
ApplicationEvaluationEntity oldApplicationEvaluation = Utils.getClonedEntityForData(entityOptional.get());
|
||||
applicationEvaluationEntity = entityOptional.get();
|
||||
|
||||
if (docRequest != null) {
|
||||
List<EvaluationDocumentRequest> existingDocs = new ArrayList<>();
|
||||
|
||||
for (EvaluationDocumentRequest doc : docRequest) {
|
||||
if (doc.getFileValue() != null) {
|
||||
Long fileId = Long.valueOf(doc.getFileValue());
|
||||
documentService.validateDocument(fileId);
|
||||
existingDocs.add(doc);
|
||||
}
|
||||
}
|
||||
String updatedEvaluationDocJson = Utils.convertObjectToJson(existingDocs);
|
||||
applicationEvaluationEntity.setEvaluationDocument(updatedEvaluationDocJson);
|
||||
}
|
||||
ApplicationEvaluationEntity savedEntity = applicationEvaluationRepository.save(applicationEvaluationEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Upload Document in Application Evaluation" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluation).newData(savedEntity).build());
|
||||
return convertToResponse(savedEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -785,8 +785,9 @@ public class AppointmentDao {
|
||||
log.info("Async document upload completed for documentId: {}", documentId);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
// Return an immediate response indicating the process is in progress
|
||||
throw new CustomValidationException(Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_UPLOADING_IN_PROGRESS));
|
||||
// throw new CustomValidationException(Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_UPLOADING_IN_PROGRESS));
|
||||
}
|
||||
|
||||
private void uploadDocumentToExternalSystemSync(Long documentId, UploadDocToExternalSystemRequest docToExternalSystemRequest) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.gepafin.tendermanagement.enums.AssignedApplicationEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest;
|
||||
import net.gepafin.tendermanagement.model.request.UpdateAssignedApplicationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
|
||||
@@ -226,7 +227,7 @@ public class AssignedApplicationsDao {
|
||||
|
||||
|
||||
public AssignedApplicationsResponse updateAssignedApplication(HttpServletRequest request,
|
||||
Long id, AssignedApplicationsRequest updateRequest) {
|
||||
Long id, UpdateAssignedApplicationRequest updateRequest) {
|
||||
UserEntity updatedByUser = validator.validateUser(request);
|
||||
log.info("Updating assigned application with ID: {}", id);
|
||||
AssignedApplicationsEntity existingAssignment = validateAssignedApplication(id);
|
||||
@@ -237,7 +238,9 @@ public class AssignedApplicationsDao {
|
||||
setIfUpdated(existingAssignment::getNote, existingAssignment::setNote, updateRequest.getNote());
|
||||
setIfUpdated(existingAssignment::getStatus, existingAssignment::setStatus, updateRequest.getStatus().name());
|
||||
setIfUpdated(existingAssignment::getAssignedBy, existingAssignment::setAssignedBy, updatedByUser.getId());
|
||||
|
||||
setIfUpdated(existingAssignment::getUserId, existingAssignment::setUserId, updateRequest.getUserId());
|
||||
Optional<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByAssignedApplicationsEntity_IdAndIsDeletedFalse(id);
|
||||
entityOptional.ifPresent(applicationEvaluationEntity -> setIfUpdated(applicationEvaluationEntity::getUserId, applicationEvaluationEntity::setUserId, updateRequest.getUserId()));
|
||||
existingAssignment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
|
||||
AssignedApplicationsEntity updatedAssignment = saveAssignedApplication(existingAssignment, oldAssignedApplicationEntity, VersionActionTypeEnum.UPDATE);
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.stream.Collectors;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
@@ -54,7 +55,7 @@ public class DocumentDao {
|
||||
private S3PathConfig s3ConfigBean;
|
||||
|
||||
@Autowired
|
||||
private ApplicationRepository applicationFormRepository;
|
||||
private ApplicationRepository applicationRepository;
|
||||
|
||||
@Autowired
|
||||
ApplicationService applicationService;
|
||||
@@ -65,6 +66,9 @@ public class DocumentDao {
|
||||
@Autowired
|
||||
ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||
|
||||
@Value("${aws.s3.bucket.name}")
|
||||
private String bucketName;
|
||||
|
||||
@@ -77,7 +81,7 @@ public class DocumentDao {
|
||||
// @Value("${aws.s3.url.folder}")
|
||||
// private String s3Folder;
|
||||
|
||||
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
||||
public List<DocumentResponseBean> uploadFiles(Long userId,List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
||||
|
||||
List<DocumentEntity> documentEntities = new ArrayList<>();
|
||||
Long source = resolveSourceId(sourceId, sourceType);
|
||||
@@ -91,6 +95,7 @@ public class DocumentDao {
|
||||
documentEntity.setType(fileType.getValue());
|
||||
documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
|
||||
documentEntity.setIsDeleted(false);
|
||||
documentEntity.setUploadedBy(userId);
|
||||
documentEntities.add(documentEntity);
|
||||
}
|
||||
}
|
||||
@@ -116,6 +121,14 @@ public class DocumentDao {
|
||||
userActionContext = UserActionContextEnum.UPLOAD_APPLICATION_DOCUMENT;
|
||||
} else if (fileType.equals(DocumentTypeEnum.IMAGES) && sourceType.equals(DocumentSourceTypeEnum.APPLICATION)) {
|
||||
userActionContext = UserActionContextEnum.UPLOAD_APPLICATION_IMAGES;
|
||||
}else if (fileType.equals(DocumentTypeEnum.DOCUMENT) && sourceType.equals(DocumentSourceTypeEnum.AMENDMENT)) {
|
||||
userActionContext = UserActionContextEnum.UPLOAD_AMENDMENT_DOCUMENT;
|
||||
} else if (fileType.equals(DocumentTypeEnum.IMAGES) && sourceType.equals(DocumentSourceTypeEnum.AMENDMENT)) {
|
||||
userActionContext = UserActionContextEnum.UPLOAD_AMENDMENT_IMAGES;
|
||||
}else if (fileType.equals(DocumentTypeEnum.DOCUMENT) && sourceType.equals(DocumentSourceTypeEnum.EVALUATION)) {
|
||||
userActionContext = UserActionContextEnum.UPLOAD_EVALUATION_DOCUMENT;
|
||||
} else if (fileType.equals(DocumentTypeEnum.IMAGES) && sourceType.equals(DocumentSourceTypeEnum.EVALUATION)) {
|
||||
userActionContext = UserActionContextEnum.UPLOAD_EVALUATION_IMAGES;
|
||||
}
|
||||
|
||||
return userActionContext;
|
||||
@@ -137,15 +150,21 @@ public class DocumentDao {
|
||||
|
||||
Long applicationId = 0L;
|
||||
Long amendmentId = 0L;
|
||||
Long evaluationId = 0L;
|
||||
Long callId = sourceId;
|
||||
if (type == DocumentSourceTypeEnum.APPLICATION) {
|
||||
applicationId = sourceId;
|
||||
callId = applicationFormRepository.findCallIdById(applicationId);
|
||||
callId = applicationRepository.findCallIdById(applicationId);
|
||||
} else if (type == DocumentSourceTypeEnum.AMENDMENT) {
|
||||
amendmentId = sourceId;
|
||||
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}else if (type == DocumentSourceTypeEnum.EVALUATION) {
|
||||
evaluationId = sourceId;
|
||||
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}
|
||||
try {
|
||||
String s3Path = generateS3Path(type, callId, applicationId, amendmentId);
|
||||
@@ -188,6 +207,7 @@ public class DocumentDao {
|
||||
Long callId = null;
|
||||
Long applicationId = null;
|
||||
Long amendmentId = null;
|
||||
Long evaluationId = null;
|
||||
|
||||
if (DocumentSourceTypeEnum.CALL.getValue().equalsIgnoreCase(documentEntity.getSource())) {
|
||||
callId = documentEntity.getSourceId();
|
||||
@@ -201,8 +221,12 @@ public class DocumentDao {
|
||||
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
} else if(DocumentSourceTypeEnum.EVALUATION.getValue().equalsIgnoreCase(documentEntity.getSource())){
|
||||
evaluationId = documentEntity.getSourceId();
|
||||
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}
|
||||
|
||||
deleteFileFromS3(documentEntity, callId, applicationId,amendmentId);
|
||||
|
||||
}
|
||||
@@ -241,8 +265,9 @@ public class DocumentDao {
|
||||
Long callId=null;
|
||||
Long applicationId=null;
|
||||
Long amendmentId=null;
|
||||
Long evaluationId=null;
|
||||
if (type.equals(DocumentSourceTypeEnum.APPLICATION)) {
|
||||
callId = applicationFormRepository.findCallIdById(id);
|
||||
callId = applicationRepository.findCallIdById(id);
|
||||
applicationId = id;
|
||||
}
|
||||
else if(type.equals(DocumentSourceTypeEnum.AMENDMENT)){
|
||||
@@ -250,7 +275,13 @@ public class DocumentDao {
|
||||
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}else if(type.equals(DocumentSourceTypeEnum.EVALUATION)){
|
||||
evaluationId = id;
|
||||
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}
|
||||
|
||||
else {
|
||||
callId = id;
|
||||
applicationId = 0L;
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.enums.ProtocolTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
@@ -42,7 +43,7 @@ public class ProtocolDao {
|
||||
return (maxProtocolNumber != null) ? maxProtocolNumber + 1 : startNumber;
|
||||
}
|
||||
|
||||
public ProtocolEntity createProtocolEntity(ApplicationEntity applicationEntity,Long protocolNumber, Long hubId){
|
||||
public ProtocolEntity createProtocolEntity(ApplicationEntity applicationEntity,Long protocolNumber, Long hubId,Boolean isForApplication){
|
||||
ProtocolEntity protocolEntity=new ProtocolEntity();
|
||||
protocolEntity.setCall(applicationEntity.getCall().getId());
|
||||
LocalDateTime utcDateTime = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
||||
@@ -51,6 +52,11 @@ public class ProtocolDao {
|
||||
protocolEntity.setTime(LocalTime.now());
|
||||
protocolEntity.setApplicationId(applicationEntity.getId());
|
||||
protocolEntity.setHubId(hubId);
|
||||
if(Boolean.TRUE.equals(isForApplication)){
|
||||
protocolEntity.setType(ProtocolTypeEnum.INPUT.getValue());
|
||||
}else {
|
||||
protocolEntity.setType(ProtocolTypeEnum.OUTPUT.getValue());
|
||||
}
|
||||
protocolRepository.save(protocolEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for "create protocol" operation. **/
|
||||
|
||||
@@ -448,12 +448,14 @@ public class UserDao {
|
||||
return authService.validateNewUserToken(token);
|
||||
}
|
||||
|
||||
public List<UserResponseBean> getAllUsers(UserEntity user, Long roleId) {
|
||||
public List<UserResponseBean> getAllUsers(UserEntity user, List<Long> roleIds) {
|
||||
List<UserEntity> users;
|
||||
if (roleId != null) {
|
||||
log.info("Fetching users by role ID: {}", roleId);
|
||||
RoleEntity roleEntity=roleService.validateRole(roleId);
|
||||
users = userRepository.findByRoleEntityIdAndHubId(roleEntity.getId(), user.getHub().getId());
|
||||
if (roleIds != null) {
|
||||
log.info("Fetching users by role ID: {}", roleIds);
|
||||
List<RoleEntity> roleEntities = roleIds.stream()
|
||||
.map(roleService::validateRole) // Assuming `validateRole` takes an ID and returns a RoleEntity
|
||||
.collect(Collectors.toList());
|
||||
users = userRepository.findByRoleEntityIdInAndHubId(roleIds, user.getHub().getId());
|
||||
} else {
|
||||
log.info("Fetching all users");
|
||||
users = userRepository.findByHubId(user.getHub().getId());
|
||||
@@ -462,7 +464,7 @@ public class UserDao {
|
||||
.map(this::convertUserEntityToUserResponse)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
log.info("Total users found with role ID {}: {}", roleId, userResponseBeans.size());
|
||||
log.info("Total users found with role ID {}: {}", roleIds, userResponseBeans.size());
|
||||
return userResponseBeans;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user