|
|
|
|
@@ -20,6 +20,7 @@ import net.gepafin.tendermanagement.model.util.SortBy;
|
|
|
|
|
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
|
|
|
|
|
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
|
|
|
|
import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository;
|
|
|
|
|
import net.gepafin.tendermanagement.repositories.AssignedApplicationsViewRepository;
|
|
|
|
|
import net.gepafin.tendermanagement.service.ApplicationService;
|
|
|
|
|
import net.gepafin.tendermanagement.service.CompanyService;
|
|
|
|
|
import net.gepafin.tendermanagement.service.UserService;
|
|
|
|
|
@@ -77,6 +78,9 @@ public class AssignedApplicationsDao {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AssignedApplicationsViewRepository assignedApplicationsViewRepository;
|
|
|
|
|
|
|
|
|
|
public AssignedApplicationsResponse createAssignedApplications(Long applicationId, Long userId, UserEntity assignedByUser, AssignedApplicationsRequest assignedApplicationsRequest) {
|
|
|
|
|
log.info("Assigning application to pre-Instructor with details: {}", applicationId, userId);
|
|
|
|
|
|
|
|
|
|
@@ -310,14 +314,13 @@ public class AssignedApplicationsDao {
|
|
|
|
|
if (pageNo == null || pageNo <= 0) {
|
|
|
|
|
pageNo = GepafinConstant.DEFAULT_PAGE;
|
|
|
|
|
}
|
|
|
|
|
Specification<AssignedApplicationsEntity> spec = searchByPagination( assignedApplicationPageableRequestBean, user,userId);
|
|
|
|
|
Page<AssignedApplicationsEntity> entityPage = assignedApplicationsRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
|
|
|
|
Specification<AssignedApplicationsView> spec = searchByPagination( assignedApplicationPageableRequestBean, user,userId);
|
|
|
|
|
Page<AssignedApplicationsView> entityPage = assignedApplicationsViewRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
|
|
|
|
// Prepare the response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<AssignedApplicationsResponse> assignedApplicationsResponses = entityPage.getContent().stream()
|
|
|
|
|
.map(application -> {
|
|
|
|
|
AssignedApplicationsResponse response = convertEntityToResponse(application);
|
|
|
|
|
AssignedApplicationsResponse response = getAssignedApplicationResponseByView(application);
|
|
|
|
|
return response;
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
@@ -334,7 +337,7 @@ public class AssignedApplicationsDao {
|
|
|
|
|
return pageableResponseBean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Specification<AssignedApplicationsEntity> searchByPagination(AssignedApplicationPageableRequestBean assignedApplicationPageableRequestBean, UserEntity userEntity,Long userId) {
|
|
|
|
|
public Specification<AssignedApplicationsView> searchByPagination(AssignedApplicationPageableRequestBean assignedApplicationPageableRequestBean, UserEntity userEntity,Long userId) {
|
|
|
|
|
return (root, query, criteriaBuilder) -> {
|
|
|
|
|
|
|
|
|
|
List<Predicate> predicates = getPredicates(assignedApplicationPageableRequestBean, criteriaBuilder, root, userEntity,userId);
|
|
|
|
|
@@ -350,30 +353,35 @@ public class AssignedApplicationsDao {
|
|
|
|
|
sortBy.setSortDesc(assignedApplicationPageableRequestBean.getGlobalFilters().getSortBy().getSortDesc());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Path<?> sortPath;
|
|
|
|
|
Join<AssignedApplicationsEntity, ApplicationEntity> applicationJoin = root.join(GepafinConstant.APPLICATION, JoinType.LEFT);
|
|
|
|
|
// Path<?> sortPath;
|
|
|
|
|
// Join<AssignedApplicationsEntity, ApplicationEntity> applicationJoin = root.join(GepafinConstant.APPLICATION, JoinType.LEFT);
|
|
|
|
|
//
|
|
|
|
|
// if (GepafinConstant.APPLICATION_ID.equals(sortBy.getColumnName())) {
|
|
|
|
|
// sortPath = root.join(GepafinConstant.APPLICATION, JoinType.LEFT).get(GepafinConstant.ID); // Join ApplicationEntity and sort by application.id
|
|
|
|
|
// }
|
|
|
|
|
// else if (GepafinConstant.PROTOCOL_NUMBER.equals(sortBy.getColumnName())) {
|
|
|
|
|
// Join<ApplicationEntity, ProtocolEntity> protocolJoin = applicationJoin.join(GepafinConstant.PROTOCOL, JoinType.LEFT);
|
|
|
|
|
// sortPath = protocolJoin.get(GepafinConstant.PROTOCOL_NUMBER);
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// sortPath = root.get(sortBy.getColumnName()); // Sorting by a field in AmendmentEntity
|
|
|
|
|
// }
|
|
|
|
|
// query.orderBy(criteriaBuilder.desc(sortPath));
|
|
|
|
|
// if (Boolean.FALSE.equals(sortBy.getSortDesc())) {
|
|
|
|
|
// query.orderBy(criteriaBuilder.asc(sortPath));
|
|
|
|
|
// }
|
|
|
|
|
// return query.where(criteriaBuilder.and(predicates.toArray(new Predicate[0]))).getRestriction();
|
|
|
|
|
|
|
|
|
|
Path<?> sortPath = root.get(sortBy.getColumnName()); // All fields are accessible directly in the view
|
|
|
|
|
query.orderBy(sortBy.getSortDesc() ? criteriaBuilder.desc(sortPath) : criteriaBuilder.asc(sortPath));
|
|
|
|
|
|
|
|
|
|
if (GepafinConstant.APPLICATION_ID.equals(sortBy.getColumnName())) {
|
|
|
|
|
sortPath = root.join(GepafinConstant.APPLICATION, JoinType.LEFT).get(GepafinConstant.ID); // Join ApplicationEntity and sort by application.id
|
|
|
|
|
}
|
|
|
|
|
else if (GepafinConstant.PROTOCOL_NUMBER.equals(sortBy.getColumnName())) {
|
|
|
|
|
Join<ApplicationEntity, ProtocolEntity> protocolJoin = applicationJoin.join(GepafinConstant.PROTOCOL, JoinType.LEFT);
|
|
|
|
|
sortPath = protocolJoin.get(GepafinConstant.PROTOCOL_NUMBER);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sortPath = root.get(sortBy.getColumnName()); // Sorting by a field in AmendmentEntity
|
|
|
|
|
}
|
|
|
|
|
query.orderBy(criteriaBuilder.desc(sortPath));
|
|
|
|
|
if (Boolean.FALSE.equals(sortBy.getSortDesc())) {
|
|
|
|
|
query.orderBy(criteriaBuilder.asc(sortPath));
|
|
|
|
|
}
|
|
|
|
|
return query.where(criteriaBuilder.and(predicates.toArray(new Predicate[0]))).getRestriction();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<Predicate> getPredicates(AssignedApplicationPageableRequestBean assignedApplicationPageableRequestBean,
|
|
|
|
|
CriteriaBuilder criteriaBuilder, Root<AssignedApplicationsEntity> root, UserEntity userEntity,Long userId) {
|
|
|
|
|
CriteriaBuilder criteriaBuilder, Root<AssignedApplicationsView> root, UserEntity userEntity,Long userId) {
|
|
|
|
|
|
|
|
|
|
Integer year = null;
|
|
|
|
|
String search = null;
|
|
|
|
|
@@ -404,12 +412,35 @@ public class AssignedApplicationsDao {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// Search in `title` and `message` (if search term is provided)
|
|
|
|
|
if (search != null && !search.isEmpty()) {
|
|
|
|
|
Predicate titlePredicate = criteriaBuilder.like(
|
|
|
|
|
criteriaBuilder.upper(root.get(GepafinConstant.NOTE)),
|
|
|
|
|
"%" + search.toUpperCase() + "%"
|
|
|
|
|
);
|
|
|
|
|
predicates.add(criteriaBuilder.or(titlePredicate));
|
|
|
|
|
// if (search != null && !search.isEmpty()) {
|
|
|
|
|
// Predicate titlePredicate = criteriaBuilder.like(
|
|
|
|
|
// criteriaBuilder.upper(root.get(GepafinConstant.NOTE)),
|
|
|
|
|
// "%" + search.toUpperCase() + "%"
|
|
|
|
|
// );
|
|
|
|
|
// predicates.add(criteriaBuilder.or(titlePredicate));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (search != null && !search.trim().isEmpty()) {
|
|
|
|
|
String pattern = "%" + search.toUpperCase() + "%";
|
|
|
|
|
List<Predicate> searchPredicates = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
searchPredicates.add(criteriaBuilder.like(criteriaBuilder.upper(root.get(GepafinConstant.CALL_NAME)), pattern));
|
|
|
|
|
searchPredicates.add(criteriaBuilder.like(criteriaBuilder.upper(root.get(GepafinConstant.COMPANY_NAME)), pattern));
|
|
|
|
|
searchPredicates.add(criteriaBuilder.like(criteriaBuilder.upper(root.get(GepafinConstant.STATUS)), pattern));
|
|
|
|
|
searchPredicates.add(criteriaBuilder.like(criteriaBuilder.upper(root.get(GepafinConstant.NDG_STRING)), pattern));
|
|
|
|
|
searchPredicates.add(criteriaBuilder.like(criteriaBuilder.upper(root.get(GepafinConstant.APPOINTMENT_ID)), pattern));
|
|
|
|
|
searchPredicates.add(criteriaBuilder.like(criteriaBuilder.upper(root.get(GepafinConstant.APPLICATION_STATUS)), pattern));
|
|
|
|
|
|
|
|
|
|
// Convert numeric fields to string for search (optional and DB-specific; otherwise exact match)
|
|
|
|
|
try {
|
|
|
|
|
Long searchLong = Long.parseLong(search);
|
|
|
|
|
searchPredicates.add(criteriaBuilder.equal(root.get(GepafinConstant.APPLICATION_ID), searchLong));
|
|
|
|
|
searchPredicates.add(criteriaBuilder.equal(root.get(GepafinConstant.PROTOCOL_NUMBER), searchLong));
|
|
|
|
|
} catch (NumberFormatException ignored) {
|
|
|
|
|
// Ignore if search is not a number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
predicates.add(criteriaBuilder.or(searchPredicates.toArray(new Predicate[0])));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by `status` (if status list is provided)
|
|
|
|
|
@@ -421,12 +452,31 @@ public class AssignedApplicationsDao {
|
|
|
|
|
}
|
|
|
|
|
predicates.add(criteriaBuilder.isFalse(root.get(GepafinConstant.IS_DELETED)));
|
|
|
|
|
|
|
|
|
|
applyFilters(root, criteriaBuilder, predicates, filters);
|
|
|
|
|
|
|
|
|
|
Utils.applyFiltersByPagination(root, criteriaBuilder, predicates, filters);
|
|
|
|
|
|
|
|
|
|
return predicates;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AssignedApplicationsResponse getAssignedApplicationResponseByView(AssignedApplicationsView view) {
|
|
|
|
|
AssignedApplicationsResponse response = new AssignedApplicationsResponse();
|
|
|
|
|
response.setId(view.getId());
|
|
|
|
|
response.setUserId(view.getUserId());
|
|
|
|
|
response.setStatus(AssignedApplicationEnum.valueOf(view.getStatus()));
|
|
|
|
|
response.setApplicationId(view.getApplicationId());
|
|
|
|
|
response.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(view.getApplicationStatus()));
|
|
|
|
|
response.setSubmissionDate(view.getSubmissionDate());
|
|
|
|
|
response.setEvaluationEndDate(view.getEvaluationEndDate());
|
|
|
|
|
response.setNdg(view.getNdg());
|
|
|
|
|
response.setAppointmentId(view.getAppointmentId());
|
|
|
|
|
response.setProtocolNumber(view.getProtocolNumber());
|
|
|
|
|
response.setCallName(view.getCallName());
|
|
|
|
|
response.setCompanyName(view.getCompanyName());
|
|
|
|
|
response.setCreatedDate(view.getCreatedDate());
|
|
|
|
|
response.setUpdatedDate(view.getUpdatedDate());
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AssignedApplicationsResponse updateAssignedApplicationStatus(HttpServletRequest request, Long assignedApplicationId, AssignedApplicationEnum status) {
|
|
|
|
|
|
|
|
|
|
AssignedApplicationsEntity assignedApplication = validateAssignedApplication(assignedApplicationId);
|
|
|
|
|
|