Merged with develop

This commit is contained in:
harish
2024-10-25 00:27:45 +05:30
34 changed files with 330 additions and 150 deletions

View File

@@ -139,7 +139,7 @@ public class ApplicationDao {
} }
formService.validateFormField(applicationRequestBean.getFormFields(),applicationEntity,formEntity); formService.validateFormField(applicationRequestBean.getFormFields(),applicationEntity,formEntity);
ApplicationFormEntity applicationFormEntity = getApplicationFormOrCreate(formEntity, applicationEntity); ApplicationFormEntity applicationFormEntity = getApplicationFormOrCreate(formEntity, applicationEntity);
createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity,formEntity); createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity, formEntity);
return getApplicationById(applicationEntity.getId(),formEntity.getId()); return getApplicationById(applicationEntity.getId(),formEntity.getId());
} }
public void validateDelegation(UserEntity user, CompanyEntity company) { public void validateDelegation(UserEntity user, CompanyEntity company) {
@@ -175,6 +175,7 @@ public class ApplicationDao {
entity.setUserId(user.getId()); entity.setUserId(user.getId());
entity.setCompany(companyEntity); entity.setCompany(companyEntity);
entity.setCall(call); entity.setCall(call);
entity.setHubId(call.getHub().getId());
entity.setIsDeleted(false); entity.setIsDeleted(false);
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue()); entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
return entity; return entity;
@@ -287,7 +288,7 @@ public class ApplicationDao {
log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType()); 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); 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) -> { return (root, query, builder) -> {
Boolean isBeneficiary = validator.checkIsBeneficiary(); Boolean isBeneficiary = validator.checkIsBeneficiary();
Predicate predicate = builder.isFalse(root.get("isDeleted")); Predicate predicate = builder.isFalse(root.get("isDeleted"));
if (isBeneficiary) { 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) { if (callId != null) {
predicate = builder.and(predicate, builder.equal(root.get("call").get("id"), callId)); predicate = builder.and(predicate, builder.equal(root.get("call").get("id"), callId));
@@ -313,7 +314,7 @@ public class ApplicationDao {
if (status != null) { if (status != null) {
predicate = builder.and(predicate, builder.equal(root.get("status"), status)); predicate = builder.and(predicate, builder.equal(root.get("status"), status));
} }
predicate = builder.and(predicate, builder.equal(root.get("hubId"), userEntity.getHub().getId()));
return predicate; return predicate;
}; };
} }
@@ -600,7 +601,7 @@ public class ApplicationDao {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_IN_PREVIOUS_STATUS)); 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()))) { 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()); Long protocolNumber = getProtocolNumber(userEntity.getHub());
ProtocolEntity protocolEntity = createProtocolEntity(applicationEntity,protocolNumber, userEntity.getHub().getId()); ProtocolEntity protocolEntity = createProtocolEntity(applicationEntity,protocolNumber, userEntity.getHub().getId());
applicationEntity.setProtocol(protocolEntity); applicationEntity.setProtocol(protocolEntity);

View File

