Skip to content

Commit

Permalink
Fixing the issue when getting null field at translator, Update logPro…
Browse files Browse the repository at this point in the history
…cessorEnabled into True (#27)
  • Loading branch information
houmilen authored May 24, 2024
1 parent 984ed07 commit 050caaf
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 36 deletions.
1 change: 1 addition & 0 deletions aws-b2bi-capability/.rpdk-config
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"codegen_template_path": "guided_aws",
"protocolVersion": "2.0.0"
},
"logProcessorEnabled": "true",
"executableEntrypoint": "software.amazon.b2bi.capability.HandlerWrapperExecutable"
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import software.amazon.cloudformation.exceptions.CfnNotFoundException
import software.amazon.cloudformation.exceptions.CfnServiceInternalErrorException
import software.amazon.cloudformation.exceptions.CfnServiceLimitExceededException
import software.amazon.cloudformation.exceptions.CfnThrottlingException
import java.time.Instant
import java.util.*
import java.util.stream.Collectors
import java.util.stream.Stream
Expand Down Expand Up @@ -84,17 +85,21 @@ object Translator {
*/
fun translateFromReadResponse(response: GetCapabilityResponse): ResourceModel {
return ResourceModel.builder()
.capabilityId(response.capabilityId().ifEmpty { null })
.capabilityArn(response.capabilityArn().ifEmpty { null })
.name(response.name().ifEmpty { null })
.type(response.typeAsString().ifEmpty { null })
.configuration(response.configuration().toResourceCapabilityConfiguration())
.capabilityId(response.capabilityId().emptyToNull())
.capabilityArn(response.capabilityArn().emptyToNull())
.name(response.name().emptyToNull())
.type(response.typeAsString().emptyToNull())
.configuration(response.configuration()?.toResourceCapabilityConfiguration())
.instructionsDocuments(response.instructionsDocuments()?.map { it.toResourceS3Location() })
.createdAt(response.createdAt().toString().ifEmpty { null })
.modifiedAt(response.modifiedAt().toString().ifEmpty { null })
.createdAt(response.createdAt().emptyToNull())
.modifiedAt(response.modifiedAt().emptyToNull())
.build()
}

private fun String?.emptyToNull() = if (this.isNullOrEmpty()) null else this

private fun Instant?.emptyToNull() = if (this == null) null else this.toString()

/**
* Request to delete a resource
* @param model resource model
Expand Down
1 change: 1 addition & 0 deletions aws-b2bi-partnership/.rpdk-config
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"codegen_template_path": "guided_aws",
"protocolVersion": "2.0.0"
},
"logProcessorEnabled": "true",
"executableEntrypoint": "software.amazon.b2bi.partnership.HandlerWrapperExecutable"
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import software.amazon.cloudformation.exceptions.CfnNotFoundException
import software.amazon.cloudformation.exceptions.CfnServiceInternalErrorException
import software.amazon.cloudformation.exceptions.CfnServiceLimitExceededException
import software.amazon.cloudformation.exceptions.CfnThrottlingException
import java.time.Instant
import java.util.*
import java.util.stream.Collectors
import java.util.stream.Stream
Expand Down Expand Up @@ -77,19 +78,23 @@ object Translator {
*/
fun translateFromReadResponse(response: GetPartnershipResponse): ResourceModel {
return ResourceModel.builder()
.profileId(response.profileId().ifEmpty { null })
.partnershipId(response.partnershipId().ifEmpty { null })
.partnershipArn(response.partnershipArn().ifEmpty { null })
.name(response.name().ifEmpty { null })
.email(response.email().ifEmpty { null })
.phone(response.phone().ifEmpty { null })
.profileId(response.profileId().emptyToNull())
.partnershipId(response.partnershipId().emptyToNull())
.partnershipArn(response.partnershipArn().emptyToNull())
.name(response.name().emptyToNull())
.email(response.email().emptyToNull())
.phone(response.phone().emptyToNull())
.capabilities(response.capabilities())
.tradingPartnerId(response.tradingPartnerId().ifEmpty { null })
.createdAt(response.createdAt().toString().ifEmpty { null })
.modifiedAt(response.modifiedAt().toString().ifEmpty { null })
.tradingPartnerId(response.tradingPartnerId().emptyToNull())
.createdAt(response.createdAt().emptyToNull())
.modifiedAt(response.modifiedAt().emptyToNull())
.build()
}

private fun String?.emptyToNull() = if (this.isNullOrEmpty()) null else this

private fun Instant?.emptyToNull() = if (this == null) null else this.toString()

/**
* Request to delete a resource
* @param model resource model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import software.amazon.cloudformation.exceptions.CfnNotFoundException
import software.amazon.cloudformation.exceptions.CfnServiceInternalErrorException
import software.amazon.cloudformation.exceptions.CfnServiceLimitExceededException
import software.amazon.cloudformation.exceptions.CfnThrottlingException
import java.time.Instant

/**
* This class is a centralized placeholder for
Expand Down Expand Up @@ -70,19 +71,23 @@ object Translator {
*/
fun translateFromReadResponse(response: GetProfileResponse): ResourceModel {
return ResourceModel.builder()
.profileId(response.profileId().ifEmpty { null })
.profileArn(response.profileArn().ifEmpty { null })
.name(response.name().ifEmpty { null })
.email(response.email().ifEmpty { null })
.phone(response.phone().ifEmpty { null })
.businessName(response.businessName().ifEmpty { null })
.logging(response.loggingAsString().ifEmpty { null })
.logGroupName(response.logGroupName().ifEmpty { null })
.createdAt(response.createdAt().toString().ifEmpty { null })
.modifiedAt(response.modifiedAt().toString().ifEmpty { null })
.profileId(response.profileId().emptyToNull())
.profileArn(response.profileArn().emptyToNull())
.name(response.name().emptyToNull())
.email(response.email()?.emptyToNull())
.phone(response.phone().emptyToNull())
.businessName(response.businessName().emptyToNull())
.logging(response.loggingAsString().emptyToNull())
.logGroupName(response.logGroupName().emptyToNull())
.createdAt(response.createdAt().emptyToNull())
.modifiedAt(response.modifiedAt().emptyToNull())
.build()
}

private fun String?.emptyToNull() = if (this.isNullOrEmpty()) null else this

private fun Instant?.emptyToNull() = if (this == null) null else this.toString()

/**
* Request to delete a resource
* @param model resource model
Expand Down
1 change: 1 addition & 0 deletions aws-b2bi-transformer/.rpdk-config
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"codegen_template_path": "guided_aws",
"protocolVersion": "2.0.0"
},
"logProcessorEnabled": "true",
"executableEntrypoint": "software.amazon.b2bi.transformer.HandlerWrapperExecutable"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import software.amazon.awssdk.services.b2bi.model.AccessDeniedException
import software.amazon.awssdk.services.b2bi.model.ConflictException
import software.amazon.awssdk.services.b2bi.model.CreateTransformerRequest
import software.amazon.awssdk.services.b2bi.model.DeleteTransformerRequest
import software.amazon.awssdk.services.b2bi.model.FileFormat
import software.amazon.awssdk.services.b2bi.model.GetTransformerRequest
import software.amazon.awssdk.services.b2bi.model.GetTransformerResponse
import software.amazon.awssdk.services.b2bi.model.InternalServerException
Expand All @@ -14,6 +15,7 @@ import software.amazon.awssdk.services.b2bi.model.ResourceNotFoundException
import software.amazon.awssdk.services.b2bi.model.ServiceQuotaExceededException
import software.amazon.awssdk.services.b2bi.model.TagResourceRequest
import software.amazon.awssdk.services.b2bi.model.ThrottlingException
import software.amazon.awssdk.services.b2bi.model.TransformerStatus
import software.amazon.awssdk.services.b2bi.model.UntagResourceRequest
import software.amazon.awssdk.services.b2bi.model.UpdateTransformerRequest
import software.amazon.awssdk.services.b2bi.model.ValidationException
Expand All @@ -27,6 +29,7 @@ import software.amazon.cloudformation.exceptions.CfnNotFoundException
import software.amazon.cloudformation.exceptions.CfnServiceInternalErrorException
import software.amazon.cloudformation.exceptions.CfnServiceLimitExceededException
import software.amazon.cloudformation.exceptions.CfnThrottlingException
import java.time.Instant
import software.amazon.awssdk.services.b2bi.model.EdiType as SdkEdi
import software.amazon.awssdk.services.b2bi.model.X12Details as SdkX12
import software.amazon.b2bi.transformer.EdiType as ResourceEdi
Expand Down Expand Up @@ -73,19 +76,27 @@ object Translator {
*/
fun translateFromReadResponse(response: GetTransformerResponse): ResourceModel {
return ResourceModel.builder()
.transformerId(response.transformerId().ifEmpty { null })
.transformerArn(response.transformerArn().ifEmpty { null })
.name(response.name().ifEmpty { null })
.fileFormat(response.fileFormat().toString().ifEmpty { null })
.mappingTemplate(response.mappingTemplate().ifEmpty { null })
.sampleDocument(response.sampleDocument().ifEmpty { null })
.ediType(response.ediType().translateToResourceEdi())
.status(response.status().toString().ifEmpty { null })
.createdAt(response.createdAt().toString().ifEmpty { null })
.modifiedAt(if (response.modifiedAt() != null) response.modifiedAt().toString() else null)
.transformerId(response.transformerId().emptyToNull())
.transformerArn(response.transformerArn().emptyToNull())
.name(response.name().emptyToNull())
.fileFormat(response.fileFormat().emptyToNull())
.mappingTemplate(response.mappingTemplate().emptyToNull())
.sampleDocument(response.sampleDocument().emptyToNull())
.ediType(response.ediType()?.translateToResourceEdi())
.status(response.status().emptyToNull())
.createdAt(response.createdAt().emptyToNull())
.modifiedAt(response.modifiedAt().emptyToNull())
.build()
}

private fun String?.emptyToNull() = if (this.isNullOrEmpty()) null else this

private fun Instant?.emptyToNull() = if (this == null) null else this.toString()

private fun FileFormat?.emptyToNull() = if (this == null) null else this.toString()

private fun TransformerStatus?.emptyToNull() = if (this == null) null else this.toString()

/**
* Request to delete a resource
* @param model resource model
Expand Down

0 comments on commit 050caaf

Please sign in to comment.