Merged with 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) {
|
||||
@@ -175,6 +175,7 @@ public class ApplicationDao {
|
||||
entity.setUserId(user.getId());
|
||||
entity.setCompany(companyEntity);
|
||||
entity.setCall(call);
|
||||
entity.setHubId(call.getHub().getId());
|
||||
entity.setIsDeleted(false);
|
||||
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
|
||||
return entity;
|
||||
@@ -287,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);
|
||||
|
||||
@@ -297,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));
|
||||
@@ -313,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;
|
||||
};
|
||||
}
|
||||
@@ -600,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,15 +51,19 @@ 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.equals(application.getStatus()))) {
|
||||
|
||||
|
||||
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, assignedApplicationsRequest);
|
||||
AssignedApplicationsResponse assignApplicationToInstructorResponse = convertEntityToResponse(assignment);
|
||||
|
||||
log.info("Application assigned succesfully {}", assignApplicationToInstructorResponse);
|
||||
return assignApplicationToInstructorResponse;
|
||||
@@ -66,7 +74,10 @@ public class AssignedApplicationsDao {
|
||||
assignApplication.setApplication(application);
|
||||
assignApplication.setAssignedBy(assignedByUser.getId());
|
||||
assignApplication.setUserId(userId);
|
||||
assignApplication.setStatus(assignedApplicationsRequest.getStatus().getValue());
|
||||
assignApplication.setStatus(AssignedApplicationEnum.ASSIGNED.getValue());
|
||||
if(assignedApplicationsRequest.getStatus() != null) {
|
||||
assignApplication.setStatus(assignedApplicationsRequest.getStatus().getValue());
|
||||
}
|
||||
assignApplication.setNote(assignedApplicationsRequest.getNote());
|
||||
assignApplication.setIsDeleted(false);
|
||||
assignApplication.setAssignedAt(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
@@ -79,17 +90,44 @@ public class AssignedApplicationsDao {
|
||||
return assignedApplication;
|
||||
}
|
||||
|
||||
public AssignedApplicationsResponse convertEntityToResponse(AssignedApplicationsEntity application, AssignedApplicationsRequest assignedApplicationsRequest){
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -111,7 +149,7 @@ public class AssignedApplicationsDao {
|
||||
Specification<AssignedApplicationsEntity> spec = search(userId);
|
||||
List<AssignedApplicationsEntity> assignedApplicationsEntityList = assignedApplicationsRepository.findAll(spec);
|
||||
return assignedApplicationsEntityList.stream()
|
||||
.map(entity -> convertEntityToResponse(entity, new AssignedApplicationsRequest()))
|
||||
.map(entity -> convertEntityToResponse(entity))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
private Specification<AssignedApplicationsEntity> search(Long userId) {
|
||||
@@ -138,7 +176,7 @@ public class AssignedApplicationsDao {
|
||||
existingAssignment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
|
||||
AssignedApplicationsEntity updatedAssignment = saveAssignedApplication(existingAssignment);
|
||||
AssignedApplicationsResponse response = convertEntityToResponse(updatedAssignment, updateRequest);
|
||||
AssignedApplicationsResponse response = convertEntityToResponse(updatedAssignment);
|
||||
log.info("Assigned application updated successfully: {}", response);
|
||||
return response;
|
||||
}
|
||||
@@ -146,7 +184,7 @@ public class AssignedApplicationsDao {
|
||||
public AssignedApplicationsResponse getAssignedApplicationById(Long id) {
|
||||
log.info("Fetching assigned application with ID: {}", id);
|
||||
AssignedApplicationsEntity assignedApplication = validateAssignedApplication(id);
|
||||
AssignedApplicationsResponse response = convertEntityToResponse(assignedApplication, new AssignedApplicationsRequest());
|
||||
AssignedApplicationsResponse response = convertEntityToResponse(assignedApplication);
|
||||
log.info("Assigned application fetched successfully: {}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -230,6 +230,7 @@ public class CallDao {
|
||||
criteriaEntity = new EvaluationCriteriaEntity();
|
||||
criteriaEntity.setCall(callEntity);
|
||||
criteriaEntity.setLookupData(lookupDataEntity);
|
||||
criteriaEntity.setScore(0L);
|
||||
criteriaEntity.setIsDeleted(false);
|
||||
}
|
||||
setIfUpdated(criteriaEntity::getScore, criteriaEntity::setScore, criteriaReq.getScore());
|
||||
@@ -653,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());
|
||||
@@ -671,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());
|
||||
@@ -717,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,
|
||||
|
||||
@@ -40,7 +40,7 @@ public class CompanyDao {
|
||||
|
||||
|
||||
public CompanyResponse createCompany(UserEntity userEntity, CompanyRequest companyRequest) {
|
||||
CompanyEntity existingCompany = companyRepository.findByVatNumber(companyRequest.getVatNumber());
|
||||
CompanyEntity existingCompany = companyRepository.findByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId());
|
||||
UserWithCompanyEntity userWithCompanyEntity = null;
|
||||
if (existingCompany != null) {
|
||||
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId())
|
||||
@@ -53,8 +53,8 @@ public class CompanyDao {
|
||||
}
|
||||
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
|
||||
} else {
|
||||
validateCompany(companyRequest);
|
||||
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(companyRequest);
|
||||
validateCompany(userEntity, companyRequest);
|
||||
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(userEntity, companyRequest);
|
||||
companyRepository.save(companyEntity);
|
||||
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
|
||||
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||
@@ -62,7 +62,7 @@ public class CompanyDao {
|
||||
}
|
||||
|
||||
|
||||
private void validateCompany(CompanyRequest companyRequest) {
|
||||
private void validateCompany(UserEntity userEntity, CompanyRequest companyRequest) {
|
||||
|
||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(companyRequest.getEmail()))
|
||||
&& Boolean.FALSE.equals(Utils.isValidEmail(companyRequest.getEmail()))) {
|
||||
@@ -73,7 +73,7 @@ public class CompanyDao {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.VATNUMBER_MANDATORY));
|
||||
}
|
||||
if (companyRepository.existsByVatNumber(companyRequest.getVatNumber())) {
|
||||
if (companyRepository.existsByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId())) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -186,7 +187,7 @@ public class CompanyDao {
|
||||
public List<CompanyResponse> getCompanyByUserId(Long userId) {
|
||||
UserEntity userEntity = userService.validateUser(userId);
|
||||
List<Long> activeCompanyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(userEntity.getId());
|
||||
List<CompanyEntity> companies = companyRepository.findByIdIn(activeCompanyIds);
|
||||
List<CompanyEntity> companies = companyRepository.findByIdInAndHubId(activeCompanyIds, userEntity.getHub().getId());
|
||||
return companies.stream().map(companyEntity -> {
|
||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyEntity.getId());
|
||||
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||
|
||||
@@ -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,27 +74,27 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
private void setNumberOfCompanies(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||
Long numberOfCompanies = companyRepository.countTotalCompanies();
|
||||
Long numberOfCompanies = companyRepository.countTotalCompaniesByHubId(requestedUserEntity.getHub().getId());
|
||||
if (numberOfCompanies != null) {
|
||||
widget1.setNumberOfCompany(numberOfCompanies);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -50,7 +50,10 @@ public class EvaluationCriteriaDao {
|
||||
.validateLookUpData(evaluationCriteriaRequest.getLookUpDataId());
|
||||
entity.setCall(callEntity);
|
||||
entity.setLookupData(looDataEntity);
|
||||
entity.setScore(evaluationCriteriaRequest.getScore());
|
||||
entity.setScore(0L);
|
||||
if (evaluationCriteriaRequest.getScore() != null) {
|
||||
entity.setScore(evaluationCriteriaRequest.getScore());
|
||||
}
|
||||
entity = evaluationCriteriaRepository.save(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ public class PdfDao {
|
||||
List<String> keys = new ArrayList<>(entry.keySet()); // Get all keys in the current map
|
||||
|
||||
// Handle based on the number of keys in the map
|
||||
if (Boolean.FALSE.equals(containsThreeValues) && keys.size() == 2) {
|
||||
if (Boolean.FALSE.equals(containsThreeValues) && (keys.size() == 2 || keys.size()<2)) {
|
||||
// Treat the first key as the "key" and second key as the "value"
|
||||
String heading = (String) entry.get(keys.get(0)); // Get value of first key
|
||||
String value1 = (String) entry.get(keys.get(1)); // Get value of second key
|
||||
@@ -475,6 +475,16 @@ public class PdfDao {
|
||||
// If the content with the matching fieldId is found, create a label-value pair
|
||||
if (matchingContent.isPresent()) {
|
||||
String name = matchingContent.get().getName();
|
||||
ContentResponseBean content = matchingContent.get();
|
||||
|
||||
// Find the setting where the name is "label"
|
||||
String contentLabel = content.getSettings().stream()
|
||||
.filter(setting -> "label".equals(setting.getName())) // Filter settings by name
|
||||
.map(SettingResponseBean::getValue) // Extract the value from the matching setting
|
||||
.map(Object::toString) // Convert the value to a string
|
||||
.findFirst() // Get the first matching value
|
||||
.orElse(null); // If no match is found, set label to null
|
||||
|
||||
if (name.equals("fileupload")) {
|
||||
|
||||
// Step 1: Check if fieldValue is an instance of List<DocumentResponseBean>
|
||||
@@ -518,12 +528,9 @@ public class PdfDao {
|
||||
}
|
||||
}
|
||||
}
|
||||
String label = matchingContent.get().getLabel();
|
||||
// Add the label-value pair to the list
|
||||
if (fieldValue != null && !fieldValue.toString().trim().isEmpty()) {
|
||||
fieldValue = findLabelInOptions(matchingContent.get().getSettings(), fieldValue);
|
||||
labelValuePairs.add(new FieldLabelValuePairRequest(label, fieldValue));
|
||||
}
|
||||
labelValuePairs.add(new FieldLabelValuePairRequest(contentLabel, fieldValue));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.gepafin.tendermanagement.config.SamlSuccessHandler;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.BeneficiaryEntity;
|
||||
import net.gepafin.tendermanagement.entities.HubEntity;
|
||||
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
@@ -84,17 +85,17 @@ public class UserDao {
|
||||
if(StringUtils.isEmpty(userReq.getHubUuid())) {
|
||||
userReq.setHubUuid(defaultHubUuid);
|
||||
}
|
||||
validateUserRequest(request, tempToken, userReq);
|
||||
HubEntity hub = hubService.getHubByUuid(userReq.getHubUuid());
|
||||
validateUserRequest(request, tempToken, userReq, hub);
|
||||
validatePassword(userReq.getPassword(), userReq.getConfPassword(), tempToken);
|
||||
|
||||
RoleEntity roleEntity = getRoleEntity(userReq.getRoleId());
|
||||
BeneficiaryEntity beneficiary = createBeneficiary(roleEntity, userReq);
|
||||
UserEntity userEntity = convertUserRequestToUserEntity(beneficiary, roleEntity, userReq);
|
||||
BeneficiaryEntity beneficiary = createBeneficiary(roleEntity, userReq, hub);
|
||||
UserEntity userEntity = convertUserRequestToUserEntity(beneficiary, roleEntity, userReq, hub);
|
||||
log.info("User created with ID: {}", userEntity.getId());
|
||||
return authService.getJWTTokenBean(userEntity, Boolean.TRUE);
|
||||
}
|
||||
|
||||
private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq) {
|
||||
private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq, HubEntity hub) {
|
||||
BeneficiaryEntity beneficiaryEntity = null;
|
||||
if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) {
|
||||
beneficiaryEntity = new BeneficiaryEntity();
|
||||
@@ -114,20 +115,22 @@ public class UserDao {
|
||||
beneficiaryEntity.setMarketing(userReq.getMarketing());
|
||||
beneficiaryEntity.setThirdParty(userReq.getThirdParty());
|
||||
beneficiaryEntity.setEmailPec(userReq.getEmailPec());
|
||||
beneficiaryEntity.setHubId(hub.getId());
|
||||
beneficiaryEntity =beneficiaryRepository.save(beneficiaryEntity);
|
||||
}
|
||||
return beneficiaryEntity;
|
||||
}
|
||||
|
||||
private void validateUserRequest(HttpServletRequest request, String tempToken, UserReq userReq) {
|
||||
private void validateUserRequest(HttpServletRequest request, String tempToken, UserReq userReq, HubEntity hub) {
|
||||
|
||||
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));
|
||||
@@ -139,7 +142,7 @@ public class UserDao {
|
||||
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
||||
}
|
||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale()))
|
||||
&& userRepository.existsByBeneficiaryCodiceFiscale(userReq.getCodiceFiscale())) {
|
||||
&& userRepository.existsByBeneficiaryCodiceFiscaleAndHubId(userReq.getCodiceFiscale(), hub.getId())) {
|
||||
log.error("User creation failed: CodiceFiscale {} already exists", userReq.getCodiceFiscale());
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.CODICE_FISCALE_EXISTS));
|
||||
@@ -151,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) {
|
||||
@@ -206,7 +213,7 @@ public class UserDao {
|
||||
return convertUserEntityToUserResponse(userEntity);
|
||||
}
|
||||
|
||||
private UserEntity convertUserRequestToUserEntity(BeneficiaryEntity beneficiary, RoleEntity roleEntity, UserReq userReq) {
|
||||
private UserEntity convertUserRequestToUserEntity(BeneficiaryEntity beneficiary, RoleEntity roleEntity, UserReq userReq, HubEntity hub) {
|
||||
UserEntity userEntity = new UserEntity();
|
||||
if(Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getPassword()))) {
|
||||
userEntity.setPassword(passwordEncoder.encode(userReq.getPassword()));
|
||||
@@ -215,7 +222,7 @@ public class UserDao {
|
||||
userEntity.setEmail(userReq.getEmail());
|
||||
userEntity.setStatus(UserStatusEnum.ACTIVE.getValue());
|
||||
userEntity.setBeneficiary(beneficiary);
|
||||
userEntity.setHub(hubService.getHubByUuid(userReq.getHubUuid()));
|
||||
userEntity.setHub(hub);
|
||||
if (Boolean.FALSE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType()))) {
|
||||
userEntity.setFirstName(userReq.getFirstName());
|
||||
userEntity.setLastName(userReq.getLastName());
|
||||
|
||||
@@ -39,4 +39,7 @@ public class ApplicationEntity extends BaseEntity {
|
||||
@OneToOne
|
||||
@JoinColumn(name = "PROTOCOL_NUMBER")
|
||||
private ProtocolEntity protocol;
|
||||
|
||||
@Column(name = "HUB_ID")
|
||||
private Long hubId;
|
||||
}
|
||||
@@ -61,4 +61,7 @@ public class BeneficiaryEntity extends BaseEntity {
|
||||
|
||||
@Column(name = "EMAIL_PEC")
|
||||
private String emailPec;
|
||||
|
||||
@Column(name = "HUB_ID")
|
||||
private Long hubId;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.math.BigDecimal;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -56,4 +58,9 @@ public class CompanyEntity extends BaseEntity{
|
||||
|
||||
@Column(name = "CONTACT_EMAIL")
|
||||
private String contactEmail;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "HUB_ID")
|
||||
private HubEntity hub;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ public enum ApplicationStatusTypeEnum {
|
||||
SUBMIT("SUBMIT"),
|
||||
AWAIT("AWAIT"),
|
||||
READY("READY"),
|
||||
DISCARD("DISCARD");
|
||||
DISCARD("DISCARD"),
|
||||
EVALUATION("EVALUATION");
|
||||
|
||||
private String value;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.gepafin.tendermanagement.model.request;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -14,6 +14,13 @@ public class AssignedApplicationsResponse extends BaseBean {
|
||||
private AssignedApplicationEnum status;
|
||||
private String note;
|
||||
private LocalDateTime assignedAt;
|
||||
private Long protocolNumber;
|
||||
private String callName;
|
||||
private String beneficiaryName;
|
||||
private LocalDateTime submissionDate;
|
||||
private LocalDateTime callStartDate;
|
||||
private LocalDateTime callEndDate;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,13 +32,13 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
|
||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.userId = :userId AND a.company.id = :companyId AND a.status = 'SUBMIT' ")
|
||||
Long countSubmittedApplicationsByUserId(@Param("userId") Long userId, @Param("companyId") Long companyId);
|
||||
|
||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'SUBMIT'")
|
||||
Long countSubmittedApplications();
|
||||
|
||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'DRAFT'")
|
||||
Long countDraftApplications();
|
||||
|
||||
List<ApplicationEntity> findByCompanyIdAndUserIdAndIsDeletedFalse(Long companyId,Long userId);
|
||||
|
||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'SUBMIT' And a.hubId = :hubId")
|
||||
public Long countSubmittedApplicationsByHubId(@Param("hubId") Long hubId);
|
||||
|
||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'DRAFT' And a.hubId = :hubId")
|
||||
public Long countDraftApplicationsByHubId(@Param("hubId") Long hubId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.gepafin.tendermanagement.repositories;
|
||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||
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.math.BigDecimal;
|
||||
@@ -11,18 +11,30 @@ import java.util.List;
|
||||
@Repository
|
||||
public interface CallRepository extends JpaRepository<CallEntity, Long> {
|
||||
|
||||
public CallEntity findByIdAndStatusNotIn(Long id, List<String> status);
|
||||
List<CallEntity> findByStatusIn(List<String> callStatus);
|
||||
// public CallEntity findByIdAndStatusNotIn(Long id, List<String> status);
|
||||
|
||||
// List<CallEntity> findByStatusIn(List<String> callStatus);
|
||||
|
||||
public CallEntity findByIdAndStatus(Long id,String status);
|
||||
// public CallEntity findByIdAndStatus(Long id,String status);
|
||||
|
||||
public Long countByStatus(String status);
|
||||
// public Long countByStatus(String status);
|
||||
|
||||
@Query("SELECT COALESCE(SUM(c.amount), 0) FROM CallEntity c WHERE c.status = 'PUBLISH'")
|
||||
BigDecimal findTotalAmountOfPublishedCalls();
|
||||
// @Query("SELECT COALESCE(SUM(c.amount), 0) FROM CallEntity c WHERE c.status = 'PUBLISH'")
|
||||
// BigDecimal findTotalAmountOfPublishedCalls();
|
||||
|
||||
@Query("SELECT c.name, COUNT(a.id) " +
|
||||
"FROM CallEntity c LEFT JOIN ApplicationEntity a ON c.id = a.call.id " +
|
||||
"GROUP BY c.name")
|
||||
List<Object[]> findApplicationsPerCall();
|
||||
// @Query("SELECT c.name, COUNT(a.id) " +
|
||||
// "FROM CallEntity c LEFT JOIN ApplicationEntity a ON c.id = a.call.id " +
|
||||
// "GROUP BY c.name")
|
||||
// List<Object[]> findApplicationsPerCall();
|
||||
|
||||
public List<CallEntity> findByStatusInAndHubId(List<String> callStatus, Long hubId);
|
||||
|
||||
public CallEntity findByIdAndStatusAndHubId(Long id, String status, Long hubId);
|
||||
|
||||
public Long countByStatusAndHubId(String status, Long hubId);
|
||||
|
||||
public CallEntity findByIdAndStatusNotInAndHubId(Long id, List<String> status, Long hubId);
|
||||
|
||||
@Query("SELECT COALESCE(SUM(c.amount), 0) FROM CallEntity c WHERE c.status = 'PUBLISH' And c.hub.id = :hubId")
|
||||
BigDecimal findTotalAmountOfPublishedCallsAndHubId(@Param("hubId") Long hubId);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
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 net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||
@@ -11,13 +12,14 @@ import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||
@Repository
|
||||
public interface CompanyRepository extends JpaRepository<CompanyEntity, Long> {
|
||||
|
||||
List<CompanyEntity> findByIdIn(List<Long> companyIds);
|
||||
List<CompanyEntity> findByIdInAndHubId(List<Long> companyIds, Long hubId);
|
||||
|
||||
Boolean existsByVatNumber(String vatNumber);
|
||||
CompanyEntity findByVatNumber(String vatNumber);
|
||||
Boolean existsByVatNumberAndHubId(String vatNumber, Long hubId);
|
||||
|
||||
@Query("SELECT COUNT(c) FROM CompanyEntity c")
|
||||
long countTotalCompanies();
|
||||
@Query("SELECT COUNT(c) FROM CompanyEntity c where c.hub.id = :hubId")
|
||||
long countTotalCompaniesByHubId(@Param("hubId") Long hubId);
|
||||
|
||||
CompanyEntity findByVatNumberAndHubId(String vatNumber, Long hubId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,21 +10,9 @@ import java.util.Optional;
|
||||
@Repository
|
||||
public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
||||
|
||||
// Optional<UserEntity> findByEmailIgnoreCase(String email);
|
||||
|
||||
// boolean existsByEmailIgnoreCase(String email);
|
||||
|
||||
// UserEntity findByEmail(String email);
|
||||
|
||||
Optional<UserEntity> findByBeneficiaryCodiceFiscale(String codiceFiscale);
|
||||
|
||||
boolean existsByBeneficiaryCodiceFiscale(String codiceFiscale);
|
||||
|
||||
UserEntity findByBeneficiaryId(Long beneficiaryId);
|
||||
|
||||
Long countByStatusAndRoleEntityRoleType(String status, String roleName);
|
||||
|
||||
Optional<UserEntity> findByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubId);
|
||||
Optional<UserEntity> findByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
|
||||
|
||||
boolean existsByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
|
||||
|
||||
@@ -35,4 +23,6 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
||||
Long countByStatusAndRoleEntityRoleTypeAndHubId(String status, String roleName, Long hubId);
|
||||
|
||||
Optional<UserEntity> findByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
|
||||
|
||||
boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,8 @@ public interface UserWithCompanyRepository extends JpaRepository<UserWithCompany
|
||||
|
||||
void deleteByCompanyIdAndIsDeletedFalse(Long companyId);
|
||||
|
||||
@Query("SELECT u.companyId FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.isDeleted = false")
|
||||
List<Long> findActiveCompanyIdsByUserId(@Param("userId") Long userId);
|
||||
|
||||
|
||||
@Query("SELECT u.companyId FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.isDeleted = false")
|
||||
List<Long> findActiveCompanyIdsByUserId(@Param("userId") Long userId);
|
||||
|
||||
Optional<UserWithCompanyEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(Long userId, Long companyId);
|
||||
|
||||
|
||||
@@ -29,6 +29,6 @@ public interface CallService {
|
||||
|
||||
CallEntity validateCall(Long callId);
|
||||
|
||||
CallEntity validatePublishedCall(Long callId);
|
||||
byte[] downloadCallDocumentsAsZip(Long callId);
|
||||
CallEntity validatePublishedCall(Long callId, Long hubId);
|
||||
byte[] downloadCallDocumentsAsZip(HttpServletRequest request, Long callId);
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ import java.util.List;
|
||||
public interface UserService {
|
||||
JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq);
|
||||
|
||||
UserResponseBean updateUser(Long userId, UpdateUserReq userReq);
|
||||
UserResponseBean updateUser(HttpServletRequest request, Long userId, UpdateUserReq userReq);
|
||||
|
||||
UserResponseBean getUserById(Long userId);
|
||||
UserResponseBean getUserById(HttpServletRequest request, Long userId);
|
||||
|
||||
void deleteUser(Long userId);
|
||||
void deleteUser(HttpServletRequest request, Long userId);
|
||||
|
||||
JWTToken login(LoginReq loginReq,HttpServletRequest request);
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
public ApplicationResponse createApplication(HttpServletRequest request, Long companyId, ApplicationRequest applicationRequest, Long callId) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
CompanyEntity companyEntity = validator.validateUserWithCompany(request, companyId);
|
||||
validator.validateUserWithCall(userEntity, callId);
|
||||
return applicationDao.createApplicationByCallId(companyEntity, applicationRequest, callId, userEntity);
|
||||
}
|
||||
|
||||
@@ -114,7 +115,6 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApplicationResponse validateApplication(HttpServletRequest request, Long applicationId) {
|
||||
return applicationDao.validateApplication(request, applicationId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class AuthenticationService {
|
||||
|
||||
public JWTToken login(LoginReq loginReq, HttpServletRequest request) {
|
||||
UserEntity user=null;
|
||||
|
||||
|
||||
LoginAttemptEntity loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request);
|
||||
log.info("Attempting login for email: {}", loginReq.getEmail());
|
||||
String emailWithHubId = loginReq.getEmail()+":"+loginReq.getHubUuid();
|
||||
@@ -211,10 +211,11 @@ public class AuthenticationService {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.INVALID_TOKEN_MSG));
|
||||
}
|
||||
HubEntity hub = hubService.getHubByUuid(samlResponseLogEntity.getHubUuid());
|
||||
Map<String, List<Object>> userAttributes = Utils
|
||||
.convertStringIntoMap(samlResponseLogEntity.getAuthenticationObject());
|
||||
String cf = userAttributes.get("CodiceFiscale").get(0).toString();
|
||||
if (userRepository.existsByBeneficiaryCodiceFiscale(cf)) {
|
||||
if (userRepository.existsByBeneficiaryCodiceFiscaleAndHubId(cf, hub.getId())) {
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_ALREADY_EXIST_MSG));
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
||||
|
||||
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.service.BeneficiaryPreferredCallService;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
@@ -17,7 +16,6 @@ import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationExceptio
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,10 +24,10 @@ public class BeneficiaryPreferredCallServiceImpl implements BeneficiaryPreferred
|
||||
|
||||
@Autowired
|
||||
private BeneficiaryPreferredCallDao beneficiaryPreferredCallDao;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@@ -81,7 +79,7 @@ public class BeneficiaryPreferredCallServiceImpl implements BeneficiaryPreferred
|
||||
}
|
||||
if(beneficiaryId!=null){
|
||||
UserEntity user = userService.getUserByBeneficiaryId(beneficiaryId);
|
||||
return validator.validateUserId(request,user.getId());
|
||||
return validator.validateUserId(request, user.getId());
|
||||
}
|
||||
else{
|
||||
return validator.validateUserId(request, userId);
|
||||
|
||||
@@ -91,13 +91,15 @@ public class CallServiceImpl implements CallService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallEntity validatePublishedCall(Long callId) {
|
||||
return callDao.validatePublishedCall(callId);
|
||||
public CallEntity validatePublishedCall(Long callId, Long hubId) {
|
||||
return callDao.validatePublishedCall(callId, hubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public byte[] downloadCallDocumentsAsZip(Long callId) {
|
||||
public byte[] downloadCallDocumentsAsZip(HttpServletRequest request, Long callId) {
|
||||
UserEntity user = validator.validateUser(request);
|
||||
validator.validateUserWithCall(user, callId);
|
||||
return callDao.downloadCallDocumentsAsZip(callId);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CompanyResponse updateCompany(HttpServletRequest request, Long companyId, CompanyRequest companyRequest) {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
return companyDao.updateCompany(userEntity, companyId, companyRequest);
|
||||
}
|
||||
|
||||
@@ -56,6 +57,7 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
@Transactional(readOnly = true)
|
||||
public CompanyResponse getCompany(HttpServletRequest request, Long companyId) {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
return companyDao.getCompany(userEntity, companyId);
|
||||
}
|
||||
|
||||
@@ -63,13 +65,14 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteCompany(HttpServletRequest request, Long companyId) {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
companyDao.deleteCompany(userEntity, companyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<CompanyResponse> getCompanyByUserId(HttpServletRequest request, Long userId) {
|
||||
validator.validateUser(request);
|
||||
validator.validateUserId(request, userId);
|
||||
return companyDao.getCompanyByUserId(userId);
|
||||
}
|
||||
|
||||
@@ -91,8 +94,7 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ByteArrayOutputStream downloadCompanyDelegation(HttpServletRequest request, Long companyId, CompanyDelegationRequest companyDelegationRequest) {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
return delegationDao.downloadCompanyDelegation(userEntity, companyId, companyDelegationRequest);
|
||||
return delegationDao.downloadCompanyDelegation(request, companyId, companyDelegationRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,8 @@ import net.gepafin.tendermanagement.dao.FlowDao;
|
||||
import net.gepafin.tendermanagement.model.request.FlowRequestBean;
|
||||
import net.gepafin.tendermanagement.model.response.FlowResponseBean;
|
||||
import net.gepafin.tendermanagement.service.FlowService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -14,16 +16,21 @@ public class FlowServiceImpl implements FlowService {
|
||||
|
||||
@Autowired
|
||||
private FlowDao flowDao;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public FlowResponseBean createOrUpdateFlow(HttpServletRequest httpServletRequest, FlowRequestBean flowRequestBean, Long callId) {
|
||||
validator.validateUserWithCall(validator.validateUser(httpServletRequest), callId);
|
||||
return flowDao.createOrUpdateFlow(flowRequestBean,callId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@org.springframework.transaction.annotation.Transactional(readOnly = true)
|
||||
public FlowResponseBean getFlowByCallId(HttpServletRequest request, Long callId) {
|
||||
validator.validateUserWithCall(validator.validateUser(request), callId);
|
||||
return flowDao.getFlowByCallId(callId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,19 +40,22 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public UserResponseBean updateUser(Long userId, UpdateUserReq userReq) {
|
||||
public UserResponseBean updateUser(HttpServletRequest request, Long userId, UpdateUserReq userReq) {
|
||||
validator.validateUserId(request, userId);
|
||||
return userDao.updateUser(userId, userReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public UserResponseBean getUserById(Long userId) {
|
||||
public UserResponseBean getUserById(HttpServletRequest request, Long userId) {
|
||||
validator.validateUserId(request, userId);
|
||||
return userDao.getUserById(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteUser(Long userId) {
|
||||
public void deleteUser(HttpServletRequest request, Long userId) {
|
||||
validator.validateUserId(request, userId);
|
||||
userDao.deleteUser(userId);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.dao.CallDao;
|
||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
@@ -73,13 +72,24 @@ public class Validator {
|
||||
}
|
||||
|
||||
public CompanyEntity validateUserWithCompany(HttpServletRequest request, Long companyId) {
|
||||
CompanyEntity companyEntity = companyService.validateCompany(companyId);
|
||||
validateHubId(request, companyEntity.getHub().getId());
|
||||
if (checkIsSuperAdmin()) {
|
||||
return companyService.validateCompany(companyId);
|
||||
return companyEntity;
|
||||
}
|
||||
Map<String, Object> userInfo = tokenProvider.getUserInfoAndUserIdFromToken(request);
|
||||
companyService.validateUserWithCompny(getUserId(userInfo), companyId);
|
||||
return companyService.validateCompany(companyId);
|
||||
}
|
||||
|
||||
public void validateHubId(HttpServletRequest request, Long hubId) {
|
||||
UserEntity user = validateUser(request);
|
||||
Long hubIdFromHttpRequest = user.getHub().getId();
|
||||
if (Boolean.FALSE.equals(hubIdFromHttpRequest.equals(hubId))) {
|
||||
throw new ForbiddenAccessException(Status.FORBIDDEN,
|
||||
Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||
}
|
||||
}
|
||||
|
||||
private Long getUserId(Map<String, Object> userInfo) {
|
||||
return Long.parseLong(userInfo.get("userId").toString());
|
||||
@@ -100,10 +110,15 @@ public class Validator {
|
||||
|
||||
public UserEntity validateUserId(HttpServletRequest request, Long userId) {
|
||||
UserEntity user = validateUser(request);
|
||||
if(user.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue()) && Boolean.FALSE.equals(user.getId().equals(userId))) {
|
||||
throw new ForbiddenAccessException(Status.FORBIDDEN, Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||
UserEntity requestedUser = userService.validateUser(userId);
|
||||
|
||||
validateHubId(request, requestedUser.getHub().getId());
|
||||
if (Boolean.FALSE.equals(user.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_SUPER_ADMIN.getValue()))
|
||||
&& Boolean.FALSE.equals(user.getId().equals(userId))) {
|
||||
throw new ForbiddenAccessException(Status.FORBIDDEN,
|
||||
Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||
}
|
||||
return userService.validateUser(userId);
|
||||
return requestedUser;
|
||||
}
|
||||
|
||||
private Long getUserIdFromToken(HttpServletRequest request) {
|
||||
|
||||
@@ -59,7 +59,7 @@ public interface UserApi {
|
||||
@RequestMapping(value = "/{userId}",
|
||||
produces = {"application/json"},
|
||||
method = RequestMethod.PUT)
|
||||
default ResponseEntity<Response<UserResponseBean>> updateUser(
|
||||
default ResponseEntity<Response<UserResponseBean>> updateUser(HttpServletRequest request,
|
||||
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId,
|
||||
@Parameter(description = "User request object", required = true) @Valid @RequestBody UpdateUserReq userReq) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
@@ -77,7 +77,7 @@ public interface UserApi {
|
||||
@RequestMapping(value = "/{userId}",
|
||||
produces = {"application/json"},
|
||||
method = RequestMethod.GET)
|
||||
default ResponseEntity<Response<UserResponseBean>> getUserById(
|
||||
default ResponseEntity<Response<UserResponseBean>> getUserById(HttpServletRequest request,
|
||||
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public interface UserApi {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
|
||||
@RequestMapping(value = "/{userId}",
|
||||
method = RequestMethod.DELETE)
|
||||
default ResponseEntity<Response<Void>> deleteUser(
|
||||
default ResponseEntity<Response<Void>> deleteUser(HttpServletRequest request,
|
||||
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class CallApiController implements CallApi {
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<byte[]> downloadCallDocumentsAsZip(HttpServletRequest request, Long callId) {
|
||||
byte[] zipFile = callService.downloadCallDocumentsAsZip(callId);
|
||||
byte[] zipFile = callService.downloadCallDocumentsAsZip(request, callId);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
|
||||
@@ -44,29 +44,29 @@ public class UserApiController implements UserApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<UserResponseBean>> updateUser(
|
||||
public ResponseEntity<Response<UserResponseBean>> updateUser(HttpServletRequest request,
|
||||
@PathVariable("userId") Long userId,
|
||||
@Valid @RequestBody UpdateUserReq userReq) {
|
||||
log.info("Update User - User ID: {}, Request Body: {}", userId, userReq);
|
||||
UserResponseBean updatedUser = userService.updateUser(userId, userReq);
|
||||
UserResponseBean updatedUser = userService.updateUser(request, userId, userReq);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(updatedUser, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_UPDATED_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<UserResponseBean>> getUserById(
|
||||
public ResponseEntity<Response<UserResponseBean>> getUserById(HttpServletRequest request,
|
||||
@PathVariable("userId") Long userId) {
|
||||
log.info("Get User by ID - User ID: {}", userId);
|
||||
UserResponseBean user = userService.getUserById(userId);
|
||||
UserResponseBean user = userService.getUserById(request, userId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(user, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USER_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> deleteUser(
|
||||
public ResponseEntity<Response<Void>> deleteUser(HttpServletRequest request,
|
||||
@PathVariable("userId") Long userId) {
|
||||
log.info("Delete User - User ID: {}", userId);
|
||||
userService.deleteUser(userId);
|
||||
userService.deleteUser(request, userId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_DELETED_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@@ -1328,4 +1328,70 @@
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
|
||||
|
||||
<changeSet id="24-10-2024_1" author="Rajesh Khore">
|
||||
<dropUniqueConstraint
|
||||
constraintName="company_vat_number_key"
|
||||
tableName="company"/>
|
||||
|
||||
<addColumn tableName="company">
|
||||
<column name="hub_id" type="INTEGER" defaultValue="1">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</addColumn>
|
||||
|
||||
<addUniqueConstraint
|
||||
columnNames="VAT_NUMBER, hub_id"
|
||||
tableName="company"
|
||||
constraintName="uk_vat_hub" />
|
||||
|
||||
<addForeignKeyConstraint
|
||||
baseTableName="company"
|
||||
baseColumnNames="hub_id"
|
||||
referencedTableName="hub"
|
||||
referencedColumnNames="id"
|
||||
constraintName="fk_company_hub" />
|
||||
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="24-10-2024_2" author="Rajesh Khore">
|
||||
<dropUniqueConstraint
|
||||
constraintName="beneficiary_codice_fiscale_key"
|
||||
tableName="beneficiary"/>
|
||||
|
||||
<addColumn tableName="beneficiary">
|
||||
<column name="hub_id" type="INTEGER" defaultValue="1">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</addColumn>
|
||||
|
||||
<addUniqueConstraint
|
||||
columnNames="CODICE_FISCALE, hub_id"
|
||||
tableName="beneficiary"
|
||||
constraintName="uk_codice_hub" />
|
||||
|
||||
<addForeignKeyConstraint
|
||||
baseTableName="beneficiary"
|
||||
baseColumnNames="hub_id"
|
||||
referencedTableName="hub"
|
||||
referencedColumnNames="id"
|
||||
constraintName="fk_beneficiary_hub" />
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="24-10-2024_3" author="Rajesh Khore">
|
||||
<addColumn tableName="application">
|
||||
<column name="hub_id" type="INTEGER" defaultValue="1">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</addColumn>
|
||||
|
||||
<addForeignKeyConstraint
|
||||
baseTableName="application"
|
||||
baseColumnNames="hub_id"
|
||||
referencedTableName="hub"
|
||||
referencedColumnNames="id"
|
||||
constraintName="fk_application_hub" />
|
||||
</changeSet>
|
||||
|
||||
|
||||
</databaseChangeLog>
|
||||
|
||||
Reference in New Issue
Block a user