Done changes related to evaluation document
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import com.amazonaws.services.dynamodbv2.xspec.L;
|
||||
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,6 +16,7 @@ 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;
|
||||
@@ -27,7 +28,6 @@ import java.util.*;
|
||||
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 {
|
||||
@@ -93,6 +93,12 @@ public class ApplicationEvaluationDao {
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private DocumentService documentService;
|
||||
|
||||
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
|
||||
|
||||
ApplicationEvaluationEntity entity = new ApplicationEvaluationEntity();
|
||||
@@ -132,11 +138,42 @@ public class ApplicationEvaluationDao {
|
||||
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 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());
|
||||
evaluationDocResponse.setFileValue(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) {
|
||||
|
||||
@@ -483,9 +520,9 @@ 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))));
|
||||
entity.setCriteria(Utils.convertObjectToJson(processCriteria(entity, req)));
|
||||
entity.setChecklist(Utils.convertObjectToJson(processChecklist(entity, req)));
|
||||
entity.setFile(Utils.convertObjectToJson(processField(entity, req)));
|
||||
entity.setIsDeleted(false);
|
||||
setIfUpdated(entity::getNote, entity::setNote, req.getNote());
|
||||
setIfUpdated(entity::getMotivation, entity::setMotivation, req.getMotivation());
|
||||
@@ -510,22 +547,6 @@ public class ApplicationEvaluationDao {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<ChecklistRequest> filterNonNullChecklist(List<ChecklistRequest> checklistRequests) {
|
||||
|
||||
return checklistRequests.stream().filter(request -> request.getValid() != null).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<CriteriaRequest> filterNonNullCriteria(List<CriteriaRequest> criteriaRequests) {
|
||||
|
||||
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 List<CriteriaRequest> processCriteria(ApplicationEvaluationEntity entity, ApplicationEvaluationRequest req) {
|
||||
|
||||
List<CriteriaRequest> incomingCriteriaList = Optional.ofNullable(req.getCriteria()).orElse(new ArrayList<>());
|
||||
@@ -645,11 +666,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) {
|
||||
@@ -661,11 +723,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) {
|
||||
|
||||
@@ -1447,5 +1517,30 @@ 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;
|
||||
if(entityOptional.isPresent()) {
|
||||
applicationEvaluationEntity = entityOptional.get();
|
||||
if (docRequest != null) {
|
||||
// String existingEvaluationDocJson = applicationEvaluationEntity.getEvaluationDocument();
|
||||
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);
|
||||
return convertToResponse(savedEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user