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

commonMain.aws.sdk.kotlin.services.codeartifact.serde.UpdatePackageGroupOriginConfigurationOperationDeserializer.kt Maven / Gradle / Ivy

The newest version!
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.codeartifact.serde

import aws.sdk.kotlin.services.codeartifact.model.CodeartifactException
import aws.sdk.kotlin.services.codeartifact.model.PackageGroupAllowedRepositoryUpdateType
import aws.sdk.kotlin.services.codeartifact.model.PackageGroupDescription
import aws.sdk.kotlin.services.codeartifact.model.PackageGroupOriginRestrictionType
import aws.sdk.kotlin.services.codeartifact.model.UpdatePackageGroupOriginConfigurationResponse
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.HttpDeserializer
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 kotlin.collections.mutableListOf
import kotlin.collections.mutableMapOf


internal class UpdatePackageGroupOriginConfigurationOperationDeserializer: HttpDeserializer.NonStreaming {

    override fun deserialize(context: ExecutionContext, call: HttpCall, payload: ByteArray?): UpdatePackageGroupOriginConfigurationResponse {
        val response = call.response
        if (!response.status.isSuccess()) {
            throwUpdatePackageGroupOriginConfigurationError(context, call, payload)
        }
        val builder = UpdatePackageGroupOriginConfigurationResponse.Builder()

        if (payload != null) {
            deserializeUpdatePackageGroupOriginConfigurationOperationBody(builder, payload)
        }
        builder.correctErrors()
        return builder.build()
    }
}

private fun throwUpdatePackageGroupOriginConfigurationError(context: ExecutionContext, call: HttpCall, payload: ByteArray?): kotlin.Nothing {
    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 CodeartifactException("Failed to parse response as 'restJson1' error", ex).also {
            setAseErrorMetadata(it, wrappedCall.response, null)
        }
    }

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

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeUpdatePackageGroupOriginConfigurationOperationBody(builder: UpdatePackageGroupOriginConfigurationResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val ALLOWEDREPOSITORYUPDATES_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map, JsonSerialName("allowedRepositoryUpdates"))
    val ALLOWEDREPOSITORYUPDATES_C0_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map)
    val ALLOWEDREPOSITORYUPDATES_C1_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List)
    val PACKAGEGROUP_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("packageGroup"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(ALLOWEDREPOSITORYUPDATES_DESCRIPTOR)
        field(PACKAGEGROUP_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                ALLOWEDREPOSITORYUPDATES_DESCRIPTOR.index -> builder.allowedRepositoryUpdates =
                    deserializer.deserializeMap(ALLOWEDREPOSITORYUPDATES_DESCRIPTOR) {
                        val map0 = mutableMapOf>>()
                        while (hasNextEntry()) {
                            val k0 = PackageGroupOriginRestrictionType.fromValue(key())
                            val v0 =
                                if (nextHasValue()) {
                                    deserializer.deserializeMap(ALLOWEDREPOSITORYUPDATES_C0_DESCRIPTOR) {
                                        val map1 = mutableMapOf>()
                                        while (hasNextEntry()) {
                                            val k1 = PackageGroupAllowedRepositoryUpdateType.fromValue(key())
                                            val v1 =
                                                if (nextHasValue()) {
                                                    deserializer.deserializeList(ALLOWEDREPOSITORYUPDATES_C1_DESCRIPTOR) {
                                                        val col2 = mutableListOf()
                                                        while (hasNextElement()) {
                                                            val el2 = if (nextHasValue()) { deserializeString() } else { deserializeNull(); continue }
                                                            col2.add(el2)
                                                        }
                                                        col2
                                                    }
                                                } else { deserializeNull(); continue }

                                            map1[k1] = v1
                                        }
                                        map1
                                    }
                                } else { deserializeNull(); continue }

                            map0[k0] = v0
                        }
                        map0
                    }
                PACKAGEGROUP_DESCRIPTOR.index -> builder.packageGroup = deserializePackageGroupDescriptionDocument(deserializer)
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy