Skip to content

Commit

Permalink
modify isInDateFolder method to include added folders (goldencopy/ass…
Browse files Browse the repository at this point in the history
…ertion)

Co-authored-by: Sylvie <[email protected]>
Co-authored-by: saquino0827 <[email protected]>
Co-authored-by: James Herr <[email protected]>
Co-authored-by: basiliskus <[email protected]>
  • Loading branch information
5 people committed Jan 15, 2025
1 parent 3723409 commit 0a66321
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ public static String createDateBasedPath(LocalDate date, String originalName) {
return buildDatePathPrefix(date) + originalName;
}

public static boolean isInDateFolder(String blobPath, LocalDate creationDate) {
String expectedPath = buildDatePathPrefix(creationDate);
public static boolean isInDateFolder(String testType, String blobPath, LocalDate creationDate) {
// /GOLDEN_COPY/2021/09/01/
// /ASSERTION/2021/09/01/
String expectedPath = testType + buildDatePathPrefix(creationDate);
return blobPath.startsWith(expectedPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public AzureBlobOrganizer(BlobContainerClient blobContainerClient) {
this.blobContainerClient = blobContainerClient;
}

private void deleteOldBlobs(String testType, ZoneId timeZone) {
// Delete the current date folder's blobs to prevent buildup when ran manually
private void deleteOldBlobsFromToday(String testType, ZoneId timeZone) {
// Check folder structures: YEAR/MONTH/DAY/Assertion_OR_GoldenCopy/
String prefix =
LocalDate.now(timeZone).format(DateTimeFormatter.ofPattern("yyyy/MM/dd"))
+ "/"
Expand All @@ -41,8 +43,8 @@ private void deleteOldBlobs(String testType, ZoneId timeZone) {

// Organize blob into folder structure: YEAR/MONTH/DAY/Assertion_OR_GoldenCopy/SOURCE_NAME
public void organizeAndCleanupBlobsByDate(int retentionDays, ZoneId timeZone) {
deleteOldBlobs(GOLDEN_COPY, timeZone);
deleteOldBlobs(ASSERTION, timeZone);
deleteOldBlobsFromToday(GOLDEN_COPY, timeZone);
deleteOldBlobsFromToday(ASSERTION, timeZone);
for (BlobItem blobItem : blobContainerClient.listBlobs()) {
String sourceName = blobItem.getName();
try {
Expand All @@ -62,15 +64,17 @@ public void organizeAndCleanupBlobsByDate(int retentionDays, ZoneId timeZone) {
continue;
}

if (AzureBlobHelper.isInDateFolder(sourceName, sourceCreationDate)) {
continue;
}

String testTypeAndSourceName = ASSERTION + sourceName;
String testType = ASSERTION;
String testTypeAndSourceName = testType + sourceName;
if (sourceBlob.getBlobName().contains("GOLDEN-COPY")) {
testType = GOLDEN_COPY;
testTypeAndSourceName = GOLDEN_COPY + sourceName;
}

if (AzureBlobHelper.isInDateFolder(testType, sourceName, sourceCreationDate)) {
continue;
}

System.out.println("Organizing blob: " + testTypeAndSourceName);

String destinationName =
Expand Down

0 comments on commit 0a66321

Please sign in to comment.