All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.aws.sdk.kotlin.services.omics.serde.GetWorkflowOperationDeserializer.kt Maven / Gradle / Ivy

There is a newer version: 1.3.37
Show newest version
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.omics.serde

import aws.sdk.kotlin.services.omics.model.Accelerators
import aws.sdk.kotlin.services.omics.model.GetWorkflowResponse
import aws.sdk.kotlin.services.omics.model.OmicsException
import aws.sdk.kotlin.services.omics.model.WorkflowEngine
import aws.sdk.kotlin.services.omics.model.WorkflowParameter
import aws.sdk.kotlin.services.omics.model.WorkflowStatus
import aws.sdk.kotlin.services.omics.model.WorkflowType
import aws.smithy.kotlin.runtime.awsprotocol.json.RestJsonErrorDeserializer
import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata
import aws.smithy.kotlin.runtime.awsprotocol.withPayload
import aws.smithy.kotlin.runtime.http.HttpCall
import aws.smithy.kotlin.runtime.http.isSuccess
import aws.smithy.kotlin.runtime.http.operation.HttpDeserialize
import aws.smithy.kotlin.runtime.http.readAll
import aws.smithy.kotlin.runtime.operation.ExecutionContext
import aws.smithy.kotlin.runtime.serde.SdkFieldDescriptor
import aws.smithy.kotlin.runtime.serde.SdkObjectDescriptor
import aws.smithy.kotlin.runtime.serde.SerialKind
import aws.smithy.kotlin.runtime.serde.asSdkSerializable
import aws.smithy.kotlin.runtime.serde.deserializeList
import aws.smithy.kotlin.runtime.serde.deserializeMap
import aws.smithy.kotlin.runtime.serde.deserializeStruct
import aws.smithy.kotlin.runtime.serde.field
import aws.smithy.kotlin.runtime.serde.json.JsonDeserializer
import aws.smithy.kotlin.runtime.serde.json.JsonSerialName
import aws.smithy.kotlin.runtime.serde.serializeList
import aws.smithy.kotlin.runtime.serde.serializeMap
import aws.smithy.kotlin.runtime.serde.serializeStruct
import aws.smithy.kotlin.runtime.time.Instant
import kotlin.collections.mutableMapOf


internal class GetWorkflowOperationDeserializer: HttpDeserialize {

    override suspend fun deserialize(context: ExecutionContext, call: HttpCall): GetWorkflowResponse {
        val response = call.response
        if (!response.status.isSuccess()) {
            throwGetWorkflowError(context, call)
        }
        val builder = GetWorkflowResponse.Builder()

        val payload = response.body.readAll()
        if (payload != null) {
            deserializeGetWorkflowOperationBody(builder, payload)
        }
        builder.correctErrors()
        return builder.build()
    }
}

