Fixed hub validation issue
This commit is contained in:
@@ -288,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);
|
||||||
|
|
||||||
@@ -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) -> {
|
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));
|
||||||
@@ -314,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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -601,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);
|
||||||
|
|||||||
@@ -654,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());
|
||||||
@@ -672,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());
|
||||||
@@ -718,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,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class CompanyDao {
|
|||||||
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
|
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
|
||||||
} else {
|
} else {
|
||||||
validateCompany(userEntity, 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);
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,8 +74,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -58,6 +60,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) {
|
||||||
try {
|
try {
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -125,11 +125,12 @@ public class UserDao {
|
|||||||
|
|
||||||
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));
|
||||||
@@ -153,11 +154,15 @@ 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()))){
|
|
||||||
|
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,
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
Translator.toLocale(GepafinConstant.CANNOT_CREATE_BENEFICIARY_USER));
|
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) {
|
||||||
if (StringUtils.isEmpty(password) || StringUtils.isEmpty(confirmPassword)) {
|
if (StringUtils.isEmpty(password) || StringUtils.isEmpty(confirmPassword)) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
|
||||||
|
|
||||||
public CallEntity findByIdAndStatus(Long id,String status);
|
// List<CallEntity> findByStatusIn(List<String> callStatus);
|
||||||
|
|
||||||
public Long countByStatus(String status);
|
// public CallEntity findByIdAndStatus(Long id,String status);
|
||||||
|
|
||||||
@Query("SELECT COALESCE(SUM(c.amount), 0) FROM CallEntity c WHERE c.status = 'PUBLISH'")
|
// public Long countByStatus(String status);
|
||||||
BigDecimal findTotalAmountOfPublishedCalls();
|
|
||||||
|
|
||||||
@Query("SELECT c.name, COUNT(a.id) " +
|
// @Query("SELECT COALESCE(SUM(c.amount), 0) FROM CallEntity c WHERE c.status = 'PUBLISH'")
|
||||||
"FROM CallEntity c LEFT JOIN ApplicationEntity a ON c.id = a.call.id " +
|
// BigDecimal findTotalAmountOfPublishedCalls();
|
||||||
"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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,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
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,12 +72,8 @@ public class Validator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CompanyEntity validateUserWithCompany(HttpServletRequest request, Long companyId) {
|
public CompanyEntity validateUserWithCompany(HttpServletRequest request, Long companyId) {
|
||||||
UserEntity user = validateUser(request);
|
|
||||||
CompanyEntity companyEntity = companyService.validateCompany(companyId);
|
CompanyEntity companyEntity = companyService.validateCompany(companyId);
|
||||||
if (Boolean.FALSE.equals(user.getHub().getId().equals(companyEntity.getHub().getId()))) {
|
validateHubId(request, companyEntity.getHub().getId());
|
||||||
throw new ForbiddenAccessException(Status.FORBIDDEN,
|
|
||||||
Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
|
||||||
}
|
|
||||||
if (checkIsSuperAdmin()) {
|
if (checkIsSuperAdmin()) {
|
||||||
return companyEntity;
|
return companyEntity;
|
||||||
}
|
}
|
||||||
@@ -86,6 +82,15 @@ public class Validator {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
@@ -107,11 +112,11 @@ public class Validator {
|
|||||||
UserEntity user = validateUser(request);
|
UserEntity user = validateUser(request);
|
||||||
UserEntity requestedUser = userService.validateUser(userId);
|
UserEntity requestedUser = userService.validateUser(userId);
|
||||||
|
|
||||||
if(Boolean.FALSE.equals(requestedUser.getHub().getId().equals(user.getHub().getId()))) {
|
validateHubId(request, requestedUser.getHub().getId());
|
||||||
throw new ForbiddenAccessException(Status.FORBIDDEN, Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
if (Boolean.FALSE.equals(user.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_SUPER_ADMIN.getValue()))
|
||||||
}
|
&& Boolean.FALSE.equals(user.getId().equals(userId))) {
|
||||||
if(user.getRoleEntity().getRoleType().equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue()) && Boolean.FALSE.equals(user.getId().equals(userId))) {
|
throw new ForbiddenAccessException(Status.FORBIDDEN,
|
||||||
throw new ForbiddenAccessException(Status.FORBIDDEN, Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||||
}
|
}
|
||||||
return requestedUser;
|
return requestedUser;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user