Updated response
This commit is contained in:
@@ -5,7 +5,6 @@ import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationEvaluationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest;
|
||||
@@ -22,7 +21,6 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -53,7 +51,11 @@ public class ApplicationEvaluationDao {
|
||||
private ApplicationFormRepository applicationFormRepository;
|
||||
@Autowired
|
||||
private ApplicationFormFieldRepository applicationFormFieldRepository;
|
||||
@Autowired AssignedApplicationsRepository assignedApplicationsRepository;
|
||||
@Autowired
|
||||
private AssignedApplicationsRepository assignedApplicationsRepository;
|
||||
@Autowired
|
||||
private CriteriaFormFieldRepository criteriaFormFieldRepository;
|
||||
|
||||
|
||||
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req,Long applicationId) {
|
||||
ApplicationEvaluationEntity entity = new ApplicationEvaluationEntity();
|
||||
@@ -67,7 +69,7 @@ public class ApplicationEvaluationDao {
|
||||
entity.setFile(Utils.convertObjectToJson(req.getField()));
|
||||
entity.setNote(req.getNote());
|
||||
entity.setIsDeleted(false);
|
||||
entity.setStatus(ApplicationEvaluationStatusTypeEnum.DRAFT.getValue());
|
||||
entity.setStatus(ApplicationEvaluationStatusTypeEnum.OPEN.getValue());
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -106,8 +108,7 @@ public class ApplicationEvaluationDao {
|
||||
: new ArrayList<>();
|
||||
|
||||
List<CriteriaResponse> criteriaResponsesFromDB = getCriteriaResponse(entity.getApplicationId());
|
||||
addMissingCriteriaResponses(criteriaResponsesFromEntity, criteriaResponsesFromDB);
|
||||
|
||||
addMissingCriteriaResponses(criteriaResponsesFromEntity, criteriaResponsesFromDB,entity.getApplicationId());
|
||||
criteriaResponsesFromEntity.forEach(criteriaResponse -> {
|
||||
EvaluationCriteriaEntity matchingEvaluationCriteria = evaluationCriterias.stream()
|
||||
.filter(evaluationCriteria -> evaluationCriteria.getId().equals(criteriaResponse.getId()))
|
||||
@@ -117,23 +118,75 @@ public class ApplicationEvaluationDao {
|
||||
if (matchingEvaluationCriteria != null) {
|
||||
criteriaResponse.setLabel(matchingEvaluationCriteria.getLookupData().getValue());
|
||||
criteriaResponse.setMaxScore(matchingEvaluationCriteria.getScore());
|
||||
|
||||
List<CriteriaMappedField> mappedFields = getMappedFieldsForCriteria(matchingEvaluationCriteria.getId(), entity.getApplicationId());
|
||||
criteriaResponse.setCriteriaMappedFields(mappedFields);
|
||||
}
|
||||
});
|
||||
|
||||
response.setCriteria(criteriaResponsesFromEntity);
|
||||
}
|
||||
|
||||
private void addMissingCriteriaResponses(List<CriteriaResponse> criteriaResponsesFromEntity, List<CriteriaResponse> criteriaResponsesFromDB) {
|
||||
private void addMissingCriteriaResponses(List<CriteriaResponse> criteriaResponsesFromEntity, List<CriteriaResponse> criteriaResponsesFromDB,Long applicationId) {
|
||||
Set<Long> existingCriteriaIds = criteriaResponsesFromEntity.stream()
|
||||
.map(CriteriaResponse::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for (CriteriaResponse dbResponse : criteriaResponsesFromDB) {
|
||||
if (!existingCriteriaIds.contains(dbResponse.getId())) {
|
||||
List<CriteriaMappedField> mappedFields = getMappedFieldsForCriteria(dbResponse.getId(), applicationId);
|
||||
dbResponse.setCriteriaMappedFields(mappedFields);
|
||||
criteriaResponsesFromEntity.add(dbResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
private List<CriteriaMappedField> getMappedFieldsForCriteria(Long evaluationCriteriaId, Long applicationId) {
|
||||
List<CriteriaFormFieldEntity> criteriaFormFields = criteriaFormFieldRepository
|
||||
.findByEvaluationCriteriaIdAndIsDeletedFalse(evaluationCriteriaId);
|
||||
List<CriteriaMappedField> mappedFields = new ArrayList<>();
|
||||
|
||||
Set<String> uniqueFieldIds = new HashSet<>();
|
||||
|
||||
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
|
||||
for (ApplicationFormEntity applicationForm : applicationForms) {
|
||||
for (CriteriaFormFieldEntity formField : criteriaFormFields) {
|
||||
String formFieldId = formField.getFormFieldId();
|
||||
|
||||
if (!uniqueFieldIds.contains(formFieldId)) {
|
||||
CriteriaMappedField mappedField = new CriteriaMappedField();
|
||||
mappedField.setId(formFieldId);
|
||||
|
||||
FormEntity formEntity = formRepository.findById(formField.getFormId()).orElse(null);
|
||||
if (formEntity != null) {
|
||||
List<ContentResponseBean> contentBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
||||
contentBeans.stream()
|
||||
.filter(contentBean -> contentBean.getId().equals(formFieldId))
|
||||
.findFirst()
|
||||
.ifPresent(contentBean -> {
|
||||
String label = contentBean.getLabel();
|
||||
if (contentBean.getSettings() != null) {
|
||||
for (SettingResponseBean setting : contentBean.getSettings()) {
|
||||
if ("label".equals(setting.getName())) {
|
||||
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
mappedField.setFieldLabel(label);
|
||||
});
|
||||
}
|
||||
|
||||
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
|
||||
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(formFieldId, applicationForm.getId(), applicationId);
|
||||
|
||||
formFieldEntityOptional.ifPresent(field -> mappedField.setFieldValue(field.getFieldValue()));
|
||||
|
||||
mappedFields.add(mappedField);
|
||||
uniqueFieldIds.add(formFieldId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mappedFields;
|
||||
}
|
||||
|
||||
private void setChecklistResponses(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response, List<CallTargetAudienceChecklistEntity> checklistEntities) {
|
||||
List<ChecklistResponse> checklistResponsesFromEntity = entity.getChecklist() != null
|
||||
@@ -173,24 +226,69 @@ public class ApplicationEvaluationDao {
|
||||
List<FieldResponse> fieldResponsesFromEntity = entity.getFile() != null
|
||||
? Utils.convertJsonToList(entity.getFile(), new TypeReference<List<FieldResponse>>() {})
|
||||
: new ArrayList<>();
|
||||
|
||||
List<FieldResponse> fieldResponsesFromDB = getFieldResponses(entity.getApplicationId());
|
||||
addMissingFieldResponses(fieldResponsesFromEntity, fieldResponsesFromDB);
|
||||
|
||||
Set<String> processedFieldIds = new HashSet<>();
|
||||
|
||||
fieldResponsesFromEntity.forEach(fieldResponse -> {
|
||||
if (processedFieldIds.contains(fieldResponse.getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
applicationFormEntities.forEach(applicationForm -> {
|
||||
FormEntity formEntity = applicationForm.getForm();
|
||||
if (formEntity != null) {
|
||||
List<ContentResponseBean> contentResponseBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
||||
contentResponseBeans.forEach(contentResponseBean -> {
|
||||
if ("fileupload".equals(contentResponseBean.getName()) && contentResponseBean.getId().equals(fieldResponse.getId())) {
|
||||
fieldResponse.setLabel(contentResponseBean.getLabel());
|
||||
String label = null;
|
||||
if (contentResponseBean.getSettings() != null) {
|
||||
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
||||
if ("label".equals(setting.getName())) {
|
||||
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldResponse.setLabel(label);
|
||||
|
||||
Optional<ApplicationFormFieldEntity> optionalFormField = applicationFormFieldRepository
|
||||
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
||||
fieldResponse.getId(), applicationForm.getId(), entity.getApplicationId()
|
||||
);
|
||||
|
||||
if (optionalFormField.isPresent()) {
|
||||
ApplicationFormFieldEntity formField = optionalFormField.get();
|
||||
if (formField.getFieldValue() != null) {
|
||||
String[] documentIds = formField.getFieldValue().split(",");
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
|
||||
for (String docId : documentIds) {
|
||||
Long documentId = Long.valueOf(docId.trim());
|
||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
responseBean.setId(documentEntity.getId());
|
||||
responseBean.setName(documentEntity.getFileName());
|
||||
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
|
||||
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
|
||||
responseBean.setSourceId(documentEntity.getSourceId());
|
||||
responseBean.setFilePath(documentEntity.getFilePath());
|
||||
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||
documentResponseBeans.add(responseBean);
|
||||
});
|
||||
}
|
||||
|
||||
fieldResponse.setFileDetail(documentResponseBeans);
|
||||
}
|
||||
}
|
||||
processedFieldIds.add(fieldResponse.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
response.setFiles(fieldResponsesFromEntity);
|
||||
}
|
||||
|
||||
@@ -209,22 +307,25 @@ public class ApplicationEvaluationDao {
|
||||
private void setApplicationDetails(ApplicationEvaluationResponse response, ApplicationEvaluationEntity entity) {
|
||||
ApplicationEntity application = applicationService.validateApplication(entity.getApplicationId() != null ? entity.getApplicationId(): null);
|
||||
UserEntity user = userService.validateUser(application.getUserId());
|
||||
|
||||
CallEntity call = callRepository.findCallEntityByApplicationId(entity.getApplicationId());
|
||||
|
||||
String firstName = user.getFirstName() != null ? user.getFirstName() : "";
|
||||
String lastName = user.getLastName() != null ? user.getLastName() : "";
|
||||
|
||||
String beneficiary = String.join(" ", firstName, lastName).trim();
|
||||
response.setBeneficiary(beneficiary);
|
||||
|
||||
response.setMinScore(call.getThreshold());
|
||||
response.setCallName(application.getCall().getName());
|
||||
response.setProtocolNumber(application.getProtocol() != null ? application.getProtocol().getProtocolNumber() : null);
|
||||
response.setSubmissionDate(application.getSubmissionDate());
|
||||
response.setEvaluationDate(application.getSubmissionDate().plusDays(30));
|
||||
response.setSubmissionDate(application.getSubmissionDate()!= null ? application.getSubmissionDate(): null);
|
||||
response.setEvaluationDate(application.getSubmissionDate()!= null ? application.getSubmissionDate().plusDays(30):null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ApplicationEvaluationResponse createOrUpdateApplicationEvaluation(UserEntity user, ApplicationEvaluationRequest req,Long applicationId) {
|
||||
Optional<ApplicationEvaluationEntity> existingEntityOptional = applicationEvaluationRepository.findByApplicationId(applicationId);
|
||||
Optional<ApplicationEvaluationEntity> existingEntityOptional = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
|
||||
ApplicationEvaluationEntity entity;
|
||||
|
||||
if (existingEntityOptional.isPresent()) {
|
||||
@@ -368,26 +469,51 @@ public class ApplicationEvaluationDao {
|
||||
}
|
||||
|
||||
|
||||
public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(UserEntity user, Long applicationId) {
|
||||
applicationService.validateApplication(applicationId);
|
||||
Optional<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByApplicationId(applicationId);
|
||||
return entityOptional.map(this::convertToResponse).orElseGet(() -> getEvaluationResponseByApplicationid(user, applicationId));
|
||||
public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(UserEntity user, Long applicationId, Long assignedApplicationId) {
|
||||
|
||||
applicationService.validateApplication(applicationId);
|
||||
|
||||
Optional<ApplicationEvaluationEntity> entityOptional;
|
||||
|
||||
if (applicationId != null && assignedApplicationId != null) {
|
||||
entityOptional = applicationEvaluationRepository.findByApplicationIdAndAssignedApplicationsEntity_IdAndIsDeletedFalse(applicationId, assignedApplicationId);
|
||||
} else if (applicationId != null) {
|
||||
entityOptional = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
|
||||
} else if (assignedApplicationId != null) {
|
||||
entityOptional = applicationEvaluationRepository.findByAssignedApplicationsEntity_IdAndIsDeletedFalse(assignedApplicationId);
|
||||
} else {
|
||||
entityOptional = applicationEvaluationRepository.findFirstByIsDeletedFalseOrderByCreatedDateDesc();
|
||||
}
|
||||
return entityOptional.map(this::convertToResponse)
|
||||
.orElseGet(() -> {
|
||||
return getEvaluationResponseByApplicationid(user, applicationId, assignedApplicationId);
|
||||
});
|
||||
}
|
||||
public ApplicationEvaluationResponse getEvaluationResponseByApplicationid(UserEntity user, Long applicationId) {
|
||||
|
||||
public ApplicationEvaluationResponse getEvaluationResponseByApplicationid(UserEntity user, Long applicationId,Long assignedApplicationId) {
|
||||
ApplicationEvaluationEntity entity = new ApplicationEvaluationEntity();
|
||||
ApplicationEvaluationResponse response = new ApplicationEvaluationResponse();
|
||||
|
||||
CallEntity call = callRepository.findCallEntityByApplicationId(applicationId);
|
||||
CallEntity call=null;
|
||||
AssignedApplicationsEntity assignedApplications=null;
|
||||
if (applicationId != null) {
|
||||
call = callRepository.findCallEntityByApplicationId(applicationId);
|
||||
assignedApplications = assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null);
|
||||
} else if (assignedApplicationId != null) {
|
||||
call = callRepository.findCallEntityByApplicationId(assignedApplicationId);
|
||||
assignedApplications = assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplicationId).orElseThrow(()->
|
||||
new ResourceNotFoundException(Status.NOT_FOUND,Translator.toLocale(GepafinConstant.ASSIGNED_APPLICATION_NOT_FOUND_MSG)));
|
||||
}
|
||||
else {
|
||||
call = callRepository.findCallEntityByApplicationId(applicationId);
|
||||
assignedApplications = assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null);}
|
||||
List<EvaluationCriteriaEntity> evaluationCriterias = evaluationCriteriaRepository.findByCallId(call.getId());
|
||||
List<CallTargetAudienceChecklistEntity> checklistEntities = callTargetAudienceChecklistRepository.findByCallId(call.getId());
|
||||
List<ApplicationFormEntity> applicationFormEntities = applicationFormRepository.findByApplicationId(applicationId);
|
||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null);
|
||||
response.setApplicationId(applicationId);
|
||||
response.setAssignedApplicationId(assignedApplications.getId());
|
||||
response.setNote(null);
|
||||
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(ApplicationEvaluationStatusTypeEnum.DRAFT.getValue()));
|
||||
|
||||
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(ApplicationEvaluationStatusTypeEnum.OPEN.getValue()));
|
||||
response.setMinScore(call.getThreshold());
|
||||
setCriteriaResponses(entity, applicationId, response, evaluationCriterias);
|
||||
setChecklistResponses(entity, applicationId, response, checklistEntities);
|
||||
setFileResponses(entity, applicationId, response, applicationFormEntities);
|
||||
@@ -408,9 +534,51 @@ public class ApplicationEvaluationDao {
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
|
||||
Map<String, CriteriaMappedField> mappedFieldMap = new HashMap<>();
|
||||
|
||||
if (matchingEvaluationCriteria != null) {
|
||||
criteriaResponse.setLabel(matchingEvaluationCriteria.getLookupData().getValue());
|
||||
criteriaResponse.setMaxScore(matchingEvaluationCriteria.getScore());
|
||||
|
||||
List<CriteriaFormFieldEntity> criteriaFormFields = criteriaFormFieldRepository
|
||||
.findByEvaluationCriteriaIdAndIsDeletedFalse(matchingEvaluationCriteria.getId());
|
||||
|
||||
for (ApplicationFormEntity applicationForm : applicationForms) {
|
||||
for (CriteriaFormFieldEntity criteriaFormField : criteriaFormFields) {
|
||||
String formFieldId = criteriaFormField.getFormFieldId();
|
||||
if (!mappedFieldMap.containsKey(formFieldId)) {
|
||||
CriteriaMappedField mappedField = new CriteriaMappedField();
|
||||
mappedField.setId(formFieldId);
|
||||
FormEntity formEntity = formRepository.findById(criteriaFormField.getFormId()).orElse(null);
|
||||
|
||||
if (formEntity != null) {
|
||||
List<ContentResponseBean> contentResponseBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
||||
contentResponseBeans.stream()
|
||||
.filter(bean -> bean.getId().equals(formFieldId))
|
||||
.findFirst()
|
||||
.ifPresent(contentResponseBean -> {
|
||||
String label = contentResponseBean.getLabel();
|
||||
if (contentResponseBean.getSettings() != null) {
|
||||
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
||||
if ("label".equals(setting.getName())) {
|
||||
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
mappedField.setFieldLabel(label);
|
||||
});
|
||||
}
|
||||
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
|
||||
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(formFieldId, applicationForm.getId(), applicationId);
|
||||
|
||||
formFieldEntityOptional.ifPresent(formField -> mappedField.setFieldValue(formField.getFieldValue()));
|
||||
mappedFieldMap.put(formFieldId, mappedField);
|
||||
}
|
||||
}
|
||||
}
|
||||
criteriaResponse.setCriteriaMappedFields(new ArrayList<>(mappedFieldMap.values()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -435,20 +603,62 @@ public class ApplicationEvaluationDao {
|
||||
|
||||
response.setChecklist(checklistResponses);
|
||||
}
|
||||
|
||||
private void setFileResponses(ApplicationEvaluationEntity entity, Long applicationId, ApplicationEvaluationResponse response, List<ApplicationFormEntity> applicationFormEntities) {
|
||||
List<FieldResponse> fieldResponses = entity.getFile() != null
|
||||
? Utils.convertJsonToList(entity.getFile(), new TypeReference<List<FieldResponse>>() {})
|
||||
: getFieldResponses(applicationId);
|
||||
Set<String> processedFieldIds = new HashSet<>();
|
||||
|
||||
fieldResponses.forEach(fieldResponse -> {
|
||||
if (processedFieldIds.contains(fieldResponse.getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
applicationFormEntities.forEach(applicationForm -> {
|
||||
FormEntity formEntity = applicationForm.getForm();
|
||||
if (formEntity != null) {
|
||||
List<ContentResponseBean> contentResponseBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
||||
contentResponseBeans.forEach(contentResponseBean -> {
|
||||
if ("fileupload".equals(contentResponseBean.getName()) && contentResponseBean.getId().equals(fieldResponse.getId())) {
|
||||
fieldResponse.setLabel(contentResponseBean.getLabel());
|
||||
String label = null;
|
||||
if (contentResponseBean.getSettings() != null) {
|
||||
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
||||
if ("label".equals(setting.getName())) {
|
||||
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldResponse.setLabel(label);
|
||||
|
||||
Optional<ApplicationFormFieldEntity> optionalFormField = applicationFormFieldRepository
|
||||
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(fieldResponse.getId(), applicationForm.getId(), applicationId);
|
||||
|
||||
if (optionalFormField.isPresent() && optionalFormField.get().getFieldValue() != null) {
|
||||
String[] documentIds = optionalFormField.get().getFieldValue().split(",");
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
|
||||
for (String docId : documentIds) {
|
||||
Long documentId = Long.valueOf(docId.trim());
|
||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
responseBean.setId(documentEntity.getId());
|
||||
responseBean.setName(documentEntity.getFileName());
|
||||
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
|
||||
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
|
||||
responseBean.setSourceId(documentEntity.getSourceId());
|
||||
responseBean.setFilePath(documentEntity.getFilePath());
|
||||
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||
documentResponseBeans.add(responseBean);
|
||||
});
|
||||
}
|
||||
|
||||
fieldResponse.setFileDetail(documentResponseBeans);
|
||||
}
|
||||
|
||||
// Mark this field ID as processed to prevent duplicates
|
||||
processedFieldIds.add(fieldResponse.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -458,6 +668,7 @@ public class ApplicationEvaluationDao {
|
||||
response.setFiles(fieldResponses);
|
||||
}
|
||||
|
||||
|
||||
private void setApplicationDetails(ApplicationEvaluationResponse response, Long applicationId, UserEntity user) {
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
userService.validateUser(application.getUserId());
|
||||
@@ -469,13 +680,15 @@ public class ApplicationEvaluationDao {
|
||||
|
||||
response.setCallName(application.getCall().getName());
|
||||
response.setProtocolNumber(application.getProtocol() != null ? application.getProtocol().getProtocolNumber() : null);
|
||||
response.setSubmissionDate(application.getSubmissionDate());
|
||||
response.setEvaluationDate(application.getSubmissionDate().plusDays(30));
|
||||
response.setSubmissionDate(application.getSubmissionDate()!= null ? application.getSubmissionDate(): null);
|
||||
response.setEvaluationDate(application.getSubmissionDate()!= null ? application.getSubmissionDate().plusDays(30):null);
|
||||
|
||||
}
|
||||
|
||||
List<CriteriaResponse> getCriteriaResponse(Long applicationId){ CallEntity call = callRepository.findCallEntityByApplicationId(applicationId);
|
||||
List<CriteriaResponse> getCriteriaResponse(Long applicationId) {
|
||||
CallEntity call = callRepository.findCallEntityByApplicationId(applicationId);
|
||||
List<EvaluationCriteriaEntity> evaluationCriterias = evaluationCriteriaRepository.findByCallId(call.getId());
|
||||
|
||||
List<CriteriaResponse> criteriaResponses = evaluationCriterias.stream().map(criteria -> {
|
||||
CriteriaResponse response = new CriteriaResponse();
|
||||
response.setId(criteria.getId());
|
||||
@@ -484,6 +697,54 @@ public class ApplicationEvaluationDao {
|
||||
response.setMaxScore(criteria.getScore());
|
||||
response.setValid(null);
|
||||
|
||||
List<CriteriaFormFieldEntity> criteriaFormFields = criteriaFormFieldRepository
|
||||
.findByEvaluationCriteriaIdAndIsDeletedFalse(criteria.getId());
|
||||
|
||||
List<CriteriaMappedField> mappedFields = new ArrayList<>();
|
||||
Set<String> processedFormFieldIds = new HashSet<>();
|
||||
|
||||
for (CriteriaFormFieldEntity criteriaFormField : criteriaFormFields) {
|
||||
if (processedFormFieldIds.contains(criteriaFormField.getFormFieldId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CriteriaMappedField mappedField = new CriteriaMappedField();
|
||||
mappedField.setId(criteriaFormField.getFormFieldId());
|
||||
|
||||
FormEntity formEntity = formRepository.findById(criteriaFormField.getFormId()).orElse(null);
|
||||
if (formEntity != null) {
|
||||
List<ContentResponseBean> contentResponseBeans = Utils.convertJsonStringToList(
|
||||
formEntity.getContent(), ContentResponseBean.class);
|
||||
contentResponseBeans.stream()
|
||||
.filter(bean -> bean.getId().equals(criteriaFormField.getFormFieldId()))
|
||||
.findFirst()
|
||||
.ifPresent(contentResponseBean -> {
|
||||
String label = contentResponseBean.getLabel();
|
||||
if (contentResponseBean.getSettings() != null) {
|
||||
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
||||
if ("label".equals(setting.getName())) {
|
||||
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
mappedField.setFieldLabel(label);
|
||||
});
|
||||
}
|
||||
|
||||
applicationFormRepository.findByApplicationId(applicationId).stream()
|
||||
.flatMap(applicationForm -> applicationFormFieldRepository
|
||||
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
||||
criteriaFormField.getFormFieldId(), applicationForm.getId(), applicationId)
|
||||
.stream())
|
||||
.findFirst()
|
||||
.ifPresent(formField -> mappedField.setFieldValue(formField.getFieldValue()));
|
||||
|
||||
mappedFields.add(mappedField);
|
||||
processedFormFieldIds.add(criteriaFormField.getFormFieldId());
|
||||
}
|
||||
|
||||
response.setCriteriaMappedFields(mappedFields);
|
||||
return response;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
@@ -503,7 +764,6 @@ public class ApplicationEvaluationDao {
|
||||
|
||||
return checklistResponses;
|
||||
}
|
||||
|
||||
public List<FieldResponse> getFieldResponses(Long applicationId) {
|
||||
List<ApplicationFormEntity> applicationFormEntities = applicationFormRepository.findByApplicationId(applicationId);
|
||||
List<FieldResponse> fieldResponses = new ArrayList<>();
|
||||
@@ -517,10 +777,10 @@ public class ApplicationEvaluationDao {
|
||||
for (ContentResponseBean contentResponseBean : contentResponseBeans) {
|
||||
if ("fileupload".equals(contentResponseBean.getName())) {
|
||||
String fieldId = contentResponseBean.getId();
|
||||
Long formId = applicationForm.getId();
|
||||
Long applicationFormId = applicationForm.getId();
|
||||
|
||||
Optional<ApplicationFormFieldEntity> optionalFormField = applicationFormFieldRepository
|
||||
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(fieldId, formId, applicationId);
|
||||
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(fieldId, applicationFormId, applicationId);
|
||||
|
||||
if (optionalFormField.isPresent()) {
|
||||
ApplicationFormFieldEntity formField = optionalFormField.get();
|
||||
@@ -528,8 +788,39 @@ public class ApplicationEvaluationDao {
|
||||
if (formField.getFieldValue() != null) {
|
||||
FieldResponse fieldResponse = new FieldResponse();
|
||||
fieldResponse.setId(fieldId);
|
||||
fieldResponse.setLabel(contentResponseBean.getLabel());
|
||||
String label = null;
|
||||
if (contentResponseBean.getSettings() != null) {
|
||||
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
||||
if ("label".equals(setting.getName())) {
|
||||
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldResponse.setLabel(label);
|
||||
fieldResponse.setValid(null);
|
||||
String[] documentIds = formField.getFieldValue().split(",");
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
|
||||
for (String docId : documentIds) {
|
||||
Long documentId = Long.valueOf(docId.trim());
|
||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
responseBean.setId(documentEntity.getId());
|
||||
responseBean.setName(documentEntity.getFileName());
|
||||
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
|
||||
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
|
||||
responseBean.setSourceId(documentEntity.getSourceId());
|
||||
responseBean.setFilePath(documentEntity.getFilePath());
|
||||
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||
documentResponseBeans.add(responseBean);
|
||||
});
|
||||
}
|
||||
|
||||
fieldResponse.setFileDetail(documentResponseBeans);
|
||||
|
||||
// Now add fieldResponse to the list
|
||||
fieldResponses.add(fieldResponse);
|
||||
}
|
||||
}
|
||||
@@ -537,7 +828,6 @@ public class ApplicationEvaluationDao {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fieldResponses;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package net.gepafin.tendermanagement.enums;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum ApplicationEvaluationStatusTypeEnum {
|
||||
DRAFT("DRAFT"),
|
||||
APPROVED("APPROVED"),
|
||||
REJECTED("REJECTED");
|
||||
OPEN ("OPEN"),
|
||||
SOCCORSO("SOCCORSO"),
|
||||
CLOSE("CLOSE");
|
||||
|
||||
private String value;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ public class ApplicationEvaluationResponse {
|
||||
private Long assignedApplicationId;
|
||||
private String note;
|
||||
private ApplicationEvaluationStatusTypeEnum status;
|
||||
private Long minScore;
|
||||
private List<CriteriaResponse> criteria;
|
||||
private List<ChecklistResponse> checklist;
|
||||
private List<FieldResponse> files;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.gepafin.tendermanagement.model.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CriteriaMappedField {
|
||||
private String id;
|
||||
private String fieldLabel;
|
||||
private String fieldValue;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package net.gepafin.tendermanagement.model.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CriteriaResponse {
|
||||
@@ -10,5 +10,6 @@ public class CriteriaResponse {
|
||||
private String label;
|
||||
private Long score;
|
||||
private Long maxScore;
|
||||
private List<CriteriaMappedField> criteriaMappedFields;
|
||||
private Boolean valid;
|
||||
}
|
||||
@@ -3,9 +3,13 @@ package net.gepafin.tendermanagement.model.response;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FieldResponse {
|
||||
private String id;
|
||||
private String label;
|
||||
private Boolean valid;
|
||||
private List<DocumentResponseBean> fileDetail ;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,13 +2,21 @@ package net.gepafin.tendermanagement.repositories;
|
||||
|
||||
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface ApplicationEvaluationRepository extends JpaRepository<ApplicationEvaluationEntity, Long> {
|
||||
Optional<ApplicationEvaluationEntity> findByApplicationId(Long applicationId);
|
||||
|
||||
Optional<ApplicationEvaluationEntity> findByApplicationIdAndIsDeletedFalse(Long applicationId);
|
||||
|
||||
Optional<ApplicationEvaluationEntity> findByAssignedApplicationsEntity_IdAndIsDeletedFalse(Long assignedApplicationId);
|
||||
|
||||
Optional<ApplicationEvaluationEntity> findByApplicationIdAndAssignedApplicationsEntity_IdAndIsDeletedFalse(Long applicationId, Long assignedApplicationId);
|
||||
|
||||
Optional<ApplicationEvaluationEntity> findFirstByIsDeletedFalseOrderByCreatedDateDesc();
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package net.gepafin.tendermanagement.repositories;
|
||||
import net.gepafin.tendermanagement.entities.AssignedApplicationsEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -9,5 +11,11 @@ import java.util.Optional;
|
||||
public interface AssignedApplicationsRepository extends JpaRepository<AssignedApplicationsEntity,Long>, JpaSpecificationExecutor<AssignedApplicationsEntity>{
|
||||
Optional<AssignedApplicationsEntity> findByApplicationIdAndIsDeletedFalse(Long applicationId);
|
||||
Optional<AssignedApplicationsEntity> findByIdAndIsDeletedFalse(Long id);
|
||||
@Query("SELECT aa FROM AssignedApplicationsEntity aa WHERE aa.isDeleted = false " +
|
||||
"AND (:applicationId IS NULL OR aa.application.id = :applicationId) " +
|
||||
"AND (:id IS NULL OR aa.id = :id)")
|
||||
Optional<AssignedApplicationsEntity> findByApplicationIdOrId(@Param("applicationId") Long applicationId,
|
||||
@Param("id") Long id);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.springframework.stereotype.Repository;
|
||||
public interface DocumentRepository extends JpaRepository<DocumentEntity, Long> {
|
||||
|
||||
@Query("SELECT d FROM DocumentEntity d WHERE d.id = :id AND d.isDeleted = false")
|
||||
Optional<DocumentEntity> findById(@Param("id") Long id);
|
||||
Optional<DocumentEntity> findByIdAndNotDeleted(@Param("id") Long id);
|
||||
|
||||
// List<DocumentEntity> findBySourceIdAndTypeAndIsDeletedFalse(Long sourceId, String type);
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ public interface ApplicationEvaluationService {
|
||||
ApplicationEvaluationResponse createOrUpdateApplicationEvaluation(HttpServletRequest request, ApplicationEvaluationRequest applicationEvaluationRequest,Long assignedApplicationsId);
|
||||
void deleteApplicationEvaluation(HttpServletRequest request,Long id);
|
||||
|
||||
ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(HttpServletRequest request,Long applicationId);
|
||||
|
||||
ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(HttpServletRequest request,Long applicationId,Long assignedApplicationId);
|
||||
ApplicationEvaluationResponse updateApplicationEvaluationStatus(HttpServletRequest request, Long applicationEvaluationId, ApplicationEvaluationStatusTypeEnum status);
|
||||
|
||||
|
||||
|
||||
@@ -47,14 +47,23 @@ public class ApplicationEvaluationServiceImpl implements ApplicationEvaluationSe
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(HttpServletRequest request,Long applicationId) {
|
||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null);
|
||||
if(assignedApplications==null){
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.ASSIGNED_APPLICATION_NOT_FOUND_WITH_ID_MSG));
|
||||
}
|
||||
UserEntity user = validator.validatePreInstructor(request, assignedApplications.getUserId());
|
||||
return applicationEvaluationDao.getApplicationEvaluationByApplicationId(user, assignedApplications.getUserId());
|
||||
public ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(
|
||||
HttpServletRequest request, Long applicationId, Long assignedApplicationId) {
|
||||
|
||||
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||
assignedApplicationsRepository.findByApplicationIdOrId(applicationId, assignedApplicationId);
|
||||
|
||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsOptional
|
||||
.orElseThrow(() -> new CustomValidationException(
|
||||
Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.ASSIGNED_APPLICATION_NOT_FOUND_WITH_ID_MSG)
|
||||
));
|
||||
UserEntity user = validator.validatePreInstructor(request, assignedApplications.getUserId());
|
||||
return applicationEvaluationDao.getApplicationEvaluationByApplicationId(
|
||||
user,
|
||||
assignedApplications.getApplication().getId(),
|
||||
assignedApplications.getId()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,9 +44,12 @@ public interface ApplicationEvaluationApi {
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) }))
|
||||
})
|
||||
@GetMapping(value = "/application/{applicationId}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
ResponseEntity<Response<ApplicationEvaluationResponse>> getApplicationEvaluationByApplicationId(HttpServletRequest request,
|
||||
@Parameter(required = true) @PathVariable("applicationId") Long applicationId);
|
||||
@GetMapping(value = "/application", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
ResponseEntity<Response<ApplicationEvaluationResponse>> getApplicationEvaluationByApplicationId(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "Application ID", required = false) @RequestParam(value = "applicationId", required = false) Long applicationId,
|
||||
@Parameter(description = "Assigned Application ID", required = false) @RequestParam(value = "assignedApplicationId", required = false) Long assignedApplicationId);
|
||||
|
||||
|
||||
@Operation(summary = "API to delete ApplicationEvaluation",
|
||||
responses = {
|
||||
@@ -67,9 +70,9 @@ public interface ApplicationEvaluationApi {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||
@PutMapping(value = "/{id}/status", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@PutMapping(value = "/{applicationId}/status", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
ResponseEntity<Response<ApplicationEvaluationResponse>> updateApplicationEvaluationStatus(HttpServletRequest request,
|
||||
@Parameter( required = true) @PathVariable("id") Long id,
|
||||
@Parameter( required = true) @PathVariable("applicationId") Long applicationId,
|
||||
@Parameter(description = "status", required = true)@RequestParam(value = "status", required = true) ApplicationEvaluationStatusTypeEnum status);
|
||||
|
||||
}
|
||||
|
||||
@@ -37,9 +37,11 @@ public class ApplicationEvaluationApiController implements ApplicationEvaluation
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<ApplicationEvaluationResponse>> getApplicationEvaluationByApplicationId(HttpServletRequest request,
|
||||
Long applicationId) {
|
||||
ApplicationEvaluationResponse response = applicationEvaluationService.getApplicationEvaluationByApplicationId(request,applicationId);
|
||||
public ResponseEntity<Response<ApplicationEvaluationResponse>> getApplicationEvaluationByApplicationId(
|
||||
HttpServletRequest request, Long applicationId, Long assignedApplicationId) {
|
||||
|
||||
ApplicationEvaluationResponse response = null;
|
||||
response = applicationEvaluationService.getApplicationEvaluationByApplicationId(request, applicationId,assignedApplicationId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.EVALUATION_FETCHED_SUCCESSFULLY)));
|
||||
}
|
||||
|
||||
@@ -1518,7 +1518,7 @@
|
||||
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="is_deleted" type="BOOLEAN" defaultValueBoolean="false">
|
||||
<column name="is_deleted" type="BOOLEAN" defaultValueBoolean="false">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
|
||||
Reference in New Issue
Block a user