Skip to content

Commit

Permalink
Merge branch 'master' into snesm/loginV2
Browse files Browse the repository at this point in the history
  • Loading branch information
snesm authored Mar 6, 2024
2 parents e3ad678 + 1f8b4f8 commit 09971da
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 6 deletions.
31 changes: 25 additions & 6 deletions prime-router/src/main/kotlin/azure/ActionHistory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import io.ktor.http.HttpStatusCode
import org.apache.logging.log4j.kotlin.Logging
import org.jooq.impl.SQLDataType
import java.io.ByteArrayOutputStream
import java.net.URI
import java.net.URISyntaxException
import java.time.LocalDateTime
import java.util.UUID

Expand Down Expand Up @@ -379,7 +381,7 @@ class ActionHistory(
reportFile.nextAction = report.nextAction
reportFile.sendingOrg = source.organization
reportFile.sendingOrgClient = source.client
reportFile.schemaName = report.schema.name
reportFile.schemaName = trimSchemaNameToMaxLength(report.schema.name)
reportFile.schemaTopic = report.schema.topic
reportFile.bodyUrl = blobInfo.blobUrl
reportFile.bodyFormat = blobInfo.format.toString()
Expand Down Expand Up @@ -415,7 +417,7 @@ class ActionHistory(
reportFile.nextAction = TaskAction.send
reportFile.receivingOrg = receiver.organizationName
reportFile.receivingOrgSvc = receiver.name
reportFile.schemaName = report.schema.name
reportFile.schemaName = trimSchemaNameToMaxLength(report.schema.name)
reportFile.schemaTopic = report.schema.topic
reportFile.bodyUrl = blobInfo.blobUrl
reportFile.bodyFormat = blobInfo.format.toString()
Expand Down Expand Up @@ -447,7 +449,7 @@ class ActionHistory(
reportFile.reportId = report.id
reportFile.receivingOrg = receiver.organizationName
reportFile.receivingOrgSvc = receiver.name
reportFile.schemaName = report.schema.name
reportFile.schemaName = trimSchemaNameToMaxLength(report.schema.name)
reportFile.schemaTopic = report.schema.topic
reportFile.itemCount = report.itemCount
reportFile.bodyFormat = report.bodyFormat.toString()
Expand All @@ -474,7 +476,7 @@ class ActionHistory(
val reportFile = ReportFile()

reportFile.reportId = report.id
reportFile.schemaName = report.schema.name
reportFile.schemaName = trimSchemaNameToMaxLength(report.schema.name)
reportFile.schemaTopic = report.schema.topic
reportFile.itemCountBeforeQualFilter = report.itemCountBeforeQualFilter

Expand Down Expand Up @@ -542,11 +544,12 @@ class ActionHistory(
receiver.fullName,
Event.EventAction.NONE
)

val reportFile = ReportFile()
reportFile.reportId = sentReportId
reportFile.receivingOrg = receiver.organizationName
reportFile.receivingOrgSvc = receiver.name
reportFile.schemaName = receiver.schemaName
reportFile.schemaName = trimSchemaNameToMaxLength(receiver.schemaName)
reportFile.schemaTopic = receiver.topic
reportFile.externalName = filename
action.externalName = filename
Expand Down Expand Up @@ -582,7 +585,7 @@ class ActionHistory(
reportFile.reportId = externalReportId // child report
reportFile.receivingOrg = parentReportFile.receivingOrg
reportFile.receivingOrgSvc = parentReportFile.receivingOrgSvc
reportFile.schemaName = parentReportFile.schemaName
reportFile.schemaName = trimSchemaNameToMaxLength(parentReportFile.schemaName)
reportFile.schemaTopic = parentReportFile.schemaTopic
reportFile.externalName = filename
action.externalName = filename
Expand Down Expand Up @@ -693,6 +696,22 @@ class ActionHistory(
}

companion object : Logging {

// The schema_name column only support 63 characters
// If the schemaName is a URI grab the path and then take the last 63
// otherwise just take the last 63
// TODO: #13598
fun trimSchemaNameToMaxLength(schemaName: String?): String? {
if (schemaName == null) {
return schemaName
}
return try {
URI(schemaName).path.replace(".yml", "").takeLast(63)
} catch (ex: URISyntaxException) {
schemaName.takeLast(63)
}
}

/**
* Get rid of this once we have moved away from the old Task table. In the meantime,
* this is a way of confirming that the new tables are robust.
Expand Down
57 changes: 57 additions & 0 deletions prime-router/src/test/kotlin/azure/ActionHistoryTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,56 @@ class ActionHistoryTests {
}
}

@Test
fun `test trackSentReport very long schema name`() {
val uuid = UUID.randomUUID()
val longNameWithClasspath =
"classpath:/metadata/hl7_mapping/receivers/STLTs/REALLY_LONG_STATE_NAME/REALLY_LONG_STATE_NAME.yml"
val longNameWithoutClasspath =
"metadata/hl7_mapping/receivers/NESTED/NESTED/STLTs/REALLY_LONG_STATE_NAME/REALLY_LONG_STATE_NAME"
val org =
DeepOrganization(
name = "myOrg",
description = "blah blah",
jurisdiction = Organization.Jurisdiction.FEDERAL,
receivers = listOf(
Receiver(
"myService", "myOrg", Topic.TEST, CustomerStatus.INACTIVE,
longNameWithClasspath,
format = Report.Format.CSV
),
Receiver(
"myServiceToo", "myOrg", Topic.TEST, CustomerStatus.INACTIVE,
longNameWithoutClasspath,
format = Report.Format.CSV
)
)
)
mockkObject(BlobAccess.Companion)
val blobUrls = mutableListOf<String>()
every { BlobAccess.uploadBlob(capture(blobUrls), any()) } returns "http://blobUrl"
every { BlobAccess.sha256Digest(any()) } returns byteArrayOf()
every { BlobAccess.uploadBody(any(), any(), any(), any(), Event.EventAction.NONE) } answers { callOriginal() }
val header = mockk<WorkflowEngine.Header>()
val inReportFile = mockk<ReportFile>()
every { header.reportFile } returns inReportFile
every { header.content } returns "".toByteArray()
every { inReportFile.itemCount } returns 15
val actionHistory1 = ActionHistory(TaskAction.receive)

actionHistory1.trackSentReport(org.receivers[0], uuid, "filename1", "params1", "result1", header)
assertThat(actionHistory1.reportsOut[uuid]).isNotNull()
assertThat(actionHistory1.reportsOut[uuid]?.schemaName)
.isEqualTo("g/receivers/STLTs/REALLY_LONG_STATE_NAME/REALLY_LONG_STATE_NAME")

val actionHistory2 = ActionHistory(TaskAction.receive)

actionHistory2.trackSentReport(org.receivers[1], uuid, "filename1", "params1", "result1", header)
assertThat(actionHistory2.reportsOut[uuid]).isNotNull()
assertThat(actionHistory2.reportsOut[uuid]?.schemaName)
.isEqualTo("STED/NESTED/STLTs/REALLY_LONG_STATE_NAME/REALLY_LONG_STATE_NAME")
}

@Test
fun `test trackDownloadedReport`() {
val metadata = UnitTestUtils.simpleMetadata
Expand Down Expand Up @@ -512,4 +562,11 @@ class ActionHistoryTests {
assertContains(blobUrls[0], org.receivers[0].fullName)
assertContains(blobUrls[1], org.receivers[1].fullName)
}

@Test
fun `test trimSchemaNameToMaxLength malformed URI`() {
val longMalformedURI = ":very_very:_long_name//with a badly formed URI that causes a parse exception"
val trimmed = ActionHistory.trimSchemaNameToMaxLength((longMalformedURI))
assertThat(trimmed).isEqualTo("ong_name//with a badly formed URI that causes a parse exception")
}
}

0 comments on commit 09971da

Please sign in to comment.