Conflict Resolved
This commit is contained in:
@@ -12,6 +12,8 @@ import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationExceptio
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.env.Environment;
|
||||
@@ -28,6 +30,8 @@ import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class AmazonS3ServiceImpl implements AmazonS3Service {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(AmazonS3ServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private AmazonS3 amazonS3;
|
||||
@@ -42,11 +46,9 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
|
||||
private String s3Url;
|
||||
|
||||
|
||||
@Override
|
||||
public String upload(String fileName, String s3Folder,
|
||||
private String upload(String fileName, String s3Folder,
|
||||
MultipartFile file) throws IOException {
|
||||
|
||||
// String path = bucketName+"/"+s3Folder;
|
||||
String path = s3Folder +"/"+fileName;
|
||||
|
||||
InputStream inputStream = file.getInputStream();
|
||||
@@ -66,17 +68,23 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
|
||||
if(Boolean.FALSE.equals(isTestProfileActivated())) {
|
||||
amazonS3.putObject(bucketName, path, inputStream, objectMetadata);
|
||||
}
|
||||
return s3Url + s3Folder +"/"+ fileName;
|
||||
path =s3Url + s3Folder +"/"+ fileName;
|
||||
log.info("File '{}' uploaded successfully to Amazon S3 with URL: {}", fileName, path);
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(String s3Folder, String fileName) {
|
||||
public Boolean delete(String s3Folder, String filePath) {
|
||||
|
||||
String fileName = Utils.extractFileName(filePath);
|
||||
String path = s3Folder +"/"+fileName;
|
||||
final DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucketName, path);
|
||||
if(Boolean.FALSE.equals(isTestProfileActivated())) {
|
||||
amazonS3.deleteObject(deleteObjectRequest);
|
||||
}
|
||||
log.info("File '{}' deleted successfully from Amazon S3", fileName);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public Boolean isTestProfileActivated() {
|
||||
@@ -85,28 +93,34 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getFile(String s3Folder, String filePath) throws IOException {
|
||||
public InputStream getFile(String s3Folder, String filePath) {
|
||||
try {
|
||||
String path = s3Folder +"/"+filePath;
|
||||
String fileName = Utils.extractFileName(filePath);
|
||||
String path = s3Folder + "/" + fileName;
|
||||
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, path);
|
||||
S3Object s3Object = amazonS3.getObject(getObjectRequest);
|
||||
log.info("File fetched successfully from Amazon S3: {}", fileName);
|
||||
return s3Object.getObjectContent();
|
||||
} catch (AmazonS3Exception e) {
|
||||
throw new IOException("Error getting file from Amazon S3", e);
|
||||
log.error("Error occurred while getting file from Amazon S3: {}", e);
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.GET_ERROR_S3));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadFileOnAmazonS3Response uploadFileOnAmazonS3(String s3Folder, MultipartFile file) {
|
||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||
String fileName = org.springframework.util.StringUtils.cleanPath(file.getOriginalFilename());
|
||||
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
firstNameContain+=Utils.randomKey(5);
|
||||
fileName = (firstNameContain + "." + extension);
|
||||
String originalFileName = org.springframework.util.StringUtils.cleanPath(file.getOriginalFilename());
|
||||
String firstNameContain = originalFileName.substring(0, originalFileName.lastIndexOf('.'));
|
||||
firstNameContain = Utils.replaceSpacesWithUnderscores(firstNameContain);
|
||||
firstNameContain += "_" + Utils.randomKey(7);
|
||||
String fileName = (firstNameContain + "." + extension);
|
||||
try {
|
||||
String filepath = upload(fileName, s3Folder, file);
|
||||
return UploadFileOnAmazonS3Response.builder().fileName(fileName).filePath(filepath).build();
|
||||
return UploadFileOnAmazonS3Response.builder().fileName(originalFileName).filePath(filepath).build();
|
||||
} catch (Exception e) {
|
||||
log.error("Error occurred while uploading file from Amazon S3: {}", e);
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||
}
|
||||
|
||||
@@ -40,21 +40,19 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApplicationResponseBean createApplication(HttpServletRequest request,
|
||||
ApplicationRequestBean applicationRequestBean, Long applicationId, Long formId) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
return applicationDao.createApplication(applicationRequestBean, userEntity, formId, applicationId);
|
||||
return applicationDao.createApplication(request, applicationRequestBean, formId, applicationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ApplicationGetResponseBean getApplicationByFormId(HttpServletRequest request, Long applicationId,Long formId) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
return applicationDao.getApplicationByFormId(applicationId,formId,userEntity);
|
||||
return applicationDao.getApplicationByFormId(request, applicationId,formId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteApplication(HttpServletRequest request, Long applicationId) {
|
||||
applicationDao.deleteById(applicationId);
|
||||
applicationDao.deleteById(request, applicationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,6 +65,7 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
public ApplicationResponse createApplication(HttpServletRequest request, Long companyId, ApplicationRequest applicationRequest, Long callId) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
CompanyEntity companyEntity = validator.validateUserWithCompany(request, companyId);
|
||||
validator.validateUserWithCall(userEntity, callId);
|
||||
return applicationDao.createApplicationByCallId(companyEntity, applicationRequest, callId, userEntity);
|
||||
}
|
||||
|
||||
@@ -74,25 +73,25 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
public NextOrPreviousFormResponse getNextOrPreviousForm(HttpServletRequest request, Long applicationId, Long formId,
|
||||
FormActionEnum action) {
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
validator.validateUserWithCompany(request, applicationEntity.getCompany().getId());
|
||||
return flowFormDao.getNextOrPreviousForm(applicationEntity, formId, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApplicationResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
return applicationDao.updateApplicationStatus(userEntity, applicationId, status);
|
||||
return applicationDao.updateApplicationStatus(request, applicationId, status);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<ApplicationResponse> getAllApplications(HttpServletRequest request, Long callId, Long companyId) {
|
||||
public List<ApplicationResponse> getAllApplications(HttpServletRequest request, Long callId, Long companyId , String status) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
if (companyId != null) {
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
}
|
||||
return applicationDao.getAllApplications(userEntity, callId, companyId);
|
||||
return applicationDao.getAllApplications(userEntity, callId, companyId , status);
|
||||
}
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -111,5 +110,12 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
public void deleteSignedDocument(HttpServletRequest request, Long applicationId) {
|
||||
applicationDao.deleteSignedDocument(request, applicationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApplicationResponse validateApplication(HttpServletRequest request, Long applicationId) {
|
||||
return applicationDao.validateApplication(request, applicationId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.dao.AssignedApplicationsDao;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest;
|
||||
import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse;
|
||||
import net.gepafin.tendermanagement.service.AssignedApplicationsService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class AssignedApplicationsServiceImpl implements AssignedApplicationsService {
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private AssignedApplicationsDao assignedApplicationsDao;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AssignedApplicationsResponse createAssignedApplications(HttpServletRequest request, Long applicationId, Long userId, AssignedApplicationsRequest assignedApplicationsRequest) {
|
||||
UserEntity assignedByUser= validator.validateUser(request);
|
||||
validator.validatePreInstructor(request, userId);
|
||||
return assignedApplicationsDao.createAssignedApplications(applicationId,userId,assignedByUser, assignedApplicationsRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteApplication(HttpServletRequest request, Long id) {
|
||||
assignedApplicationsDao.deleteById(request, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<AssignedApplicationsResponse> getAllAssignedApplications(HttpServletRequest request, Long userId) {
|
||||
return assignedApplicationsDao.getAllAssignedApplications(request, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AssignedApplicationsResponse updateAssignedApplication(HttpServletRequest request, Long id, AssignedApplicationsRequest updatedAssignedApplicationRequest) {
|
||||
return assignedApplicationsDao.updateAssignedApplication(request, id, updatedAssignedApplicationRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public AssignedApplicationsResponse getAssignedApplicationById(HttpServletRequest request, Long id) {
|
||||
return assignedApplicationsDao.getAssignedApplicationById(request, id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.dao.CompanyDao;
|
||||
import net.gepafin.tendermanagement.dao.LoginAttemptDao;
|
||||
import net.gepafin.tendermanagement.dao.RoleDao;
|
||||
import net.gepafin.tendermanagement.entities.HubEntity;
|
||||
import net.gepafin.tendermanagement.entities.LoginAttemptEntity;
|
||||
import net.gepafin.tendermanagement.entities.SamlResponseEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
@@ -22,6 +23,7 @@ import net.gepafin.tendermanagement.model.response.UserSamlResponse;
|
||||
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||
import net.gepafin.tendermanagement.repositories.SamlResponseRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.service.HubService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
@@ -63,6 +65,9 @@ public class AuthenticationService {
|
||||
|
||||
@Autowired
|
||||
private LoginAttemptDao loginAttemptDao;
|
||||
|
||||
@Autowired
|
||||
private HubService hubService;
|
||||
|
||||
@Autowired
|
||||
public AuthenticationService(TokenProvider tokenProvider, AuthenticationManager authenticationManager) {
|
||||
@@ -70,17 +75,18 @@ public class AuthenticationService {
|
||||
this.authenticationManager = authenticationManager;
|
||||
}
|
||||
|
||||
public JWTToken login(LoginReq loginReq,HttpServletRequest request) {
|
||||
public JWTToken login(LoginReq loginReq, HttpServletRequest request) {
|
||||
UserEntity user=null;
|
||||
|
||||
|
||||
LoginAttemptEntity loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request);
|
||||
log.info("Attempting login for email: {}", loginReq.getEmail());
|
||||
String emailWithHubId = loginReq.getEmail()+":"+loginReq.getHubUuid();
|
||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
|
||||
loginReq.getEmail(), loginReq.getPassword());
|
||||
emailWithHubId, loginReq.getPassword());
|
||||
Authentication authentication = this.authenticationManager.authenticate(authenticationToken);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
log.info("Authentication successful for email: {}", loginReq.getEmail());
|
||||
user = userRepository.findByEmailIgnoreCase(loginReq.getEmail())
|
||||
user = userRepository.findByEmailIgnoreCaseAndHubUniqueUuid(loginReq.getEmail(), loginReq.getHubUuid())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||
loginAttemptEntity.setUserId(user.getId());
|
||||
@@ -185,10 +191,11 @@ public class AuthenticationService {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.INVALID_TOKEN_MSG));
|
||||
}
|
||||
HubEntity hub = hubService.getHubByUuid(samlResponseLogEntity.getHubUuid());
|
||||
Map<String, List<Object>> userAttributes = Utils
|
||||
.convertStringIntoMap(samlResponseLogEntity.getAuthenticationObject());
|
||||
String cf = userAttributes.get("CodiceFiscale").get(0).toString();
|
||||
UserEntity userEntity = userRepository.findByBeneficiaryCodiceFiscale(cf)
|
||||
UserEntity userEntity = userRepository.findByBeneficiaryCodiceFiscaleAndHubId(cf, hub.getId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||
//samlResponseLogRepository.delete(samlResponseLogEntity);
|
||||
@@ -204,10 +211,11 @@ public class AuthenticationService {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.INVALID_TOKEN_MSG));
|
||||
}
|
||||
HubEntity hub = hubService.getHubByUuid(samlResponseLogEntity.getHubUuid());
|
||||
Map<String, List<Object>> userAttributes = Utils
|
||||
.convertStringIntoMap(samlResponseLogEntity.getAuthenticationObject());
|
||||
String cf = userAttributes.get("CodiceFiscale").get(0).toString();
|
||||
if (userRepository.existsByBeneficiaryCodiceFiscale(cf)) {
|
||||
if (userRepository.existsByBeneficiaryCodiceFiscaleAndHubId(cf, hub.getId())) {
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_ALREADY_EXIST_MSG));
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
||||
|
||||
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.service.BeneficiaryPreferredCallService;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
@@ -17,7 +16,6 @@ import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationExceptio
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,10 +24,10 @@ public class BeneficiaryPreferredCallServiceImpl implements BeneficiaryPreferred
|
||||
|
||||
@Autowired
|
||||
private BeneficiaryPreferredCallDao beneficiaryPreferredCallDao;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@@ -37,22 +35,22 @@ public class BeneficiaryPreferredCallServiceImpl implements BeneficiaryPreferred
|
||||
@Override
|
||||
public BeneficiaryPreferredCallResponseBean createBeneficiaryPreferredCall(HttpServletRequest request, BeneficiaryPreferredCallReq beneficiaryPreferredCallRequest) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
return beneficiaryPreferredCallDao.createBeneficiaryPreferredCall(beneficiaryPreferredCallRequest,userEntity);
|
||||
return beneficiaryPreferredCallDao.createBeneficiaryPreferredCall(request, beneficiaryPreferredCallRequest,userEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeneficiaryPreferredCallResponseBean getBeneficiaryPreferredCallById(HttpServletRequest request, Long id) {
|
||||
return beneficiaryPreferredCallDao.getBeneficiaryPreferredCallById(id);
|
||||
return beneficiaryPreferredCallDao.getBeneficiaryPreferredCallById(request, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBeneficiaryPreferredCall(HttpServletRequest request, Long id) {
|
||||
beneficiaryPreferredCallDao.deleteBeneficiaryPreferredCallById(id);
|
||||
beneficiaryPreferredCallDao.deleteBeneficiaryPreferredCallById(request, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BeneficiaryPreferredCallResponseBean> getAllBeneficiaryPreferredCalls(HttpServletRequest request) {
|
||||
return beneficiaryPreferredCallDao.getAllBeneficiaryPreferredCalls();
|
||||
return beneficiaryPreferredCallDao.getAllBeneficiaryPreferredCalls(request);
|
||||
}
|
||||
|
||||
// @Override
|
||||
@@ -68,6 +66,7 @@ public class BeneficiaryPreferredCallServiceImpl implements BeneficiaryPreferred
|
||||
@Override
|
||||
public List<BeneficiaryPreferredCallResponseBean> getBeneficiaryPreferredCallByUserId(HttpServletRequest request,Long userId,Long beneficiaryId,Long companyId) {
|
||||
UserEntity userEntity =validateGetBeneficiaryPreferredCallrequest(request,userId,beneficiaryId);
|
||||
validator.validateUserId(request, userEntity.getId());
|
||||
return beneficiaryPreferredCallDao.getBeneficiaryPreferredCallByUserId(userEntity,companyId);
|
||||
}
|
||||
|
||||
@@ -81,7 +80,7 @@ public class BeneficiaryPreferredCallServiceImpl implements BeneficiaryPreferred
|
||||
}
|
||||
if(beneficiaryId!=null){
|
||||
UserEntity user = userService.getUserByBeneficiaryId(beneficiaryId);
|
||||
return validator.validateUserId(request,user.getId());
|
||||
return validator.validateUserId(request, user.getId());
|
||||
}
|
||||
else{
|
||||
return validator.validateUserId(request, userId);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
||||
import net.gepafin.tendermanagement.dao.CallDao;
|
||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
@@ -12,12 +11,13 @@ import net.gepafin.tendermanagement.model.request.UpdateCallRequestStep1;
|
||||
import net.gepafin.tendermanagement.model.response.CallDetailsResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.CallResponse;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service
|
||||
@@ -27,59 +27,61 @@ public class CallServiceImpl implements CallService {
|
||||
private CallDao callDao;
|
||||
|
||||
@Autowired
|
||||
private TokenProvider tokenProvider;
|
||||
private Validator validator;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CallResponse createCallStep1(HttpServletRequest request, CreateCallRequestStep1 createCallRequest) {
|
||||
Map<String, Object> userInfo= tokenProvider.getUserInfoAndUserIdFromToken(request);
|
||||
return callDao.createCallStep1(createCallRequest, Long.parseLong(userInfo.get("userId").toString()));
|
||||
UserEntity user = validator.validateUser(request);
|
||||
return callDao.createCallStep1(createCallRequest, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CallResponse createCallStep2(HttpServletRequest request, Long callId, CreateCallRequestStep2 createCallRequest) {
|
||||
Map<String, Object> userInfo= tokenProvider.getUserInfoAndUserIdFromToken(request);
|
||||
return callDao.createCallStep2(callId, createCallRequest, Long.parseLong(userInfo.get("userId").toString()));
|
||||
UserEntity user = validator.validateUser(request);
|
||||
CallEntity call = validator.validateUserWithCall(user, callId);
|
||||
return callDao.createCallStep2(call, createCallRequest, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CallResponse updateCallStep1(HttpServletRequest request, Long callId,
|
||||
UpdateCallRequestStep1 updateCallRequest) {
|
||||
Map<String, Object> userInfo= tokenProvider.getUserInfoAndUserIdFromToken(request);
|
||||
return callDao.updateCallStep1(callId, updateCallRequest, Long.parseLong(userInfo.get("userId").toString()));
|
||||
UserEntity user = validator.validateUser(request);
|
||||
CallEntity call = validator.validateUserWithCall(user, callId);
|
||||
return callDao.updateCallStep1(call, updateCallRequest, user);
|
||||
}
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public CallResponse getCallById(Long callId) {
|
||||
return callDao.getCallById(callId);
|
||||
public CallResponse getCallById(HttpServletRequest request, Long callId) {
|
||||
UserEntity user = validator.validateUser(request);
|
||||
CallEntity call = validator.validateUserWithCall(user, callId);
|
||||
return callDao.getCallById(call);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request) {
|
||||
Map<String, Object> userInfo= tokenProvider.getUserInfoAndUserIdFromToken(request);
|
||||
UserEntity user=tokenProvider.validateUser(userInfo);
|
||||
UserEntity user = validator.validateUser(request);
|
||||
return callDao.getAllCalls(user);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CallResponse validateCallData(Long callId) {
|
||||
return callDao.validateCallData(callDao.validateCall(callId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallEntity getCallEntityById(Long id){
|
||||
return callDao.getCallEntityById(id);
|
||||
public CallResponse validateCallData(HttpServletRequest request, Long callId) {
|
||||
UserEntity user = validator.validateUser(request);
|
||||
CallEntity call = validator.validateUserWithCall(user, callId);
|
||||
return callDao.validateCallData(call);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CallResponse updateCallStatus(HttpServletRequest request, Long callId, CallStatusEnum statusReq) {
|
||||
return callDao.updateCallStatus(callId, statusReq);
|
||||
UserEntity user = validator.validateUser(request);
|
||||
CallEntity call = validator.validateUserWithCall(user, callId);
|
||||
return callDao.updateCallStatus(call, statusReq);
|
||||
|
||||
}
|
||||
|
||||
@@ -88,13 +90,17 @@ public class CallServiceImpl implements CallService {
|
||||
return callDao.validateCall(callId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallEntity validatePublishedCall(Long callId) {
|
||||
return callDao.validatePublishedCall(callId);
|
||||
}
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public byte[] downloadCallDocumentsAsZip(Long callId) {
|
||||
return callDao.downloadCallDocumentsAsZip(callId);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public CallEntity validatePublishedCall(Long callId, Long hubId) {
|
||||
return callDao.validatePublishedCall(callId, hubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public byte[] downloadCallDocumentsAsZip(HttpServletRequest request, Long callId) {
|
||||
UserEntity user = validator.validateUser(request);
|
||||
validator.validateUserWithCall(user, callId);
|
||||
return callDao.downloadCallDocumentsAsZip(callId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CompanyResponse updateCompany(HttpServletRequest request, Long companyId, CompanyRequest companyRequest) {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
return companyDao.updateCompany(userEntity, companyId, companyRequest);
|
||||
}
|
||||
|
||||
@@ -56,6 +57,7 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
@Transactional(readOnly = true)
|
||||
public CompanyResponse getCompany(HttpServletRequest request, Long companyId) {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
return companyDao.getCompany(userEntity, companyId);
|
||||
}
|
||||
|
||||
@@ -63,13 +65,14 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteCompany(HttpServletRequest request, Long companyId) {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
companyDao.deleteCompany(userEntity, companyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<CompanyResponse> getCompanyByUserId(HttpServletRequest request, Long userId) {
|
||||
validator.validateUser(request);
|
||||
validator.validateUserId(request, userId);
|
||||
return companyDao.getCompanyByUserId(userId);
|
||||
}
|
||||
|
||||
@@ -91,8 +94,7 @@ public class CompanyServiceImpl implements CompanyService {
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ByteArrayOutputStream downloadCompanyDelegation(HttpServletRequest request, Long companyId, CompanyDelegationRequest companyDelegationRequest) {
|
||||
UserEntity userEntity =validator.validateUser(request);
|
||||
return delegationDao.downloadCompanyDelegation(userEntity, companyId, companyDelegationRequest);
|
||||
return delegationDao.downloadCompanyDelegation(request, companyId, companyDelegationRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,8 @@ public class DashboardServiceImpl implements DashboardService {
|
||||
|
||||
@Override
|
||||
public SuperAdminWidgetResponseBean getDashboardWidgetForSuperAdmin(HttpServletRequest request) {
|
||||
return dashboardDao.getDashboardWidget();
|
||||
UserEntity userEntity=validator.validateUser(request);
|
||||
return dashboardDao.getDashboardWidget(userEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DocumentServiceImpl implements DocumentService {
|
||||
|
||||
@Override
|
||||
public DocumentResponseBean updateDocument(HttpServletRequest httpServletRequest, Long documentId, MultipartFile file, DocumentTypeEnum documentTypeEnum) {
|
||||
return documentDao.updateDocument(documentId,file,documentTypeEnum);
|
||||
return documentDao.updateDocument(documentId, file,documentTypeEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.dao.EvaluationCriteriaDao;
|
||||
import net.gepafin.tendermanagement.entities.EvaluationCriteriaEntity;
|
||||
import net.gepafin.tendermanagement.model.request.EvaluationCriteriaRequest;
|
||||
import net.gepafin.tendermanagement.model.response.EvaluationCriteriaResponseBean;
|
||||
import net.gepafin.tendermanagement.service.EvaluationCriteriaService;
|
||||
@@ -33,4 +34,9 @@ public class EvaluationCriteriaServiceImpl implements EvaluationCriteriaService
|
||||
public void deleteEvaluationCriteria(HttpServletRequest request,Long id) {
|
||||
evaluationCriteriaDao.deleteEvaluationCriteria(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EvaluationCriteriaEntity validateEvaluationCriteria(Long id) {
|
||||
return evaluationCriteriaDao.validateEvaluationCriteria(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import net.gepafin.tendermanagement.dao.FlowDao;
|
||||
import net.gepafin.tendermanagement.model.request.FlowRequestBean;
|
||||
import net.gepafin.tendermanagement.model.response.FlowResponseBean;
|
||||
import net.gepafin.tendermanagement.service.FlowService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -14,16 +16,21 @@ public class FlowServiceImpl implements FlowService {
|
||||
|
||||
@Autowired
|
||||
private FlowDao flowDao;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public FlowResponseBean createOrUpdateFlow(HttpServletRequest httpServletRequest, FlowRequestBean flowRequestBean, Long callId) {
|
||||
validator.validateUserWithCall(validator.validateUser(httpServletRequest), callId);
|
||||
return flowDao.createOrUpdateFlow(flowRequestBean,callId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@org.springframework.transaction.annotation.Transactional(readOnly = true)
|
||||
public FlowResponseBean getFlowByCallId(HttpServletRequest request, Long callId) {
|
||||
validator.validateUserWithCall(validator.validateUser(request), callId);
|
||||
return flowDao.getFlowByCallId(callId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,15 @@ package net.gepafin.tendermanagement.service.impl;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.dao.FormDao;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||
import net.gepafin.tendermanagement.entities.FormEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.FormRequest;
|
||||
import net.gepafin.tendermanagement.model.response.FormResponseBean;
|
||||
import net.gepafin.tendermanagement.service.FormService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -19,26 +22,33 @@ public class FormServiceImpl implements FormService {
|
||||
|
||||
@Autowired
|
||||
private FormDao formDao;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Override
|
||||
public FormResponseBean createForm(HttpServletRequest request,Long callId, FormRequest formRequest) {
|
||||
return formDao.createForm(callId,formRequest);
|
||||
UserEntity user = validator.validateUser(request);
|
||||
CallEntity call = validator.validateUserWithCall(user, callId);
|
||||
return formDao.createForm(call,formRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormResponseBean updateForm(HttpServletRequest request, Long formId, FormRequest formRequest,Boolean forceDeleteFlow) {
|
||||
return formDao.updateForm(formId,formRequest,forceDeleteFlow);
|
||||
UserEntity user = validator.validateUser(request);
|
||||
return formDao.updateForm(user, formId,formRequest,forceDeleteFlow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormResponseBean getFormById(HttpServletRequest request, Long formId) {
|
||||
return formDao.getFormEntityById(formId);
|
||||
UserEntity user = validator.validateUser(request);
|
||||
return formDao.getFormEntityById(user, formId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteForm(HttpServletRequest request, Long formId) {
|
||||
formDao.deleteFormById(formId);
|
||||
return;
|
||||
UserEntity user = validator.validateUser(request);
|
||||
formDao.deleteFormById(user, formId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,7 +58,9 @@ public class FormServiceImpl implements FormService {
|
||||
|
||||
@Override
|
||||
public List<FormResponseBean> getFormsByCallId(HttpServletRequest request, Long callId) {
|
||||
return formDao.getFormsByCallId(callId);
|
||||
UserEntity user = validator.validateUser(request);
|
||||
CallEntity call = validator.validateUserWithCall(user, callId);
|
||||
return formDao.getFormsByCallId(call);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import net.gepafin.tendermanagement.dao.HubDao;
|
||||
import net.gepafin.tendermanagement.entities.HubEntity;
|
||||
import net.gepafin.tendermanagement.model.request.HubReq;
|
||||
import net.gepafin.tendermanagement.model.response.HubResponseBean;
|
||||
import net.gepafin.tendermanagement.service.HubService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class HubServiceImpl implements HubService {
|
||||
|
||||
@Autowired
|
||||
private HubDao hubDao;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public HubResponseBean createHub(HubReq hubReq) {
|
||||
return hubDao.createHub(hubReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public HubResponseBean updateHub(Long hubId, HubReq hubReq) {
|
||||
return hubDao.updateHub(hubId, hubReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public HubResponseBean getHubById(Long hubId) {
|
||||
return hubDao.getHubById(hubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<HubResponseBean> getAllHubs() {
|
||||
return hubDao.getAllHubs();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteHub(Long hubId) {
|
||||
hubDao.deleteHub(hubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HubEntity getHubByUuid(String hubUuid) {
|
||||
return hubDao.getHubByUuid(hubUuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HubResponseBean getHubByHubUuid(String uuid) {
|
||||
return hubDao.getHubByHubUuid(uuid);
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,15 @@ package net.gepafin.tendermanagement.service.impl;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.dao.LoginAttemptDao;
|
||||
import net.gepafin.tendermanagement.entities.LoginAttemptEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.LoginAttemptResultEnum;
|
||||
import net.gepafin.tendermanagement.enums.LoginAttemptTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.LoginAttemptReq;
|
||||
import net.gepafin.tendermanagement.model.response.LoginAttemptPageableResponseBean;
|
||||
import net.gepafin.tendermanagement.service.LoginAttemptService;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -19,22 +22,30 @@ public class LoginAttemptServiceImpl implements LoginAttemptService {
|
||||
|
||||
@Autowired
|
||||
LoginAttemptDao loginAttemptDao;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Override
|
||||
public LoginAttemptPageableResponseBean<List<LoginAttemptEntity>> getLoginAttemptsList(Integer pageNo, Integer pageLimit) {
|
||||
return loginAttemptDao.getLoginAttemptsList(pageNo, pageLimit);
|
||||
public LoginAttemptPageableResponseBean<List<LoginAttemptEntity>> getLoginAttemptsList(HttpServletRequest request, Integer pageNo, Integer pageLimit) {
|
||||
return loginAttemptDao.getLoginAttemptsList(validator.validateUser(request), pageNo, pageLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLoginAttempt(LoginAttemptReq loginAttemptReq, HttpServletRequest request) {
|
||||
String ipAddress = Utils.getClientIpAddress(request);
|
||||
String userAgent = request.getHeader("user-agent");
|
||||
|
||||
LoginAttemptEntity loginAttemptEntity = new LoginAttemptEntity();
|
||||
loginAttemptEntity.setType(LoginAttemptTypeEnum.SWITCH.getValue());
|
||||
loginAttemptEntity.setIpAddress(ipAddress);
|
||||
loginAttemptEntity.setUserAgent(userAgent);
|
||||
loginAttemptEntity.setUsername(loginAttemptReq.getUserName());
|
||||
loginAttemptEntity.setResult(LoginAttemptResultEnum.SUCCESS.getValue());
|
||||
if(loginAttemptReq.getUserId() != null) {
|
||||
UserEntity userEntity = validator.validateUserId(request, loginAttemptReq.getUserId());
|
||||
loginAttemptEntity.setUserId(userEntity.getId());
|
||||
}
|
||||
loginAttemptDao.createLoginAttempt(loginAttemptEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import net.gepafin.tendermanagement.dao.S3ConfigDao;
|
||||
import net.gepafin.tendermanagement.entities.S3ConfigEntity;
|
||||
import net.gepafin.tendermanagement.model.request.S3ConfigReq;
|
||||
import net.gepafin.tendermanagement.model.response.S3ConfigBean;
|
||||
import net.gepafin.tendermanagement.service.S3ConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class S3ConfigServiceImpl implements S3ConfigService {
|
||||
@Autowired
|
||||
S3ConfigDao s3ConfigDao;
|
||||
|
||||
@Override
|
||||
public S3ConfigBean addS3Path(S3ConfigReq s3Path) {
|
||||
|
||||
return s3ConfigDao.addS3Path(s3Path);
|
||||
}
|
||||
@Override
|
||||
public Optional<S3ConfigEntity> getS3PathByType(String type) {
|
||||
|
||||
return s3ConfigDao.getS3PathByType(type);
|
||||
}
|
||||
@Override
|
||||
@Transactional
|
||||
public S3ConfigEntity deleteS3PathById(Long id) {
|
||||
|
||||
return s3ConfigDao.deleteS3PathConfigById(id);
|
||||
}
|
||||
@Override
|
||||
@Transactional
|
||||
public S3ConfigBean updateS3PathConfiguration(S3ConfigReq s3PathConfigurationReq, Long id) {
|
||||
|
||||
return s3ConfigDao.updateS3PathConfiguration(s3PathConfigurationReq, id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import com.amazonaws.AmazonServiceException;
|
||||
import com.amazonaws.SdkClientException;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.amazonaws.services.s3.model.GetObjectRequest;
|
||||
import com.amazonaws.services.s3.model.ObjectMetadata;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.gepafin.tendermanagement.dao.S3PathConfig;
|
||||
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationSignedDocumentRepository;
|
||||
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class S3ReUploadMigrationService {
|
||||
|
||||
private static final String OLD_BUCKET = "mementoresources";
|
||||
|
||||
private static final String SECURE_KEY = "267163962963";
|
||||
|
||||
@Autowired
|
||||
private DocumentRepository documentRepository;
|
||||
|
||||
@Autowired
|
||||
private AmazonS3Client s3Client;
|
||||
|
||||
@Autowired
|
||||
private S3PathConfig s3ConfigBean;
|
||||
|
||||
@Autowired
|
||||
private ApplicationRepository applicationRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationSignedDocumentRepository applicationSignedDocumentRepository;
|
||||
|
||||
@Autowired
|
||||
private AmazonS3 amazonS3;
|
||||
|
||||
@Value("${aws.s3.url}")
|
||||
private String s3Url;
|
||||
|
||||
private boolean migrationCompleted = false;
|
||||
|
||||
public String reUploadAndMigrateDocuments(String providedKey) {
|
||||
|
||||
if (migrationCompleted) {
|
||||
return "Migration already completed.";
|
||||
}
|
||||
|
||||
// Validate the provided key
|
||||
if (!isValidKey(providedKey)) {
|
||||
return "Invalid or missing migration key.";
|
||||
}
|
||||
|
||||
List<DocumentEntity> documents = documentRepository.findAllByIsDeleteFalse();
|
||||
|
||||
if (documents.isEmpty()) {
|
||||
return "No documents found to migrate.";
|
||||
}
|
||||
|
||||
for (DocumentEntity document : documents) {
|
||||
String oldUrl = document.getFilePath(); // This should contain the full URL
|
||||
log.info("Processing {}", oldUrl);
|
||||
|
||||
try {
|
||||
File localFile = downloadFileFromS3(oldUrl);
|
||||
String newKey = generateNewS3Path(document); // Make sure this generates the correct new path
|
||||
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
|
||||
updateDocumentPathAndDeleteOldEntry(document, uploadedPath);
|
||||
} catch (Exception e) {
|
||||
log.error("Error processing document {}: {}", document.getId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
return "Migrated Successfully.";
|
||||
}
|
||||
|
||||
private boolean isValidKey(String providedKey) {
|
||||
|
||||
return providedKey != null && providedKey.equals(SECURE_KEY);
|
||||
}
|
||||
|
||||
private File downloadFileFromS3(String fileUrl) throws Exception {
|
||||
|
||||
String key = extractS3KeyFromUrl(fileUrl); // Get the S3 key from the URL
|
||||
File localFile = new File("/tmp/" + extractFileName(key)); // Save file locally
|
||||
|
||||
GetObjectRequest getObjectRequest = new GetObjectRequest(OLD_BUCKET, key); // Use the key
|
||||
|
||||
try (InputStream s3Stream = s3Client.getObject(getObjectRequest).getObjectContent(); FileOutputStream outputStream = new FileOutputStream(localFile)) {
|
||||
s3Stream.transferTo(outputStream);
|
||||
}
|
||||
|
||||
log.info("Downloaded file from old S3 bucket: {}", key);
|
||||
return localFile;
|
||||
}
|
||||
|
||||
private String extractS3KeyFromUrl(String url) {
|
||||
// Assuming the URL structure is consistent
|
||||
return url.replace("https://mementoresources.s3.eu-west-1.amazonaws.com/", "");
|
||||
}
|
||||
|
||||
private String uploadFileToNewBucket(File localFile, String s3Folder) {
|
||||
|
||||
InputStream inputStream = null; // Declare the InputStream here for cleanup
|
||||
try {
|
||||
// Extract file name from the local file
|
||||
String fileName = extractFileName(localFile.getAbsolutePath()); // Get the file name
|
||||
String path = s3Folder + "/" + fileName; // Construct the S3 path
|
||||
|
||||
// Create InputStream from the local file
|
||||
inputStream = new FileInputStream(localFile);
|
||||
|
||||
// Set up object metadata
|
||||
ObjectMetadata objectMetadata = new ObjectMetadata();
|
||||
objectMetadata.setContentType("application/octet-stream");
|
||||
objectMetadata.setContentLength(localFile.length());
|
||||
|
||||
// Upload to S3
|
||||
s3Client.putObject(OLD_BUCKET, path, inputStream, objectMetadata);
|
||||
|
||||
// Construct the full S3 URL
|
||||
String fullUrl = String.format("https://%s.s3.%s.amazonaws.com/%s", OLD_BUCKET, "eu-west-1", path);
|
||||
log.info("File '{}' uploaded successfully to Amazon S3 with URL: {}", fileName, fullUrl);
|
||||
return fullUrl;
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("IOException occurred during file upload for '{}': {}", localFile.getName(), e.getMessage());
|
||||
throw new RuntimeException("Upload failed for: " + s3Folder + "/" + localFile.getName(), e);
|
||||
} catch (AmazonServiceException e) {
|
||||
log.error("Amazon service exception while uploading file '{}': {}", localFile.getName(), e.getMessage());
|
||||
throw new RuntimeException("Upload failed for: " + s3Folder + "/" + localFile.getName(), e);
|
||||
} catch (SdkClientException e) {
|
||||
log.error("SDK client exception while uploading file '{}': {}", localFile.getName(), e.getMessage());
|
||||
throw new RuntimeException("Upload failed for: " + s3Folder + "/" + localFile.getName(), e);
|
||||
} finally {
|
||||
// Close InputStream if it was opened
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.warn("Failed to close InputStream for file '{}': {}", localFile.getName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String generateNewS3Path(DocumentEntity document) {
|
||||
|
||||
DocumentSourceTypeEnum sourceType = DocumentSourceTypeEnum.valueOf(document.getSource());
|
||||
Long callId;
|
||||
|
||||
if (sourceType.equals(DocumentSourceTypeEnum.CALL)) {
|
||||
return s3ConfigBean.generateDocumentPath(sourceType, document.getSourceId(), 0L);
|
||||
} else {
|
||||
callId = applicationRepository.findCallIdById(document.getSourceId());
|
||||
return s3ConfigBean.generateDocumentPath(sourceType, callId, document.getSourceId());
|
||||
}
|
||||
}
|
||||
|
||||
private String extractFileName(String filePath) {
|
||||
|
||||
String[] parts = filePath.split("/");
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
|
||||
|
||||
private void updateDocumentPathAndDeleteOldEntry(DocumentEntity document, String newPath) {
|
||||
|
||||
String fileName = extractFileName(newPath);
|
||||
DocumentEntity newDocument = new DocumentEntity();
|
||||
newDocument.setFilePath(newPath);
|
||||
newDocument.setSource(document.getSource());
|
||||
newDocument.setType(document.getType());
|
||||
newDocument.setIsDeleted(false);
|
||||
newDocument.setSourceId(document.getSourceId());
|
||||
newDocument.setFileName(fileName);
|
||||
|
||||
documentRepository.save(newDocument);
|
||||
documentRepository.delete(document);
|
||||
|
||||
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,11 @@ package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.gepafin.tendermanagement.config.SamlSuccessHandler;
|
||||
import net.gepafin.tendermanagement.dao.UserDao;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.model.request.LoginReq;
|
||||
import net.gepafin.tendermanagement.model.request.UpdateUserReq;
|
||||
import net.gepafin.tendermanagement.model.request.UserReq;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.response.UserSamlResponse;
|
||||
@@ -32,42 +30,37 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private SamlSuccessHandler samlSuccessHandler;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq) {
|
||||
if (tempToken == null) {
|
||||
validator.validateRequest(request,RoleStatusEnum.ROLE_SUPER_ADMIN);
|
||||
}else {
|
||||
samlSuccessHandler.validateToken(tempToken, userReq.getCodiceFiscale());
|
||||
}
|
||||
return userDao.createUser(request, tempToken, userReq);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public UserResponseBean updateUser(Long userId, UpdateUserReq userReq) {
|
||||
public UserResponseBean updateUser(HttpServletRequest request, Long userId, UpdateUserReq userReq) {
|
||||
validator.validateUserId(request, userId);
|
||||
return userDao.updateUser(userId, userReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public UserResponseBean getUserById(Long userId) {
|
||||
public UserResponseBean getUserById(HttpServletRequest request, Long userId) {
|
||||
validator.validateUserId(request, userId);
|
||||
return userDao.getUserById(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteUser(Long userId) {
|
||||
public void deleteUser(HttpServletRequest request, Long userId) {
|
||||
validator.validateUserId(request, userId);
|
||||
userDao.deleteUser(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JWTToken login(LoginReq loginReq,HttpServletRequest request) {
|
||||
public JWTToken login(LoginReq loginReq, HttpServletRequest request) {
|
||||
return userDao.login(loginReq,request);
|
||||
|
||||
}
|
||||
@@ -87,8 +80,8 @@ public class UserServiceImpl implements UserService {
|
||||
return userDao.resetPassword(resetPasswordReq);
|
||||
}
|
||||
@Override
|
||||
public Boolean changePassword(ChangePasswordRequest request){
|
||||
return userDao.changePassword(request);
|
||||
public Boolean changePassword(HttpServletRequest httpServletRequest, ChangePasswordRequest request){
|
||||
return userDao.changePassword(validator.validateUser(httpServletRequest), request);
|
||||
}
|
||||
@Override
|
||||
public void logoutUser(HttpServletRequest request, HttpServletResponse response) {
|
||||
@@ -127,8 +120,8 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<UserResponseBean> getAllUsers(Long roleId) {
|
||||
// Calling DAO Function
|
||||
return userDao.getAllUsers(roleId);
|
||||
public List<UserResponseBean> getAllUsers(HttpServletRequest request, Long roleId) {
|
||||
UserEntity user=validator.validateUser(request);
|
||||
return userDao.getAllUsers(user, roleId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import com.amazonaws.AmazonServiceException;
|
||||
import com.amazonaws.SdkClientException;
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.amazonaws.services.s3.model.GetObjectRequest;
|
||||
import com.amazonaws.services.s3.model.ObjectMetadata;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.gepafin.tendermanagement.dao.S3PathConfig;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationSignedDocumentEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserCompanyDelegationEntity;
|
||||
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationSignedDocumentRepository;
|
||||
import net.gepafin.tendermanagement.repositories.S3ConfigRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserCompanyDelegationRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserSignedAndDelegationServiceImpl {
|
||||
private static final String OLD_BUCKET = "mementoresources";
|
||||
|
||||
private static final String NEW_BUCKET = "mementoresources";
|
||||
|
||||
private static final String SECURE_KEY = "267163962963";
|
||||
|
||||
@Autowired
|
||||
private UserCompanyDelegationRepository userCompanyDelegationRepository;
|
||||
|
||||
@Autowired
|
||||
private AmazonS3Client s3Client;
|
||||
|
||||
@Autowired
|
||||
private S3PathConfig s3ConfigBean;
|
||||
|
||||
@Autowired
|
||||
private ApplicationSignedDocumentRepository applicationSignedDocumentRepository;
|
||||
|
||||
@Autowired
|
||||
ApplicationRepository applicationRepository;
|
||||
|
||||
@Autowired
|
||||
S3ConfigRepository s3ConfigRepository;
|
||||
|
||||
@Value("${aws.s3.url}")
|
||||
private String s3Url;
|
||||
|
||||
private boolean migrationCompleted = false;
|
||||
|
||||
|
||||
public String migrateUserDelegatedDocuments(String providedKey) {
|
||||
|
||||
if (migrationCompleted) {
|
||||
return "Migration already completed.";
|
||||
}
|
||||
|
||||
// Validate the provided key
|
||||
if (isValidKey(providedKey)) {
|
||||
return "Invalid or missing migration key.";
|
||||
}
|
||||
|
||||
List<UserCompanyDelegationEntity> documents = userCompanyDelegationRepository.findAllByStatus("ACTIVE");
|
||||
|
||||
if (documents.isEmpty()) {
|
||||
return "No documents found to migrate.";
|
||||
}
|
||||
|
||||
for (UserCompanyDelegationEntity document : documents) {
|
||||
String oldUrl = document.getFilePath();
|
||||
log.info("Processing user designated document: {}", oldUrl);
|
||||
|
||||
try {
|
||||
File localFile = downloadFileFromS3(oldUrl);
|
||||
String newKey = generateNewS3PathForDelegationDoc();
|
||||
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
|
||||
updateDelegatedDocumentPathAndDeleteOldEntry(document, uploadedPath);
|
||||
} catch (Exception e) {
|
||||
log.error("Error processing user designated document {}: {}", document.getId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
return "Migrated";
|
||||
}
|
||||
|
||||
|
||||
public String migrateUserSignedDocuments(String providedKey) {
|
||||
|
||||
if (migrationCompleted) {
|
||||
return "Migration already completed.";
|
||||
}
|
||||
|
||||
// Validate the provided key
|
||||
if (isValidKey(providedKey)) {
|
||||
return "Invalid or missing migration key.";
|
||||
}
|
||||
List<ApplicationSignedDocumentEntity> documents = applicationSignedDocumentRepository.findAllByIsStatus("ACTIVE");
|
||||
|
||||
if (documents.isEmpty()) {
|
||||
return "No documents found to migrate.";
|
||||
}
|
||||
|
||||
for (ApplicationSignedDocumentEntity document : documents) {
|
||||
String oldUrl = document.getFilePath();
|
||||
log.info("Processing user signed document: {}", oldUrl);
|
||||
|
||||
try {
|
||||
File localFile = downloadFileFromS3(oldUrl);
|
||||
String newKey = generateNewS3PathForUserSignedDoc(document);
|
||||
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
|
||||
updateDocumentPathAndDeleteOldEntry(document, uploadedPath);
|
||||
} catch (Exception e) {
|
||||
log.error("Error processing user signed document {}: {}", document.getId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
return "Migrated.";
|
||||
}
|
||||
|
||||
private boolean isValidKey(String providedKey) {
|
||||
|
||||
return providedKey == null || !providedKey.equals(SECURE_KEY);
|
||||
}
|
||||
|
||||
private String generateNewS3PathForDelegationDoc() {
|
||||
|
||||
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_DELEGATION, 0L, 0L);
|
||||
}
|
||||
|
||||
private String generateNewS3PathForUserSignedDoc(ApplicationSignedDocumentEntity document) {
|
||||
// Fetch the list of application IDs associated with the document
|
||||
List<Long> applicationIds = applicationSignedDocumentRepository.findApplicationIdIdsById(document.getId());
|
||||
List<String> paths = new ArrayList<>();
|
||||
|
||||
// Loop through the application IDs and generate paths
|
||||
for (Long applicationId : applicationIds) {
|
||||
Long callId = applicationRepository.findCallIdById(applicationId);
|
||||
|
||||
// Construct the path for the current application and call ID
|
||||
String newPath = String.format("%s/call/call_%d/application/application_%d/user_signed_document", s3ConfigRepository.getPathByTypeOther(
|
||||
String.valueOf(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT)) , callId, applicationId);
|
||||
|
||||
log.info("Generated new S3 path: {}", newPath);
|
||||
paths.add(newPath);
|
||||
}
|
||||
|
||||
return String.join(",", paths);
|
||||
}
|
||||
|
||||
private File downloadFileFromS3(String fileUrl) throws Exception {
|
||||
|
||||
String key = extractS3KeyFromUrl(fileUrl);
|
||||
File localFile = new File("/tmp/" + extractFileName(key));
|
||||
|
||||
GetObjectRequest getObjectRequest = new GetObjectRequest(OLD_BUCKET, key);
|
||||
|
||||
try (InputStream s3Stream = s3Client.getObject(getObjectRequest).getObjectContent(); FileOutputStream outputStream = new FileOutputStream(localFile)) {
|
||||
s3Stream.transferTo(outputStream);
|
||||
}
|
||||
|
||||
log.info("Downloaded file from old S3 bucket: {}", key);
|
||||
return localFile;
|
||||
}
|
||||
|
||||
private String extractS3KeyFromUrl(String url) {
|
||||
|
||||
return url.replace("https://mementoresources.s3.eu-west-1.amazonaws.com/", "");
|
||||
}
|
||||
|
||||
private String uploadFileToNewBucket(File localFile, String s3Path) {
|
||||
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
String fileName = extractFileName(localFile.getAbsolutePath()); // Extract file name
|
||||
String fullPath = String.format("%s/%s", s3Path, fileName); // Construct full path
|
||||
|
||||
inputStream = new FileInputStream(localFile); // Create InputStream
|
||||
|
||||
// Set metadata for the file
|
||||
ObjectMetadata objectMetadata = new ObjectMetadata();
|
||||
objectMetadata.setContentLength(localFile.length());
|
||||
objectMetadata.setContentType("application/octet-stream");
|
||||
|
||||
// Upload the file to S3 with the constructed path
|
||||
s3Client.putObject(NEW_BUCKET, fullPath, inputStream, objectMetadata);
|
||||
|
||||
// Construct the full S3 URL for the uploaded file
|
||||
String fullUrl = String.format("https://%s.s3.%s.amazonaws.com/%s", NEW_BUCKET, "eu-west-1", fullPath);
|
||||
log.info("File '{}' uploaded successfully to Amazon S3 with URL: {}", fileName, fullUrl);
|
||||
return fullUrl;
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("IOException occurred during file upload for '{}': {}", localFile.getName(), e.getMessage());
|
||||
throw new RuntimeException("Upload failed for: " + localFile, e);
|
||||
} catch (AmazonServiceException e) {
|
||||
log.error("Amazon service exception while uploading file '{}': {}", localFile.getName(), e.getMessage());
|
||||
throw new RuntimeException("Upload failed for: " + localFile, e);
|
||||
} catch (SdkClientException e) {
|
||||
log.error("SDK client exception while uploading file '{}': {}", localFile.getName(), e.getMessage());
|
||||
throw new RuntimeException("Upload failed for: " + localFile, e);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.warn("Failed to close InputStream for file '{}': {}", localFile.getName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String extractFileName(String filePath) {
|
||||
|
||||
String[] parts = filePath.split("/");
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
private String extractFileNameFromPath(String path) {
|
||||
|
||||
return path.substring(path.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
private void updateDocumentPathAndDeleteOldEntry(ApplicationSignedDocumentEntity document, String newPath) {
|
||||
|
||||
ApplicationSignedDocumentEntity newDocument = new ApplicationSignedDocumentEntity();
|
||||
String fileName = extractFileNameFromPath(newPath);
|
||||
newDocument.setFilePath(newPath);
|
||||
newDocument.setFileName(fileName);
|
||||
newDocument.setApplication(document.getApplication());
|
||||
newDocument.setStatus("ACTIVE");
|
||||
|
||||
applicationSignedDocumentRepository.save(newDocument);
|
||||
applicationSignedDocumentRepository.delete(document);
|
||||
|
||||
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
|
||||
}
|
||||
|
||||
private void updateDelegatedDocumentPathAndDeleteOldEntry(UserCompanyDelegationEntity document, String newPath) {
|
||||
|
||||
String fileName = extractFileNameFromPath(newPath);
|
||||
UserCompanyDelegationEntity newDocument = new UserCompanyDelegationEntity();
|
||||
newDocument.setFilePath(newPath);
|
||||
newDocument.setFileName(fileName);
|
||||
newDocument.setBeneficiaryId(document.getBeneficiaryId());
|
||||
newDocument.setUserId(document.getUserId());
|
||||
newDocument.setCompanyId(document.getCompanyId());
|
||||
newDocument.setStatus("ACTIVE");
|
||||
|
||||
userCompanyDelegationRepository.save(newDocument);
|
||||
userCompanyDelegationRepository.delete(document);
|
||||
|
||||
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user