From f67d4722f2626896f1491d8dd48c3b93b25916b8 Mon Sep 17 00:00:00 2001 From: Mykhailo Lytvyn Date: Sun, 7 Jan 2024 13:27:49 +0100 Subject: [PATCH] #933 | Added special translator modifiers `expr`, `version`, `system`, `class` --- CHANGELOG.md | 1 + .../constants/modifier/AttributeModifier.kt | 8 +++- .../documentation/ImpexDocumentationTarget.kt | 42 ++++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 182e4055d..474ded304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ - Parse and style password encoding prefixes as field value [#931](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/931) - Suggest the next available type code when there is no value [#923](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/923) - Improved code completion for `translator` modifier [#932](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/932) +- Added special translator modifiers `expr`, `version`, `system`, `class` [#933](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/933) ### `ImpEx` inspection rules - Inspect type set for `disable.UniqueAttributesValidator.for.types` type modifier [#896](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/896) diff --git a/src/com/intellij/idea/plugin/hybris/impex/constants/modifier/AttributeModifier.kt b/src/com/intellij/idea/plugin/hybris/impex/constants/modifier/AttributeModifier.kt index d573d9051..2551af7f6 100644 --- a/src/com/intellij/idea/plugin/hybris/impex/constants/modifier/AttributeModifier.kt +++ b/src/com/intellij/idea/plugin/hybris/impex/constants/modifier/AttributeModifier.kt @@ -31,7 +31,7 @@ import com.intellij.openapi.project.Project */ enum class AttributeModifier( override val modifierName: String, - private val modifierValues: Set = emptySet() + private val modifierValues: Set = emptySet(), ) : ImpexModifier { UNIQUE("unique", HybrisConstants.IMPEX_MODIFIER_BOOLEAN_VALUES), @@ -66,7 +66,11 @@ enum class AttributeModifier( TRANSLATOR("translator") { override fun getLookupElements(project: Project) = ImpexImplementationClassCompletionContributor.getInstance(project) .getImplementationsForClasses(*HybrisConstants.CLASS_FQN_IMPEX_TRANSLATORS) - }; + }, + EXPR("expr"), + SYSTEM("system"), + VERSION("version"), + CLASSIFICATION_CLASS("class"); override fun getLookupElements(project: Project): Set = modifierValues .map { ImpExLookupElementFactory.buildModifierValue(it) } diff --git a/src/com/intellij/idea/plugin/hybris/impex/lang/documentation/ImpexDocumentationTarget.kt b/src/com/intellij/idea/plugin/hybris/impex/lang/documentation/ImpexDocumentationTarget.kt index 666a16747..4b72ee4ce 100644 --- a/src/com/intellij/idea/plugin/hybris/impex/lang/documentation/ImpexDocumentationTarget.kt +++ b/src/com/intellij/idea/plugin/hybris/impex/lang/documentation/ImpexDocumentationTarget.kt @@ -1,5 +1,5 @@ /* - * This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. + * This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA. * Copyright (C) 2019-2024 EPAM Systems and contributors * * This program is free software: you can redistribute it and/or modify @@ -73,6 +73,46 @@ class ImpexDocumentationTarget(val element: PsiElement, private val originalElem ImpexTypes.ATTRIBUTE_NAME -> { when (element.text) { + AttributeModifier.EXPR.modifierName -> impexDoc { + typeModifier(element.text) + subHeader("VelocityTranslator") + externalLink( + "Special Value Translators", + "https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/aa417173fe4a4ba5a473c93eb730a417/4ce7b82cbc574456ac197393f88e5cc6.html?locale=en-US#special-value-translators" + ) + texts( + "The VelocityTranslator is used only for export. It can be used for exporting a value for an item using a velocity expression.", + "With that, you can export a constant value or can aggregate different attributes.", + "Using the following header at an export of an order item, the code of the order is exported as well as the id and name of the user owning the order and its payment address, street name, and country.", + ) + example(""" + INSERT_UPDATE Order; code[unique=true]; \ + @template1[translator=de.hybris.jakarta.ext.impex.jalo.translators.VelocityTranslator, expr='${"$"}item.user.getUID()']; \ + @template2[translator=de.hybris.jakarta.ext.impex.jalo.translators.VelocityTranslator, expr='${"$"}item.user.name']; + """.trimIndent()) + }.build() + + AttributeModifier.CLASSIFICATION_CLASS.modifierName, + AttributeModifier.SYSTEM.modifierName, + AttributeModifier.VERSION.modifierName -> impexDoc { + typeModifier(element.text) + subHeader("ClassificationAttributeTranslator") + externalLink( + "Special Value Translators", + "https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/aa417173fe4a4ba5a473c93eb730a417/4ce7b82cbc574456ac197393f88e5cc6.html?locale=en-US#special-value-translators" + ) + texts( + "Instead of importing each product feature one by one you can assign all features of a product with one value line using this translator.", + "Therefore you have to declare a special attribute for each feature to import.", + "Assuming you want to set a value for feature type at your product a suitable header could be as follows:", + ) + example(""" + UPDATE Product; code[unique=true]; @type[system='SampleClassification',version='1.0',translator=de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeTranslator;] + """.trimIndent()) + texts("In this example, the modifiers system and version, which are both mandatory, specify the classification system version of the product feature.") + texts("One more optional modifier class can be used with this translator.") + }.build() + TypeModifier.DISABLE_UNIQUE_ATTRIBUTES_VALIDATOR_FOR_TYPES.modifierName -> impexDoc { typeModifier(element.text) externalLink(