@@ -9,6 +9,7 @@ import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
import net.gepafin.tendermanagement.enums.AssignedApplicationEnum; import net.gepafin.tendermanagement.enums.AssignedApplicationEnum;
import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest; import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest;
import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse; import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse;
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository; import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository;
import net.gepafin.tendermanagement.service.ApplicationService; import net.gepafin.tendermanagement.service.ApplicationService;
import net.gepafin.tendermanagement.service.UserService; import net.gepafin.tendermanagement.service.UserService;
@@ -31,13 +32,16 @@ import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
public class AssignedApplicationsDao { public class AssignedApplicationsDao {
@Autowired @Autowired
ApplicationService applicationService; private ApplicationService applicationService;
@Autowired @Autowired
AssignedApplicationsRepository assignedApplicationsRepository; private ApplicationRepository applicationRepository;
@Autowired @Autowired
UserService userService; private AssignedApplicationsRepository assignedApplicationsRepository;
@Autowired
private UserService userService;
public AssignedApplicationsResponse createAssignedApplications(Long applicationId, Long userId, UserEntity assignedByUser, AssignedApplicationsRequest assignedApplicationsRequest){ public AssignedApplicationsResponse createAssignedApplications(Long applicationId, Long userId, UserEntity assignedByUser, AssignedApplicationsRequest assignedApplicationsRequest){
log.info("Assigning application to pre-Instructor with details: {}", applicationId,userId); 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)); throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_ASSIGNED));
} }
ApplicationEntity application = applicationService.validateApplication(applicationId); 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( throw new CustomValidationException(
Status.BAD_REQUEST, Status.BAD_REQUEST,
Translator.toLocale(GepafinConstant.INVALID_APPLICATION_STATUS) Translator.toLocale(GepafinConstant.INVALID_APPLICATION_STATUS)
); );
} }
application.setStatus(ApplicationStatusTypeEnum.EVALUATION.getValue());
applicationRepository.save(application);
UserEntity user = userService.validateUser(userId); UserEntity user = userService.validateUser(userId);
AssignedApplicationsEntity assignment = createAssignmentEntity(application, user.getId(), assignedByUser, assignedApplicationsRequest); AssignedApplicationsEntity assignment = createAssignmentEntity(application, user.getId(), assignedByUser, assignedApplicationsRequest);
AssignedApplicationsResponse assignApplicationToInstructorResponse = convertEntityToResponse(assignment, assignedApplicationsRequest); AssignedApplicationsResponse assignApplicationToInstructorResponse = convertEntityToResponse(assignment);
log.info("Application assigned succesfully {}", assignApplicationToInstructorResponse); log.info("Application assigned succesfully {}", assignApplicationToInstructorResponse);
return assignApplicationToInstructorResponse; return assignApplicationToInstructorResponse;
@@ -66,7 +74,10 @@ public class AssignedApplicationsDao {
assignApplication.setApplication(application); assignApplication.setApplication(application);
assignApplication.setAssignedBy(assignedByUser.getId()); assignApplication.setAssignedBy(assignedByUser.getId());
assignApplication.setUserId(userId); 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.setNote(assignedApplicationsRequest.getNote());
assignApplication.setIsDeleted(false); assignApplication.setIsDeleted(false);
assignApplication.setAssignedAt(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); assignApplication.setAssignedAt(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
@@ -79,17 +90,44 @@ public class AssignedApplicationsDao {
return assignedApplication; return assignedApplication;
} }
public AssignedApplicationsResponse convertEntityToResponse(AssignedApplicationsEntity application, AssignedApplicationsRequest assignedApplicationsRequest){ public AssignedApplicationsResponse convertEntityToResponse(AssignedApplicationsEntity assignedApplications){
AssignedApplicationsResponse assignedApplicationsResponse = new AssignedApplicationsResponse(); AssignedApplicationsResponse assignedApplicationsResponse = new AssignedApplicationsResponse();
assignedApplicationsResponse.setId(application.getId()); assignedApplicationsResponse.setId(assignedApplications.getId());
assignedApplicationsResponse.setApplicationId(application.getApplication().getId()); assignedApplicationsResponse.setApplicationId(assignedApplications.getApplication().getId());
assignedApplicationsResponse.setAssignedBy(application.getAssignedBy());
assignedApplicationsResponse.setUserId(application.getUserId()); ApplicationEntity application = applicationService.validateApplication(assignedApplications.getApplication().getId());
assignedApplicationsResponse.setCreatedDate(application.getCreatedDate()); String callName = application.getCall() != null ? application.getCall().getName() : "";
assignedApplicationsResponse.setUpdatedDate(application.getUpdatedDate()); LocalDateTime callEndDate = application.getCall().getEndDate();
assignedApplicationsResponse.setNote(application.getNote()); LocalDateTime callStartDate = application.getCall().getStartDate();
assignedApplicationsResponse.setStatus(AssignedApplicationEnum.valueOf(application.getStatus()));
assignedApplicationsResponse.setAssignedAt(application.getAssignedAt()); 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; return assignedApplicationsResponse;
} }
@@ -111,7 +149,7 @@ public class AssignedApplicationsDao {
Specification<AssignedApplicationsEntity> spec = search(userId); Specification<AssignedApplicationsEntity> spec = search(userId);
List<AssignedApplicationsEntity> assignedApplicationsEntityList = assignedApplicationsRepository.findAll(spec); List<AssignedApplicationsEntity> assignedApplicationsEntityList = assignedApplicationsRepository.findAll(spec);
return assignedApplicationsEntityList.stream() return assignedApplicationsEntityList.stream()
.map(entity -> convertEntityToResponse(entity, new AssignedApplicationsRequest())) .map(entity -> convertEntityToResponse(entity))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private Specification<AssignedApplicationsEntity> search(Long userId) { private Specification<AssignedApplicationsEntity> search(Long userId) {
@@ -138,7 +176,7 @@ public class AssignedApplicationsDao {
existingAssignment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); existingAssignment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
AssignedApplicationsEntity updatedAssignment = saveAssignedApplication(existingAssignment); AssignedApplicationsEntity updatedAssignment = saveAssignedApplication(existingAssignment);
AssignedApplicationsResponse response = convertEntityToResponse(updatedAssignment, updateRequest); AssignedApplicationsResponse response = convertEntityToResponse(updatedAssignment);
log.info("Assigned application updated successfully: {}", response); log.info("Assigned application updated successfully: {}", response);
return response; return response;
} }
@@ -146,7 +184,7 @@ public class AssignedApplicationsDao {
public AssignedApplicationsResponse getAssignedApplicationById(Long id) { public AssignedApplicationsResponse getAssignedApplicationById(Long id) {
log.info("Fetching assigned application with ID: {}", id); log.info("Fetching assigned application with ID: {}", id);
AssignedApplicationsEntity assignedApplication = validateAssignedApplication(id); AssignedApplicationsEntity assignedApplication = validateAssignedApplication(id);
AssignedApplicationsResponse response = convertEntityToResponse(assignedApplication, new AssignedApplicationsRequest()); AssignedApplicationsResponse response = convertEntityToResponse(assignedApplication);
log.info("Assigned application fetched successfully: {}", response); log.info("Assigned application fetched successfully: {}", response);
return response; return response;
} }

View File

@@ -230,6 +230,7 @@ public class CallDao {
criteriaEntity = new EvaluationCriteriaEntity(); criteriaEntity = new EvaluationCriteriaEntity();
criteriaEntity.setCall(callEntity); criteriaEntity.setCall(callEntity);
criteriaEntity.setLookupData(lookupDataEntity); criteriaEntity.setLookupData(lookupDataEntity);
criteriaEntity.setScore(0L);
criteriaEntity.setIsDeleted(false); criteriaEntity.setIsDeleted(false);
} }
setIfUpdated(criteriaEntity::getScore, criteriaEntity::setScore, criteriaReq.getScore()); setIfUpdated(criteriaEntity::getScore, criteriaEntity::setScore, criteriaReq.getScore());
@@ -653,7 +654,7 @@ public class CallDao {
if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) { if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) {
callStatusList = List.of(CallStatusEnum.PUBLISH.getValue()); callStatusList = List.of(CallStatusEnum.PUBLISH.getValue());
} }
List<CallEntity> calls = callRepository.findByStatusIn(callStatusList); List<CallEntity> calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId());
return calls.stream() return calls.stream()
.map(this::convertToCallDetailsResponseBean) .map(this::convertToCallDetailsResponseBean)
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -671,13 +672,13 @@ public class CallDao {
callResponseBean.setStatus(CallStatusEnum.valueOf(callEntity.getStatus())); callResponseBean.setStatus(CallStatusEnum.valueOf(callEntity.getStatus()));
return callResponseBean; return callResponseBean;
} }
public CallEntity getCallEntityById(Long id){ // public CallEntity getCallEntityById(Long id){
CallEntity callEntity=callRepository.findByIdAndStatusNotIn(id,List.of(CallStatusEnum.PUBLISH.getValue())); // CallEntity callEntity=callRepository.findByIdAndStatusNotInAndHubId(id, List.of(CallStatusEnum.PUBLISH.getValue()));
if(callEntity==null){ // if(callEntity==null){
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)); // throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND));
} // }
return callEntity; // return callEntity;
} // }
public CallResponse updateCallStatus(CallEntity callEntity, CallStatusEnum statusReq) { public CallResponse updateCallStatus(CallEntity callEntity, CallStatusEnum statusReq) {
CallStatusEnum currentStatus = CallStatusEnum.valueOf(callEntity.getStatus()); 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 CallEntity callEntity= callRepository
.findByIdAndStatus(callId, CallStatusEnum.PUBLISH.getValue()); .findByIdAndStatusAndHubId(callId, CallStatusEnum.PUBLISH.getValue(), hubId);
if(callEntity==null){ if(callEntity==null){
throw new ResourceNotFoundException( throw new ResourceNotFoundException(
Status.NOT_FOUND, Status.NOT_FOUND,

View File

@@ -40,7 +40,7 @@ public class CompanyDao {
public CompanyResponse createCompany(UserEntity userEntity, CompanyRequest companyRequest) { 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; UserWithCompanyEntity userWithCompanyEntity = null;
if (existingCompany != null) { if (existingCompany != null) {
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()) UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId())
@@ -53,8 +53,8 @@ public class CompanyDao {
} }
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity); return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
} else { } else {
validateCompany(companyRequest); validateCompany(userEntity, companyRequest);
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(companyRequest); CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(userEntity, companyRequest);
companyRepository.save(companyEntity); companyRepository.save(companyEntity);
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant()); userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity); 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())) if (Boolean.FALSE.equals(StringUtils.isEmpty(companyRequest.getEmail()))
&& Boolean.FALSE.equals(Utils.isValidEmail(companyRequest.getEmail()))) { && Boolean.FALSE.equals(Utils.isValidEmail(companyRequest.getEmail()))) {
@@ -73,7 +73,7 @@ public class CompanyDao {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VATNUMBER_MANDATORY)); Translator.toLocale(GepafinConstant.VATNUMBER_MANDATORY));
} }
if (companyRepository.existsByVatNumber(companyRequest.getVatNumber())) { if (companyRepository.existsByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId())) {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS)); Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
} }
@@ -91,7 +91,7 @@ public class CompanyDao {
return userWithCompanyRepository.save(userWithCompanyEntity); return userWithCompanyRepository.save(userWithCompanyEntity);
} }
private CompanyEntity convertCompanyRequestToCompanyEntity(CompanyRequest request) { private CompanyEntity convertCompanyRequestToCompanyEntity(UserEntity userEntity, CompanyRequest request) {
CompanyEntity entity = new CompanyEntity(); CompanyEntity entity = new CompanyEntity();
entity.setCompanyName(request.getCompanyName()); entity.setCompanyName(request.getCompanyName());
entity.setVatNumber(request.getVatNumber()); entity.setVatNumber(request.getVatNumber());
@@ -108,6 +108,7 @@ public class CompanyDao {
entity.setAnnualRevenue(request.getAnnualRevenue()); entity.setAnnualRevenue(request.getAnnualRevenue());
entity.setContactName(request.getContactName()); entity.setContactName(request.getContactName());
entity.setContactEmail(request.getContactEmail()); entity.setContactEmail(request.getContactEmail());
entity.setHub(userEntity.getHub());
return entity; return entity;
} }
@@ -186,7 +187,7 @@ public class CompanyDao {
public List<CompanyResponse> getCompanyByUserId(Long userId) { public List<CompanyResponse> getCompanyByUserId(Long userId) {
UserEntity userEntity = userService.validateUser(userId); UserEntity userEntity = userService.validateUser(userId);
List<Long> activeCompanyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(userEntity.getId()); 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 -> { return companies.stream().map(companyEntity -> {
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyEntity.getId()); UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyEntity.getId());
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity); return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);

View File

@@ -60,7 +60,7 @@ public class DashboardDao {
} }
private void setActiveCalls(Widget1 widget1, UserEntity requestedUserEntity) { 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) { if (activeCalls != null) {
widget1.setNumberOfActiveCalls(activeCalls); widget1.setNumberOfActiveCalls(activeCalls);
} }
@@ -74,27 +74,27 @@ public class DashboardDao {
} }
} }
private void setTotalActiveFinancing(Widget1 widget1, UserEntity requestedUserEntity) { private void setTotalActiveFinancing(Widget1 widget1, UserEntity requestedUser) {
BigDecimal totalActiveFinancing = callRepository.findTotalAmountOfPublishedCalls(); BigDecimal totalActiveFinancing = callRepository.findTotalAmountOfPublishedCallsAndHubId(requestedUser.getHub().getId());
widget1.setTotalActiveFinancing(totalActiveFinancing); widget1.setTotalActiveFinancing(totalActiveFinancing);
} }
private void setSubmittedApplications(Widget1 widget1, UserEntity requestedUserEntity) { private void setSubmittedApplications(Widget1 widget1, UserEntity requestedUserEntity) {
Long submittedApplications = applicationRepository.countSubmittedApplications(); Long submittedApplications = applicationRepository.countSubmittedApplicationsByHubId(requestedUserEntity.getHub().getId());
if (submittedApplications != null) { if (submittedApplications != null) {
widget1.setNumberOfSubmittedApplications(submittedApplications); widget1.setNumberOfSubmittedApplications(submittedApplications);
} }
} }
private void setDraftApplications(Widget1 widget1, UserEntity requestedUserEntity) { private void setDraftApplications(Widget1 widget1, UserEntity requestedUserEntity) {
Long draftApplications = applicationRepository.countDraftApplications(); Long draftApplications = applicationRepository.countDraftApplicationsByHubId(requestedUserEntity.getHub().getId());
if (draftApplications != null) { if (draftApplications != null) {
widget1.setNumberOfDraftApplications(draftApplications); widget1.setNumberOfDraftApplications(draftApplications);
} }
} }
private void setNumberOfCompanies(Widget1 widget1, UserEntity requestedUserEntity) { private void setNumberOfCompanies(Widget1 widget1, UserEntity requestedUserEntity) {
Long numberOfCompanies = companyRepository.countTotalCompanies(); Long numberOfCompanies = companyRepository.countTotalCompaniesByHubId(requestedUserEntity.getHub().getId());
if (numberOfCompanies != null) { if (numberOfCompanies != null) {
widget1.setNumberOfCompany(numberOfCompanies); widget1.setNumberOfCompany(numberOfCompanies);
} }
@@ -104,7 +104,7 @@ public class DashboardDao {
CompanyEntity company) { CompanyEntity company) {
BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder() BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder()
.numberOfApplications(0L).numberOfCalls(0L).numberOfIntegratedDocuments(0L).build(); .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) { if (activeCalls != null) {
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls); beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls);
} }

