Search in sources :

Example 11 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class RequestReply method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    final Element request = object.getChildren().get(0);
    final Element reply = object.getChildren().get(1);
    if (object.getAttribute("storePrefix") != null) {
        report.report("transports.requestReplyStorePrefix", object, request);
        object.removeAttribute("storePrefix");
    }
    if (RequestReplyMigrableConnector.JMS.equals(resolveEndpointConnector(request)) && RequestReplyMigrableConnector.JMS.equals(resolveEndpointConnector(reply))) {
        handleGlobalEndpointsRefs(request, reply);
        final Optional<Element> requestConnector = resolveJmsConnector(request, getApplicationModel());
        final Optional<Element> replyConnector = resolveJmsConnector(reply, getApplicationModel());
        if (!requestConnector.equals(replyConnector)) {
            restoreConnectorRef(request, reply, requestConnector, replyConnector);
            String destination = processAddress(reply, report).map(address -> {
                String path = address.getPath();
                if ("topic".equals(path)) {
                    return "TOPIC:" + address.getPort();
                } else {
                    return path;
                }
            }).orElseGet(() -> {
                if (reply.getAttributeValue("queue") != null) {
                    return reply.getAttributeValue("queue");
                } else {
                    return "TOPIC:" + reply.getAttributeValue("topic");
                }
            });
            request.setAttribute("reply-to", destination, Namespace.getNamespace("migration", "migration"));
            migrateToReplyFlow(object, report, request, reply);
            return;
        }
        migrateJmsRequestReply(object, report, request, reply, requestConnector);
    } else if (RequestReplyMigrableConnector.VM.equals(resolveEndpointConnector(request)) && RequestReplyMigrableConnector.VM.equals(resolveEndpointConnector(reply))) {
        handleGlobalEndpointsRefs(request, reply);
        final Optional<Element> requestConnector = resolveVmConector(request, getApplicationModel());
        final Optional<Element> replyConnector = resolveVmConector(reply, getApplicationModel());
        if (!requestConnector.equals(replyConnector)) {
            restoreConnectorRef(request, reply, requestConnector, replyConnector);
            migrateToReplyFlow(object, report, request, reply);
            return;
        }
        migrateVmRequestReply(object, report, request, reply, requestConnector);
    } else {
        migrateToReplyFlow(object, report, request, reply);
    }
}
Also used : AbstractVmEndpoint.resolveVmConector(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.resolveVmConector) AbstractVmEndpoint.migrateVmConfig(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.migrateVmConfig) JmsOutboundEndpoint.migrateOutboundJmsEndpoint(com.mulesoft.tools.migration.library.mule.steps.jms.JmsOutboundEndpoint.migrateOutboundJmsEndpoint) VM_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.VM_NAMESPACE) AbstractGlobalEndpointMigratorStep.copyAttributes(com.mulesoft.tools.migration.step.AbstractGlobalEndpointMigratorStep.copyAttributes) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Content(org.jdom2.Content) TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) AbstractJmsEndpoint.resolveJmsConnector(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.resolveJmsConnector) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) VmOutboundEndpoint.migrateOutboundVmEndpoint(com.mulesoft.tools.migration.library.mule.steps.vm.VmOutboundEndpoint.migrateOutboundVmEndpoint) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) JMS_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.JMS_NAMESPACE) Optional(java.util.Optional) AbstractVmEndpoint.getVmConfigName(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.getVmConfigName) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) Namespace(org.jdom2.Namespace) AbstractJmsEndpoint.addAttributesToInboundProperties(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.addAttributesToInboundProperties) TransportsUtils.extractInboundChildren(com.mulesoft.tools.migration.step.util.TransportsUtils.extractInboundChildren) TransportsUtils.migrateOutboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure) AbstractJmsEndpoint.migrateJmsConfig(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.migrateJmsConfig) Element(org.jdom2.Element) Optional(java.util.Optional) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) Element(org.jdom2.Element)

