Merge pull request #113 from Kitzanos/feature/GEPAFINBE-100
GEPAFINBE-100,99(Script for migrating deleted documents)
This commit is contained in:
@@ -202,14 +202,8 @@ public class DelegationDao {
|
||||
.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(), userWithCompanyEntity.getId(),
|
||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||
|
||||
UserCompanyDelegationEntity oldUserCompanyDelegationEntity = Utils.getClonedEntityForData(userCompanyDelegationEntity);
|
||||
if (userCompanyDelegationEntity != null) {
|
||||
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "update user company delegation status" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserCompanyDelegationEntity)
|
||||
.newData(userCompanyDelegationEntity).build());
|
||||
deleteDelegationFromS3(userCompanyDelegationEntity);
|
||||
}
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3ForCompanyDelegation(file);
|
||||
userCompanyDelegationEntity = new UserCompanyDelegationEntity();
|
||||
@@ -282,16 +276,22 @@ public class DelegationDao {
|
||||
.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(), userWithCompanyEntity.getId(),
|
||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||
//cloned entity for old data
|
||||
UserCompanyDelegationEntity oldUserCompanyDelegation = Utils.getClonedEntityForData(userCompanyDelegationEntity);
|
||||
|
||||
if (userCompanyDelegationEntity == null) {
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||
}
|
||||
amazonS3Service.deleteDelegationfromS3(userCompanyDelegationEntity);
|
||||
deleteDelegationFromS3(userCompanyDelegationEntity);
|
||||
}
|
||||
|
||||
public void deleteDelegationFromS3(UserCompanyDelegationEntity userCompanyDelegationEntity) {
|
||||
UserCompanyDelegationEntity oldUserCompanyDelegation = Utils.getClonedEntityForData(userCompanyDelegationEntity);
|
||||
String oldS3Path = userCompanyDelegationEntity.getFilePath();
|
||||
String newS3Path = s3ConfigBean.generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum.DELETED_USER_DELEGATION);
|
||||
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(userCompanyDelegationEntity.getFileName(), oldS3Path, newS3Path);
|
||||
userCompanyDelegationEntity.setFileName(response.getFileName());
|
||||
userCompanyDelegationEntity.setFilePath(response.getFilePath());
|
||||
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Soft Deleting company delegation " operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldUserCompanyDelegation).newData(userCompanyDelegationEntity)
|
||||
|
||||
@@ -4,9 +4,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
@@ -21,7 +19,6 @@ import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository;
|
||||
@@ -188,7 +185,6 @@ public class DocumentDao {
|
||||
if(Boolean.TRUE.equals(documentEntity.getIsDeleted())){
|
||||
return;
|
||||
}
|
||||
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
|
||||
Long callId = null;
|
||||
Long applicationId = null;
|
||||
Long amendmentId = null;
|
||||
@@ -207,13 +203,8 @@ public class DocumentDao {
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}
|
||||
|
||||
amazonS3Service.deleteFileFromS3(documentEntity, callId, applicationId,amendmentId);
|
||||
documentEntity.setIsDeleted(true);
|
||||
documentRepository.save(documentEntity);
|
||||
deleteFileFromS3(documentEntity, callId, applicationId,amendmentId);
|
||||
|
||||
/** 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(oldDocumentEntity).newData(documentEntity).build());
|
||||
}
|
||||
|
||||
public DocumentEntity validateDocument(Long id) {
|
||||
@@ -275,4 +266,26 @@ public class DocumentDao {
|
||||
DocumentEntity documentEntity = validateDocument(documentId);
|
||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||
}
|
||||
|
||||
public void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId) {
|
||||
try {
|
||||
|
||||
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
|
||||
String oldS3Path = documentEntity.getFilePath();
|
||||
String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.valueOf("DELETED_" + documentEntity.getSource().toUpperCase()), callId, applicationId,amendmentId);
|
||||
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(documentEntity.getFileName(), oldS3Path, newS3Path);
|
||||
documentEntity.setFileName(response.getFileName());
|
||||
documentEntity.setFilePath(response.getFilePath());
|
||||
documentEntity.setIsDeleted(true);
|
||||
documentRepository.save(documentEntity);
|
||||
|
||||
/** 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(oldDocumentEntity).newData(documentEntity).build());
|
||||
log.info("File for document ID {} successfully moved to deleted folder.", documentEntity.getId());
|
||||
} catch (Exception e) {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user