Skip to content

Commit 7d3b0ea

Browse files
author
David Hasani
committed
address comment
1 parent f2e440b commit 7d3b0ea

File tree

11 files changed

+146
-62
lines changed

11 files changed

+146
-62
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.utils.isValidCode
5050
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.pollTransformationStatusAndPlan
5151
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.toTransformationLanguage
5252
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.CodeWhispererCodeScanSession
53+
import software.aws.toolkits.jetbrains.utils.notifyStickyInfo
5354
import software.aws.toolkits.resources.message
5455
import java.io.File
5556
import java.io.FileInputStream
@@ -269,7 +270,8 @@ class CodeModernizerSession(
269270
} finally {
270271
telemetry.uploadProject(payloadSize, startTime, true, telemetryErrorMessage)
271272
if (payload != null) {
272-
deleteUploadArtifact(payload)
273+
// TO-DO: revert
274+
// deleteUploadArtifact(payload)
273275
}
274276
}
275277

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private val confirmUserSelectionSQLConversionModuleSchemaButton = Button(
6060
private val confirmUserSelectionSQLConversionMetadataButton = Button(
6161
keepCardAfterClick = true,
6262
waitMandatoryFormItems = true,
63-
text = message("codemodernizer.chat.message.button.select"),
63+
text = message("codemodernizer.chat.message.button.select_sql_metadata"),
6464
id = CodeTransformButtonId.SelectSQLMetadata.id,
6565
)
6666

@@ -229,7 +229,7 @@ private fun getUserHilSelectionMarkdown(dependencyName: String, currentVersion:
229229
""".trimIndent()
230230

231231
fun buildChooseTransformationObjectiveChatContent() = CodeTransformChatMessageContent(
232-
message = "Choose your transformation objective",
232+
message = message("codemodernizer.chat.message.choose_objective"),
233233
type = CodeTransformChatMessageType.FinalizedAnswer,
234234
)
235235

@@ -334,12 +334,12 @@ fun buildModuleSchemaFormChatContent(project: Project, javaModules: List<Virtual
334334

335335
fun buildModuleSchemaFormIntroChatContent() = CodeTransformChatMessageContent(
336336
type = CodeTransformChatMessageType.FinalizedAnswer,
337-
message = "I can convert your embedded SQL, but I need some more info from you first.",
337+
message = message("codemodernizer.chat.message.sql_module_schema_prompt"),
338338
)
339339

340340
fun buildSQLMetadataValidationSuccessIntroChatContent() = CodeTransformChatMessageContent(
341341
type = CodeTransformChatMessageType.FinalizedAnswer,
342-
message = "I detected the following in your .sct metadata file.",
342+
message = message("codemodernizer.chat.message.sql_metadata_success"),
343343
)
344344

345345
fun buildSQLMetadataValidationSuccessDetailsChatContent(validationResult: SqlMetadataValidationResult) = CodeTransformChatMessageContent(

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class CodeTransformChatController(
162162
private suspend fun getUserObjective(tabId: String) {
163163
codeTransformChatHelper.addNewMessage(buildChooseTransformationObjectiveChatContent())
164164
codeTransformChatHelper.sendChatInputEnabledMessage(tabId, true)
165-
codeTransformChatHelper.sendUpdatePlaceholderMessage(tabId, "Enter 'language upgrade' or 'SQL conversion'")
165+
codeTransformChatHelper.sendUpdatePlaceholderMessage(tabId, message("codemodernizer.chat.message.choose_objective"))
166166
}
167167

168168
private suspend fun validateAndReplyOnError(transformationType: CodeTransformType): ValidationResult? {
@@ -310,12 +310,13 @@ class CodeTransformChatController(
310310
override suspend fun processCodeTransformSelectSQLMetadataAction(message: IncomingCodeTransformMessage.CodeTransformSelectSQLMetadata) {
311311
runInEdt {
312312
val descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor()
313-
.withDescription("Select metadata ZIP file")
313+
.withDescription("Upload metadata file")
314314
.withFileFilter { it.extension == "zip" }
315315

316316
val selectedZipFile = FileChooser.chooseFile(descriptor, null, null) ?: return@runInEdt
317-
val extractedZip = createTempDirectory("codeTransformSQLMetadata", null) // .path.toVirtualFile()
318-
unzipFile(selectedZipFile.toNioPath(), extractedZip.toPath())
317+
val extractedZip = createTempDirectory("codeTransformSQLMetadata", null)
318+
319+
unzipFile(selectedZipFile.toNioPath(), extractedZip.toPath(), true)
319320

320321
val sctFile = extractedZip.listFiles { file -> file.name.endsWith(".sct") }.firstOrNull()
321322

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/CodeModernizerSessionContext.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.toolwindow.CodeMo
2626
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getPathToHilArtifactPomFolder
2727
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getPathToHilDependenciesRootDir
2828
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getPathToHilUploadZip
29+
import software.aws.toolkits.jetbrains.utils.notifyStickyInfo
2930
import software.aws.toolkits.resources.message
3031
import java.io.File
3132
import java.io.IOException
@@ -51,6 +52,8 @@ const val MAVEN_BUILD_RUN_UNIT_TESTS = "clean test"
5152
const val MAVEN_BUILD_SKIP_UNIT_TESTS = "clean test-compile"
5253
const val MAVEN_DEFAULT_BUILD_DIRECTORY_NAME = "target"
5354
const val IDEA_DIRECTORY_NAME = ".idea"
55+
const val GIT_DIRECTORY_NAME = ".git"
56+
const val DS_STORE_FILE_NAME = ".DS_Store"
5457
const val INVALID_SUFFIX_SHA = "sha1"
5558
const val INVALID_SUFFIX_REPOSITORIES = "repositories"
5659
const val ORACLE_DB = "ORACLE"
@@ -69,26 +72,25 @@ data class CodeModernizerSessionContext(
6972
private val mapper = jacksonObjectMapper()
7073
private val ignoredDependencyFileExtensions = setOf(INVALID_SUFFIX_SHA, INVALID_SUFFIX_REPOSITORIES)
7174

72-
fun File.isMavenTargetFolder(): Boolean {
75+
private fun File.isMavenTargetFolder(): Boolean {
7376
val hasPomSibling = this.resolveSibling(MAVEN_CONFIGURATION_FILE_NAME).exists()
7477
val isMavenTargetDirName = this.isDirectory && this.name == MAVEN_DEFAULT_BUILD_DIRECTORY_NAME
7578
return isMavenTargetDirName && hasPomSibling
7679
}
7780

78-
fun File.isIdeaFolder(): Boolean {
79-
val isIdea = this.isDirectory && this.name == IDEA_DIRECTORY_NAME
80-
return isIdea
81-
}
81+
private fun File.isIdeaFolder(): Boolean = this.isDirectory && this.name == IDEA_DIRECTORY_NAME
82+
83+
private fun File.isGitFolder(): Boolean = this.isDirectory && this.name == GIT_DIRECTORY_NAME
8284

8385
private fun findDirectoriesToExclude(sourceFolder: File): List<File> {
8486
val excluded = mutableListOf<File>()
8587
sourceFolder.walkTopDown().onEnter {
86-
if (it.isMavenTargetFolder() || it.isIdeaFolder()) {
88+
if (it.isMavenTargetFolder() || it.isIdeaFolder() || it.isGitFolder()) {
8789
excluded.add(it)
8890
return@onEnter false
8991
}
9092
return@onEnter true
91-
}.forEach {
93+
}.forEach { _ ->
9294
// noop, collects the sequence
9395
}
9496
return excluded
@@ -202,7 +204,7 @@ data class CodeModernizerSessionContext(
202204
val files = root?.let {
203205
VfsUtil.collectChildrenRecursively(it).filter { child ->
204206
val childPath = Path(child.path)
205-
!child.isDirectory && directoriesToExclude.none { dir -> childPath.startsWith(dir.toPath()) }
207+
!child.isDirectory && !child.name.endsWith(DS_STORE_FILE_NAME) && directoriesToExclude.none { dir -> childPath.startsWith(dir.toPath()) }
206208
}
207209
}
208210
val dependencyFiles = if (depDirectory != null) {

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/CustomerSelection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ data class CustomerSelection(
1111
val configurationFile: VirtualFile? = null, // used to ZIP module
1212
val sourceJavaVersion: JavaSdkVersion, // always needed, use default of JDK_8 for SQL conversions for startJob API call
1313
val targetJavaVersion: JavaSdkVersion = JavaSdkVersion.JDK_17,
14-
val sourceVendor: String = "ORACLE", // only one supported
14+
val sourceVendor: String = ORACLE_DB, // only one supported
1515
val targetVendor: String? = null,
1616
val sourceServerName: String? = null,
1717
val sqlMetadataZip: File? = null,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.services.codemodernizer.model
5+
6+
import com.fasterxml.jackson.annotation.JsonProperty
7+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
8+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
9+
10+
@JacksonXmlRootElement(localName = "tree")
11+
data class SctMetadata(
12+
@JsonProperty("instances")
13+
val instances: Instances
14+
)
15+
16+
data class Instances(
17+
@JsonProperty("ProjectModel")
18+
val projectModel: ProjectModel
19+
)
20+
21+
data class ProjectModel(
22+
@JsonProperty("entities")
23+
val entities: Entities,
24+
@JsonProperty("relations")
25+
val relations: Relations,
26+
)
27+
28+
data class Entities(
29+
@JsonProperty("sources")
30+
val sources: Sources,
31+
@JsonProperty("targets")
32+
val targets: Targets,
33+
)
34+
35+
data class Sources(
36+
@JsonProperty("DbServer")
37+
val dbServer: DbServer,
38+
)
39+
40+
data class Targets(
41+
@JsonProperty("DbServer")
42+
val dbServer: DbServer,
43+
)
44+
45+
data class DbServer(
46+
@JsonProperty("vendor")
47+
val vendor: String,
48+
@JsonProperty("name")
49+
val name: String,
50+
)
51+
52+
data class Relations(
53+
@JsonProperty("server-node-location")
54+
@JacksonXmlElementWrapper(useWrapping = false)
55+
val serverNodeLocation: List<ServerNodeLocation>,
56+
)
57+
58+
data class ServerNodeLocation(
59+
@JsonProperty("FullNameNodeInfoList")
60+
val fullNameNodeInfoList: FullNameNodeInfoList,
61+
)
62+
63+
data class FullNameNodeInfoList(
64+
@JsonProperty("nameParts")
65+
val nameParts: NameParts,
66+
)
67+
68+
data class NameParts(
69+
@JsonProperty("FullNameNodeInfo")
70+
@JacksonXmlElementWrapper(useWrapping = false)
71+
val fullNameNodeInfo: List<FullNameNodeInfo>,
72+
)
73+
74+
data class FullNameNodeInfo(
75+
@JsonProperty("typeNode")
76+
val typeNode: String,
77+
@JsonProperty("nameNode")
78+
val nameNode: String,
79+
)

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/ZipManifest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ data class ZipManifest(
1111
val hilCapabilities: List<String> = listOf(HIL_1P_UPGRADE_CAPABILITY),
1212
val transformCapabilities: List<String> = listOf(EXPLAINABILITY_V1),
1313
val customBuildCommand: String = MAVEN_BUILD_RUN_UNIT_TESTS,
14-
val requestedConversions: RequestedConversions = RequestedConversions(sqlConversion = null),
14+
val requestedConversions: RequestedConversions? = null, // only used for SQL conversions for now
1515
)
1616

1717
data class RequestedConversions(

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

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
package software.aws.toolkits.jetbrains.services.codemodernizer.utils
55

6-
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule
6+
import com.fasterxml.jackson.databind.DeserializationFeature
77
import com.fasterxml.jackson.dataformat.xml.XmlMapper
8+
import com.fasterxml.jackson.module.kotlin.readValue
9+
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
810
import com.intellij.openapi.application.runReadAction
911
import com.intellij.openapi.fileEditor.FileDocumentManager
1012
import com.intellij.openapi.util.io.FileUtil
@@ -26,8 +28,10 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.constants.HIL_UPL
2628
import software.aws.toolkits.jetbrains.services.codemodernizer.controller.CodeTransformChatController
2729
import software.aws.toolkits.jetbrains.services.codemodernizer.model.DependencyUpdatesReport
2830
import software.aws.toolkits.jetbrains.services.codemodernizer.model.MAVEN_CONFIGURATION_FILE_NAME
31+
import software.aws.toolkits.jetbrains.services.codemodernizer.model.SctMetadata
2932
import software.aws.toolkits.jetbrains.services.codemodernizer.model.SqlMetadataValidationResult
3033
import software.aws.toolkits.jetbrains.services.codewhisperer.util.content
34+
import software.aws.toolkits.jetbrains.utils.notifyStickyInfo
3135
import software.aws.toolkits.resources.message
3236
import java.io.File
3337
import java.io.FileOutputStream
@@ -109,14 +113,20 @@ fun parseBuildFile(buildFile: VirtualFile?): String? {
109113
/**
110114
* Unzips a zip into a dir. Returns the true when successfully unzips the file pointed to by [zipFilePath] to [destDir]
111115
*/
112-
fun unzipFile(zipFilePath: Path, destDir: Path): Boolean {
116+
fun unzipFile(zipFilePath: Path, destDir: Path, isSqlMetadata: Boolean = false): Boolean {
113117
if (!zipFilePath.exists()) return false
114118
val zipFile = ZipFile(zipFilePath.toFile())
115119
zipFile.use { file ->
116120
file.entries().asSequence()
117121
.filterNot { it.isDirectory }
118122
.map { zipEntry ->
119-
val destPath = destDir.resolve(zipEntry.name)
123+
var fileName = zipEntry.name
124+
if (isSqlMetadata) {
125+
// when manually compressing ZIP files, the files get unzipped under a subdirectory where we extract them to,
126+
// this change puts the files directly under the root of the target directory, which is what we want
127+
fileName = zipEntry.name.substringAfterLast(File.separatorChar)
128+
}
129+
val destPath = destDir.resolve(fileName)
120130
destPath.createParentDirectories()
121131
FileOutputStream(destPath.toFile()).use { targetFile ->
122132
zipFile.getInputStream(zipEntry).copyTo(targetFile)
@@ -137,57 +147,44 @@ fun validateSctMetadata(sctFile: File?): SqlMetadataValidationResult {
137147
if (sctFile == null) {
138148
return SqlMetadataValidationResult(false, message("codemodernizer.chat.message.validation.error.missing_sct_file"))
139149
}
140-
val fileContent = sctFile.readBytes().toString(Charsets.UTF_8)
141-
val xmlDeserializer = XmlMapper(JacksonXmlModule())
142-
var sctMetadata: Map<*, *>? = null
150+
151+
val xmlMapper = XmlMapper().registerKotlinModule().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
152+
153+
val sctMetadata: SctMetadata
143154
try {
144-
sctMetadata = xmlDeserializer.readValue(fileContent, Any::class.java) as Map<*, *>
155+
sctMetadata = xmlMapper.readValue<SctMetadata>(sctFile)
145156
} catch (e: Exception) {
146157
getLogger<CodeTransformChatController>().error { "Error parsing .sct metadata file; invalid XML encountered." }
147158
return SqlMetadataValidationResult(false, message("codemodernizer.chat.message.validation.error.invalid_sct"))
148159
}
149160

150161
try {
151-
val instances = sctMetadata["instances"] as Map<*, *>
152-
val projectModel = instances["ProjectModel"] as Map<*, *>
153-
val entities = projectModel["entities"] as Map<*, *>
154-
155-
val sources = entities["sources"] as Map<*, *>
156-
val sourceDbServer = sources["DbServer"] as Map<*, *>
157-
val sourceVendor = (sourceDbServer["vendor"] as String).trim().uppercase()
162+
val projectModel = sctMetadata.instances.projectModel
163+
val sourceDbServer = projectModel.entities.sources.dbServer
164+
val sourceVendor = sourceDbServer.vendor.trim().uppercase()
158165
if (sourceVendor != "ORACLE") {
159166
return SqlMetadataValidationResult(false, message("codemodernizer.chat.message.validation.error.invalid_source_db"))
160167
}
161168

162-
val sourceServerName = (sourceDbServer["name"] as String).trim()
169+
val sourceServerName = sourceDbServer.name.trim()
163170

164-
val targets = entities["targets"] as Map<*, *>
165-
val targetDbServer = targets["DbServer"] as Map<*, *>
166-
val targetVendor = (targetDbServer["vendor"] as String).trim().uppercase()
171+
val targetDbServer = projectModel.entities.targets.dbServer
172+
val targetVendor = targetDbServer.vendor.trim().uppercase()
167173
if (targetVendor != "AURORA_POSTGRESQL" && targetVendor != "RDS_POSTGRESQL") {
168174
return SqlMetadataValidationResult(false, message("codemodernizer.chat.message.validation.error.invalid_target_db"))
169175
}
170176

171-
val relations = projectModel["relations"] as Map<*, *>
172-
val serverNodeLocations = relations["server-node-location"] as List<Map<*, *>>
173177
val schemaNames = mutableSetOf<String>()
174-
for (serverNodeLocation in serverNodeLocations) {
175-
val fullNameNodeInfoList = serverNodeLocation["FullNameNodeInfoList"] as Map<*, *>
176-
val nameParts = fullNameNodeInfoList["nameParts"] as Map<*, *>
177-
var fullNameNodeInfo = nameParts["FullNameNodeInfo"]
178-
if (fullNameNodeInfo is Map<*, *>) {
179-
continue
180-
} else {
181-
fullNameNodeInfo = fullNameNodeInfo as List<Map<*, *>>
182-
}
183-
fullNameNodeInfo.forEach { node ->
184-
if ((node["typeNode"] as String).lowercase() == "schema") {
185-
schemaNames.add((node["nameNode"] as String).uppercase()) // user will choose one later
178+
projectModel.relations.serverNodeLocation.forEach { serverNodeLocation ->
179+
val fullNameNodeInfoList = serverNodeLocation.fullNameNodeInfoList.nameParts.fullNameNodeInfo
180+
fullNameNodeInfoList.forEach { node ->
181+
if (node.typeNode.lowercase() == "schema") {
182+
schemaNames.add(node.nameNode.uppercase())
186183
}
187184
}
188185
}
189-
// .sct metadata file is valid, return SqlMetadataValidationResult with all data we parsed
190-
return SqlMetadataValidationResult(true, "", sourceVendor, targetVendor, sourceServerName, schemaNames)
186+
notifyStickyInfo("successfully parsed .sct file", "$sourceVendor, $targetVendor, $sourceServerName, $schemaNames")
187+
return SqlMetadataValidationResult(true, "", sourceVendor, targetVendor, sourceServerName!!, schemaNames)
191188
} catch (e: Exception) {
192189
getLogger<CodeTransformChatController>().error { "Error parsing .sct metadata file: $e" }
193190
return SqlMetadataValidationResult(false, message("codemodernizer.chat.message.validation.error.invalid_sct"))

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererConstants.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ object CodeWhispererConstants {
119119
}
120120

121121
object Config {
122-
const val CODEWHISPERER_ENDPOINT = "https://codewhisperer.us-east-1.amazonaws.com/" // PROD
122+
const val CODEWHISPERER_ENDPOINT = "https://rts.gamma-us-east-1.codewhisperer.ai.aws.dev/" // PROD
123123
const val CODEWHISPERER_IDPOOL_ID = "us-east-1:70717e99-906f-4add-908c-bd9074a2f5b9"
124124
val Sigv4ClientRegion = Region.US_EAST_1
125125
val BearerClientRegion = Region.US_EAST_1

plugins/amazonq/mynah-ui/src/mynah-ui/ui/tabs/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class TabDataGenerator {
3131
])
3232

3333
// feature flag for SQL transformations
34-
private isSQLTransformReady: boolean = false
34+
private isSQLTransformReady: boolean = true
3535

3636
private tabWelcomeMessage: Map<TabType, string> = new Map([
3737
[

0 commit comments

Comments
 (0)