Example 12 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class DbConfig method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    if ("template-query".equals(object.getName())) {
        List<Element> templateRefs = getApplicationModel().getNodes("//*[namespace-uri() = '" + DB_NAMESPACE_URI + "' and local-name() = 'template-query-ref' and @name = '" + object.getAttributeValue("name") + "']");
        for (Element templateRef : new ArrayList<>(templateRefs)) {
            List<Content> migratedChildren = object.cloneContent();
            for (Content migratedChild : migratedChildren) {
                if (Element == migratedChild.getCType() && "in-param".equals(((Element) migratedChild).getName())) {
                    Element migratedChildElement = (Element) migratedChild;
                    if (migratedChildElement.getAttribute("defaultValue") != null) {
                        migratedChildElement.getAttribute("defaultValue").setName("value");
                    }
                }
            }
            templateRef.getParent().addContent(templateRef.getParent().indexOf(templateRef), migratedChildren);
            templateRef.detach();
        }
        object.detach();
        return;
    }
    Element dataTypes = object.getChild("data-types", DB_NAMESPACE);
    if (dataTypes != null) {
        dataTypes.setName("column-types");
        for (Element dataType : dataTypes.getChildren("data-type", DB_NAMESPACE)) {
            dataType.setName("column-type");
            dataType.getAttribute("name").setName("typeName");
        }
    }
    Element connection = null;
    if (object.getAttribute("dataSource-ref") != null) {
        report.report("db.referencedDataSource", object, object, object.getName());
        connection = new Element("data-source-connection", DB_NAMESPACE);
        object.addContent(connection);
        copyAttributeIfPresent(object, connection, "dataSource-ref", "dataSourceRef");
        List<Attribute> otherAttributes = object.getAttributes().stream().filter(att -> !"name".equals(att.getName())).collect(toList());
        if (!otherAttributes.isEmpty()) {
            report.report("db.configAttributesOverlap", connection, connection, otherAttributes.toString());
        }
    } else if (object.getAttribute("url") != null) {
        connection = new Element("generic-connection", DB_NAMESPACE);
        object.addContent(connection);
        copyAttributeIfPresent(object, connection, "user");
        copyAttributeIfPresent(object, connection, "password");
        copyAttributeIfPresent(object, connection, "url");
        copyAttributeIfPresent(object, connection, "useXaTransactions");
        copyAttributeIfPresent(object, connection, "transactionIsolation");
        if (!copyAttributeIfPresent(object, connection, "driverClassName")) {
            if ("derby-config".equals(object.getName())) {
                connection.setAttribute("driverClassName", "org.apache.derby.jdbc.EmbeddedDriver");
            } else if ("mysql-config".equals(object.getName())) {
                connection.setAttribute("driverClassName", "com.mysql.jdbc.Driver");
                report.report("db.jdbcDriverDependency", connection, connection);
            } else if ("oracle-config".equals(object.getName())) {
                connection.setAttribute("driverClassName", "oracle.jdbc.driver.OracleDriver");
                report.report("db.jdbcDriverDependency", connection, connection);
            } else {
                report.report("db.jdbcDriverDependency", connection, connection);
            }
        }
        report.report("db.jdbcUrlForSpecificEngine", connection, connection);
        Element connectionProps = object.getChild("connection-properties", DB_NAMESPACE);
        if (connectionProps != null) {
            // Have to use isPresent() because connection cannot be final
            Optional<Element> userProp = connectionProps.getChildren("property", DB_NAMESPACE).stream().filter(p -> "user".equals(p.getAttributeValue("key"))).findFirst();
            if (userProp.isPresent()) {
                connection.setAttribute("user", userProp.get().getAttributeValue("value"));
                connectionProps.removeContent(userProp.get());
            }
            if (connectionProps.getChildren().isEmpty()) {
                object.removeContent(connectionProps);
            }
        }
    } else if ("derby-config".equals(object.getName())) {
        connection = new Element("derby-connection", DB_NAMESPACE);
        object.addContent(connection);
        copyAttributeIfPresent(object, connection, "user");
        copyAttributeIfPresent(object, connection, "password");
        copyAttributeIfPresent(object, connection, "useXaTransactions");
        copyAttributeIfPresent(object, connection, "transactionIsolation");
    } else if ("mysql-config".equals(object.getName())) {
        connection = new Element("my-sql-connection", DB_NAMESPACE);
        object.addContent(connection);
        copyAttributeIfPresent(object, connection, "database");
        copyAttributeIfPresent(object, connection, "host");
        copyAttributeIfPresent(object, connection, "port");
        copyAttributeIfPresent(object, connection, "user");
        copyAttributeIfPresent(object, connection, "password");
        copyAttributeIfPresent(object, connection, "useXaTransactions");
        copyAttributeIfPresent(object, connection, "transactionIsolation");
        report.report("db.jdbcDriverDependency", connection, connection);
    } else if ("oracle-config".equals(object.getName())) {
        connection = new Element("oracle-connection", DB_NAMESPACE);
        object.addContent(connection);
        copyAttributeIfPresent(object, connection, "host");
        copyAttributeIfPresent(object, connection, "port");
        copyAttributeIfPresent(object, connection, "instance");
        copyAttributeIfPresent(object, connection, "user");
        copyAttributeIfPresent(object, connection, "password");
        copyAttributeIfPresent(object, connection, "useXaTransactions");
        copyAttributeIfPresent(object, connection, "transactionIsolation");
        report.report("db.jdbcDriverDependency", connection, connection);
    }
    migrateReconnection(connection, object, report);
    final List<Element> configChildren = new ArrayList<>(object.getChildren());
    Collections.reverse(configChildren);
    for (Element element : configChildren) {
        if (element != connection) {
            element.detach();
            if (!"reconnect-forever".equals(element.getName()) && !"reconnect".equals(element.getName())) {
                connection.addContent(0, element);
            }
        }
    }
    object.setName("config");
}
Also used : MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Content(org.jdom2.Content) ArrayList(java.util.ArrayList) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) Collectors.toList(java.util.stream.Collectors.toList) Attribute(org.jdom2.Attribute) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Element(org.jdom2.Content.CType.Element) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Optional(java.util.Optional) Namespace(org.jdom2.Namespace) XmlDslUtils.migrateReconnection(com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateReconnection) Collections(java.util.Collections) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) Optional(java.util.Optional) Attribute(org.jdom2.Attribute) Content(org.jdom2.Content) Element(org.jdom2.Content.CType.Element) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList)

