Skip to content

Commit

Permalink
add Kotlin lintered files
Browse files Browse the repository at this point in the history
  • Loading branch information
scmacdon committed Jun 11, 2024
1 parent 523dab6 commit 0948d7f
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 232 deletions.
4 changes: 2 additions & 2 deletions kotlin/services/translate/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ repositories {
}
apply(plugin = "org.jlleitschuh.gradle.ktlint")
dependencies {
implementation("aws.sdk.kotlin:translate:1.0.30")
implementation("aws.sdk.kotlin:secretsmanager:1.0.30")
implementation("aws.sdk.kotlin:translate:1.2.28")
implementation("aws.sdk.kotlin:secretsmanager:1.2.28")
implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0")
implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0")
implementation("com.google.code.gson:gson:2.10")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,108 +1,109 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.translate

// snippet-start:[translate.kotlin._batch.import]
import aws.sdk.kotlin.services.translate.TranslateClient
import aws.sdk.kotlin.services.translate.model.DescribeTextTranslationJobRequest
import aws.sdk.kotlin.services.translate.model.InputDataConfig
import aws.sdk.kotlin.services.translate.model.OutputDataConfig
import aws.sdk.kotlin.services.translate.model.StartTextTranslationJobRequest
import kotlinx.coroutines.delay
import kotlin.system.exitProcess
// snippet-end:[translate.kotlin._batch.import]

/**
Before running this Kotlin code example, set up your development environment,
including your credentials.
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main(args: Array<String>) {

val usage = """
Usage:
<s3Uri> <s3UriOut> <jobName> <dataAccessRoleArn>
Where:
s3Uri - The URI of the Amazon S3 bucket where the documents to translate are located.
s3UriOut - The URI of the Amazon S3 bucket where the translated documents are saved to.
jobName - The job name.
dataAccessRoleArn - The Amazon Resource Name (ARN) value of the role required for translation jobs.
"""

if (args.size != 4) {
println(usage)
exitProcess(0)
}

val s3Uri = args[0]
val s3UriOut = args[1]
val jobName = args[2]
val dataAccessRoleArn = args[3]
translateDocuments(s3Uri, s3UriOut, jobName, dataAccessRoleArn)
}

// snippet-start:[translate.kotlin._batch.main]
suspend fun translateDocuments(
s3UriVal: String?,
s3UriOutVal: String?,
jobNameVal: String?,
dataAccessRoleArnVal: String?
): String? {

val sleepTime: Long = 5
val dataConfig = InputDataConfig {
s3Uri = s3UriVal
contentType = "text/plain"
}

val outputDataConfigVal = OutputDataConfig {
s3Uri = s3UriOutVal
}

val myList = mutableListOf<String>()
myList.add("fr")

val textTranslationJobRequest = StartTextTranslationJobRequest {
jobName = jobNameVal
dataAccessRoleArn = dataAccessRoleArnVal
inputDataConfig = dataConfig
outputDataConfig = outputDataConfigVal
sourceLanguageCode = "en"
targetLanguageCodes = myList
}

TranslateClient { region = "us-west-2" }.use { translateClient ->
val textTranslationJobResponse = translateClient.startTextTranslationJob(textTranslationJobRequest)

// Keep checking until job is done.
val jobDone = false
var jobStatus: String
val jobIdVal: String? = textTranslationJobResponse.jobId

val jobRequest = DescribeTextTranslationJobRequest {
jobId = jobIdVal
}

while (!jobDone) {

// Check status on each loop.
val response = translateClient.describeTextTranslationJob(jobRequest)
jobStatus = response.textTranslationJobProperties?.jobStatus.toString()
println(jobStatus)

if (jobStatus.contains("COMPLETED"))
break
else {
print(".")

delay(sleepTime * 1000)
}
}
return textTranslationJobResponse.jobId
}
}
// snippet-end:[translate.kotlin._batch.main]
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.translate

// snippet-start:[translate.kotlin._batch.import]
import aws.sdk.kotlin.services.translate.TranslateClient
import aws.sdk.kotlin.services.translate.model.DescribeTextTranslationJobRequest
import aws.sdk.kotlin.services.translate.model.InputDataConfig
import aws.sdk.kotlin.services.translate.model.OutputDataConfig
import aws.sdk.kotlin.services.translate.model.StartTextTranslationJobRequest
import kotlinx.coroutines.delay
import kotlin.system.exitProcess
// snippet-end:[translate.kotlin._batch.import]

/**
Before running this Kotlin code example, set up your development environment,
including your credentials.
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main(args: Array<String>) {
val usage = """
Usage:
<s3Uri> <s3UriOut> <jobName> <dataAccessRoleArn>
Where:
s3Uri - The URI of the Amazon S3 bucket where the documents to translate are located.
s3UriOut - The URI of the Amazon S3 bucket where the translated documents are saved to.
jobName - The job name.
dataAccessRoleArn - The Amazon Resource Name (ARN) value of the role required for translation jobs.
"""

if (args.size != 4) {
println(usage)
exitProcess(0)
}

val s3Uri = args[0]
val s3UriOut = args[1]
val jobName = args[2]
val dataAccessRoleArn = args[3]
translateDocuments(s3Uri, s3UriOut, jobName, dataAccessRoleArn)
}

// snippet-start:[translate.kotlin._batch.main]
suspend fun translateDocuments(
s3UriVal: String?,
s3UriOutVal: String?,
jobNameVal: String?,
dataAccessRoleArnVal: String?
): String? {
val sleepTime: Long = 5
val dataConfig =
InputDataConfig {
s3Uri = s3UriVal
contentType = "text/plain"
}

val outputDataConfigVal =
OutputDataConfig {
s3Uri = s3UriOutVal
}

val myList = mutableListOf<String>()
myList.add("fr")

val textTranslationJobRequest =
StartTextTranslationJobRequest {
jobName = jobNameVal
dataAccessRoleArn = dataAccessRoleArnVal
inputDataConfig = dataConfig
outputDataConfig = outputDataConfigVal
sourceLanguageCode = "en"
targetLanguageCodes = myList
}

TranslateClient { region = "us-west-2" }.use { translateClient ->
val textTranslationJobResponse = translateClient.startTextTranslationJob(textTranslationJobRequest)

// Keep checking until job is done.
val jobDone = false
var jobStatus: String
val jobIdVal: String? = textTranslationJobResponse.jobId

val jobRequest =
DescribeTextTranslationJobRequest {
jobId = jobIdVal
}

while (!jobDone) {
// Check status on each loop.
val response = translateClient.describeTextTranslationJob(jobRequest)
jobStatus = response.textTranslationJobProperties?.jobStatus.toString()
println(jobStatus)

if (jobStatus.contains("COMPLETED")) {
break
} else {
print(".")

delay(sleepTime * 1000)
}
}
return textTranslationJobResponse.jobId
}
}
// snippet-end:[translate.kotlin._batch.main]
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.translate

// snippet-start:[translate.kotlin._describe_jobs.import]
import aws.sdk.kotlin.services.translate.TranslateClient
import aws.sdk.kotlin.services.translate.model.DescribeTextTranslationJobRequest
import kotlin.system.exitProcess
// snippet-end:[translate.kotlin._describe_jobs.import]

/**
Before running this Kotlin code example, set up your development environment,
including your credentials.
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main(args: Array<String>) {

val usage = """
Usage:
<jobId>
Where:
jobId - A translation job ID value. You can obtain this value from the BatchTranslation example.
"""

if (args.size != 1) {
println(usage)
exitProcess(0)
}

val jobId = args[0]
describeTranslationJob(jobId)
}

// snippet-start:[translate.kotlin._describe_jobs.main]
suspend fun describeTranslationJob(id: String?) {

val textTranslationJobRequest = DescribeTextTranslationJobRequest {
jobId = id!!
}

TranslateClient { region = "us-west-2" }.use { translateClient ->
val jobResponse = translateClient.describeTextTranslationJob(textTranslationJobRequest)
println("The job status is ${jobResponse.textTranslationJobProperties?.jobStatus}.")
}
}
// snippet-end:[translate.kotlin._describe_jobs.main]
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.translate

// snippet-start:[translate.kotlin._describe_jobs.import]
import aws.sdk.kotlin.services.translate.TranslateClient
import aws.sdk.kotlin.services.translate.model.DescribeTextTranslationJobRequest
import kotlin.system.exitProcess
// snippet-end:[translate.kotlin._describe_jobs.import]

/**
Before running this Kotlin code example, set up your development environment,
including your credentials.
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main(args: Array<String>) {
val usage = """
Usage:
<jobId>
Where:
jobId - A translation job ID value. You can obtain this value from the BatchTranslation example.
"""

if (args.size != 1) {
println(usage)
exitProcess(0)
}

val jobId = args[0]
describeTranslationJob(jobId)
}

// snippet-start:[translate.kotlin._describe_jobs.main]
suspend fun describeTranslationJob(id: String?) {
val textTranslationJobRequest =
DescribeTextTranslationJobRequest {
jobId = id!!
}

TranslateClient { region = "us-west-2" }.use { translateClient ->
val jobResponse = translateClient.describeTextTranslationJob(textTranslationJobRequest)
println("The job status is ${jobResponse.textTranslationJobProperties?.jobStatus}.")
}
}
// snippet-end:[translate.kotlin._describe_jobs.main]
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ suspend fun main() {

// snippet-start:[translate.kotlin._list_jobs.main]
suspend fun getTranslationJobs() {

val textTranslationJobsRequest = ListTextTranslationJobsRequest {
maxResults = 10
}
val textTranslationJobsRequest =
ListTextTranslationJobsRequest {
maxResults = 10
}

TranslateClient { region = "us-west-2" }.use { translateClient ->
val response = translateClient.listTextTranslationJobs(textTranslationJobsRequest)
Expand Down
Loading

0 comments on commit 0948d7f

Please sign in to comment.