Skip to content

Commit

Permalink
Merge branch 'develop' into dev-feature-notifications-workflow-orches…
Browse files Browse the repository at this point in the history
…trator-graphql
  • Loading branch information
manu-govind authored Sep 25, 2024
2 parents 50a8f15 + 3bdee7b commit c0a65f6
Show file tree
Hide file tree
Showing 63 changed files with 3,089 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/graphql-service-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Run Gradle Test
run: ./gradlew test
run: ./gradlew test
35 changes: 31 additions & 4 deletions pstatus-graphql-ktor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ dependencies {
testImplementation "io.ktor:ktor-server-tests-jvm:$ktor_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"

// testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
// testImplementation 'org.mockito:mockito-core:4.6.1'
// testImplementation 'org.mockito:mockito-junit-jupiter:4.6.1'

testImplementation "org.junit.jupiter:junit-jupiter-api:5.8.1"
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.8.1"
testImplementation "org.mockito:mockito-core:4.5.1"
Expand Down Expand Up @@ -108,4 +104,35 @@ jib {
}
}

test {

// Discover and execute JUnit Platform-based (JUnit 5, JUnit Jupiter) tests
// JUnit 5 has the ability to execute JUnit 4 tests as well
useJUnitPlatform()

//Change this to "true" if we want to execute unit tests
systemProperty("isTestEnvironment", "false")

// Set the test classpath, if required
}

sourceSets {
main {
java {
srcDir 'src/kotlin'
}
resources {
srcDir 'src/resources'
}
}
test {
java {
srcDir 'src/kotlin'
}
resources {
srcDir 'src/resources'
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fun KoinApplication.loadKoinModules(environment: ApplicationEnvironment): KoinAp
// Create a CosmosDB config that can be dependency injected (for health checks)
single(createdAtStart = true) { CosmosConfiguration(uri, authKey) }
}

return modules(listOf(cosmosModule))
}

Expand All @@ -34,15 +35,20 @@ fun main(args: Array<String>) {
}

fun Application.module() {
graphQLModule()
configureRouting()

install(Koin) {
loadKoinModules(environment)
}
graphQLModule()
configureRouting()

install(ContentNegotiation) {
jackson()
}




// See https://opensource.expediagroup.com/graphql-kotlin/docs/schema-generator/writing-schemas/scalars
RuntimeWiring.newRuntimeWiring().scalar(ExtendedScalars.Date)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gov.cdc.ocio.processingstatusapi.models

/**
* Enumeration of the possible sort orders for queries.
*/
enum class ReportContentType (val type: String){
JSON("application/json"),
JSON_SHORT("json"),
BASE64("base64");

companion object {
fun fromString(type: String): ReportContentType {
return values().find { it.type.equals(type, ignoreCase = true) }
?: throw IllegalArgumentException("Unsupported content type: $type")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gov.cdc.ocio.processingstatusapi.models.reports.inputs

import com.expediagroup.graphql.generator.annotations.GraphQLDescription

@GraphQLDescription("Input type for tags")
data class DataInput(
@GraphQLDescription("Tag key")
val key: String,

@GraphQLDescription("Tag value")
val value: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gov.cdc.ocio.processingstatusapi.models.reports.inputs

import com.expediagroup.graphql.generator.annotations.GraphQLDescription

@GraphQLDescription("Input type for issues")
data class IssueInput(
@GraphQLDescription("Issue code")
val code: String? = null,

@GraphQLDescription("Issue description")
val description: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gov.cdc.ocio.processingstatusapi.models.reports.inputs

import com.expediagroup.graphql.generator.annotations.GraphQLDescription
import gov.cdc.ocio.processingstatusapi.models.submission.Aggregation

@GraphQLDescription("Input type for message metadata")
data class MessageMetadataInput(
@GraphQLDescription("Unique Identifier for that message")
val messageUUID: String? = null,

@GraphQLDescription("MessageHash value")
val messageHash: String? = null,

@GraphQLDescription("Single or Batch message")
val aggregation: Aggregation? = null,

@GraphQLDescription("Message Index")
val messageIndex: Int? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package gov.cdc.ocio.processingstatusapi.models.reports.inputs

import com.expediagroup.graphql.generator.annotations.GraphQLDescription
import java.time.OffsetDateTime

@GraphQLDescription("Input type for creating or updating a report")
data class ReportInput(
@GraphQLDescription("Identifier of the report recorded by the database")
val id: String? = null,

@GraphQLDescription("Upload identifier this report belongs to")
val uploadId: String? = null,

@GraphQLDescription("Unique report identifier")
val reportId: String? = null,

@GraphQLDescription("Data stream ID")
val dataStreamId: String? = null,

@GraphQLDescription("Data stream route")
val dataStreamRoute: String? = null,

@GraphQLDescription("Date/time of when the upload was first ingested into the data-exchange")
val dexIngestDateTime: OffsetDateTime? = null,

@GraphQLDescription("Message metadata")
val messageMetadata: MessageMetadataInput? = null,

@GraphQLDescription("Stage info")
val stageInfo: StageInfoInput? = null,

@GraphQLDescription("Tags")
val tags: List<TagInput>? = null,

@GraphQLDescription("Data")
val data: List<DataInput>? = null,

@GraphQLDescription("Indicates the content type of the content; e.g. JSON, XML")
val contentType: String? = null,

@GraphQLDescription("Jurisdiction report belongs to; set to null if not applicable")
val jurisdiction: String? = null,

@GraphQLDescription("Sender ID this report belongs to; set to null if not applicable")
val senderId: String? = null,

@GraphQLDescription("Data Producer ID stated in the report; set to null if not applicable")
val dataProducerId: String? = null,

@GraphQLDescription("Content of the report. If the report is JSON then the content will be a map, otherwise, it will be a string")
var content : String? = null,

@GraphQLDescription("Timestamp when the report was recorded in the database")
val timestamp: OffsetDateTime? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gov.cdc.ocio.processingstatusapi.models.reports.inputs

import com.expediagroup.graphql.generator.annotations.GraphQLDescription
import gov.cdc.ocio.processingstatusapi.models.submission.Status
import java.time.OffsetDateTime

@GraphQLDescription("Input type for stage info")
data class StageInfoInput(
@GraphQLDescription("Service")
val service: String? = null,

@GraphQLDescription("Stage name a.k.a action")
val action: String? = null,

@GraphQLDescription("Version")
val version: String? = null,

@GraphQLDescription("Status- SUCCESS OR FAILURE")
val status: Status? = null,

@GraphQLDescription("Issues array")
val issues: List<IssueInput>? = null,

@GraphQLDescription("Start processing time")
val startProcessingTime: OffsetDateTime? = null,

@GraphQLDescription("End processing time")
val endProcessingTime: OffsetDateTime? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gov.cdc.ocio.processingstatusapi.models.reports.inputs

import com.expediagroup.graphql.generator.annotations.GraphQLDescription

@GraphQLDescription("Input type for tags")
data class TagInput(
@GraphQLDescription("Tag key")
val key: String,

@GraphQLDescription("Tag value")
val value: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gov.cdc.ocio.processingstatusapi.mutations

import com.expediagroup.graphql.generator.annotations.GraphQLDescription
import com.expediagroup.graphql.server.operations.Mutation
import gov.cdc.ocio.processingstatusapi.exceptions.BadRequestException
import gov.cdc.ocio.processingstatusapi.exceptions.ContentException
import gov.cdc.ocio.processingstatusapi.models.reports.inputs.ReportInput
import gov.cdc.ocio.processingstatusapi.services.ReportMutationService

/**
* ReportMutationService class handles GraphQL mutations for report creation and replacement.
*
* This service provides a single mutation operation to either create a new report or replace an
* existing report in the system. It utilizes the ReportMutation class to perform the actual
* upsert operation based on the provided input and action.
*
* Annotations:
* - GraphQLDescription: Provides descriptions for the class and its methods for GraphQL documentation.
*
* Dependencies:
* - ReportInput: Represents the input model for report data.
*/
@GraphQLDescription("A Mutation Service to either create a new report or replace an existing report")
class ReportMutation() : Mutation {

/**
* Upserts a report based on the provided input and action.
*
* This function serves as a GraphQL mutation to create a new report or replace an existing one.
* It delegates the actual upsert logic to the ReportMutation class.
*
* @param input The ReportInput containing details of the report to be created or replaced.
* @param action A string specifying the action to perform: "create" or "replace".
* @return The result of the upsert operation, handled by the ReportMutation class.
*/
@GraphQLDescription("Create upload")
@Suppress("unused")
@Throws(BadRequestException::class, ContentException::class, Exception::class)
fun upsertReport(
@GraphQLDescription(
"*Report Input* to be created or updated:\n"
)
input: ReportInput,
@GraphQLDescription(
"*Action*: Can be one of the following values\n"
+ "`create`: Create new report\n"
+ "`replace`: Replace existing report\n"
)
action: String
) = ReportMutationService().upsertReport(input, action)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import gov.cdc.ocio.processingstatusapi.mutations.DataStreamTopErrorsNotificatio
import gov.cdc.ocio.processingstatusapi.mutations.DeadlineCheckSubscriptionMutationService
import gov.cdc.ocio.processingstatusapi.mutations.NotificationsMutationService
import gov.cdc.ocio.processingstatusapi.mutations.UploadErrorsNotificationSubscriptionMutationService
import gov.cdc.ocio.processingstatusapi.mutations.ReportMutation
import gov.cdc.ocio.processingstatusapi.queries.*
import io.ktor.http.*
import io.ktor.serialization.jackson.*
Expand Down Expand Up @@ -83,6 +84,9 @@ fun Application.graphQLModule() {
// install(CORS) {
// anyHost()
// }

// val reportMutation by inject<ReportMutation>() // Inject ReportMutation from Koin

install(GraphQL) {
schema {
packages = listOf("gov.cdc.ocio.processingstatusapi")
Expand All @@ -99,6 +103,8 @@ fun Application.graphQLModule() {
DataStreamTopErrorsNotificationSubscriptionMutationService(),
DeadlineCheckSubscriptionMutationService(),
UploadErrorsNotificationSubscriptionMutationService()
ReportMutation()

)
// subscriptions = listOf(
// ErrorSubscriptionService()
Expand Down
Loading

0 comments on commit c0a65f6

Please sign in to comment.