Example 13 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport 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 14 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class ImapInboundEndpoint method migrateImapConfig.

public Element migrateImapConfig(Element object, MigrationReport report, Optional<Element> connector) {
    String configName = connector.map(conn -> conn.getAttributeValue("name")).orElse((object.getAttribute("name") != null ? object.getAttributeValue("name") : (object.getAttribute("ref") != null ? object.getAttributeValue("ref") : "")).replaceAll("\\\\", "_") + "ImapConfig");
    Optional<Element> config = getApplicationModel().getNodeOptional("*/*[namespace-uri() = '" + EMAIL_NAMESPACE.getURI() + "' and local-name() = 'imap-config' and @name='" + configName + "']");
    return config.orElseGet(() -> {
        final Element imapCfg = new Element("imap-config", EMAIL_NAMESPACE);
        imapCfg.setAttribute("name", configName);
        Element connection = createConnection();
        imapCfg.addContent(connection);
        addTopLevelElement(imapCfg, connector.map(c -> c.getDocument()).orElse(object.getDocument()));
        return imapCfg;
    });
}
Also used : TransportsUtils.migrateSchedulingStrategy(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateSchedulingStrategy) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) OptionalInt(java.util.OptionalInt) TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) Attribute(org.jdom2.Attribute) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Optional(java.util.Optional) TransportsUtils.handleServiceOverrides(com.mulesoft.tools.migration.step.util.TransportsUtils.handleServiceOverrides) XmlDslUtils.migrateReconnection(com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateReconnection) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Example 15 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class NotFilter method negateValidator.

public Element negateValidator(Element validator, MigrationReport report, Element original) {
    if ("is-true".equals(validator.getName())) {
        validator.setName("is-false");
    } else if ("is-false".equals(validator.getName())) {
        validator.setName("is-true");
    } else if ("matches-regex".equals(validator.getName())) {
        Attribute regexAttr = validator.getAttribute("regex");
        if (regexAttr.getValue().startsWith("(?!") && regexAttr.getValue().endsWith(")")) {
            regexAttr.setValue(StringUtils.substring(regexAttr.getValue(), 3, -1));
        } else {
            regexAttr.setValue("(?!" + regexAttr.getValue() + ")");
        }
    } else if ("any".equals(validator.getName())) {
        validator.setName("all");
        validator.getChildren().forEach(c -> negateValidator(c, report, original));
    } else if ("all".equals(validator.getName())) {
        validator.setName("any");
        validator.getChildren().forEach(c -> negateValidator(c, report, original));
    } else {
        report.report("filters.negated", original, validator);
    }
    return validator;
}
Also used : Collectors.toList(java.util.stream.Collectors.toList) Attribute(org.jdom2.Attribute) List(java.util.List) XmlDslUtils.getCoreXPathSelector(com.mulesoft.tools.migration.step.util.XmlDslUtils.getCoreXPathSelector) XmlDslUtils.addElementsAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementsAfter) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) StringUtils(org.apache.commons.lang3.StringUtils) Content(org.jdom2.Content) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute)

Aggregations

MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)33 Element (org.jdom2.Element)28 Optional (java.util.Optional)16 Namespace (org.jdom2.Namespace)16 CORE_NAMESPACE (com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE)13 List (java.util.List)13 ExpressionMigratorAware (com.mulesoft.tools.migration.step.ExpressionMigratorAware)12 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)12 Attribute (org.jdom2.Attribute)12 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)11 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)11 TransportsUtils.processAddress (com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress)10 XmlDslUtils.copyAttributeIfPresent (com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent)9 XmlDslUtils.addElementAfter (com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter)8 Collectors.toList (java.util.stream.Collectors.toList)8 XmlDslUtils.addTopLevelElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement)7 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)6 TransportsUtils.migrateOutboundEndpointStructure (com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure)6 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)6 StringUtils (org.apache.commons.lang3.StringUtils)6