View File

@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.CompanyEntity; 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.service.UserService;
import net.gepafin.tendermanagement.util.DateTimeUtil; import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.Utils; 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.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException; import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status; import net.gepafin.tendermanagement.web.rest.api.errors.Status;
@@ -38,7 +40,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status;
@Component @Component
public class DelegationDao { public class DelegationDao {
private static final String DEFAULT_PLACEHOLDER = "____________________"; // private static final String DEFAULT_PLACEHOLDER = "____________________";
@Autowired @Autowired
private UserService userService; private UserService userService;
@@ -57,6 +59,9 @@ public class DelegationDao {
@Autowired @Autowired
private UserCompanyDelegationRepository userCompanyDelegationRepository; private UserCompanyDelegationRepository userCompanyDelegationRepository;
@Autowired
private Validator validator;
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) { public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
@@ -89,9 +94,10 @@ public class DelegationDao {
return new XWPFDocument(templateStream); 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(); 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); CompanyEntity companyEntity = companyDao.validateCompany(companyId);
companyDao.getUserWithCompany(userEntity.getId(), companyId); companyDao.getUserWithCompany(userEntity.getId(), companyId);
updatePlaceholdersForDelegation(user, companyEntity, placeholders, companyDelegationRequest); updatePlaceholdersForDelegation(user, companyEntity, placeholders, companyDelegationRequest);

View File

@@ -50,7 +50,10 @@ public class EvaluationCriteriaDao {
.validateLookUpData(evaluationCriteriaRequest.getLookUpDataId()); .validateLookUpData(evaluationCriteriaRequest.getLookUpDataId());
entity.setCall(callEntity); entity.setCall(callEntity);
entity.setLookupData(looDataEntity); entity.setLookupData(looDataEntity);
entity.setScore(evaluationCriteriaRequest.getScore()); entity.setScore(0L);
if (evaluationCriteriaRequest.getScore() != null) {
entity.setScore(evaluationCriteriaRequest.getScore());
}
entity = evaluationCriteriaRepository.save(entity); entity = evaluationCriteriaRepository.save(entity);
return entity; return entity;
} }

View File

@@ -251,7 +251,7 @@ public class PdfDao {
List<String> keys = new ArrayList<>(entry.keySet()); // Get all keys in the current map List<String> keys = new ArrayList<>(entry.keySet()); // Get all keys in the current map
// Handle based on the number of keys in the 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" // 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 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 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 the content with the matching fieldId is found, create a label-value pair
if (matchingContent.isPresent()) { if (matchingContent.isPresent()) {
String name = matchingContent.get().getName(); 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")) { if (name.equals("fileupload")) {
// Step 1: Check if fieldValue is an instance of List<DocumentResponseBean> // 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 // Add the label-value pair to the list
if (fieldValue != null && !fieldValue.toString().trim().isEmpty()) {
fieldValue = findLabelInOptions(matchingContent.get().getSettings(), fieldValue); fieldValue = findLabelInOptions(matchingContent.get().getSettings(), fieldValue);
labelValuePairs.add(new FieldLabelValuePairRequest(label, fieldValue)); labelValuePairs.add(new FieldLabelValuePairRequest(contentLabel, fieldValue));
}
} }
} }

View File

@@ -6,6 +6,7 @@ import net.gepafin.tendermanagement.config.SamlSuccessHandler;
import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.BeneficiaryEntity; import net.gepafin.tendermanagement.entities.BeneficiaryEntity;
import net.gepafin.tendermanagement.entities.HubEntity;
import net.gepafin.tendermanagement.entities.RoleEntity; import net.gepafin.tendermanagement.entities.RoleEntity;
import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.RoleStatusEnum; import net.gepafin.tendermanagement.enums.RoleStatusEnum;
@@ -84,17 +85,17 @@ public class UserDao {
if(StringUtils.isEmpty(userReq.getHubUuid())) { if(StringUtils.isEmpty(userReq.getHubUuid())) {
userReq.setHubUuid(defaultHubUuid); userReq.setHubUuid(defaultHubUuid);
} }
validateUserRequest(request, tempToken, userReq); HubEntity hub = hubService.getHubByUuid(userReq.getHubUuid());
validateUserRequest(request, tempToken, userReq, hub);
validatePassword(userReq.getPassword(), userReq.getConfPassword(), tempToken); validatePassword(userReq.getPassword(), userReq.getConfPassword(), tempToken);
RoleEntity roleEntity = getRoleEntity(userReq.getRoleId()); RoleEntity roleEntity = getRoleEntity(userReq.getRoleId());
BeneficiaryEntity beneficiary = createBeneficiary(roleEntity, userReq); BeneficiaryEntity beneficiary = createBeneficiary(roleEntity, userReq, hub);
UserEntity userEntity = convertUserRequestToUserEntity(beneficiary, roleEntity, userReq); UserEntity userEntity = convertUserRequestToUserEntity(beneficiary, roleEntity, userReq, hub);
log.info("User created with ID: {}", userEntity.getId()); log.info("User created with ID: {}", userEntity.getId());
return authService.getJWTTokenBean(userEntity, Boolean.TRUE); 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; BeneficiaryEntity beneficiaryEntity = null;
if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) { if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) {
beneficiaryEntity = new BeneficiaryEntity(); beneficiaryEntity = new BeneficiaryEntity();
@@ -114,20 +115,22 @@ public class UserDao {
beneficiaryEntity.setMarketing(userReq.getMarketing()); beneficiaryEntity.setMarketing(userReq.getMarketing());
beneficiaryEntity.setThirdParty(userReq.getThirdParty()); beneficiaryEntity.setThirdParty(userReq.getThirdParty());
beneficiaryEntity.setEmailPec(userReq.getEmailPec()); beneficiaryEntity.setEmailPec(userReq.getEmailPec());
beneficiaryEntity.setHubId(hub.getId());
beneficiaryEntity =beneficiaryRepository.save(beneficiaryEntity); beneficiaryEntity =beneficiaryRepository.save(beneficiaryEntity);
} }
return 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) { if (tempToken == null) {
validator.validateRequest(request,RoleStatusEnum.ROLE_SUPER_ADMIN); validator.validateRequest(request,RoleStatusEnum.ROLE_SUPER_ADMIN);
UserEntity userEntity = validator.validateUser(request);
userReq.setHubUuid(userEntity.getHub().getUniqueUuid());
}else { }else {
samlSuccessHandler.validateToken(tempToken, userReq.getCodiceFiscale(), userReq.getHubUuid()); samlSuccessHandler.validateToken(tempToken, userReq.getCodiceFiscale(), userReq.getHubUuid());
} }
RoleEntity role = roleService.validateRole(userReq.getRoleId());
if (Boolean.FALSE.equals(Utils.isValidEmail(userReq.getEmail()))) { if (Boolean.FALSE.equals(Utils.isValidEmail(userReq.getEmail()))) {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VALIDATE_EMAIL)); Translator.toLocale(GepafinConstant.VALIDATE_EMAIL));
@@ -139,7 +142,7 @@ public class UserDao {
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS)); Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
} }
if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale())) 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()); log.error("User creation failed: CodiceFiscale {} already exists", userReq.getCodiceFiscale());
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.CODICE_FISCALE_EXISTS)); Translator.toLocale(GepafinConstant.CODICE_FISCALE_EXISTS));
@@ -151,10 +154,14 @@ public class UserDao {
if (tempToken != null) { if (tempToken != null) {
userReq.setRoleId(null); userReq.setRoleId(null);
} }
if(tempToken == null && Boolean.TRUE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(role.getRoleType()))){
throw new CustomValidationException(Status.VALIDATION_ERROR, if (tempToken == null) {
Translator.toLocale(GepafinConstant.CANNOT_CREATE_BENEFICIARY_USER)); 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) { private void validatePassword(String password, String confirmPassword, String tempToken) {
@@ -206,7 +213,7 @@ public class UserDao {
return convertUserEntityToUserResponse(userEntity); 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(); UserEntity userEntity = new UserEntity();
if(Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getPassword()))) { if(Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getPassword()))) {
userEntity.setPassword(passwordEncoder.encode(userReq.getPassword())); userEntity.setPassword(passwordEncoder.encode(userReq.getPassword()));
@@ -215,7 +222,7 @@ public class UserDao {
userEntity.setEmail(userReq.getEmail()); userEntity.setEmail(userReq.getEmail());
userEntity.setStatus(UserStatusEnum.ACTIVE.getValue()); userEntity.setStatus(UserStatusEnum.ACTIVE.getValue());
userEntity.setBeneficiary(beneficiary); userEntity.setBeneficiary(beneficiary);
userEntity.setHub(hubService.getHubByUuid(userReq.getHubUuid())); userEntity.setHub(hub);
if (Boolean.FALSE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType()))) { if (Boolean.FALSE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType()))) {
userEntity.setFirstName(userReq.getFirstName()); userEntity.setFirstName(userReq.getFirstName());
userEntity.setLastName(userReq.getLastName()); userEntity.setLastName(userReq.getLastName());

View File

@@ -39,4 +39,7 @@ public class ApplicationEntity extends BaseEntity {
@OneToOne @OneToOne
@JoinColumn(name = "PROTOCOL_NUMBER") @JoinColumn(name = "PROTOCOL_NUMBER")
private ProtocolEntity protocol; private ProtocolEntity protocol;
@Column(name = "HUB_ID")
private Long hubId;
} }

View File

@@ -61,4 +61,7 @@ public class BeneficiaryEntity extends BaseEntity {
@Column(name = "EMAIL_PEC") @Column(name = "EMAIL_PEC")
private String emailPec; private String emailPec;
@Column(name = "HUB_ID")
private Long hubId;
} }

View File

@@ -4,6 +4,8 @@ import java.math.BigDecimal;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import lombok.Data; import lombok.Data;
@@ -56,4 +58,9 @@ public class CompanyEntity extends BaseEntity{
@Column(name = "CONTACT_EMAIL") @Column(name = "CONTACT_EMAIL")
private String contactEmail; private String contactEmail;
@ManyToOne
@JoinColumn(name = "HUB_ID")
private HubEntity hub;
} }

View File

@@ -8,7 +8,8 @@ public enum ApplicationStatusTypeEnum {
SUBMIT("SUBMIT"), SUBMIT("SUBMIT"),
AWAIT("AWAIT"), AWAIT("AWAIT"),
READY("READY"), READY("READY"),
DISCARD("DISCARD"); DISCARD("DISCARD"),
EVALUATION("EVALUATION");
private String value; private String value;

View File

@@ -2,7 +2,6 @@ package net.gepafin.tendermanagement.model.request;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List; import java.util.List;
import lombok.Data; import lombok.Data;

View File

@@ -14,6 +14,13 @@ public class AssignedApplicationsResponse extends BaseBean {
private AssignedApplicationEnum status; private AssignedApplicationEnum status;
private String note; private String note;
private LocalDateTime assignedAt; private LocalDateTime assignedAt;
private Long protocolNumber;
private String callName;
private String beneficiaryName;
private LocalDateTime submissionDate;
private LocalDateTime callStartDate;
private LocalDateTime callEndDate;
} }

View File

@@ -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' ") @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); 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); 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);
} }

View File

@@ -1,8 +1,8 @@
package net.gepafin.tendermanagement.repositories; package net.gepafin.tendermanagement.repositories;
import net.gepafin.tendermanagement.entities.CallEntity; 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.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -11,18 +11,30 @@ import java.util.List;
@Repository @Repository
public interface CallRepository extends JpaRepository<CallEntity, Long> { public interface CallRepository extends JpaRepository<CallEntity, Long> {
public CallEntity findByIdAndStatusNotIn(Long id, List<String> status); // public CallEntity findByIdAndStatusNotIn(Long id, List<String> status);
List<CallEntity> findByStatusIn(List<String> callStatus);
// 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'") // @Query("SELECT COALESCE(SUM(c.amount), 0) FROM CallEntity c WHERE c.status = 'PUBLISH'")
BigDecimal findTotalAmountOfPublishedCalls(); // BigDecimal findTotalAmountOfPublishedCalls();
@Query("SELECT c.name, COUNT(a.id) " + // @Query("SELECT c.name, COUNT(a.id) " +
"FROM CallEntity c LEFT JOIN ApplicationEntity a ON c.id = a.call.id " + // "FROM CallEntity c LEFT JOIN ApplicationEntity a ON c.id = a.call.id " +
"GROUP BY c.name") // "GROUP BY c.name")
List<Object[]> findApplicationsPerCall(); // 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);
} }