private suspend fun throwGetWorkflowError(context: ExecutionContext, call: HttpCall): kotlin.Nothing {
    val payload = call.response.body.readAll()
    val wrappedResponse = call.response.withPayload(payload)
    val wrappedCall = call.copy(response = wrappedResponse)

    val errorDetails = try {
        RestJsonErrorDeserializer.deserialize(call.response.headers, payload)
    } catch (ex: Exception) {
        throw OmicsException("Failed to parse response as 'restJson1' error", ex).also {
            setAseErrorMetadata(it, wrappedCall.response, null)
        }
    }

    val ex = when(errorDetails.code) {
        "AccessDeniedException" -> AccessDeniedExceptionDeserializer().deserialize(context, wrappedCall)
        "ConflictException" -> ConflictExceptionDeserializer().deserialize(context, wrappedCall)
        "InternalServerException" -> InternalServerExceptionDeserializer().deserialize(context, wrappedCall)
        "RequestTimeoutException" -> RequestTimeoutExceptionDeserializer().deserialize(context, wrappedCall)
        "ResourceNotFoundException" -> ResourceNotFoundExceptionDeserializer().deserialize(context, wrappedCall)
        "ServiceQuotaExceededException" -> ServiceQuotaExceededExceptionDeserializer().deserialize(context, wrappedCall)
        "ThrottlingException" -> ThrottlingExceptionDeserializer().deserialize(context, wrappedCall)
        "ValidationException" -> ValidationExceptionDeserializer().deserialize(context, wrappedCall)
        else -> OmicsException(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeGetWorkflowOperationBody(builder: GetWorkflowResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val ACCELERATORS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("accelerators"))
    val ARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("arn"))
    val CREATIONTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("creationTime"))
    val DEFINITION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("definition"))
    val DESCRIPTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("description"))
    val DIGEST_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("digest"))
    val ENGINE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("engine"))
    val ID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("id"))
    val MAIN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("main"))
    val METADATA_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map, JsonSerialName("metadata"))
    val NAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("name"))
    val PARAMETERTEMPLATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map, JsonSerialName("parameterTemplate"))
    val STATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("status"))
    val STATUSMESSAGE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("statusMessage"))
    val STORAGECAPACITY_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Integer, JsonSerialName("storageCapacity"))
    val TAGS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map, JsonSerialName("tags"))
    val TYPE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("type"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(ACCELERATORS_DESCRIPTOR)
        field(ARN_DESCRIPTOR)
        field(CREATIONTIME_DESCRIPTOR)
        field(DEFINITION_DESCRIPTOR)
        field(DESCRIPTION_DESCRIPTOR)
        field(DIGEST_DESCRIPTOR)
        field(ENGINE_DESCRIPTOR)
        field(ID_DESCRIPTOR)
        field(MAIN_DESCRIPTOR)
        field(METADATA_DESCRIPTOR)
        field(NAME_DESCRIPTOR)
        field(PARAMETERTEMPLATE_DESCRIPTOR)
        field(STATUS_DESCRIPTOR)
        field(STATUSMESSAGE_DESCRIPTOR)
        field(STORAGECAPACITY_DESCRIPTOR)
        field(TAGS_DESCRIPTOR)
        field(TYPE_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                ACCELERATORS_DESCRIPTOR.index -> builder.accelerators = deserializeString().let { Accelerators.fromValue(it) }
                ARN_DESCRIPTOR.index -> builder.arn = deserializeString()
                CREATIONTIME_DESCRIPTOR.index -> builder.creationTime = deserializeString().let { Instant.fromIso8601(it) }
                DEFINITION_DESCRIPTOR.index -> builder.definition = deserializeString()
                DESCRIPTION_DESCRIPTOR.index -> builder.description = deserializeString()
                DIGEST_DESCRIPTOR.index -> builder.digest = deserializeString()
                ENGINE_DESCRIPTOR.index -> builder.engine = deserializeString().let { WorkflowEngine.fromValue(it) }
                ID_DESCRIPTOR.index -> builder.id = deserializeString()
                MAIN_DESCRIPTOR.index -> builder.main = deserializeString()
                METADATA_DESCRIPTOR.index -> builder.metadata =
                    deserializer.deserializeMap(METADATA_DESCRIPTOR) {
                        val map0 = mutableMapOf()
                        while (hasNextEntry()) {
                            val k0 = key()
                            val v0 = if (nextHasValue()) { deserializeString() } else { deserializeNull(); continue }
                            map0[k0] = v0
                        }
                        map0
                    }
                NAME_DESCRIPTOR.index -> builder.name = deserializeString()
                PARAMETERTEMPLATE_DESCRIPTOR.index -> builder.parameterTemplate =
                    deserializer.deserializeMap(PARAMETERTEMPLATE_DESCRIPTOR) {
                        val map0 = mutableMapOf()
                        while (hasNextEntry()) {
                            val k0 = key()
                            val v0 = if (nextHasValue()) { deserializeWorkflowParameterDocument(deserializer) } else { deserializeNull(); continue }
                            map0[k0] = v0
                        }
                        map0
                    }
                STATUS_DESCRIPTOR.index -> builder.status = deserializeString().let { WorkflowStatus.fromValue(it) }
                STATUSMESSAGE_DESCRIPTOR.index -> builder.statusMessage = deserializeString()
                STORAGECAPACITY_DESCRIPTOR.index -> builder.storageCapacity = deserializeInt()
                TAGS_DESCRIPTOR.index -> builder.tags =
                    deserializer.deserializeMap(TAGS_DESCRIPTOR) {
                        val map0 = mutableMapOf()
                        while (hasNextEntry()) {
                            val k0 = key()
                            val v0 = if (nextHasValue()) { deserializeString() } else { deserializeNull(); continue }
                            map0[k0] = v0
                        }
                        map0
                    }
                TYPE_DESCRIPTOR.index -> builder.type = deserializeString().let { WorkflowType.fromValue(it) }
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy