Merge pull request #226 from Kitzanos/feature/GEPAFINBE-167

GEPAFINBE-167(Beneficiary - upload company documents)
This commit is contained in:
Rinaldo
2025-02-25 09:17:09 +01:00
committed by GitHub
35 changed files with 1565 additions and 14 deletions

View File

@@ -433,6 +433,21 @@ public class GepafinConstant {
public static final String FORMULA_AMOUNT_NOT_MATCHED="formula.amount.not.matches.requested.amount"; public static final String FORMULA_AMOUNT_NOT_MATCHED="formula.amount.not.matches.requested.amount";
public static final String CRITERIA_TABLE_COLUMNS="criteria_table_columns"; public static final String CRITERIA_TABLE_COLUMNS="criteria_table_columns";
public static final String COMPANY_DOCUMENT_NOT_FOUND = "company.document.not.found";
public static final String COMPANY_DOCUMENT_UPDATED_SUCCESSFULLY = "company.document.updated.successfully";
public static final String COMPANY_DOCUMENT_COPIED_SUCCESSFULLY = "company.document.copied.successfully";
public static final String COMPANY_DOCUMENT_FETCHED_SUCCESSFULLY = "company.document.fetched.successfully";
public static final String DOCUMENT_CATEGORY_CREATE_SUCCESS = "document.category.success";
public static final String DOCUMENT_CATEGORY_GET_SUCCESS = "document.category.get.success";
public static final String DOCUMENT_CATEGORY_NOT_FOUND = "document.category.not.found";
public static final String DOCUMENT_CATEGORY_DELETE_SUCCESS = "document.category.delete.success";
public static final String DOCUMENT_CATEGORY_UPDATE_SUCCESS = "document.category.update.success";
public static final String ERROR_MOVING_FILE_TO_DELETED_FOLDER = "error.moving.file.to.deleted.folder";
public static final String CATEGORY_CANNOT_BE_DELETED = "category.cannot.be.deleted";
public static final String INVALID_EXPIRATION_DATE = "invalid.expiration.date";
public static final String LABEL="label"; public static final String LABEL="label";
public static final String FORMULA="formula"; public static final String FORMULA="formula";
public static final String VARIABLE="variable"; public static final String VARIABLE="variable";

View File

@@ -0,0 +1,334 @@
package net.gepafin.tendermanagement.dao;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CopyObjectRequest;
import jakarta.persistence.criteria.Predicate;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.enums.*;
import net.gepafin.tendermanagement.model.request.CompanyDocumentRequest;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.model.response.DocumentCategoryResponse;
import net.gepafin.tendermanagement.model.response.CompanyDocumentResponseBean;
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
import net.gepafin.tendermanagement.repositories.CompanyDocumentRepository;
import net.gepafin.tendermanagement.repositories.DocumentRepository;
import net.gepafin.tendermanagement.service.AmazonS3Service;
import net.gepafin.tendermanagement.service.ApplicationService;
import net.gepafin.tendermanagement.service.CompanyService;
import net.gepafin.tendermanagement.service.impl.AmazonS3ServiceImpl;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.util.Validator;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
@Slf4j
@Component
public class CompanyDocumentDao {
@Autowired
private S3PathConfig s3ConfigBean;
@Autowired
private AmazonS3Service amazonS3Service;
@Autowired
private CompanyDocumentRepository companyDocumentRepository;
@Autowired
private LoggingUtil loggingUtil;
@Autowired
private HttpServletRequest request;
@Autowired
private DocumentCategoryDao categoryDao;
@Autowired
private CompanyService companyService;
@Value("${aws.s3.bucket.name}")
private String bucketName;
@Autowired
private AmazonS3Client s3Client;
@Autowired
private DocumentRepository documentRepository;
@Autowired
private CallDao callDao;
@Autowired
private ApplicationService applicationService;
@Autowired
private AmazonS3ServiceImpl amazonS3ServiceImpl;
@Autowired
private Validator validator;
public List<CompanyDocumentResponseBean> uploadFileForCompany(HttpServletRequest request, Long userId, List<MultipartFile> files, Long companyId, Long documentCategoryId, CompanyDocumentTypeEnum companyDocumentSourceTypeEnum, LocalDateTime expirationDate){
DocumentCategoryEntity categoryEntity = categoryDao.validateCategory(documentCategoryId);
validator.validateUserWithCompany(request,companyId);
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userId,companyId);
LocalDateTime currentDate = LocalDateTime.now();
if (expirationDate.isBefore(currentDate)) {
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.INVALID_EXPIRATION_DATE));
}
List<CompanyDocumentEntity> companyDocumentEntities = new ArrayList<>();
for (MultipartFile file : files){
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3(file, companyDocumentSourceTypeEnum, companyId);
if (uploadFileOnAmazonS3Response != null) {
CompanyDocumentEntity companyDocumentEntity = new CompanyDocumentEntity();
companyDocumentEntity.setFileName(uploadFileOnAmazonS3Response.getFileName());
companyDocumentEntity.setCompanyId(companyId);
companyDocumentEntity.setType(companyDocumentSourceTypeEnum.getValue());
companyDocumentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
companyDocumentEntity.setIsDeleted(false);
companyDocumentEntity.setUploadedBy(userId);
if (expirationDate.isBefore(currentDate.plusDays(7))) {
companyDocumentEntity.setStatus(CompanyDocumentStatusEnum.DUE.getValue());
} else {
companyDocumentEntity.setStatus(CompanyDocumentStatusEnum.VALID.getValue());
}
companyDocumentEntity.setCategoryEntity(categoryEntity);
companyDocumentEntity.setUserWithCompany(userWithCompanyEntity);
companyDocumentEntity.setExpirationDate(expirationDate);
companyDocumentEntities.add(companyDocumentEntity);
}
}
companyDocumentRepository.saveAll(companyDocumentEntities);
/** This code is responsible for adding a version history log for the "Upload company document" operation. **/
companyDocumentEntities.forEach(entity -> loggingUtil.addVersionHistory(
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(entity).build()));
return companyDocumentEntities.stream()
.map(this::convertToCompanyDocumentResponseBean)
.collect(Collectors.toList());
}
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3(MultipartFile file, CompanyDocumentTypeEnum type, Long companyId) {
try {
String s3Path = generateS3PathForCompany(type,companyId);
log.info("Generated S3 path {}", s3Path);
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
} catch (Exception e) {
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
}
}
public String generateS3PathForCompany(CompanyDocumentTypeEnum typeOfDocument, Long companyId) {
try {
return s3ConfigBean.generateCompanyDocumentPath(typeOfDocument, companyId);
} catch (IllegalArgumentException e) {
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
}
}
public CompanyDocumentEntity validateCompanyDocument(Long id) {
return companyDocumentRepository.findByIdAndNotDeleted(id).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.COMPANY_DOCUMENT_NOT_FOUND)));
}
public CompanyDocumentResponseBean convertToCompanyDocumentResponseBean(CompanyDocumentEntity entity) {
CompanyDocumentResponseBean responseBean = new CompanyDocumentResponseBean();
DocumentCategoryEntity categoryEntity = entity.getCategoryEntity();
DocumentCategoryResponse responseCategory = categoryDao.convertToResponseBean(categoryEntity);
responseBean.setId(entity.getId());
responseBean.setName(entity.getFileName());
responseBean.setType(CompanyDocumentTypeEnum.valueOf(entity.getType()));
responseBean.setFilePath(entity.getFilePath());
responseBean.setCompanyId(entity.getCompanyId());
responseBean.setExpirationDate(entity.getExpirationDate());
responseBean.setStatus(entity.getStatus());
responseBean.setUploadedBy(entity.getUploadedBy());
responseBean.setCategory(responseCategory);
responseBean.setUserWithCompanyId(entity.getUserWithCompany().getId());
responseBean.setCreatedDate(entity.getCreatedDate());
responseBean.setUpdatedDate(entity.getUpdatedDate());
return responseBean;
}
public CompanyDocumentResponseBean updateCompanyDocument(HttpServletRequest request,Long companyDocumentId, CompanyDocumentRequest companyDocumentRequest){
CompanyDocumentEntity companyDocumentEntity = validateCompanyDocument(companyDocumentId);
validator.validateUserWithCompany(request,companyDocumentEntity.getCompanyId());
CompanyDocumentEntity oldCompanyDocumentData = Utils.getClonedEntityForData(companyDocumentEntity);
LocalDateTime currentDate = LocalDateTime.now();
if (companyDocumentRequest.getExpirationDate() != null) {
if (companyDocumentRequest.getExpirationDate().isBefore(currentDate)) {
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.INVALID_EXPIRATION_DATE));
}
companyDocumentEntity.setExpirationDate(companyDocumentRequest.getExpirationDate());
if (companyDocumentRequest.getExpirationDate().isBefore(currentDate.plusDays(7))) {
companyDocumentEntity.setStatus(CompanyDocumentStatusEnum.DUE.getValue());
} else {
companyDocumentEntity.setStatus(CompanyDocumentStatusEnum.VALID.getValue());
}
}
if (companyDocumentRequest.getCategoryId() != null && companyDocumentRequest.getCategoryId() >0) {
DocumentCategoryEntity categoryEntity = categoryDao.validateCategory(companyDocumentRequest.getCategoryId());
setIfUpdated(companyDocumentEntity::getCategoryEntity, companyDocumentEntity::setCategoryEntity, categoryEntity);
}
companyDocumentRepository.save(companyDocumentEntity);
/** This code is responsible for adding a version history log for the "updating company document" operation. **/
loggingUtil.addVersionHistory(
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCompanyDocumentData).newData(companyDocumentEntity).build());
return convertToCompanyDocumentResponseBean(companyDocumentEntity);
}
public CompanyDocumentResponseBean getCompanyDocument(UserEntity user ,Long companyDocumentId) {
CompanyDocumentEntity companyDocumentEntity = validateCompanyDocument(companyDocumentId);
validator.validateUserWithCompany(request,companyDocumentEntity.getCompanyId());
return convertToCompanyDocumentResponseBean(companyDocumentEntity);
}
public void deleteCompanyFile(Long companyDocumentId){
CompanyDocumentEntity companyDocumentEntity = validateCompanyDocument(companyDocumentId);
deleteCompanyFileFromS3(companyDocumentEntity);
}
public void deleteCompanyFileFromS3(CompanyDocumentEntity companyDocumentEntity){
try {
CompanyDocumentEntity oldCompanyDocumentEntity = Utils.getClonedEntityForData(companyDocumentEntity);
validator.validateUserWithCompany(request,companyDocumentEntity.getCompanyId());
String oldCompanyDocumentPath = companyDocumentEntity.getFilePath();
String newS3Path = s3ConfigBean.generateCompanyDocumentPathForOther(CompanyDocSourceTypeEnum.valueOf("DELETED_" + companyDocumentEntity.getType().toUpperCase()), companyDocumentEntity.getCompanyId());
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(companyDocumentEntity.getFileName(), oldCompanyDocumentPath, newS3Path);
companyDocumentEntity.setFileName(response.getFileName());
companyDocumentEntity.setFilePath(response.getFilePath());
companyDocumentEntity.setIsDeleted(true);
companyDocumentRepository.save(companyDocumentEntity);
/** This code is responsible for adding a version history log for the "Soft delete document" operation. **/
loggingUtil.addVersionHistory(
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldCompanyDocumentEntity).newData(companyDocumentEntity).build());
log.info("File for company document ID {} successfully moved to deleted folder.", companyDocumentEntity.getId());
}
catch (Exception e) {
log.error("Error moving file for company document ID {} to deleted folder: {}", companyDocumentEntity.getId(), e.getMessage());
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.ERROR_MOVING_FILE_TO_DELETED_FOLDER));
}
}
public UserActionContextEnum getUserActionContextEnum(CompanyDocumentTypeEnum type){
UserActionContextEnum userActionContext = null;
if (type.equals(CompanyDocumentTypeEnum.COMPANY_DOCUMENT)){
userActionContext = UserActionContextEnum.UPLOAD_COMPANY_DOCUMENT;
}
else if(type.equals(CompanyDocumentTypeEnum.PERSONAL_DOCUMENT)){
userActionContext = UserActionContextEnum.UPLOAD_COMPANY_PERSONAL_DOCUMENT;
}
return userActionContext;
}
public DocumentResponseBean validateAndDuplicateCompanyDocument(HttpServletRequest request , Long userId ,Long companyDocumentId , Long applicationId , DocumentTypeEnum documentTypeEnum){
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId);
CompanyDocumentEntity companyDocumentEntity = validateCompanyDocument(companyDocumentId);
validator.validateUserWithCompany(request,companyDocumentEntity.getCompanyId());
String oldS3Path = companyDocumentEntity.getFilePath();
String newS3Path = s3ConfigBean.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION,applicationEntity.getCall().getId(),applicationId,0L);
log.info("Original Paths - oldPath: {}, newPath: {}", oldS3Path, newS3Path);
oldS3Path = amazonS3ServiceImpl.decodeS3Key(amazonS3ServiceImpl.cleanOldPath(oldS3Path));
newS3Path = amazonS3ServiceImpl.cleanNewPath(oldS3Path, newS3Path);
log.info("Moving file from {} to {} in bucket {}", oldS3Path, newS3Path, bucketName);
CopyObjectRequest copyRequest = new CopyObjectRequest(bucketName, oldS3Path, bucketName, newS3Path);
s3Client.copyObject(copyRequest);
log.info("File copied successfully from {} to {}", oldS3Path, newS3Path);
DocumentEntity entity = new DocumentEntity();
entity.setFilePath(newS3Path);
entity.setFileName(companyDocumentEntity.getFileName());
entity.setSource(DocumentSourceTypeEnum.APPLICATION.getValue());
entity.setType(documentTypeEnum.getValue());
entity.setSourceId(applicationId);
entity.setUploadedBy(userId);
documentRepository.save(entity);
/** This code is responsible for adding a version history log for the "inserting data" operation. **/
loggingUtil.addVersionHistory(
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(entity).build());
DocumentResponseBean responseBean = callDao.convertToDocumentResponseBean(entity);
return responseBean;
}
public List<CompanyDocumentResponseBean> getAllCompanyDocument(UserEntity user , Long companyId, CompanyDocumentTypeEnum typeEnum){
validator.validateUserWithCompany(request, companyId);
companyService.validateCompany(companyId);
Specification<CompanyDocumentEntity> spec = filterCompanyDocuments(companyId, user.getId(), typeEnum);
List<CompanyDocumentEntity> companyDocumentEntities = companyDocumentRepository.findAll(spec);
return companyDocumentEntities.stream()
.map(this::convertToCompanyDocumentResponseBean)
.collect(Collectors.toList());
}
private Specification<CompanyDocumentEntity> filterCompanyDocuments(Long companyId, Long userId, CompanyDocumentTypeEnum typeEnum) {
return (root, query, builder) -> {
Predicate predicate = builder.equal(root.get("companyId"), companyId);
if (typeEnum != null) {
if (typeEnum == CompanyDocumentTypeEnum.COMPANY_DOCUMENT) {
// Case 1: Fetch only COMPANY_DOCUMENT type documents for the given company
predicate = builder.and(predicate, builder.equal(root.get("type"), CompanyDocumentTypeEnum.COMPANY_DOCUMENT.getValue()));
} else if (typeEnum == CompanyDocumentTypeEnum.PERSONAL_DOCUMENT) {
// Case 2: Fetch only PERSONAL_DOCUMENT type documents for the logged-in user
predicate = builder.and(
predicate,
builder.equal(root.get("type"), CompanyDocumentTypeEnum.PERSONAL_DOCUMENT.getValue()),
builder.equal(root.get("userWithCompany").get("userId"), userId)
);
}
}
// Case 3: If typeEnum is null, fetch all documents for the company and personal documents for the user
Predicate companyPredicate = builder.equal(root.get("companyId"), companyId);
Predicate personalPredicate = builder.and(
builder.equal(root.get("type"), CompanyDocumentTypeEnum.PERSONAL_DOCUMENT.getValue()),
builder.equal(root.get("userWithCompany").get("userId"), userId)
);
predicate = builder.and(predicate, builder.or(companyPredicate, personalPredicate));
return predicate;
};
}
}