View File

@@ -4,6 +4,7 @@ import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import net.gepafin.tendermanagement.entities.CompanyEntity; import net.gepafin.tendermanagement.entities.CompanyEntity;
@@ -11,13 +12,14 @@ import net.gepafin.tendermanagement.entities.CompanyEntity;
@Repository @Repository
public interface CompanyRepository extends JpaRepository<CompanyEntity, Long> { 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); Boolean existsByVatNumberAndHubId(String vatNumber, Long hubId);
CompanyEntity findByVatNumber(String vatNumber);
@Query("SELECT COUNT(c) FROM CompanyEntity c") @Query("SELECT COUNT(c) FROM CompanyEntity c where c.hub.id = :hubId")
long countTotalCompanies(); long countTotalCompaniesByHubId(@Param("hubId") Long hubId);
CompanyEntity findByVatNumberAndHubId(String vatNumber, Long hubId);
} }

View File

@@ -10,21 +10,9 @@ import java.util.Optional;
@Repository @Repository
public interface UserRepository extends JpaRepository<UserEntity, Long> { 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); UserEntity findByBeneficiaryId(Long beneficiaryId);
Long countByStatusAndRoleEntityRoleType(String status, String roleName); Optional<UserEntity> findByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
Optional<UserEntity> findByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubId);
boolean existsByEmailIgnoreCaseAndHubUniqueUuid(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); Long countByStatusAndRoleEntityRoleTypeAndHubId(String status, String roleName, Long hubId);
Optional<UserEntity> findByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); Optional<UserEntity> findByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId);
} }

View File

@@ -14,10 +14,8 @@ public interface UserWithCompanyRepository extends JpaRepository<UserWithCompany
void deleteByCompanyIdAndIsDeletedFalse(Long companyId); void deleteByCompanyIdAndIsDeletedFalse(Long companyId);
@Query("SELECT u.companyId FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.isDeleted = false") @Query("SELECT u.companyId FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.isDeleted = false")
List<Long> findActiveCompanyIdsByUserId(@Param("userId") Long userId); List<Long> findActiveCompanyIdsByUserId(@Param("userId") Long userId);
Optional<UserWithCompanyEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(Long userId, Long companyId); Optional<UserWithCompanyEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(Long userId, Long companyId);

View File

@@ -29,6 +29,6 @@ public interface CallService {
CallEntity validateCall(Long callId); CallEntity validateCall(Long callId);
CallEntity validatePublishedCall(Long callId); CallEntity validatePublishedCall(Long callId, Long hubId);
byte[] downloadCallDocumentsAsZip(Long callId); byte[] downloadCallDocumentsAsZip(HttpServletRequest request, Long callId);
} }

View File

@@ -17,11 +17,11 @@ import java.util.List;
public interface UserService { public interface UserService {
JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq); 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); JWTToken login(LoginReq loginReq,HttpServletRequest request);

View File

@@ -65,6 +65,7 @@ public class ApplicationServiceImpl implements ApplicationService {
public ApplicationResponse createApplication(HttpServletRequest request, Long companyId, ApplicationRequest applicationRequest, Long callId) { public ApplicationResponse createApplication(HttpServletRequest request, Long companyId, ApplicationRequest applicationRequest, Long callId) {
UserEntity userEntity = validator.validateUser(request); UserEntity userEntity = validator.validateUser(request);
CompanyEntity companyEntity = validator.validateUserWithCompany(request, companyId); CompanyEntity companyEntity = validator.validateUserWithCompany(request, companyId);
validator.validateUserWithCall(userEntity, callId);
return applicationDao.createApplicationByCallId(companyEntity, applicationRequest, callId, userEntity); return applicationDao.createApplicationByCallId(companyEntity, applicationRequest, callId, userEntity);
} }
@@ -114,7 +115,6 @@ public class ApplicationServiceImpl implements ApplicationService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ApplicationResponse validateApplication(HttpServletRequest request, Long applicationId) { public ApplicationResponse validateApplication(HttpServletRequest request, Long applicationId) {
return applicationDao.validateApplication(request, applicationId); return applicationDao.validateApplication(request, applicationId);
} }

View File

@@ -77,7 +77,7 @@ public class AuthenticationService {
public JWTToken login(LoginReq loginReq, HttpServletRequest request) { public JWTToken login(LoginReq loginReq, HttpServletRequest request) {
UserEntity user=null; UserEntity user=null;
LoginAttemptEntity loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request); LoginAttemptEntity loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request);
log.info("Attempting login for email: {}", loginReq.getEmail()); log.info("Attempting login for email: {}", loginReq.getEmail());
String emailWithHubId = loginReq.getEmail()+":"+loginReq.getHubUuid(); String emailWithHubId = loginReq.getEmail()+":"+loginReq.getHubUuid();
@@ -211,10 +211,11 @@ public class AuthenticationService {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.INVALID_TOKEN_MSG)); Translator.toLocale(GepafinConstant.INVALID_TOKEN_MSG));
} }
HubEntity hub = hubService.getHubByUuid(samlResponseLogEntity.getHubUuid());
Map<String, List<Object>> userAttributes = Utils Map<String, List<Object>> userAttributes = Utils
.convertStringIntoMap(samlResponseLogEntity.getAuthenticationObject()); .convertStringIntoMap(samlResponseLogEntity.getAuthenticationObject());
String cf = userAttributes.get("CodiceFiscale").get(0).toString(); String cf = userAttributes.get("CodiceFiscale").get(0).toString();
if (userRepository.existsByBeneficiaryCodiceFiscale(cf)) { if (userRepository.existsByBeneficiaryCodiceFiscaleAndHubId(cf, hub.getId())) {
throw new ResourceNotFoundException(Status.NOT_FOUND, throw new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.USER_ALREADY_EXIST_MSG)); Translator.toLocale(GepafinConstant.USER_ALREADY_EXIST_MSG));
} }

