Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into develop

This commit is contained in:
harish
2024-10-24 23:58:23 +05:30
21 changed files with 125 additions and 85 deletions

View File

@@ -139,7 +139,7 @@ public class ApplicationDao {
}
formService.validateFormField(applicationRequestBean.getFormFields(),applicationEntity,formEntity);
ApplicationFormEntity applicationFormEntity = getApplicationFormOrCreate(formEntity, applicationEntity);
createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity,formEntity);
createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity, formEntity);
return getApplicationById(applicationEntity.getId(),formEntity.getId());
}
public void validateDelegation(UserEntity user, CompanyEntity company) {
@@ -288,7 +288,7 @@ public class ApplicationDao {
log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
Specification<ApplicationEntity> spec = search(userEntity.getId(), callId, companyId,status);
Specification<ApplicationEntity> spec = search(userEntity, callId, companyId,status);
List<ApplicationEntity> applicationEntities = applicationRepository.findAll(spec);
@@ -298,12 +298,12 @@ public class ApplicationDao {
}
private Specification<ApplicationEntity> search(Long userId, Long callId, Long companyId,String status) {
private Specification<ApplicationEntity> search(UserEntity userEntity, Long callId, Long companyId,String status) {
return (root, query, builder) -> {
Boolean isBeneficiary = validator.checkIsBeneficiary();
Predicate predicate = builder.isFalse(root.get("isDeleted"));
if (isBeneficiary) {
predicate = builder.and(predicate, builder.equal(root.get("userId"), userId));
predicate = builder.and(predicate, builder.equal(root.get("userId"), userEntity.getId()));
}
if (callId != null) {
predicate = builder.and(predicate, builder.equal(root.get("call").get("id"), callId));
@@ -314,7 +314,7 @@ public class ApplicationDao {
if (status != null) {
predicate = builder.and(predicate, builder.equal(root.get("status"), status));
}
predicate = builder.and(predicate, builder.equal(root.get("hubId"), userEntity.getHub().getId()));
return predicate;
};
}
@@ -601,7 +601,7 @@ public class ApplicationDao {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_IN_PREVIOUS_STATUS));
}
if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) {
callService.validatePublishedCall(applicationEntity.getCall().getId());
callService.validatePublishedCall(applicationEntity.getCall().getId(), userEntity.getHub().getId());
Long protocolNumber = getProtocolNumber(userEntity.getHub());
ProtocolEntity protocolEntity = createProtocolEntity(applicationEntity,protocolNumber, userEntity.getHub().getId());
applicationEntity.setProtocol(protocolEntity);

View File

@@ -654,7 +654,7 @@ public class CallDao {
if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) {
callStatusList = List.of(CallStatusEnum.PUBLISH.getValue());
}
List<CallEntity> calls = callRepository.findByStatusIn(callStatusList);
List<CallEntity> calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId());
return calls.stream()
.map(this::convertToCallDetailsResponseBean)
.collect(Collectors.toList());
@@ -672,13 +672,13 @@ public class CallDao {
callResponseBean.setStatus(CallStatusEnum.valueOf(callEntity.getStatus()));
return callResponseBean;
}
public CallEntity getCallEntityById(Long id){
CallEntity callEntity=callRepository.findByIdAndStatusNotIn(id,List.of(CallStatusEnum.PUBLISH.getValue()));
if(callEntity==null){
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND));
}
return callEntity;
}
// public CallEntity getCallEntityById(Long id){
// CallEntity callEntity=callRepository.findByIdAndStatusNotInAndHubId(id, List.of(CallStatusEnum.PUBLISH.getValue()));
// if(callEntity==null){
// throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND));
// }
// return callEntity;
// }
public CallResponse updateCallStatus(CallEntity callEntity, CallStatusEnum statusReq) {
CallStatusEnum currentStatus = CallStatusEnum.valueOf(callEntity.getStatus());
@@ -718,9 +718,9 @@ public class CallDao {
}
}
public CallEntity validatePublishedCall(Long callId) {
public CallEntity validatePublishedCall(Long callId, Long hubId) {
CallEntity callEntity= callRepository
.findByIdAndStatus(callId, CallStatusEnum.PUBLISH.getValue());
.findByIdAndStatusAndHubId(callId, CallStatusEnum.PUBLISH.getValue(), hubId);
if(callEntity==null){
throw new ResourceNotFoundException(
Status.NOT_FOUND,

View File

@@ -54,7 +54,7 @@ public class CompanyDao {
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
} else {
validateCompany(userEntity, companyRequest);
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(companyRequest);
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(userEntity, companyRequest);
companyRepository.save(companyEntity);
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
@@ -91,7 +91,7 @@ public class CompanyDao {
return userWithCompanyRepository.save(userWithCompanyEntity);
}
private CompanyEntity convertCompanyRequestToCompanyEntity(CompanyRequest request) {
private CompanyEntity convertCompanyRequestToCompanyEntity(UserEntity userEntity, CompanyRequest request) {
CompanyEntity entity = new CompanyEntity();
entity.setCompanyName(request.getCompanyName());
entity.setVatNumber(request.getVatNumber());
@@ -108,6 +108,7 @@ public class CompanyDao {
entity.setAnnualRevenue(request.getAnnualRevenue());
entity.setContactName(request.getContactName());
entity.setContactEmail(request.getContactEmail());
entity.setHub(userEntity.getHub());
return entity;
}

View File

@@ -60,7 +60,7 @@ public class DashboardDao {
}
private void setActiveCalls(Widget1 widget1, UserEntity requestedUserEntity) {
Long activeCalls = callRepository.countByStatus(CallStatusEnum.PUBLISH.getValue());
Long activeCalls = callRepository.countByStatusAndHubId(CallStatusEnum.PUBLISH.getValue(), requestedUserEntity.getHub().getId());
if (activeCalls != null) {
widget1.setNumberOfActiveCalls(activeCalls);
}
@@ -74,20 +74,20 @@ public class DashboardDao {
}
}
private void setTotalActiveFinancing(Widget1 widget1, UserEntity requestedUserEntity) {
BigDecimal totalActiveFinancing = callRepository.findTotalAmountOfPublishedCalls();
private void setTotalActiveFinancing(Widget1 widget1, UserEntity requestedUser) {
BigDecimal totalActiveFinancing = callRepository.findTotalAmountOfPublishedCallsAndHubId(requestedUser.getHub().getId());
widget1.setTotalActiveFinancing(totalActiveFinancing);
}
private void setSubmittedApplications(Widget1 widget1, UserEntity requestedUserEntity) {
Long submittedApplications = applicationRepository.countSubmittedApplications();
Long submittedApplications = applicationRepository.countSubmittedApplicationsByHubId(requestedUserEntity.getHub().getId());
if (submittedApplications != null) {
widget1.setNumberOfSubmittedApplications(submittedApplications);
}
}
private void setDraftApplications(Widget1 widget1, UserEntity requestedUserEntity) {
Long draftApplications = applicationRepository.countDraftApplications();
Long draftApplications = applicationRepository.countDraftApplicationsByHubId(requestedUserEntity.getHub().getId());
if (draftApplications != null) {
widget1.setNumberOfDraftApplications(draftApplications);
}
@@ -104,7 +104,7 @@ public class DashboardDao {
CompanyEntity company) {
BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder()
.numberOfApplications(0L).numberOfCalls(0L).numberOfIntegratedDocuments(0L).build();
Long activeCalls = callRepository.countByStatus(CallStatusEnum.PUBLISH.getValue());
Long activeCalls = callRepository.countByStatusAndHubId(CallStatusEnum.PUBLISH.getValue(), userEntity.getHub().getId());
if (activeCalls != null) {
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls);
}

View File

@@ -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);

View File

@@ -125,11 +125,12 @@ public class UserDao {
if (tempToken == null) {
validator.validateRequest(request,RoleStatusEnum.ROLE_SUPER_ADMIN);
UserEntity userEntity = validator.validateUser(request);
userReq.setHubUuid(userEntity.getHub().getUniqueUuid());
}else {
samlSuccessHandler.validateToken(tempToken, userReq.getCodiceFiscale(), userReq.getHubUuid());
}
RoleEntity role = roleService.validateRole(userReq.getRoleId());
if (Boolean.FALSE.equals(Utils.isValidEmail(userReq.getEmail()))) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VALIDATE_EMAIL));
@@ -153,10 +154,14 @@ public class UserDao {
if (tempToken != null) {
userReq.setRoleId(null);
}
if(tempToken == null && Boolean.TRUE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(role.getRoleType()))){
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.CANNOT_CREATE_BENEFICIARY_USER));
}
if (tempToken == null) {
RoleEntity role = roleService.validateRole(userReq.getRoleId());
if (Boolean.TRUE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(role.getRoleType()))) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.CANNOT_CREATE_BENEFICIARY_USER));
}
}
}
private void validatePassword(String password, String confirmPassword, String tempToken) {