generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add fields jurisdiction, senderId to ReportDeadLetter * Update sort * Unit Test for getUploads * Send Date with milliseconds for getUploads. Sort the items in the Page after the page data is returned. * Unit Tests for getUploads * ReportCounts tests
- Loading branch information
1 parent
97c222f
commit b791651
Showing
13 changed files
with
767 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
pstatus-graphql-ktor/src/main/kotlin/gov/cdc/ocio/processingstatusapi/utils/SortUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package gov.cdc.ocio.processingstatusapi.utils | ||
|
||
import gov.cdc.ocio.processingstatusapi.models.query.UploadsStatus | ||
|
||
/** | ||
* Utility class for sorting operations on UploadsStatus. | ||
*/ | ||
object SortUtils { | ||
|
||
private enum class SortOrder { ASC, DESC } | ||
|
||
/** | ||
* Sorts the items in UploadsStatus based on the specified field and order. | ||
* | ||
* @param uploadsStatus The UploadsStatus instance to be sorted. | ||
* @param field The field name to sort by. | ||
* @param order The order to sort in ("asc" or "desc"). | ||
*/ | ||
fun sortByField(uploadsStatus: UploadsStatus, field: String, order: String) { | ||
val sortOrder = try { | ||
SortOrder.valueOf(order.uppercase()) | ||
} catch (e: IllegalArgumentException) { | ||
throw IllegalArgumentException("Unsupported order: $order") | ||
} | ||
|
||
when (field) { | ||
"date" -> { | ||
if (sortOrder == SortOrder.ASC) { | ||
uploadsStatus.items.sortBy { it.timestamp } | ||
} else { | ||
uploadsStatus.items.sortByDescending { it.timestamp } | ||
} | ||
} | ||
"fileName" -> { | ||
if (sortOrder == SortOrder.ASC) { | ||
uploadsStatus.items.sortBy { it.fileName } | ||
} else { | ||
uploadsStatus.items.sortByDescending { it.fileName } | ||
} | ||
} | ||
"dataStreamId" -> { | ||
if (sortOrder == SortOrder.ASC) { | ||
uploadsStatus.items.sortBy { | ||
(it.metadata?.get("data_stream_id") as? String)?.toLowerCase() ?: "" | ||
} | ||
} else { | ||
uploadsStatus.items.sortByDescending { | ||
(it.metadata?.get("data_stream_id") as? String)?.toLowerCase() ?: "" | ||
} | ||
} | ||
} | ||
"dataStreamRoute" -> { | ||
if (sortOrder == SortOrder.ASC) { | ||
uploadsStatus.items.sortBy { | ||
(it.metadata?.get("data_stream_route") as? String)?.toLowerCase() ?: "" | ||
} | ||
} else { | ||
uploadsStatus.items.sortByDescending { | ||
(it.metadata?.get("data_stream_route") as? String)?.toLowerCase() ?: "" | ||
} | ||
} | ||
} | ||
"status" -> { | ||
if (sortOrder == SortOrder.ASC) { | ||
uploadsStatus.items.sortBy { it.status } | ||
} else { | ||
uploadsStatus.items.sortByDescending { it.status } | ||
} | ||
} | ||
"jurisdiction" -> { | ||
if (sortOrder == SortOrder.ASC) { | ||
uploadsStatus.items.sortBy { it.jurisdiction } | ||
} else { | ||
uploadsStatus.items.sortByDescending { it.jurisdiction } | ||
} | ||
} | ||
"senderId" -> { | ||
if (sortOrder == SortOrder.ASC) { | ||
uploadsStatus.items.sortBy { it.senderId } | ||
} else { | ||
uploadsStatus.items.sortByDescending { it.senderId } | ||
} | ||
} | ||
else -> uploadsStatus.items.sortByDescending { it.timestamp } | ||
} | ||
|
||
|
||
//Sort the senderIds and jurisdiction fields in the PageSummary | ||
uploadsStatus.summary.senderIds.sort() | ||
uploadsStatus.summary.jurisdictions.sort() | ||
|
||
} | ||
} |
Oops, something went wrong.