View File

@@ -9,7 +9,6 @@ import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq; import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean; import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.service.BeneficiaryPreferredCallService; import net.gepafin.tendermanagement.service.BeneficiaryPreferredCallService;
import net.gepafin.tendermanagement.service.UserService; import net.gepafin.tendermanagement.service.UserService;
import net.gepafin.tendermanagement.util.Validator; 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 net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.List; import java.util.List;
@@ -26,10 +24,10 @@ public class BeneficiaryPreferredCallServiceImpl implements BeneficiaryPreferred
@Autowired @Autowired
private BeneficiaryPreferredCallDao beneficiaryPreferredCallDao; private BeneficiaryPreferredCallDao beneficiaryPreferredCallDao;
@Autowired @Autowired
private Validator validator; private Validator validator;
@Autowired
private UserRepository userRepository;
@Autowired @Autowired
private UserService userService; private UserService userService;
@@ -81,7 +79,7 @@ public class BeneficiaryPreferredCallServiceImpl implements BeneficiaryPreferred
} }
if(beneficiaryId!=null){ if(beneficiaryId!=null){
UserEntity user = userService.getUserByBeneficiaryId(beneficiaryId); UserEntity user = userService.getUserByBeneficiaryId(beneficiaryId);
return validator.validateUserId(request,user.getId()); return validator.validateUserId(request, user.getId());
} }
else{ else{
return validator.validateUserId(request, userId); return validator.validateUserId(request, userId);

View File

@@ -91,13 +91,15 @@ public class CallServiceImpl implements CallService {
} }
@Override @Override
public CallEntity validatePublishedCall(Long callId) { public CallEntity validatePublishedCall(Long callId, Long hubId) {
return callDao.validatePublishedCall(callId); return callDao.validatePublishedCall(callId, hubId);
} }
@Override @Override
@Transactional(readOnly = true) @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); return callDao.downloadCallDocumentsAsZip(callId);
} }

View File

