Search in sources :

Example 1 with DefaultMelCompatibilityResolver

use of com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver in project mule-migration-assistant by mulesoft.

the class MelToDwExpressionMigrator method translateSingleExpression.

public String translateSingleExpression(String unwrappedExpression, boolean dataWeaveBodyOnly, Element element, boolean enricher) {
    logger.debug("  --->> Evaluating MEL expression at element {} -> {}", element != null ? element.getName() : "null", unwrappedExpression);
    String migratedExpression;
    MigrationResult result;
    try {
        result = Migrator.migrate(unwrappedExpression);
        migratedExpression = result.getGeneratedCode();
    } catch (Exception e) {
        return compatibilityResolver.resolve(unwrappedExpression, element, report, model, this, enricher);
    }
    if (result.metadata().children().exists(a -> a instanceof NonMigratable)) {
        List<NonMigratable> metadata = (List<NonMigratable>) (List<?>) JavaConverters.seqAsJavaList(result.metadata().children()).stream().filter(a -> a instanceof NonMigratable).collect(toList());
        metadata.forEach(a -> report.report(a.reason(), element, element));
        return new DefaultMelCompatibilityResolver().resolve(unwrappedExpression, element, report, model, this, enricher);
    }
    if (migratedExpression.contains("message.inboundAttachments")) {
        report.report("message.expressionsAttachments", element, element);
    }
    if (result.metadata().children().exists(a -> a instanceof JavaModuleRequired)) {
        Dependency javaModuleDependency = new Dependency.DependencyBuilder().withGroupId("org.mule.module").withArtifactId("mule-java-module").withVersion(targetVersion("mule-java-module")).withClassifier("mule-plugin").build();
        model.getPomModel().ifPresent(m -> m.addDependency(javaModuleDependency));
    }
    migratedExpression = resolveServerContext(migratedExpression);
    migratedExpression = resolveIdentifiers(migratedExpression);
    if (dataWeaveBodyOnly) {
        migratedExpression = migratedExpression.replaceFirst("%dw 2\\.0\n---", "").trim();
    }
    report.melExpressionSuccess(unwrappedExpression);
    return escapeUnderscores(migratedExpression);
}
Also used : MelCompatibilityResolver(com.mulesoft.tools.migration.library.tools.mel.MelCompatibilityResolver) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) StringUtils.join(org.apache.commons.lang3.StringUtils.join) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) Matcher(java.util.regex.Matcher) Objects.requireNonNull(java.util.Objects.requireNonNull) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) DefaultMelCompatibilityResolver(com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver) Logger(org.slf4j.Logger) com.mulesoft.tools(com.mulesoft.tools) PluginsVersions.targetVersion(com.mulesoft.tools.migration.library.tools.PluginsVersions.targetVersion) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Dependency(com.mulesoft.tools.migration.project.model.pom.Dependency) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) JavaConverters(scala.collection.JavaConverters) Pattern(java.util.regex.Pattern) XmlDslUtils.addCompatibilityNamespace(com.mulesoft.tools.migration.step.util.XmlDslUtils.addCompatibilityNamespace) Element(org.jdom2.Element) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Dependency(com.mulesoft.tools.migration.project.model.pom.Dependency) DefaultMelCompatibilityResolver(com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver)

Example 2 with DefaultMelCompatibilityResolver

use of com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver in project mule-migration-assistant by mulesoft.

the class DbDdlExecute method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    migrateSql(object);
    if (object.getAttribute("source") != null) {
        report.report("db.source", object, object);
        object.removeAttribute("source");
    }
    migrateOperationStructure(getApplicationModel(), object, report, false, getExpressionMigrator(), new DefaultMelCompatibilityResolver());
}
Also used : DefaultMelCompatibilityResolver(com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver)

Example 3 with DefaultMelCompatibilityResolver

use of com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver in project mule-migration-assistant by mulesoft.

