Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into develop
This commit is contained in:
@@ -139,7 +139,7 @@ public class ApplicationDao {
|
||||
}
|
||||
formService.validateFormField(applicationRequestBean.getFormFields(),applicationEntity,formEntity);
|
||||
ApplicationFormEntity applicationFormEntity = getApplicationFormOrCreate(formEntity, applicationEntity);
|
||||
createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity,formEntity);
|
||||
createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity, formEntity);
|
||||
return getApplicationById(applicationEntity.getId(),formEntity.getId());
|
||||
}
|
||||
public void validateDelegation(UserEntity user, CompanyEntity company) {
|
||||
@@ -288,7 +288,7 @@ public class ApplicationDao {
|
||||
|
||||
log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
|
||||
|
||||
Specification<ApplicationEntity> spec = search(userEntity.getId(), callId, companyId,status);
|
||||
Specification<ApplicationEntity> spec = search(userEntity, callId, companyId,status);
|
||||
|
||||
List<ApplicationEntity> applicationEntities = applicationRepository.findAll(spec);
|
||||
|
||||
@@ -298,12 +298,12 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
|
||||
private Specification<ApplicationEntity> search(Long userId, Long callId, Long companyId,String status) {
|
||||
private Specification<ApplicationEntity> search(UserEntity userEntity, Long callId, Long companyId,String status) {
|
||||
return (root, query, builder) -> {
|
||||
Boolean isBeneficiary = validator.checkIsBeneficiary();
|
||||
Predicate predicate = builder.isFalse(root.get("isDeleted"));
|
||||
if (isBeneficiary) {
|
||||
predicate = builder.and(predicate, builder.equal(root.get("userId"), userId));
|
||||
predicate = builder.and(predicate, builder.equal(root.get("userId"), userEntity.getId()));
|
||||
}
|
||||
if (callId != null) {
|
||||
predicate = builder.and(predicate, builder.equal(root.get("call").get("id"), callId));
|
||||
@@ -314,7 +314,7 @@ public class ApplicationDao {
|
||||
if (status != null) {
|
||||
predicate = builder.and(predicate, builder.equal(root.get("status"), status));
|
||||
}
|
||||
|
||||
predicate = builder.and(predicate, builder.equal(root.get("hubId"), userEntity.getHub().getId()));
|
||||
return predicate;
|
||||
};
|
||||
}
|
||||
@@ -601,7 +601,7 @@ public class ApplicationDao {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_IN_PREVIOUS_STATUS));
|
||||
}
|
||||
if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) {
|
||||
callService.validatePublishedCall(applicationEntity.getCall().getId());
|
||||
callService.validatePublishedCall(applicationEntity.getCall().getId(), userEntity.getHub().getId());
|
||||
Long protocolNumber = getProtocolNumber(userEntity.getHub());
|
||||
ProtocolEntity protocolEntity = createProtocolEntity(applicationEntity,protocolNumber, userEntity.getHub().getId());
|
||||
applicationEntity.setProtocol(protocolEntity);
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.AssignedApplicationEnum;
|
||||
import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest;
|
||||
import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository;
|
||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
@@ -31,13 +32,16 @@ import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
public class AssignedApplicationsDao {
|
||||
|
||||
@Autowired
|
||||
ApplicationService applicationService;
|
||||
private ApplicationService applicationService;
|
||||
|
||||
@Autowired
|
||||
AssignedApplicationsRepository assignedApplicationsRepository;
|
||||
private ApplicationRepository applicationRepository;
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
private AssignedApplicationsRepository assignedApplicationsRepository;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
public AssignedApplicationsResponse createAssignedApplications(Long applicationId, Long userId, UserEntity assignedByUser, AssignedApplicationsRequest assignedApplicationsRequest){
|
||||
log.info("Assigning application to pre-Instructor with details: {}", applicationId,userId);
|
||||
@@ -47,12 +51,16 @@ public class AssignedApplicationsDao {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_ASSIGNED));
|
||||
}
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
|
||||
|
||||
if (Boolean.FALSE.equals(ApplicationStatusTypeEnum.SUBMIT.getValue().equals(application.getStatus()))) {
|
||||
throw new CustomValidationException(
|
||||
Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.INVALID_APPLICATION_STATUS)
|
||||
);
|
||||
}
|
||||
application.setStatus(ApplicationStatusTypeEnum.EVALUATION.getValue());
|
||||
applicationRepository.save(application);
|
||||
UserEntity user = userService.validateUser(userId);
|
||||
AssignedApplicationsEntity assignment = createAssignmentEntity(application, user.getId(), assignedByUser, assignedApplicationsRequest);
|
||||
AssignedApplicationsResponse assignApplicationToInstructorResponse = convertEntityToResponse(assignment);
|
||||
@@ -82,17 +90,44 @@ public class AssignedApplicationsDao {
|
||||
return assignedApplication;
|
||||
}
|
||||
|
||||
public AssignedApplicationsResponse convertEntityToResponse(AssignedApplicationsEntity application){
|
||||
public AssignedApplicationsResponse convertEntityToResponse(AssignedApplicationsEntity assignedApplications){
|
||||
AssignedApplicationsResponse assignedApplicationsResponse = new AssignedApplicationsResponse();
|
||||
assignedApplicationsResponse.setId(application.getId());
|
||||
assignedApplicationsResponse.setApplicationId(application.getApplication().getId());
|
||||
assignedApplicationsResponse.setAssignedBy(application.getAssignedBy());
|
||||
assignedApplicationsResponse.setUserId(application.getUserId());
|
||||
assignedApplicationsResponse.setCreatedDate(application.getCreatedDate());
|
||||
assignedApplicationsResponse.setUpdatedDate(application.getUpdatedDate());
|
||||
assignedApplicationsResponse.setNote(application.getNote());
|
||||
assignedApplicationsResponse.setStatus(AssignedApplicationEnum.valueOf(application.getStatus()));
|
||||
assignedApplicationsResponse.setAssignedAt(application.getAssignedAt());
|
||||
assignedApplicationsResponse.setId(assignedApplications.getId());
|
||||
assignedApplicationsResponse.setApplicationId(assignedApplications.getApplication().getId());
|
||||
|
||||
ApplicationEntity application = applicationService.validateApplication(assignedApplications.getApplication().getId());
|
||||
String callName = application.getCall() != null ? application.getCall().getName() : "";
|
||||
LocalDateTime callEndDate = application.getCall().getEndDate();
|
||||
LocalDateTime callStartDate = application.getCall().getStartDate();
|
||||
|
||||
Long protocolNumber = (application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null)
|
||||
? application.getProtocol().getProtocolNumber()
|
||||
: 0;
|
||||
LocalDateTime submissionDate = application.getSubmissionDate();
|
||||
UserEntity userEntity = userService.validateUser(application.getUserId());
|
||||
|
||||
String firstName = userEntity.getBeneficiary() != null ? userEntity.getBeneficiary().getFirstName() : null;
|
||||
String lastName = userEntity.getBeneficiary() != null ? userEntity.getBeneficiary().getLastName() : null;
|
||||
|
||||
String beneficiaryName = (firstName != null && !firstName.isBlank() ? firstName : "") +
|
||||
(lastName != null && !lastName.isBlank() ? " " + lastName : "");
|
||||
|
||||
beneficiaryName = beneficiaryName.isBlank() ? "" : beneficiaryName;
|
||||
|
||||
assignedApplicationsResponse.setAssignedBy(assignedApplications.getAssignedBy());
|
||||
assignedApplicationsResponse.setUserId(assignedApplications.getUserId());
|
||||
assignedApplicationsResponse.setCreatedDate(assignedApplications.getCreatedDate());
|
||||
assignedApplicationsResponse.setUpdatedDate(assignedApplications.getUpdatedDate());
|
||||
assignedApplicationsResponse.setNote(assignedApplications.getNote());
|
||||
assignedApplicationsResponse.setStatus(AssignedApplicationEnum.valueOf(assignedApplications.getStatus()));
|
||||
assignedApplicationsResponse.setAssignedAt(assignedApplications.getAssignedAt());
|
||||
assignedApplicationsResponse.setProtocolNumber(protocolNumber);
|
||||
assignedApplicationsResponse.setCallName(callName);
|
||||
assignedApplicationsResponse.setBeneficiaryName(beneficiaryName);
|
||||
assignedApplicationsResponse.setSubmissionDate(submissionDate);
|
||||
assignedApplicationsResponse.setCallEndDate(callEndDate);
|
||||
assignedApplicationsResponse.setCallStartDate(callStartDate);
|
||||
|
||||
return assignedApplicationsResponse;
|
||||
}
|
||||
|
||||
|
||||
@@ -654,7 +654,7 @@ public class CallDao {
|
||||
if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) {
|
||||
callStatusList = List.of(CallStatusEnum.PUBLISH.getValue());
|
||||
}
|
||||
List<CallEntity> calls = callRepository.findByStatusIn(callStatusList);
|
||||
List<CallEntity> calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId());
|
||||
return calls.stream()
|
||||
.map(this::convertToCallDetailsResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
@@ -672,13 +672,13 @@ public class CallDao {
|
||||
callResponseBean.setStatus(CallStatusEnum.valueOf(callEntity.getStatus()));
|
||||
return callResponseBean;
|
||||
}
|
||||
public CallEntity getCallEntityById(Long id){
|
||||
CallEntity callEntity=callRepository.findByIdAndStatusNotIn(id,List.of(CallStatusEnum.PUBLISH.getValue()));
|
||||
if(callEntity==null){
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND));
|
||||
}
|
||||
return callEntity;
|
||||
}
|
||||
// public CallEntity getCallEntityById(Long id){
|
||||
// CallEntity callEntity=callRepository.findByIdAndStatusNotInAndHubId(id, List.of(CallStatusEnum.PUBLISH.getValue()));
|
||||
// if(callEntity==null){
|
||||
// throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND));
|
||||
// }
|
||||
// return callEntity;
|
||||
// }
|
||||
|
||||
public CallResponse updateCallStatus(CallEntity callEntity, CallStatusEnum statusReq) {
|
||||
CallStatusEnum currentStatus = CallStatusEnum.valueOf(callEntity.getStatus());
|
||||
@@ -718,9 +718,9 @@ public class CallDao {
|
||||
|
||||
}
|
||||
}
|
||||
public CallEntity validatePublishedCall(Long callId) {
|
||||
public CallEntity validatePublishedCall(Long callId, Long hubId) {
|
||||
CallEntity callEntity= callRepository
|
||||
.findByIdAndStatus(callId, CallStatusEnum.PUBLISH.getValue());
|
||||
.findByIdAndStatusAndHubId(callId, CallStatusEnum.PUBLISH.getValue(), hubId);
|
||||
if(callEntity==null){
|
||||
throw new ResourceNotFoundException(
|
||||
Status.NOT_FOUND,
|
||||
|
||||
@@ -54,7 +54,7 @@ public class CompanyDao {
|
||||
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
|
||||
} else {
|
||||
validateCompany(userEntity, companyRequest);
|
||||
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(companyRequest);
|
||||
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(userEntity, companyRequest);
|
||||
companyRepository.save(companyEntity);
|
||||
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
|
||||
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||
@@ -91,7 +91,7 @@ public class CompanyDao {
|
||||
return userWithCompanyRepository.save(userWithCompanyEntity);
|
||||
}
|
||||
|
||||
private CompanyEntity convertCompanyRequestToCompanyEntity(CompanyRequest request) {
|
||||
private CompanyEntity convertCompanyRequestToCompanyEntity(UserEntity userEntity, CompanyRequest request) {
|
||||
CompanyEntity entity = new CompanyEntity();
|
||||
entity.setCompanyName(request.getCompanyName());
|
||||
entity.setVatNumber(request.getVatNumber());
|
||||
@@ -108,6 +108,7 @@ public class CompanyDao {
|
||||
entity.setAnnualRevenue(request.getAnnualRevenue());
|
||||
entity.setContactName(request.getContactName());
|
||||
entity.setContactEmail(request.getContactEmail());
|
||||
entity.setHub(userEntity.getHub());
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class DashboardDao {
|
||||
}
|
||||
|
||||
private void setActiveCalls(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||
Long activeCalls = callRepository.countByStatus(CallStatusEnum.PUBLISH.getValue());
|
||||
Long activeCalls = callRepository.countByStatusAndHubId(CallStatusEnum.PUBLISH.getValue(), requestedUserEntity.getHub().getId());
|
||||
if (activeCalls != null) {
|
||||
widget1.setNumberOfActiveCalls(activeCalls);
|
||||
}
|
||||
@@ -74,20 +74,20 @@ public class DashboardDao {
|
||||
}
|
||||
}
|
||||
|
||||
private void setTotalActiveFinancing(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||
BigDecimal totalActiveFinancing = callRepository.findTotalAmountOfPublishedCalls();
|
||||
private void setTotalActiveFinancing(Widget1 widget1, UserEntity requestedUser) {
|
||||
BigDecimal totalActiveFinancing = callRepository.findTotalAmountOfPublishedCallsAndHubId(requestedUser.getHub().getId());
|
||||
widget1.setTotalActiveFinancing(totalActiveFinancing);
|
||||
}
|
||||
|
||||
private void setSubmittedApplications(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||
Long submittedApplications = applicationRepository.countSubmittedApplications();
|
||||
Long submittedApplications = applicationRepository.countSubmittedApplicationsByHubId(requestedUserEntity.getHub().getId());
|
||||
if (submittedApplications != null) {
|
||||
widget1.setNumberOfSubmittedApplications(submittedApplications);
|
||||
}
|
||||
}
|
||||
|
||||
private void setDraftApplications(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||
Long draftApplications = applicationRepository.countDraftApplications();
|
||||
Long draftApplications = applicationRepository.countDraftApplicationsByHubId(requestedUserEntity.getHub().getId());
|
||||
if (draftApplications != null) {
|
||||
widget1.setNumberOfDraftApplications(draftApplications);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class DashboardDao {
|
||||
CompanyEntity company) {
|
||||
BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder()
|
||||
.numberOfApplications(0L).numberOfCalls(0L).numberOfIntegratedDocuments(0L).build();
|
||||
Long activeCalls = callRepository.countByStatus(CallStatusEnum.PUBLISH.getValue());
|
||||
Long activeCalls = callRepository.countByStatusAndHubId(CallStatusEnum.PUBLISH.getValue(), userEntity.getHub().getId());
|
||||
if (activeCalls != null) {
|
||||
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||
@@ -31,6 +32,7 @@ import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
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;
|
||||
@@ -38,7 +40,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
@Component
|
||||
public class DelegationDao {
|
||||
|
||||
private static final String DEFAULT_PLACEHOLDER = "____________________";
|
||||
// private static final String DEFAULT_PLACEHOLDER = "____________________";
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@@ -57,6 +59,9 @@ public class DelegationDao {
|
||||
|
||||
@Autowired
|
||||
private UserCompanyDelegationRepository userCompanyDelegationRepository;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
|
||||
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
|
||||
@@ -89,9 +94,10 @@ public class DelegationDao {
|
||||
return new XWPFDocument(templateStream);
|
||||
}
|
||||
|
||||
public ByteArrayOutputStream downloadCompanyDelegation(UserEntity userEntity, Long companyId, CompanyDelegationRequest companyDelegationRequest) {
|
||||
public ByteArrayOutputStream downloadCompanyDelegation(HttpServletRequest request, Long companyId, CompanyDelegationRequest companyDelegationRequest) {
|
||||
Map<String, String> placeholders = getDefaultPlaceholders();
|
||||
UserResponseBean user = userService.getUserById(userEntity.getId());
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
UserResponseBean user = userService.getUserById(request, userEntity.getId());
|
||||
CompanyEntity companyEntity = companyDao.validateCompany(companyId);
|
||||
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||
updatePlaceholdersForDelegation(user, companyEntity, placeholders, companyDelegationRequest);
|
||||
|
||||
@@ -125,11 +125,12 @@ public class UserDao {
|
||||
|
||||
if (tempToken == null) {
|
||||
validator.validateRequest(request,RoleStatusEnum.ROLE_SUPER_ADMIN);
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
userReq.setHubUuid(userEntity.getHub().getUniqueUuid());
|
||||
}else {
|
||||
samlSuccessHandler.validateToken(tempToken, userReq.getCodiceFiscale(), userReq.getHubUuid());
|
||||
}
|
||||
|
||||
RoleEntity role = roleService.validateRole(userReq.getRoleId());
|
||||
if (Boolean.FALSE.equals(Utils.isValidEmail(userReq.getEmail()))) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.VALIDATE_EMAIL));
|
||||
@@ -153,10 +154,14 @@ public class UserDao {
|
||||
if (tempToken != null) {
|
||||
userReq.setRoleId(null);
|
||||
}
|
||||
if(tempToken == null && Boolean.TRUE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(role.getRoleType()))){
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.CANNOT_CREATE_BENEFICIARY_USER));
|
||||
}
|
||||
|
||||
if (tempToken == null) {
|
||||
RoleEntity role = roleService.validateRole(userReq.getRoleId());
|
||||
if (Boolean.TRUE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(role.getRoleType()))) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.CANNOT_CREATE_BENEFICIARY_USER));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validatePassword(String password, String confirmPassword, String tempToken) {
|
||||
|
||||
Reference in New Issue
Block a user