@@ -49,6 +49,7 @@ public class CompanyServiceImpl implements CompanyService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public CompanyResponse updateCompany(HttpServletRequest request, Long companyId, CompanyRequest companyRequest) { public CompanyResponse updateCompany(HttpServletRequest request, Long companyId, CompanyRequest companyRequest) {
UserEntity userEntity =validator.validateUser(request); UserEntity userEntity =validator.validateUser(request);
validator.validateUserWithCompany(request, companyId);
return companyDao.updateCompany(userEntity, companyId, companyRequest); return companyDao.updateCompany(userEntity, companyId, companyRequest);
} }
@@ -56,6 +57,7 @@ public class CompanyServiceImpl implements CompanyService {
@Transactional(readOnly = true) @Transactional(readOnly = true)
public CompanyResponse getCompany(HttpServletRequest request, Long companyId) { public CompanyResponse getCompany(HttpServletRequest request, Long companyId) {
UserEntity userEntity =validator.validateUser(request); UserEntity userEntity =validator.validateUser(request);
validator.validateUserWithCompany(request, companyId);
return companyDao.getCompany(userEntity, companyId); return companyDao.getCompany(userEntity, companyId);
} }
@@ -63,13 +65,14 @@ public class CompanyServiceImpl implements CompanyService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteCompany(HttpServletRequest request, Long companyId) { public void deleteCompany(HttpServletRequest request, Long companyId) {
UserEntity userEntity =validator.validateUser(request); UserEntity userEntity =validator.validateUser(request);
validator.validateUserWithCompany(request, companyId);
companyDao.deleteCompany(userEntity, companyId); companyDao.deleteCompany(userEntity, companyId);
} }
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<CompanyResponse> getCompanyByUserId(HttpServletRequest request, Long userId) { public List<CompanyResponse> getCompanyByUserId(HttpServletRequest request, Long userId) {
validator.validateUser(request); validator.validateUserId(request, userId);
return companyDao.getCompanyByUserId(userId); return companyDao.getCompanyByUserId(userId);
} }
@@ -91,8 +94,7 @@ public class CompanyServiceImpl implements CompanyService {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ByteArrayOutputStream downloadCompanyDelegation(HttpServletRequest request, Long companyId, CompanyDelegationRequest companyDelegationRequest) { public ByteArrayOutputStream downloadCompanyDelegation(HttpServletRequest request, Long companyId, CompanyDelegationRequest companyDelegationRequest) {
UserEntity userEntity =validator.validateUser(request); return delegationDao.downloadCompanyDelegation(request, companyId, companyDelegationRequest);
return delegationDao.downloadCompanyDelegation(userEntity, companyId, companyDelegationRequest);
} }
@Override @Override

View File

@@ -5,6 +5,8 @@ import net.gepafin.tendermanagement.dao.FlowDao;
import net.gepafin.tendermanagement.model.request.FlowRequestBean; import net.gepafin.tendermanagement.model.request.FlowRequestBean;
import net.gepafin.tendermanagement.model.response.FlowResponseBean; import net.gepafin.tendermanagement.model.response.FlowResponseBean;
import net.gepafin.tendermanagement.service.FlowService; import net.gepafin.tendermanagement.service.FlowService;
import net.gepafin.tendermanagement.util.Validator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -14,16 +16,21 @@ public class FlowServiceImpl implements FlowService {
@Autowired @Autowired
private FlowDao flowDao; private FlowDao flowDao;
@Autowired
private Validator validator;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public FlowResponseBean createOrUpdateFlow(HttpServletRequest httpServletRequest, FlowRequestBean flowRequestBean, Long callId) { public FlowResponseBean createOrUpdateFlow(HttpServletRequest httpServletRequest, FlowRequestBean flowRequestBean, Long callId) {
validator.validateUserWithCall(validator.validateUser(httpServletRequest), callId);
return flowDao.createOrUpdateFlow(flowRequestBean,callId); return flowDao.createOrUpdateFlow(flowRequestBean,callId);
} }
@Override @Override
@org.springframework.transaction.annotation.Transactional(readOnly = true) @org.springframework.transaction.annotation.Transactional(readOnly = true)
public FlowResponseBean getFlowByCallId(HttpServletRequest request, Long callId) { public FlowResponseBean getFlowByCallId(HttpServletRequest request, Long callId) {
validator.validateUserWithCall(validator.validateUser(request), callId);
return flowDao.getFlowByCallId(callId); return flowDao.getFlowByCallId(callId);
} }
} }

View File

@@ -40,19 +40,22 @@ public class UserServiceImpl implements UserService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @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); return userDao.updateUser(userId, userReq);
} }
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public UserResponseBean getUserById(Long userId) { public UserResponseBean getUserById(HttpServletRequest request, Long userId) {
validator.validateUserId(request, userId);
return userDao.getUserById(userId); return userDao.getUserById(userId);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteUser(Long userId) { public void deleteUser(HttpServletRequest request, Long userId) {
validator.validateUserId(request, userId);
userDao.deleteUser(userId); userDao.deleteUser(userId);
} }

View File

@@ -4,7 +4,6 @@ import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.config.jwt.TokenProvider; import net.gepafin.tendermanagement.config.jwt.TokenProvider;
import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.dao.CallDao;
import net.gepafin.tendermanagement.entities.CallEntity; import net.gepafin.tendermanagement.entities.CallEntity;
import net.gepafin.tendermanagement.entities.CompanyEntity; import net.gepafin.tendermanagement.entities.CompanyEntity;
import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.entities.UserEntity;
@@ -73,13 +72,24 @@ public class Validator {
} }
public CompanyEntity validateUserWithCompany(HttpServletRequest request, Long companyId) { public CompanyEntity validateUserWithCompany(HttpServletRequest request, Long companyId) {
CompanyEntity companyEntity = companyService.validateCompany(companyId);
validateHubId(request, companyEntity.getHub().getId());
if (checkIsSuperAdmin()) { if (checkIsSuperAdmin()) {
return companyService.validateCompany(companyId); return companyEntity;
} }
Map<String, Object> userInfo = tokenProvider.getUserInfoAndUserIdFromToken(request); Map<String, Object> userInfo = tokenProvider.getUserInfoAndUserIdFromToken(request);
companyService.validateUserWithCompny(getUserId(userInfo), companyId); companyService.validateUserWithCompny(getUserId(userInfo), companyId);
return companyService.validateCompany(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) { private Long getUserId(Map<String, Object> userInfo) {
return Long.parseLong(userInfo.get("userId").toString()); return Long.parseLong(userInfo.get("userId").toString());
@@ -100,10 +110,15 @@ public class Validator {
public UserEntity validateUserId(HttpServletRequest request, Long userId) { public UserEntity validateUserId(HttpServletRequest request, Long userId) {
UserEntity user = validateUser(request); UserEntity user = validateUser(request);
if(user.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue()) && Boolean.FALSE.equals(user.getId().equals(userId))) { UserEntity requestedUser = userService.validateUser(userId);
throw new ForbiddenAccessException(Status.FORBIDDEN, Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
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) { private Long getUserIdFromToken(HttpServletRequest request) {

View File

@@ -59,7 +59,7 @@ public interface UserApi {
@RequestMapping(value = "/{userId}", @RequestMapping(value = "/{userId}",
produces = {"application/json"}, produces = {"application/json"},
method = RequestMethod.PUT) 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 = "The user id", required = true) @PathVariable("userId") Long userId,
@Parameter(description = "User request object", required = true) @Valid @RequestBody UpdateUserReq userReq) { @Parameter(description = "User request object", required = true) @Valid @RequestBody UpdateUserReq userReq) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
@@ -77,7 +77,7 @@ public interface UserApi {
@RequestMapping(value = "/{userId}", @RequestMapping(value = "/{userId}",
produces = {"application/json"}, produces = {"application/json"},
method = RequestMethod.GET) 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) { @Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
} }
@@ -93,7 +93,7 @@ public interface UserApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))}) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
@RequestMapping(value = "/{userId}", @RequestMapping(value = "/{userId}",
method = RequestMethod.DELETE) 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) { @Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
} }

View File

@@ -88,7 +88,7 @@ public class CallApiController implements CallApi {
} }
@Override @Override
public ResponseEntity<byte[]> downloadCallDocumentsAsZip(HttpServletRequest request, Long callId) { public ResponseEntity<byte[]> downloadCallDocumentsAsZip(HttpServletRequest request, Long callId) {
byte[] zipFile = callService.downloadCallDocumentsAsZip(callId); byte[] zipFile = callService.downloadCallDocumentsAsZip(request, callId);
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);

View File

@@ -44,29 +44,29 @@ public class UserApiController implements UserApi {
} }
@Override @Override
public ResponseEntity<Response<UserResponseBean>> updateUser( public ResponseEntity<Response<UserResponseBean>> updateUser(HttpServletRequest request,
@PathVariable("userId") Long userId, @PathVariable("userId") Long userId,
@Valid @RequestBody UpdateUserReq userReq) { @Valid @RequestBody UpdateUserReq userReq) {
log.info("Update User - User ID: {}, Request Body: {}", userId, 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) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(updatedUser, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_UPDATED_SUCCESS_MSG))); .body(new Response<>(updatedUser, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_UPDATED_SUCCESS_MSG)));
} }
@Override @Override
public ResponseEntity<Response<UserResponseBean>> getUserById( public ResponseEntity<Response<UserResponseBean>> getUserById(HttpServletRequest request,
@PathVariable("userId") Long userId) { @PathVariable("userId") Long userId) {
log.info("Get User by ID - User ID: {}", 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) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(user, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USER_SUCCESS_MSG))); .body(new Response<>(user, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USER_SUCCESS_MSG)));
} }
@Override @Override
public ResponseEntity<Response<Void>> deleteUser( public ResponseEntity<Response<Void>> deleteUser(HttpServletRequest request,
@PathVariable("userId") Long userId) { @PathVariable("userId") Long userId) {
log.info("Delete User - User ID: {}", userId); log.info("Delete User - User ID: {}", userId);
userService.deleteUser(userId); userService.deleteUser(request, userId);
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_DELETED_SUCCESS_MSG))); .body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_DELETED_SUCCESS_MSG)));
} }

View File

@@ -1328,4 +1328,70 @@
referencedColumnNames="id"/> referencedColumnNames="id"/>
</changeSet> </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> </databaseChangeLog>