the class DbDelete method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    migrateSql(object);
    if ("true".equals(object.getAttributeValue("bulkMode"))) {
        object.setName("bulk-delete");
        object.removeAttribute("bulkMode");
        migrateBulkInputParams(object);
    } else {
        List<Element> paramTypes = object.getChildren("in-param", DB_NAMESPACE).stream().filter(ip -> ip.getAttribute("type") != null).map(ip -> new Element("parameter-type", DB_NAMESPACE).setAttribute("key", ip.getAttributeValue("name")).setAttribute("type", ip.getAttributeValue("type"))).collect(toList());
        if (!paramTypes.isEmpty()) {
            object.addContent(new Element("parameter-types", DB_NAMESPACE).addContent(paramTypes));
        }
        migrateInputParams(object);
    }
    if (object.getAttribute("source") != null) {
        report.report("db.source", object, object);
        object.removeAttribute("source");
    }
    migrateOperationStructure(getApplicationModel(), object, report, false, getExpressionMigrator(), new DefaultMelCompatibilityResolver());
}
Also used : Collectors.toList(java.util.stream.Collectors.toList) DefaultMelCompatibilityResolver(com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver) List(java.util.List) XmlDslUtils.migrateOperationStructure(com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateOperationStructure) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Element(org.jdom2.Element) Element(org.jdom2.Element) DefaultMelCompatibilityResolver(com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver)

Example 4 with DefaultMelCompatibilityResolver

use of com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver in project mule-migration-assistant by mulesoft.

the class DbExecute method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    object.setName("execute-script");
    if (object.getAttribute("file") == null) {
        String sql = getExpressionMigrator().migrateExpression(object.getText(), true, object);
        object.removeContent();
        object.addContent(setText(new Element("sql", DB_NAMESPACE), getExpressionMigrator().migrateExpression(sql, true, object)));
    }
    if (object.getAttribute("source") != null) {
        report.report("db.source", object, object);
        object.removeAttribute("source");
    }
    migrateOperationStructure(getApplicationModel(), object, report, false, getExpressionMigrator(), new DefaultMelCompatibilityResolver());
}
Also used : Element(org.jdom2.Element) DefaultMelCompatibilityResolver(com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver)

Example 5 with DefaultMelCompatibilityResolver

use of com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver in project mule-migration-assistant by mulesoft.

the class DbInsert method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    migrateSql(object);
    if ("true".equals(object.getAttributeValue("bulkMode"))) {
        object.setName("bulk-insert");
        object.removeAttribute("bulkMode");
        migrateBulkInputParams(object);
    } else {
        migrateInputParamTypes(object);
        migrateInputParams(object);
    }
    if (object.getAttribute("autoGeneratedKeysColumnIndexes") != null) {
        object.addContent(new Element("auto-generated-keys-column-indexes", DB_NAMESPACE).addContent(new Element("auto-generated-keys-column-index", DB_NAMESPACE).setAttribute("value", object.getAttributeValue("autoGeneratedKeysColumnIndexes"))));
        object.removeAttribute("autoGeneratedKeysColumnIndexes");
    }
    if (object.getAttribute("autoGeneratedKeysColumnNames") != null) {
        object.addContent(new Element("auto-generated-keys-column-names", DB_NAMESPACE).addContent(new Element("auto-generated-keys-column-name", DB_NAMESPACE).setAttribute("value", object.getAttributeValue("autoGeneratedKeysColumnNames"))));
        object.removeAttribute("autoGeneratedKeysColumnNames");
    }
    if (object.getAttribute("source") != null) {
        report.report("db.source", object, object);
        object.removeAttribute("source");
    }
    migrateOperationStructure(getApplicationModel(), object, report, false, getExpressionMigrator(), new DefaultMelCompatibilityResolver());
}
Also used : Element(org.jdom2.Element) DefaultMelCompatibilityResolver(com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver)

Aggregations

DefaultMelCompatibilityResolver (com.mulesoft.tools.migration.library.tools.mel.DefaultMelCompatibilityResolver)8 Element (org.jdom2.Element)5 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)3 List (java.util.List)3 Collectors.toList (java.util.stream.Collectors.toList)3 XmlDslUtils.migrateOperationStructure (com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateOperationStructure)2 com.mulesoft.tools (com.mulesoft.tools)1 PluginsVersions.targetVersion (com.mulesoft.tools.migration.library.tools.PluginsVersions.targetVersion)1 MelCompatibilityResolver (com.mulesoft.tools.migration.library.tools.mel.MelCompatibilityResolver)1 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)1 Dependency (com.mulesoft.tools.migration.project.model.pom.Dependency)1 XmlDslUtils.addCompatibilityNamespace (com.mulesoft.tools.migration.step.util.XmlDslUtils.addCompatibilityNamespace)1 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)1 String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Function (java.util.function.Function)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1