Skip to content

Commit 2858151

Browse files
author
David Hasani
committed
address final 11/18 comments
1 parent da97538 commit 2858151

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import com.intellij.openapi.module.ModuleUtil
1111
import com.intellij.openapi.projectRoots.JavaSdkVersion
1212
import com.intellij.openapi.util.io.FileUtil.createTempDirectory
1313
import com.intellij.openapi.vfs.VirtualFile
14-
import kotlinx.coroutines.CoroutineScope
1514
import kotlinx.coroutines.delay
16-
import kotlinx.coroutines.launch
1715
import kotlinx.coroutines.runBlocking
16+
import kotlinx.coroutines.withContext
1817
import software.aws.toolkits.core.utils.debug
1918
import software.aws.toolkits.core.utils.error
2019
import software.aws.toolkits.core.utils.getLogger
@@ -322,12 +321,12 @@ class CodeTransformChatController(
322321
}
323322

324323
override suspend fun processCodeTransformSelectSQLMetadataAction(message: IncomingCodeTransformMessage.CodeTransformSelectSQLMetadata) {
325-
runInEdt {
324+
withContext(EDT) {
326325
val descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor()
327326
.withDescription("Select metadata file")
328327
.withFileFilter { it.extension == "zip" }
329328

330-
val selectedZipFile = FileChooser.chooseFile(descriptor, null, null) ?: return@runInEdt
329+
val selectedZipFile = FileChooser.chooseFile(descriptor, null, null) ?: return@withContext
331330
val extractedZip = createTempDirectory("codeTransformSQLMetadata", null)
332331

333332
unzipFile(selectedZipFile.toNioPath(), extractedZip.toPath(), true)
@@ -337,36 +336,32 @@ class CodeTransformChatController(
337336
val metadataValidationResult = validateSctMetadata(sctFile)
338337

339338
if (!metadataValidationResult.valid) {
340-
CoroutineScope(EDT).launch {
341-
codeTransformChatHelper.run {
342-
addNewMessage(buildSQLMetadataValidationErrorChatContent(metadataValidationResult.errorReason))
343-
addNewMessage(buildStartNewTransformFollowup())
344-
}
339+
codeTransformChatHelper.run {
340+
addNewMessage(buildSQLMetadataValidationErrorChatContent(metadataValidationResult.errorReason))
341+
addNewMessage(buildStartNewTransformFollowup())
345342
}
346-
return@runInEdt
343+
return@withContext
347344
}
348345

349-
CoroutineScope(EDT).launch {
350-
codeTransformChatHelper.run {
351-
addNewMessage(buildSQLMetadataValidationSuccessIntroChatContent())
352-
addNewMessage(buildSQLMetadataValidationSuccessDetailsChatContent(metadataValidationResult))
353-
addNewMessage(buildModuleSchemaFormIntroChatContent())
354-
addNewMessage(
355-
buildModuleSchemaFormChatContent(context.project, context.project.getJavaModulesWithSQL(), metadataValidationResult.schemaOptions)
356-
)
357-
}
358-
val selection = CustomerSelection(
359-
// for SQL conversions (no sourceJavaVersion), use dummy value of Java 8 so that startJob API can be called
360-
sourceJavaVersion = JavaSdkVersion.JDK_1_8,
361-
targetJavaVersion = JavaSdkVersion.JDK_17,
362-
sourceVendor = metadataValidationResult.sourceVendor,
363-
targetVendor = metadataValidationResult.targetVendor,
364-
sourceServerName = metadataValidationResult.sourceServerName,
365-
sqlMetadataZip = extractedZip,
346+
codeTransformChatHelper.run {
347+
addNewMessage(buildSQLMetadataValidationSuccessIntroChatContent())
348+
addNewMessage(buildSQLMetadataValidationSuccessDetailsChatContent(metadataValidationResult))
349+
addNewMessage(buildModuleSchemaFormIntroChatContent())
350+
addNewMessage(
351+
buildModuleSchemaFormChatContent(context.project, context.project.getJavaModulesWithSQL(), metadataValidationResult.schemaOptions)
366352
)
367-
codeModernizerManager.createCodeModernizerSession(selection, context.project)
368-
telemetry.submitSelection("Confirm-SQL", selection)
369353
}
354+
val selection = CustomerSelection(
355+
// for SQL conversions (no sourceJavaVersion), use dummy value of Java 8 so that startJob API can be called
356+
sourceJavaVersion = JavaSdkVersion.JDK_1_8,
357+
targetJavaVersion = JavaSdkVersion.JDK_17,
358+
sourceVendor = metadataValidationResult.sourceVendor,
359+
targetVendor = metadataValidationResult.targetVendor,
360+
sourceServerName = metadataValidationResult.sourceServerName,
361+
sqlMetadataZip = extractedZip,
362+
)
363+
codeModernizerManager.createCodeModernizerSession(selection, context.project)
364+
telemetry.submitSelection("Confirm-SQL", selection)
370365
}
371366
}
372367

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fun validateSctMetadata(sctFile: File?): SqlMetadataValidationResult {
151151
try {
152152
sctMetadata = XML_MAPPER.readValue<SctMetadata>(sctFile)
153153
} catch (e: Exception) {
154-
getLogger<CodeTransformChatController>().error { "Error parsing .sct metadata file; invalid XML encountered. $e" }
154+
getLogger<CodeTransformChatController>().error { "Error parsing .sct metadata file; invalid XML encountered: ${e.localizedMessage}" }
155155
return SqlMetadataValidationResult(false, message("codemodernizer.chat.message.validation.error.invalid_sct"))
156156
}
157157

@@ -182,7 +182,7 @@ fun validateSctMetadata(sctFile: File?): SqlMetadataValidationResult {
182182
}
183183
return SqlMetadataValidationResult(true, "", sourceVendor, targetVendor, sourceServerName, schemaNames)
184184
} catch (e: Exception) {
185-
getLogger<CodeTransformChatController>().error { "Error parsing .sct metadata file: $e" }
185+
getLogger<CodeTransformChatController>().error { "Error parsing .sct metadata file: ${e.localizedMessage}" }
186186
return SqlMetadataValidationResult(false, message("codemodernizer.chat.message.validation.error.invalid_sct"))
187187
}
188188
}

plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ code.aws.workspaces.short=Dev Environments
564564
codemodernizer.builderrordialog.description.title=Error occurred when building your project
565565
codemodernizer.chat.form.user_selection.item.choose_module=Choose a module to transform
566566
codemodernizer.chat.form.user_selection.item.choose_skip_tests_option=Choose to skip unit tests
567-
codemodernizer.chat.form.user_selection.item.choose_sql_metadata_file=Okay, I can convert the embedded SQL code for your Oracle to PostgreSQL transformation. To get started, upload the zipped metadata file from your schema conversion in AWS Data Migration Service (DMS). To retrieve the metadata file:\n1. Open your database migration project in the AWS DMS console.\n2. Open the schema conversion and choose **Convert the embedded SQL in your application**.\n3. Choose the link to Amazon S3 console.\n\nYou can download the metadata file from the {schema-conversion-project}/ directory. For more info, refer to the [documentation](https://docs.aws.amazon.com/dms/latest/userguide/schema-conversion-save-apply.html#schema-conversion-save).
567+
codemodernizer.chat.form.user_selection.item.choose_sql_metadata_file=Okay, I can convert the embedded SQL code for your Oracle to PostgreSQL transformation. To get started, upload the zipped metadata file from your schema conversion in AWS Data Migration Service (DMS). To retrieve the metadata file:\n1. Open your database migration project in the AWS DMS console.\n2. Open the schema conversion and choose **Convert the embedded SQL in your application**.\n3. Once you complete the conversion, close the project and go to the S3 bucket where your project is stored.\n4. Open the folder and find the project folder ("sct-project").\n5. Download the object inside the project folder. This will be a zip file.\n\nFor more info, refer to the [documentation](https://docs.aws.amazon.com/dms/latest/userguide/schema-conversion-save-apply.html#schema-conversion-save).
568568
codemodernizer.chat.form.user_selection.item.choose_target_version=Choose the target code version
569569
codemodernizer.chat.form.user_selection.title=Q - Code transformation
570570
codemodernizer.chat.message.absolute_path_detected=I detected {0} potential absolute file path(s) in your {1} file: **{2}**. Absolute file paths might cause issues when I build your code. Any errors will show up in the build log.

0 commit comments

Comments
 (0)