document code updation.
This commit is contained in:
@@ -80,7 +80,7 @@ public class S3ReUploadMigrationService {
|
|||||||
File localFile = downloadFileFromS3(oldUrl);
|
File localFile = downloadFileFromS3(oldUrl);
|
||||||
String newKey = generateNewS3Path(document); // Make sure this generates the correct new path
|
String newKey = generateNewS3Path(document); // Make sure this generates the correct new path
|
||||||
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
|
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
|
||||||
updateDocumentPathAndDeleteOldEntry(document, uploadedPath);
|
updateDocumentPathAndNameEntry(document, uploadedPath);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error processing document {}: {}", document.getId(), e.getMessage());
|
log.error("Error processing document {}: {}", document.getId(), e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -178,20 +178,12 @@ public class S3ReUploadMigrationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateDocumentPathAndDeleteOldEntry(DocumentEntity document, String newPath) {
|
private void updateDocumentPathAndNameEntry(DocumentEntity document, String newPath) {
|
||||||
|
|
||||||
String fileName = extractFileName(newPath);
|
String fileName = extractFileName(newPath);
|
||||||
DocumentEntity newDocument = new DocumentEntity();
|
document.setFilePath(newPath);
|
||||||
newDocument.setFilePath(newPath);
|
document.setFileName(fileName);
|
||||||
newDocument.setSource(document.getSource());
|
documentRepository.save(document);
|
||||||
newDocument.setType(document.getType());
|
|
||||||
newDocument.setIsDeleted(false);
|
|
||||||
newDocument.setSourceId(document.getSourceId());
|
|
||||||
newDocument.setFileName(fileName);
|
|
||||||
|
|
||||||
documentRepository.save(newDocument);
|
|
||||||
documentRepository.delete(document);
|
|
||||||
|
|
||||||
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
|
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class UserSignedAndDelegationServiceImpl {
|
|||||||
private static final String OLD_BUCKET = "mementoresources";
|
private static final String OLD_BUCKET = "mementoresources";
|
||||||
|
|
||||||
private static final String NEW_BUCKET = "mementoresources";
|
private static final String NEW_BUCKET = "mementoresources";
|
||||||
|
|
||||||
private static final String SECURE_KEY = "267163962963";
|
private static final String SECURE_KEY = "267163962963";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -49,7 +49,7 @@ public class UserSignedAndDelegationServiceImpl {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ApplicationRepository applicationRepository;
|
ApplicationRepository applicationRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
S3ConfigRepository s3ConfigRepository;
|
S3ConfigRepository s3ConfigRepository;
|
||||||
|
|
||||||
@@ -58,7 +58,6 @@ public class UserSignedAndDelegationServiceImpl {
|
|||||||
|
|
||||||
private boolean migrationCompleted = false;
|
private boolean migrationCompleted = false;
|
||||||
|
|
||||||
|
|
||||||
public String migrateUserDelegatedDocuments(String providedKey) {
|
public String migrateUserDelegatedDocuments(String providedKey) {
|
||||||
|
|
||||||
if (migrationCompleted) {
|
if (migrationCompleted) {
|
||||||
@@ -84,7 +83,7 @@ public class UserSignedAndDelegationServiceImpl {
|
|||||||
File localFile = downloadFileFromS3(oldUrl);
|
File localFile = downloadFileFromS3(oldUrl);
|
||||||
String newKey = generateNewS3PathForDelegationDoc();
|
String newKey = generateNewS3PathForDelegationDoc();
|
||||||
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
|
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
|
||||||
updateDelegatedDocumentPathAndDeleteOldEntry(document, uploadedPath);
|
updateDelegatedDocumentPathAndNameEntry(document, uploadedPath);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error processing user designated document {}: {}", document.getId(), e.getMessage());
|
log.error("Error processing user designated document {}: {}", document.getId(), e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -92,7 +91,6 @@ public class UserSignedAndDelegationServiceImpl {
|
|||||||
return "Migrated";
|
return "Migrated";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String migrateUserSignedDocuments(String providedKey) {
|
public String migrateUserSignedDocuments(String providedKey) {
|
||||||
|
|
||||||
if (migrationCompleted) {
|
if (migrationCompleted) {
|
||||||
@@ -117,7 +115,7 @@ public class UserSignedAndDelegationServiceImpl {
|
|||||||
File localFile = downloadFileFromS3(oldUrl);
|
File localFile = downloadFileFromS3(oldUrl);
|
||||||
String newKey = generateNewS3PathForUserSignedDoc(document);
|
String newKey = generateNewS3PathForUserSignedDoc(document);
|
||||||
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
|
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
|
||||||
updateDocumentPathAndDeleteOldEntry(document, uploadedPath);
|
updateDocumentPathAndNameEntry(document, uploadedPath);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error processing user signed document {}: {}", document.getId(), e.getMessage());
|
log.error("Error processing user signed document {}: {}", document.getId(), e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -227,35 +225,21 @@ public class UserSignedAndDelegationServiceImpl {
|
|||||||
return path.substring(path.lastIndexOf('/') + 1);
|
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);
|
String fileName = extractFileNameFromPath(newPath);
|
||||||
newDocument.setFilePath(newPath);
|
document.setFilePath(newPath);
|
||||||
newDocument.setFileName(fileName);
|
document.setFileName(fileName);
|
||||||
newDocument.setApplication(document.getApplication());
|
applicationSignedDocumentRepository.save(document);
|
||||||
newDocument.setStatus("ACTIVE");
|
|
||||||
|
|
||||||
applicationSignedDocumentRepository.save(newDocument);
|
|
||||||
applicationSignedDocumentRepository.delete(document);
|
|
||||||
|
|
||||||
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
|
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);
|
String fileName = extractFileNameFromPath(newPath);
|
||||||
UserCompanyDelegationEntity newDocument = new UserCompanyDelegationEntity();
|
document.setFilePath(newPath);
|
||||||
newDocument.setFilePath(newPath);
|
document.setFileName(fileName);
|
||||||
newDocument.setFileName(fileName);
|
userCompanyDelegationRepository.save(document);
|
||||||
newDocument.setBeneficiaryId(document.getBeneficiaryId());
|
|
||||||
newDocument.setUserId(document.getUserId());
|
|
||||||
newDocument.setCompanyId(document.getCompanyId());
|
|
||||||
newDocument.setStatus("ACTIVE");
|
|
||||||
|
|
||||||
userCompanyDelegationRepository.save(newDocument);
|
|
||||||
userCompanyDelegationRepository.delete(document);
|
|
||||||
|
|
||||||
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
|
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1443,7 +1443,7 @@
|
|||||||
<column name="bucket_name" value="mementoresources"/>
|
<column name="bucket_name" value="mementoresources"/>
|
||||||
<column name="created_date" value="2024-10-25 03:00:00"/>
|
<column name="created_date" value="2024-10-25 03:00:00"/>
|
||||||
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
||||||
<column name="parent_folder" value="gepafin/staging"/>
|
<column name="parent_folder" value="gepafin/local"/>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<insert tableName="s3_path_configuration">
|
<insert tableName="s3_path_configuration">
|
||||||
@@ -1452,7 +1452,7 @@
|
|||||||
<column name="bucket_name" value="mementoresources"/>
|
<column name="bucket_name" value="mementoresources"/>
|
||||||
<column name="created_date" value="2024-10-25 03:00:00"/>
|
<column name="created_date" value="2024-10-25 03:00:00"/>
|
||||||
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
||||||
<column name="parent_folder" value="gepafin/staging"/>
|
<column name="parent_folder" value="gepafin/local"/>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<insert tableName="s3_path_configuration">
|
<insert tableName="s3_path_configuration">
|
||||||
@@ -1461,7 +1461,7 @@
|
|||||||
<column name="bucket_name" value="mementoresources"/>
|
<column name="bucket_name" value="mementoresources"/>
|
||||||
<column name="created_date" value="2024-10-25 03:00:00"/>
|
<column name="created_date" value="2024-10-25 03:00:00"/>
|
||||||
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
||||||
<column name="parent_folder" value="gepafin/staging"/>
|
<column name="parent_folder" value="gepafin/local"/>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<insert tableName="s3_path_configuration">
|
<insert tableName="s3_path_configuration">
|
||||||
@@ -1470,7 +1470,7 @@
|
|||||||
<column name="bucket_name" value="mementoresources"/>
|
<column name="bucket_name" value="mementoresources"/>
|
||||||
<column name="created_date" value="2024-10-25 03:00:00"/>
|
<column name="created_date" value="2024-10-25 03:00:00"/>
|
||||||
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
||||||
<column name="parent_folder" value="gepafin/staging"/>
|
<column name="parent_folder" value="gepafin/local"/>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<insert tableName="s3_path_configuration">
|
<insert tableName="s3_path_configuration">
|
||||||
@@ -1479,7 +1479,7 @@
|
|||||||
<column name="bucket_name" value="mementoresources"/>
|
<column name="bucket_name" value="mementoresources"/>
|
||||||
<column name="created_date" value="2024-10-25 03:00:00"/>
|
<column name="created_date" value="2024-10-25 03:00:00"/>
|
||||||
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
||||||
<column name="parent_folder" value="gepafin/staging"/>
|
<column name="parent_folder" value="gepafin/local"/>
|
||||||
</insert>
|
</insert>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user