View File

@@ -0,0 +1,111 @@
package net.gepafin.tendermanagement.dao;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.DocumentCategoryEntity;
import net.gepafin.tendermanagement.entities.CompanyDocumentEntity;
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
import net.gepafin.tendermanagement.model.request.DocumentCategoryRequest;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.model.response.DocumentCategoryResponse;
import net.gepafin.tendermanagement.repositories.DocumentCategoryRepository;
import net.gepafin.tendermanagement.repositories.CompanyDocumentRepository;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
@Component
public class DocumentCategoryDao {
@Autowired
private DocumentCategoryRepository categoryRepository;
@Autowired
private LoggingUtil loggingUtil;
@Autowired
private HttpServletRequest request;
@Autowired
private CompanyDocumentRepository companyDocumentRepository;
public DocumentCategoryResponse createDocumentCategory(HttpServletRequest request, DocumentCategoryRequest categoryRequest){
DocumentCategoryEntity entity = createCategoryEntity(new DocumentCategoryEntity(),categoryRequest);
categoryRepository.save(entity);
/** This code is responsible for adding a version history log for the "Create Company Document Category" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(entity).build());
return convertToResponseBean(entity);
}
public DocumentCategoryEntity createCategoryEntity(DocumentCategoryEntity entity, DocumentCategoryRequest companyDocumentCategoryRequest){
entity.setCategoryName(companyDocumentCategoryRequest.getCategoryName());
entity.setDescription(companyDocumentCategoryRequest.getDescription());
entity.setIsDeleted(false);
return entity;
}
public DocumentCategoryResponse convertToResponseBean(DocumentCategoryEntity entity){
DocumentCategoryResponse response = new DocumentCategoryResponse();
response.setId(entity.getId());
response.setCategoryName(entity.getCategoryName());
response.setDescription(entity.getDescription());
response.setCreatedDate(entity.getCreatedDate());
response.setUpdatedDate(entity.getUpdatedDate());
return response;
}
public DocumentCategoryResponse getDocumentCategoryById(HttpServletRequest request, Long id){
return convertToResponseBean(validateCategory(id));
}
public DocumentCategoryEntity validateCategory(Long id) {
return categoryRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.DOCUMENT_CATEGORY_NOT_FOUND)));
}
public void deleteDocumentCategory(HttpServletRequest request,Long id) {
DocumentCategoryEntity entity = validateCategory(id);
List<CompanyDocumentEntity> companyDocumentEntities = companyDocumentRepository.findByCategoryEntityId(id);
if (!companyDocumentEntities.isEmpty()){
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.CATEGORY_CANNOT_BE_DELETED));
}
DocumentCategoryEntity oldCategoryEntity = Utils.getClonedEntityForData(entity);
entity.setIsDeleted(true);
categoryRepository.save(entity);
/** This code is responsible for adding a version history log for the "soft delete category" operation **/
loggingUtil.addVersionHistory(
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldCategoryEntity).newData(entity).build());
}
public DocumentCategoryResponse updateDocumentCategory(HttpServletRequest request, Long id , DocumentCategoryRequest categoryRequest){
DocumentCategoryEntity entity = validateCategory(id);
DocumentCategoryEntity oldCategoryEntity = Utils.getClonedEntityForData(entity);
DocumentCategoryEntity newCategoryEntity = updateCategoryEntity(entity, categoryRequest);
/** This code is responsible for adding a version history log for the "Update Category" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCategoryEntity).newData(newCategoryEntity).build());
return convertToResponseBean(entity);
}
public DocumentCategoryEntity updateCategoryEntity(DocumentCategoryEntity entity , DocumentCategoryRequest categoryRequest){
setIfUpdated(entity::getCategoryName, entity::setCategoryName, categoryRequest.getCategoryName());
setIfUpdated(entity::getDescription, entity::setDescription, categoryRequest.getDescription());
return entity;
}
}

View File

@@ -316,7 +316,7 @@ public class DocumentDao {
log.info("File for document ID {} successfully moved to deleted folder.", documentEntity.getId()); log.info("File for document ID {} successfully moved to deleted folder.", documentEntity.getId());
} catch (Exception e) { } catch (Exception e) {
log.error("Error moving file for document ID {} to deleted folder: {}", documentEntity.getId(), e.getMessage()); log.error("Error moving file for document ID {} to deleted folder: {}", documentEntity.getId(), e.getMessage());
throw new CustomValidationException(Status.VALIDATION_ERROR, "Error occurred while moving file to deleted folder."); throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.ERROR_MOVING_FILE_TO_DELETED_FOLDER));
} }
} }
} }

View File

@@ -8,12 +8,7 @@ import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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.ApplicationEntity; import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
import net.gepafin.tendermanagement.entities.NotificationEntity;
import net.gepafin.tendermanagement.entities.NotificationTypeEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
import net.gepafin.tendermanagement.enums.NotificationEnum; import net.gepafin.tendermanagement.enums.NotificationEnum;
import net.gepafin.tendermanagement.enums.NotificationTypeEnum; import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
import net.gepafin.tendermanagement.enums.RoleStatusEnum; import net.gepafin.tendermanagement.enums.RoleStatusEnum;
@@ -28,6 +23,7 @@ import net.gepafin.tendermanagement.repositories.NotificationTypeRepository;
import net.gepafin.tendermanagement.repositories.UserRepository; import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository; import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
import net.gepafin.tendermanagement.service.ApplicationService; import net.gepafin.tendermanagement.service.ApplicationService;
import net.gepafin.tendermanagement.service.CompanyService;
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.web.rest.api.errors.CustomValidationException; import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
@@ -81,6 +77,9 @@ public class NotificationDao {
@Autowired @Autowired
private UserDao userDao; private UserDao userDao;
@Autowired
private CompanyService companyService;
public NotificationResponse sendNotification(NotificationReq notificationReq) { public NotificationResponse sendNotification(NotificationReq notificationReq) {
// Ensure userId is properly set in notificationReq if not already // Ensure userId is properly set in notificationReq if not already
@@ -416,6 +415,18 @@ public class NotificationDao {
return predicates; return predicates;
} }
public void sendNotificationToBeneficiaryForDocumentExpiration(CompanyDocumentEntity companyDocumentEntity, NotificationTypeEnum notificationTypeEnum) {
CompanyEntity companyEntity = companyService.validateCompany(companyDocumentEntity.getCompanyId());
Map<String, String> placeHolders = new HashMap<>();
placeHolders.put("{{file_name}}", companyDocumentEntity.getFileName());
placeHolders.put("{{company_name}}", companyEntity.getCompanyName());
placeHolders.put("{{expiration_date}}", companyDocumentEntity.getExpirationDate().toString());
NotificationReq notificationReq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, companyDocumentEntity.getUserWithCompany().getUserId(), companyDocumentEntity.getUserWithCompany(),
listOf(companyDocumentEntity.getCompanyId()));
sendNotification(notificationReq);
}
public PageableResponseBean<List<NotificationResponse>> getNotificationsByUserIdAndCompanyIdByPagination(Long userId, Long companyId, NotificationRequestBean notificationRequestBean) { public PageableResponseBean<List<NotificationResponse>> getNotificationsByUserIdAndCompanyIdByPagination(Long userId, Long companyId, NotificationRequestBean notificationRequestBean) {
UserWithCompanyEntity userWithCompany; UserWithCompanyEntity userWithCompany;
if (companyId != null) { if (companyId != null) {

View File

@@ -1,6 +1,8 @@
package net.gepafin.tendermanagement.dao; package net.gepafin.tendermanagement.dao;
import net.gepafin.tendermanagement.entities.S3ConfigEntity; import net.gepafin.tendermanagement.entities.S3ConfigEntity;
import net.gepafin.tendermanagement.enums.CompanyDocSourceTypeEnum;
import net.gepafin.tendermanagement.enums.CompanyDocumentTypeEnum;
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum; import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum; import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
import net.gepafin.tendermanagement.repositories.S3ConfigRepository; import net.gepafin.tendermanagement.repositories.S3ConfigRepository;
@@ -49,4 +51,29 @@ public class S3PathConfig {
public String getBucketNameForCallAppType(DocumentSourceTypeEnum type){ public String getBucketNameForCallAppType(DocumentSourceTypeEnum type){
return s3ConfigRepository.getBucketNameByType(type); return s3ConfigRepository.getBucketNameByType(type);
} }
public String generateCompanyDocumentPath(CompanyDocumentTypeEnum type, Long companyId) {
S3ConfigEntity config = getCompanyDocumentPath(type);
return config.getParentFolder() + "/" + buildCompanyDocumentS3Path(config.getPath(), companyId);
}
private String buildCompanyDocumentS3Path(String pathTemplate, Long companyId) {
return pathTemplate
.replace("{company_id}", companyId != null && companyId != 0L ? "company_" + companyId : "");
}
private S3ConfigEntity getCompanyDocumentPath(CompanyDocumentTypeEnum type) {
return s3ConfigRepository.getPathByType(type.name()).orElseThrow(() -> new IllegalArgumentException("No path configuration found for type: " + type));
}
private S3ConfigEntity getCompanyDocumentPathForOther(CompanyDocSourceTypeEnum type) {
return s3ConfigRepository.getPathByType(type.name()).orElseThrow(() -> new IllegalArgumentException("No path configuration found for type: " + type));
}
public String generateCompanyDocumentPathForOther(CompanyDocSourceTypeEnum type, Long companyId) {
S3ConfigEntity config = getCompanyDocumentPathForOther(type);
return config.getParentFolder() + "/" + buildCompanyDocumentS3Path(config.getPath(),companyId);
}
} }

View File

@@ -0,0 +1,46 @@
package net.gepafin.tendermanagement.entities;
import jakarta.persistence.*;
import lombok.Data;
import java.time.LocalDateTime;
@Entity
@Table(name = "COMPANY_DOCUMENT")
@Data
public class CompanyDocumentEntity extends BaseEntity {
@Column(name = "FILE_NAME")
private String fileName;
@Column(name = "FILE_PATH")
private String filePath;
@Column(name="TYPE")
private String type;
@Column(name="COMPANY_ID")
private Long companyId;
@Column(name ="IS_DELETED")
private Boolean isDeleted = false;
@Column(name="UPLOADED_BY")
private Long uploadedBy;
@Column(name = "EXPIRATION_DATE")
private LocalDateTime expirationDate;
@Column(name ="STATUS")
private String status;
@ManyToOne
@JoinColumn(name = "USER_WITH_COMPANY_ID")
private UserWithCompanyEntity userWithCompany;
@ManyToOne
@JoinColumn(name = "DOCUMENT_CATEGORY_ID")
private DocumentCategoryEntity categoryEntity;
}

View File

@@ -0,0 +1,22 @@
package net.gepafin.tendermanagement.entities;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data;
@Entity
@Table(name = "document_category")
@Data
public class DocumentCategoryEntity extends BaseEntity {
@Column(name = "CATEGORY_NAME")
private String categoryName;
@Column(name = "DESCRIPTION")
private String description;
@Column(name ="IS_DELETED")
private Boolean isDeleted = false;
}

View File

@@ -0,0 +1,19 @@
package net.gepafin.tendermanagement.enums;
public enum CompanyDocSourceTypeEnum {
DELETED_PERSONAL_DOCUMENT("DELETED_PERSONAL_DOCUMENT"),
DELETED_COMPANY_DOCUMENT("DELETED_COMPANY_DOCUMENT");
private String value;
CompanyDocSourceTypeEnum(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}

View File

@@ -0,0 +1,17 @@
package net.gepafin.tendermanagement.enums;
public enum CompanyDocumentStatusEnum {
VALID("VALID"),
DUE("DUE"),
EXPIRED("EXPIRED");
private String value;
CompanyDocumentStatusEnum(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}

View File

@@ -0,0 +1,16 @@
package net.gepafin.tendermanagement.enums;
public enum CompanyDocumentTypeEnum {
COMPANY_DOCUMENT("COMPANY_DOCUMENT"),
PERSONAL_DOCUMENT("PERSONAL_DOCUMENT");
private String value;
CompanyDocumentTypeEnum(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}

View File

@@ -5,7 +5,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
public enum ExpirationTypeEnum { public enum ExpirationTypeEnum {
AMENDMENT("AMENDMENT"), AMENDMENT("AMENDMENT"),
EVALUATION("EVALUATION"); EVALUATION("EVALUATION"),
COMPANY_DOCUMENT("COMPANY_DOCUMENT");
private String value; private String value;

View File

@@ -13,7 +13,8 @@ public enum NotificationTypeEnum {
EVALUATION_CREATION("EVALUATION_CREATION"), EVALUATION_CREATION("EVALUATION_CREATION"),
EVALUATION_EXPIRED("EVALUATION_EXPIRED"), EVALUATION_EXPIRED("EVALUATION_EXPIRED"),
AMENDMENT_EXPIRATION_REMINDER("AMENDMENT_EXPIRATION_REMINDER"), AMENDMENT_EXPIRATION_REMINDER("AMENDMENT_EXPIRATION_REMINDER"),
EVALUATION_EXPIRATION_REMINDER("EVALUATION_EXPIRATION_REMINDER"); EVALUATION_EXPIRATION_REMINDER("EVALUATION_EXPIRATION_REMINDER"),
COMPANY_DOCUMENT_EXPIRATION_REMINDER("COMPANY_DOCUMENT_EXPIRATION_REMINDER");
private final String value; private final String value;

View File

@@ -193,6 +193,21 @@ public enum UserActionContextEnum {
GET_USER_ACTION("GET_USER_ACTION"), GET_USER_ACTION("GET_USER_ACTION"),
GET_ACTION_CONTEXT_LABELS("GET_ACTION_CONTEXT_LABELS"), GET_ACTION_CONTEXT_LABELS("GET_ACTION_CONTEXT_LABELS"),
GET_COMPANY_DOCUMENT("GET_COMPANY_DOCUMENT"),
DELETE_COMPANY_DOCUMENT("DELETE_COMPANY_DOCUMENT"),
UPLOAD_COMPANY_DOCUMENT("UPLOAD_COMPANY_DOCUMENT"),
UPLOAD_COMPANY_PERSONAL_DOCUMENT("UPLOAD_COMPANY_PERSONAL_DOCUMENT"),
GET_ALL_COMPANY_DOCUMENT("GET_ALL_COMPANY_DOCUMENT"),
UPDATE_COMPANY_DOCUMENT("UPDATE_COMPANY_DOCUMENT"),
DUPLICATE_COMPANY_DOCUMENT("DUPLICATE_COMPANY_DOCUMENT"),
CREATE_DOCUMENT_CATEGORY("CREATE_DOCUMENT_CATEGORY"),
GET_DOCUMENT_CATEGORY("GET_DOCUMENT_CATEGORY"),
DELETE_DOCUMENT_CATEGORY("DELETE_DOCUMENT_CATEGORY"),
UPDATE_DOCUMENT_CATEGORY("UPDATE_DOCUMENT_CATEGORY"),
COMPANY_DOCUMENT_EXPIRATION_SCHEDULER("COMPANY_DOCUMENT_EXPIRATION_SCHEDULER"),
GET_ALL_ASSIGNED_APPLICATION_BY_PAGINATION("GET_ALL_ASSIGNED_APPLICATION_BY_PAGINATION"), GET_ALL_ASSIGNED_APPLICATION_BY_PAGINATION("GET_ALL_ASSIGNED_APPLICATION_BY_PAGINATION"),
GET_ALL_APPLICATION_AMENDMENT_BY_PAGINATION("GET_ALL_APPLICATION_AMENDMENT_BY_PAGINATION"), GET_ALL_APPLICATION_AMENDMENT_BY_PAGINATION("GET_ALL_APPLICATION_AMENDMENT_BY_PAGINATION"),
GET_ALL_USER_ACTION_BY_PAGINATION("GET_ALL_USER_ACTION_BY_PAGINATION"), GET_ALL_USER_ACTION_BY_PAGINATION("GET_ALL_USER_ACTION_BY_PAGINATION"),

View File

@@ -0,0 +1,12 @@
package net.gepafin.tendermanagement.model.request;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class CompanyDocumentRequest {
private Long categoryId;
private LocalDateTime expirationDate;
}

View File

@@ -0,0 +1,9 @@
package net.gepafin.tendermanagement.model.request;
import lombok.Data;
@Data
public class DocumentCategoryRequest {
private String categoryName;
private String description;
}

View File

@@ -0,0 +1,29 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Data;
import net.gepafin.tendermanagement.enums.CompanyDocumentTypeEnum;
import net.gepafin.tendermanagement.model.BaseBean;
import java.time.LocalDateTime;
@Data
public class CompanyDocumentResponseBean extends BaseBean {
private String name;
private String filePath;
private CompanyDocumentTypeEnum type;
private Long companyId;
private String status;
private LocalDateTime expirationDate;
private Long uploadedBy;
private Long userWithCompanyId;
private DocumentCategoryResponse category;
}

View File

@@ -0,0 +1,11 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Data;
import net.gepafin.tendermanagement.model.BaseBean;
@Data
public class DocumentCategoryResponse extends BaseBean {
private String categoryName;
private String description;
}

View File

@@ -0,0 +1,41 @@
package net.gepafin.tendermanagement.repositories;
import feign.Param;
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
import net.gepafin.tendermanagement.entities.CompanyDocumentEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
@Repository
public interface CompanyDocumentRepository extends JpaRepository<CompanyDocumentEntity,Long>, JpaSpecificationExecutor<CompanyDocumentEntity> {
@Query("SELECT c FROM CompanyDocumentEntity c WHERE c.id = :id AND c.isDeleted = false")
Optional<CompanyDocumentEntity> findByIdAndNotDeleted(@Param("id") Long id);
@Query("SELECT d FROM CompanyDocumentEntity d " +
"WHERE d.isDeleted = false " +
"AND d.expirationDate BETWEEN :startTime AND :endTime")
List<CompanyDocumentEntity> findExpiringBetween(LocalDateTime startTime, LocalDateTime endTime);
@Query("SELECT c FROM CompanyDocumentEntity c " +
"WHERE c.isDeleted = false " +
"AND c.expirationDate < :now")
List<CompanyDocumentEntity> findByExpirationDateBeforeAndIsDeletedFalse(LocalDateTime now);
@Query("SELECT c FROM CompanyDocumentEntity c " +
"WHERE c.companyId = :companyId " +
"AND c.isDeleted = false")
List<CompanyDocumentEntity> findByCompanyId(Long companyId);
List<CompanyDocumentEntity> findByCategoryEntityId(Long categoryId);
}

View File

@@ -0,0 +1,9 @@
package net.gepafin.tendermanagement.repositories;
import net.gepafin.tendermanagement.entities.DocumentCategoryEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DocumentCategoryRepository extends JpaRepository<DocumentCategoryEntity,Long> {
}

View File

@@ -0,0 +1,113 @@
package net.gepafin.tendermanagement.scheduler;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.dao.NotificationDao;
import net.gepafin.tendermanagement.entities.CompanyDocumentEntity;
import net.gepafin.tendermanagement.entities.ExpirationConfigEntity;
import net.gepafin.tendermanagement.enums.*;
import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.repositories.CompanyDocumentRepository;
import net.gepafin.tendermanagement.repositories.ExpirationConfigRepository;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List;
@Component
public class CompanyDocumentExpirationScheduler {
@Autowired
private CompanyDocumentRepository companyDocumentRepository;
@Autowired
private NotificationDao notificationDao;
@Autowired
private LoggingUtil loggingUtil;
@Autowired
private HttpServletRequest request;
@Autowired
private ExpirationConfigRepository expirationConfigRepository;
private static final Logger log = LoggerFactory.getLogger(ExpirationScheduler.class);
@Scheduled(cron = "0 0 4 * * ?")
public void processDocumentExpiration(){
log.info("Starting the Document Expiration scheduler...");
try {
Utils.setHttpServletRequestForScheduler();
// Logging user action for the scheduler operation
loggingUtil.logUserActionWithoutToken(
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.SCHEDULER)
.actionContext(UserActionContextEnum.COMPANY_DOCUMENT_EXPIRATION_SCHEDULER).build());
log.info("Starting processing expiration notifications for document");
processExpirationReminder(ExpirationTypeEnum.COMPANY_DOCUMENT);
updateExpiredDocuments();
log.info("Expiration scheduler completed successfully.");
}
catch (Exception e){
log.error("An error occurred during the Notification Expiration Scheduler of Document: {}", e.getMessage(), e);
}
}
private void processExpirationReminder(ExpirationTypeEnum typeEnum){
List<ExpirationConfigEntity> configEntities = expirationConfigRepository.findByTypeAndIsDeletedFalse(typeEnum.getValue());
for (ExpirationConfigEntity config : configEntities){
Long daysBefore = config.getIntervalDays();
LocalDateTime now = LocalDateTime.now();
LocalDateTime startDate = now.plusDays(daysBefore).withHour(0).withMinute(0).withSecond(0).withNano(2);
LocalDateTime endDate = startDate.plusDays(1).minusNanos(2);
processDocumentExpiration(startDate, endDate, daysBefore);
}
}
private void processDocumentExpiration(LocalDateTime startDate, LocalDateTime endDate, Long daysBefore){
List<CompanyDocumentEntity> expiringDocuments = companyDocumentRepository.findExpiringBetween(startDate, endDate);
for (CompanyDocumentEntity document : expiringDocuments) {
notificationDao.sendNotificationToBeneficiaryForDocumentExpiration(document, NotificationTypeEnum.COMPANY_DOCUMENT_EXPIRATION_REMINDER);
updateDocumentStatus(document, CompanyDocumentStatusEnum.DUE.getValue());
}
}
private void updateDocumentStatus(CompanyDocumentEntity companyDocument,String status) {
CompanyDocumentEntity oldCompanyDocumentEntity = Utils.getClonedEntityForData(companyDocument);
companyDocument.setStatus(status);
companyDocumentRepository.save(companyDocument);
// Logging version history for the update operation
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request)
.actionType(VersionActionTypeEnum.UPDATE).oldData(oldCompanyDocumentEntity)
.newData(companyDocument).build());
log.info("Updated document status for document: {}", companyDocument.getFileName());
}
private void updateExpiredDocuments() {
LocalDateTime now = LocalDateTime.now();
List<CompanyDocumentEntity> expiredDocuments = companyDocumentRepository.findByExpirationDateBeforeAndIsDeletedFalse(now);
for (CompanyDocumentEntity document : expiredDocuments) {
updateDocumentStatus(document, CompanyDocumentStatusEnum.EXPIRED.getValue());
}
}
}

View File

@@ -0,0 +1,29 @@
package net.gepafin.tendermanagement.service;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.enums.CompanyDocumentTypeEnum;
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
import net.gepafin.tendermanagement.model.request.CompanyDocumentRequest;
import net.gepafin.tendermanagement.model.response.CompanyDocumentResponseBean;
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDateTime;
import java.util.List;
public interface CompanyDocumentService {
List<CompanyDocumentResponseBean> uploadFileForCompany(HttpServletRequest request, List<MultipartFile> files, Long companyId, Long documentCategoryId, CompanyDocumentTypeEnum documentSourceTypeEnum, LocalDateTime expirationDate);
CompanyDocumentResponseBean updateCompanyDocument(HttpServletRequest httpServletRequest, Long companyDocumentId, CompanyDocumentRequest companyDocumentRequest);
CompanyDocumentResponseBean getCompanyDocument(HttpServletRequest request, Long companyDocumentId);
void deleteCompanyFile(HttpServletRequest request,Long companyDocumentId);
DocumentResponseBean validateAndDuplicateCompanyDocument(HttpServletRequest request, Long companyDocumentId, Long applicationId, DocumentTypeEnum typeEnum);
List<CompanyDocumentResponseBean> getAllCompanyDocument(HttpServletRequest request ,Long companyId , CompanyDocumentTypeEnum typeEnum);
}

View File

@@ -0,0 +1,13 @@
package net.gepafin.tendermanagement.service;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.model.request.DocumentCategoryRequest;
import net.gepafin.tendermanagement.model.response.DocumentCategoryResponse;
public interface DocumentCategoryService {
DocumentCategoryResponse createDocumentCategory(HttpServletRequest request, DocumentCategoryRequest categoryRequest);
DocumentCategoryResponse getDocumentCategoryById(HttpServletRequest request, Long id);
void deleteDocumentCategory(HttpServletRequest request,Long id);
DocumentCategoryResponse updateDocumentCategory(HttpServletRequest request, Long id, DocumentCategoryRequest categoryRequest);
}

View File

@@ -153,7 +153,7 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
} }
} }
private String decodeS3Key(String key) { public String decodeS3Key(String key) {
return URLDecoder.decode(key, StandardCharsets.UTF_8); return URLDecoder.decode(key, StandardCharsets.UTF_8);
} }
@@ -186,11 +186,11 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
} }
} }
private String cleanNewPath(String oldPath, String newPath) { public String cleanNewPath(String oldPath, String newPath) {
return newPath + "/" + oldPath.substring(oldPath.lastIndexOf("/") + 1); return newPath + "/" + oldPath.substring(oldPath.lastIndexOf("/") + 1);
} }
private String cleanOldPath(String oldPath) { public String cleanOldPath(String oldPath) {
return oldPath.replace(s3Url, ""); return oldPath.replace(s3Url, "");
} }
} }

View File

@@ -0,0 +1,66 @@
package net.gepafin.tendermanagement.service.impl;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.dao.CompanyDocumentDao;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.CompanyDocumentTypeEnum;
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
import net.gepafin.tendermanagement.model.request.CompanyDocumentRequest;
import net.gepafin.tendermanagement.model.response.CompanyDocumentResponseBean;
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
import net.gepafin.tendermanagement.service.CompanyDocumentService;
import net.gepafin.tendermanagement.util.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@Service
public class CompanyDocumentServiceImpl implements CompanyDocumentService {
@Autowired
private Validator validator;
@Autowired
private CompanyDocumentDao companyDocumentDao;
@Override
public List<CompanyDocumentResponseBean> uploadFileForCompany(HttpServletRequest request, List<MultipartFile> files, Long companyId, Long documentCategoryId , CompanyDocumentTypeEnum documentSourceTypeEnum, LocalDateTime expirationDate) {
Map<String, Object> userInfo = validator.getUserInfoFromToken(request);
Long userId = validator.getUserId(userInfo);
return companyDocumentDao.uploadFileForCompany(request,userId,files,companyId,documentCategoryId,documentSourceTypeEnum,expirationDate);
}
@Override
public CompanyDocumentResponseBean updateCompanyDocument(HttpServletRequest request, Long companyDocumentId, CompanyDocumentRequest companyDocumentRequest) {
validator.validateUser(request);
return companyDocumentDao.updateCompanyDocument(request,companyDocumentId, companyDocumentRequest);
}
@Override
public CompanyDocumentResponseBean getCompanyDocument(HttpServletRequest request, Long companyDocumentId) {
UserEntity user = validator.validateUser(request);
return companyDocumentDao.getCompanyDocument(user , companyDocumentId);
}
@Override
public void deleteCompanyFile(HttpServletRequest request,Long companyDocumentId) {
validator.validateUser(request);
companyDocumentDao.deleteCompanyFile(companyDocumentId);
}
@Override
public DocumentResponseBean validateAndDuplicateCompanyDocument(HttpServletRequest request, Long companyDocumentId, Long applicationId, DocumentTypeEnum typeEnum) {
UserEntity user = validator.validateUser(request);
return companyDocumentDao.validateAndDuplicateCompanyDocument(request, user.getId(), companyDocumentId,applicationId,typeEnum);
}
@Override
public List<CompanyDocumentResponseBean> getAllCompanyDocument(HttpServletRequest request, Long companyId, CompanyDocumentTypeEnum typeEnum) {
UserEntity user = validator.validateUser(request);
return companyDocumentDao.getAllCompanyDocument(user,companyId,typeEnum);
}
}

View File

@@ -0,0 +1,51 @@
package net.gepafin.tendermanagement.service.impl;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.dao.DocumentCategoryDao;
import net.gepafin.tendermanagement.model.request.DocumentCategoryRequest;
import net.gepafin.tendermanagement.model.response.DocumentCategoryResponse;
import net.gepafin.tendermanagement.service.DocumentCategoryService;
import net.gepafin.tendermanagement.util.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class DocumentCategoryServiceImpl implements DocumentCategoryService {
@Autowired
DocumentCategoryDao categoryDao;
@Autowired
private Validator validator;
@Override
@Transactional(rollbackFor = Exception.class)
public DocumentCategoryResponse createDocumentCategory(HttpServletRequest request, DocumentCategoryRequest categoryRequest) {
validator.validateUser(request);
return categoryDao.createDocumentCategory(request,categoryRequest);
}
@Override
@Transactional(readOnly = true)
public DocumentCategoryResponse getDocumentCategoryById(HttpServletRequest request, Long id) {
validator.validateUser(request);
return categoryDao.getDocumentCategoryById(request,id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDocumentCategory(HttpServletRequest request, Long id) {
validator.validateUser(request);
categoryDao.deleteDocumentCategory(request,id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public DocumentCategoryResponse updateDocumentCategory(HttpServletRequest request, Long id, DocumentCategoryRequest categoryRequest) {
validator.validateUser(request);
return categoryDao.updateDocumentCategory(request,id,categoryRequest);
}
}

View File

@@ -0,0 +1,122 @@
package net.gepafin.tendermanagement.web.rest.api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import net.gepafin.tendermanagement.enums.CompanyDocumentTypeEnum;
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
import net.gepafin.tendermanagement.model.request.CompanyDocumentRequest;
import net.gepafin.tendermanagement.model.request.FormRequest;
import net.gepafin.tendermanagement.model.response.CompanyDocumentResponseBean;
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDateTime;
import java.util.List;
@Validated
public interface CompanyDocumentApi {
@Operation(summary = "Api to upload a file for company",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))})
@PostMapping(value = "/company/{companyId}/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
default ResponseEntity<Response<List<CompanyDocumentResponseBean>>> uploadFileForCompany(HttpServletRequest httpServletRequest,
@Parameter(description = "Company Id", required = true) @PathVariable("companyId") Long companyId,
@Parameter(description = "The Document Category id", required = true) @RequestParam(value = "documentCategoryId", required = false) Long documentCategoryId,
@RequestParam("documentType") CompanyDocumentTypeEnum documentTypeEnum,
@RequestParam("expirationDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime expirationDate,
@RequestParam("file") List<MultipartFile> files) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
@Operation(summary = "Api to update company document",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))})
@PutMapping(value = "/{id}",produces = "application/json")
default ResponseEntity<Response<CompanyDocumentResponseBean>> updateCompanyDocument(HttpServletRequest httpServletRequest, @Parameter(description = "Company Document Id", required = true) @PathVariable("id") Long companyDocumentId,@Valid @RequestBody CompanyDocumentRequest companyDocumentRequest) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
@Operation(summary = "API to get company document by id",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) }))
})
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Response<CompanyDocumentResponseBean>> getCompanyDocumentById(HttpServletRequest request,
@Parameter(description = "Company Document Id", required = true)
@PathVariable("id") Long id);
@Operation(summary = "API to delete a file by company document id",
responses = {
@ApiResponse(responseCode = "200", description = "File deleted successfully"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
})
@DeleteMapping(value = "")
default ResponseEntity<Response<Void>> deleteCompanyFile(HttpServletRequest httpServletRequest,
@RequestParam( "id") Long id) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
@Operation(summary = "Api to copy a company document",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))})
@PutMapping(value = "/{id}/document/upload", produces = MediaType.APPLICATION_JSON_VALUE)
default ResponseEntity<Response<DocumentResponseBean>> validateAndDuplicateCompanyDocument (HttpServletRequest httpServletRequest, @Parameter(description = "Company Document Id", required = true) @PathVariable("id") Long companyDocumentId,
@Parameter(description = "Application Id", required = true) @RequestParam Long applicationId,
@RequestParam("documentType") DocumentTypeEnum documentTypeEnum) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
@Operation(summary = "API to get all company documents",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) }))
})
@GetMapping(value = "/company/{companyId}", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Response<List<CompanyDocumentResponseBean>>> getAllCompanyDocuments(HttpServletRequest request,
@Parameter(description = "Company Id", required = true)
@PathVariable("companyId") Long companyId , @RequestParam(value = "documentType", required = false) CompanyDocumentTypeEnum documentTypeEnum);
}

View File

@@ -0,0 +1,82 @@
package net.gepafin.tendermanagement.web.rest.api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import net.gepafin.tendermanagement.model.request.DocumentCategoryRequest;
import net.gepafin.tendermanagement.model.response.DocumentCategoryResponse;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@Validated
public interface DocumentCategoryApi {
@Operation(summary = "Api to create document category", responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
})
@PostMapping(value = "", produces = "application/json")
ResponseEntity<Response<DocumentCategoryResponse>> createDocumentCategory(HttpServletRequest request,
@Parameter(description = "Company Document Category request object", required = true)
@Valid @RequestBody DocumentCategoryRequest categoryRequest);
@Operation(summary = "Api to get document category by id", responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
})
@GetMapping(value = "/{id}", produces = "application/json")
ResponseEntity<Response<DocumentCategoryResponse>> getDocumentCategoryById(HttpServletRequest request,
@Parameter(description = "The document category id", required = true)
@PathVariable("id") Long id);
@Operation(summary = "Api to delete a document category", responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
})
@DeleteMapping(value = "/{id}")
ResponseEntity<Response<Void>> deleteDocumentCategory(HttpServletRequest request,
@Parameter(description = "The document category id", required = true)
@PathVariable("id") Long id);
@Operation(summary = "API to update a document category", responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
})
@PutMapping(value = "/{id}", produces = "application/json")
ResponseEntity<Response<DocumentCategoryResponse>> updateDocumentCategory(HttpServletRequest request,
@Parameter(description = "The document category id", required = true)
@PathVariable("id") Long id,
@Parameter(description = "Category request object", required = true)
@Valid @RequestBody DocumentCategoryRequest categoryRequest);
}

View File

@@ -0,0 +1,118 @@
package net.gepafin.tendermanagement.web.rest.api.impl;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.dao.CompanyDocumentDao;
import net.gepafin.tendermanagement.enums.*;
import net.gepafin.tendermanagement.model.request.CompanyDocumentRequest;
import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.model.response.CompanyDocumentResponseBean;
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.CompanyDocumentService;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.web.rest.api.CompanyDocumentApi;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDateTime;
import java.util.List;
@RestController
@RequestMapping("${openapi.gepafin.base-path:/v1/companyDocument}")
@Slf4j
public class CompanyDocumentApiControlller implements CompanyDocumentApi {
@Autowired
private CompanyDocumentService companyDocumentService;
@Autowired
private LoggingUtil loggingUtil;
@Autowired
private CompanyDocumentDao companyDocumentDao;
@Override
public ResponseEntity<Response<List<CompanyDocumentResponseBean>>> uploadFileForCompany(HttpServletRequest request, Long companyId, Long documentCategoryId, CompanyDocumentTypeEnum companyDocumentSourceTypeEnum, LocalDateTime expirationDate,
List<MultipartFile> files) {
try {
UserActionContextEnum userActionContext = companyDocumentDao.getUserActionContextEnum(companyDocumentSourceTypeEnum);
/** This code is responsible for creating user action logs for the "upload document for company" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.UPLOAD).actionContext(userActionContext).build());
List<CompanyDocumentResponseBean> responseBeans = companyDocumentService.uploadFileForCompany(request,files, companyId, documentCategoryId ,companyDocumentSourceTypeEnum,expirationDate);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<List<CompanyDocumentResponseBean>>(responseBeans, Status.SUCCESS, Translator.toLocale(GepafinConstant.FILES_UPLOADED_MSG)));
} catch (CustomValidationException ex) {
throw ex;
}
}
@Override
public ResponseEntity<Response<CompanyDocumentResponseBean>> updateCompanyDocument(HttpServletRequest httpServletRequest, Long companyDocumentId, CompanyDocumentRequest companyDocumentRequest) {
/** This code is responsible for creating user action logs for the "update company document" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(httpServletRequest).actionType(UserActionLogsEnum.UPDATE).actionContext(UserActionContextEnum.UPDATE_COMPANY_DOCUMENT).build());
CompanyDocumentResponseBean responseBeans = companyDocumentService.updateCompanyDocument(httpServletRequest, companyDocumentId, companyDocumentRequest);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<CompanyDocumentResponseBean>(responseBeans, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_DOCUMENT_UPDATED_SUCCESSFULLY)));
}
@Override
public ResponseEntity<Response<CompanyDocumentResponseBean>> getCompanyDocumentById(HttpServletRequest request, Long id) {
/** This code is responsible for creating user action logs for the "Get Company Document" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_COMPANY_DOCUMENT).build());
CompanyDocumentResponseBean companyDocumentResponseBean = companyDocumentService.getCompanyDocument(request, id);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<CompanyDocumentResponseBean>(companyDocumentResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_DOCUMENT_FETCHED_SUCCESSFULLY)));
}
@Override
public ResponseEntity<Response<Void>> deleteCompanyFile(HttpServletRequest request, Long companyDocumentId) {
/** This code is responsible for creating user action logs for the "delete company document" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DELETE).actionContext(UserActionContextEnum.DELETE_COMPANY_DOCUMENT).build());
companyDocumentService.deleteCompanyFile(request,companyDocumentId);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<Void>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.FILE_DELETED_SUCCESSFULLY_MSG)));
}
@Override
public ResponseEntity<Response<DocumentResponseBean>> validateAndDuplicateCompanyDocument(HttpServletRequest httpServletRequest, Long companyDocumentId , Long applicationId,DocumentTypeEnum typeEnum) {
/** This code is responsible for creating user action logs for the "duplicate company document" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(httpServletRequest).actionType(UserActionLogsEnum.UPDATE).actionContext(UserActionContextEnum.DUPLICATE_COMPANY_DOCUMENT).build());
DocumentResponseBean responseBeans = companyDocumentService.validateAndDuplicateCompanyDocument(httpServletRequest, companyDocumentId,applicationId,typeEnum);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<DocumentResponseBean>(responseBeans, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_DOCUMENT_COPIED_SUCCESSFULLY)));
}
@Override
public ResponseEntity<Response<List<CompanyDocumentResponseBean>>> getAllCompanyDocuments(HttpServletRequest request, Long companyId, CompanyDocumentTypeEnum typeEnum) {
log.info("Get All Company Document");
/** This code is responsible for creating user action logs for the "get all Company Document" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW)
.actionContext(UserActionContextEnum.GET_ALL_COMPANY_DOCUMENT).build());
List<CompanyDocumentResponseBean> companyDocumentResponseBeans = companyDocumentService.getAllCompanyDocument(request,companyId,typeEnum);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(companyDocumentResponseBeans, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_DOCUMENT_FETCHED_SUCCESSFULLY)));
}
}

View File

@@ -0,0 +1,82 @@
package net.gepafin.tendermanagement.web.rest.api.impl;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.DocumentCategoryRequest;
import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.model.response.DocumentCategoryResponse;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.DocumentCategoryService;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.web.rest.api.DocumentCategoryApi;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("${openapi.gepafin.base-path:/v1/documentCategory}")
public class DocumentCategoryApiController implements DocumentCategoryApi {
@Autowired
LoggingUtil loggingUtil;
@Autowired
DocumentCategoryService categoryService;
public ResponseEntity<Response<DocumentCategoryResponse>> createDocumentCategory(HttpServletRequest request, @Valid DocumentCategoryRequest categoryRequest){
/** This code is responsible for creating user action logs for the "Create Document category" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.INSERT)
.actionContext(UserActionContextEnum.CREATE_DOCUMENT_CATEGORY).build());
DocumentCategoryResponse categoryResponse = categoryService.createDocumentCategory(request,categoryRequest);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(categoryResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_CATEGORY_CREATE_SUCCESS)));
}
@Override
public ResponseEntity<Response<DocumentCategoryResponse>> getDocumentCategoryById(HttpServletRequest request, Long id) {
/** This code is responsible for creating user action logs for the "get document category by id" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW)
.actionContext(UserActionContextEnum.GET_DOCUMENT_CATEGORY).build());
DocumentCategoryResponse categoryResponse = categoryService.getDocumentCategoryById(request,id);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(categoryResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_CATEGORY_GET_SUCCESS)));
}
@Override
public ResponseEntity<Response<Void>> deleteDocumentCategory(HttpServletRequest request, Long id) {
/** This code is responsible for creating user action logs for the "Delete category" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DELETE).actionContext(UserActionContextEnum.DELETE_DOCUMENT_CATEGORY).build());
categoryService.deleteDocumentCategory(request,id);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_CATEGORY_DELETE_SUCCESS)));
}
@Override
public ResponseEntity<Response<DocumentCategoryResponse>> updateDocumentCategory(HttpServletRequest request, Long id, DocumentCategoryRequest categoryRequest) {
/** This code is responsible for "Updating Category details" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.UPDATE)
.actionContext(UserActionContextEnum.UPDATE_DOCUMENT_CATEGORY).build());
DocumentCategoryResponse categoryResponse = categoryService.updateDocumentCategory(request,id, categoryRequest);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(categoryResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_CATEGORY_UPDATE_SUCCESS)));
}
}

View File

@@ -2429,6 +2429,103 @@
<modifyDataType tableName="call" columnName="product_id" newDataType="INTEGER"/> <modifyDataType tableName="call" columnName="product_id" newDataType="INTEGER"/>
</changeSet> </changeSet>
<changeSet id="24-02-2025_RK_192024" author="Rajesh Khore">
<createTable tableName="document_category">
<column name="id" type="INTEGER" autoIncrement="true">
<constraints primaryKey="true" primaryKeyName="document_category_pkey" nullable="false"/>
</column>
<column name="CATEGORY_NAME" type="VARCHAR(255)"/>
<column name="DESCRIPTION" type="TEXT"/>
<column name="IS_DELETED" type="BOOLEAN" defaultValue="false"/>
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
<constraints nullable="false"/>
</column>
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
<constraints nullable="true"/>
</column>
</createTable>
</changeSet>
<changeSet id="24-02-2025_RK_190220" author="Rajesh Khore">
<createTable tableName="company_document">
<column name="id" type="INTEGER" autoIncrement="true">
<constraints primaryKey="true" primaryKeyName="company_document_pkey" nullable="false"/>
</column>
<column name="file_name" type="VARCHAR(255)"/>
<column name="file_path" type="TEXT"/>
<column name="type" type="VARCHAR(255)"/>
<column name="is_deleted" type="BOOLEAN" defaultValueBoolean="false"/>
<column name="uploaded_by" type="INTEGER"/>
<column name="expiration_date" type="TIMESTAMP WITHOUT TIME ZONE">
<constraints nullable="false"/>
</column>
<column name="status" type="VARCHAR(255)"/>
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE">
<constraints nullable="false"/>
</column>
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE">
<constraints nullable="true"/>
</column>
<column name="USER_WITH_COMPANY_ID" type="INTEGER">
<constraints foreignKeyName="fk_USER_WITH_COMPANY_COMPANY_DOCUMENT" references="user_with_company(id)" nullable="false"/>
</column>
<column name="COMPANY_ID" type="INTEGER">
<constraints nullable="true" foreignKeyName="fk_COMPANY_COMPANY_DOCUMENT" references="company(id)"/>
</column>
<column name="DOCUMENT_CATEGORY_ID" type="INTEGER">
<constraints nullable="true" foreignKeyName="fk_DOCUMENT_CATEGORY_COMPANY_DOCUMENT" references="document_category(id)"/>
</column>
</createTable>
</changeSet>
<changeSet id="24-02-2025_RK_020220" author="Rajesh Khore">
<insert tableName="s3_path_configuration">
<column name="type" value="COMPANY_DOCUMENT"/>
<column name="path" value="company/{company_id}"/>
<column name="bucket_name" value="mementoresources"/>
<column name="created_date" value="2025-02-20 03:00:00"/>
<column name="updated_date" value="2025-02-20 03:00:00"/>
<column name="parent_folder" value="gepafin/local"/>
</insert>
<insert tableName="s3_path_configuration">
<column name="type" value="DELETED_PERSONAL_DOCUMENT"/>
<column name="path" value="company/{company_id}/deleted"/>
<column name="bucket_name" value="mementoresources"/>
<column name="created_date" value="2025-02-20 03:00:00"/>
<column name="updated_date" value="2025-02-20 03:00:00"/>
<column name="parent_folder" value="gepafin/local"/>
</insert>
<insert tableName="s3_path_configuration">
<column name="type" value="PERSONAL_DOCUMENT"/>
<column name="path" value="company/{company_id}"/>
<column name="bucket_name" value="mementoresources"/>
<column name="created_date" value="2025-02-20 03:00:00"/>
<column name="updated_date" value="2025-02-20 03:00:00"/>
<column name="parent_folder" value="gepafin/local"/>
</insert>
<insert tableName="s3_path_configuration">
<column name="type" value="DELETED_COMPANY_DOCUMENT"/>
<column name="path" value="company/{company_id}/deleted"/>
<column name="bucket_name" value="mementoresources"/>
<column name="created_date" value="2025-02-20 03:00:00"/>
<column name="updated_date" value="2025-02-20 03:00:00"/>
<column name="parent_folder" value="gepafin/local"/>
</insert>
</changeSet>
<changeSet id="24-02-2025_RK_125215" author="Rajesh Khore">
<sqlFile dbms="postgresql"
path="db/dump/updated_expiration_scheduler_data_24_02_2025.sql"/>
</changeSet>
<changeSet id="24-02-2025_RK_125145" author="Rajesh Khore">
<sqlFile dbms="postgresql"
path="db/dump/updated_json_template_for_notification_24_02_2025.sql"/>
</changeSet>
<changeSet id="17-02-2025_PK_025237" author="Piyush Kag"> <changeSet id="17-02-2025_PK_025237" author="Piyush Kag">
<renameColumn tableName="call" <renameColumn tableName="call"
oldColumnName="product_id" oldColumnName="product_id"

View File

@@ -0,0 +1,3 @@
INSERT INTO expiration_config (interval_days, type, created_date, updated_date)
VALUES
(7, 'COMPANY_DOCUMENT', '2025-02-24T11:00:51', '2025-02-24T11:00:51');

View File

@@ -0,0 +1,2 @@
INSERT INTO notification_type (notification_name,title, json_template,created_date,updated_date,is_deleted) VALUES
('COMPANY_DOCUMENT_EXPIRATION_REMINDER','Il documento sta per scadere','Il documento "{{file_name}}" per lazienda "{{company_name}}" scadrà il {{expiration_date}}. Assicurati di rinnovarlo o sostituirlo prima della scadenza.','2025-02-24T10:16:26.472Z','2025-02-24T10:16:26.472Z','false');

View File

@@ -376,6 +376,19 @@ validation.required.requested.amount=The Requested Amount configuration should b
company.id.not.null=Company ID cannot be null. company.id.not.null=Company ID cannot be null.
formula.amount.not.matches.requested.amount= The {0} does not matches to calculated amount. formula.amount.not.matches.requested.amount= The {0} does not matches to calculated amount.
document.category.update.success = Document Category updated successfully.
document.category.delete.success = Document Category deleted successfully.
document.category.get.success = Document Category fetched successfully.
document.category.success = Document Category created successfully.
document.category.not.found = Document Category not found.
error.moving.file.to.deleted.folder = Error occurred while moving company file to deleted folder.
company.document.fetched.successfully = Company Document fetched successfully.
company.document.updated.successfully = Company Document Updated successfully.
category.cannot.be.deleted = Category cannot be deleted as it is associated with company documents.
company.document.copied.successfully = Company Document Copied successfully.
invalid.expiration.date = Invalid Expiration Date
appointment.cannot.be.created = Appointment cannot be created because call doesn't have the template id. appointment.cannot.be.created = Appointment cannot be created because call doesn't have the template id.

View File

@@ -160,7 +160,7 @@ validation.field.max_length=Il campo {0} deve essere lungo al massimo {1} caratt
validation.field.pattern=Il campo {0} non corrisponde al modello richiesto. validation.field.pattern=Il campo {0} non corrisponde al modello richiesto.
validation.field.not_null=Il campo {0} non deve essere nullo. validation.field.not_null=Il campo {0} non deve essere nullo.
validation.field.not_empty=Il campo {0} non deve essere vuoto. validation.field.not_empty=Il campo {0} non deve essere vuoto.
validation.field.max_value=Il campo {0} non deve essere più grande di {1}. validation.field.max_value=Il campo {0} non deve essere pi<EFBFBD> grande di {1}.
validation.field.min_value=Il campo {0} deve essere maggiore di {1}. validation.field.min_value=Il campo {0} deve essere maggiore di {1}.
validation.field.min.checkbox=Il campo {0} dovrebbe essere controllato almeno per {1}. validation.field.min.checkbox=Il campo {0} dovrebbe essere controllato almeno per {1}.
validation.field.max.checkbox=Il campo {0} dovrebbe avere solo {1} selezionato. validation.field.max.checkbox=Il campo {0} dovrebbe avere solo {1} selezionato.
@@ -367,6 +367,20 @@ validation.required.requested.amount=La configurazione dell'importo richiesto
company.id.not.null=L'ID dell'azienda non pu? essere nullo. company.id.not.null=L'ID dell'azienda non pu? essere nullo.
formula.amount.not.matches.requested.amount=Il {0} non corrisponde all'importo calcolato. formula.amount.not.matches.requested.amount=Il {0} non corrisponde all'importo calcolato.
appointment.cannot.be.created = Impossibile creare l'appuntamento perché la chiamata non ha l'ID del modello di appuntamento. document.category.update.success = Categoria documento aggiornata correttamente.
document.category.delete.success = Categoria documento eliminata correttamente.
document.category.not.found = Categoria documento non trovata.
document.category.get.success = Categoria del documento recuperata correttamente.
document.category.success =Categoria documento creata correttamente.
company.document.copied.successfully = Documento aziendale copiato correttamente.
error.moving.file.to.deleted.folder = Si è verificato un errore durante lo spostamento del file aziendale nella cartella eliminata.ss
company.document.fetched.successfully = Documento aziendale recuperato con successo.
company.document.updated.successfully = Documento aziendale aggiornato con successo.
category.cannot.be.deleted = La categoria non può essere eliminata perché è associata a documenti aziendali.
invalid.expiration.date = Data di scadenza non valida
appointment.cannot.be.created = Impossibile creare l'appuntamento perch<63> la chiamata non ha l'ID del modello di appuntamento.
appointment.not.created = Appuntamento non creato, riprova appointment.not.created = Appuntamento non creato, riprova
validation.failed.checklist=Convalida fallita per la checklist. validation.failed.checklist=Convalida fallita per la checklist.