document code updation.

This commit is contained in:
piyuskag
2024-10-28 11:22:48 +05:30
parent 9dc523a649
commit e1b6ec6c02
3 changed files with 22 additions and 46 deletions

View File

@@ -32,7 +32,7 @@ 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
@@ -49,7 +49,7 @@ public class UserSignedAndDelegationServiceImpl {
@Autowired
ApplicationRepository applicationRepository;
@Autowired
S3ConfigRepository s3ConfigRepository;
@@ -58,7 +58,6 @@ public class UserSignedAndDelegationServiceImpl {
private boolean migrationCompleted = false;
public String migrateUserDelegatedDocuments(String providedKey) {
if (migrationCompleted) {
@@ -84,7 +83,7 @@ public class UserSignedAndDelegationServiceImpl {
File localFile = downloadFileFromS3(oldUrl);
String newKey = generateNewS3PathForDelegationDoc();
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
updateDelegatedDocumentPathAndDeleteOldEntry(document, uploadedPath);
updateDelegatedDocumentPathAndNameEntry(document, uploadedPath);
} catch (Exception e) {
log.error("Error processing user designated document {}: {}", document.getId(), e.getMessage());
}
@@ -92,7 +91,6 @@ public class UserSignedAndDelegationServiceImpl {
return "Migrated";
}
public String migrateUserSignedDocuments(String providedKey) {
if (migrationCompleted) {
@@ -117,7 +115,7 @@ public class UserSignedAndDelegationServiceImpl {
File localFile = downloadFileFromS3(oldUrl);
String newKey = generateNewS3PathForUserSignedDoc(document);
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
updateDocumentPathAndDeleteOldEntry(document, uploadedPath);
updateDocumentPathAndNameEntry(document, uploadedPath);
} catch (Exception e) {
log.error("Error processing user signed document {}: {}", document.getId(), e.getMessage());
}
@@ -227,35 +225,21 @@ public class UserSignedAndDelegationServiceImpl {
return path.substring(path.lastIndexOf('/') + 1);
}
private void updateDocumentPathAndDeleteOldEntry(ApplicationSignedDocumentEntity document, String newPath) {
private void updateDocumentPathAndNameEntry(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);
document.setFilePath(newPath);
document.setFileName(fileName);
applicationSignedDocumentRepository.save(document);
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
}
private void updateDelegatedDocumentPathAndDeleteOldEntry(UserCompanyDelegationEntity document, String newPath) {
private void updateDelegatedDocumentPathAndNameEntry(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);
document.setFilePath(newPath);
document.setFileName(fileName);
userCompanyDelegationRepository.save(document);
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
}
}