Search in sources :

Example 1 with CORE_EE_NAMESPACE

use of com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_EE_NAMESPACE in project mule-migration-assistant by mulesoft.

the class JmsInboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    jmsTransportLib(getApplicationModel());
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    Element tx = object.getChild("transaction", JMS_NAMESPACE);
    while (tx != null) {
        String txAction = mapTransactionalAction(tx.getAttributeValue("action"), report, tx, object);
        object.setAttribute("transactionalAction", txAction);
        object.removeChild("transaction", JMS_NAMESPACE);
        tx = object.getChild("transaction", JMS_NAMESPACE);
    }
    while (object.getChild("xa-transaction", CORE_NAMESPACE) != null) {
        Element xaTx = object.getChild("xa-transaction", CORE_NAMESPACE);
        String txAction = mapTransactionalAction(xaTx.getAttributeValue("action"), report, xaTx, object);
        object.setAttribute("transactionalAction", txAction);
        object.setAttribute("transactionType", "XA");
        object.removeChild("xa-transaction", CORE_NAMESPACE);
    }
    while (object.getChild("multi-transaction", CORE_EE_NAMESPACE) != null) {
        Element multiTx = object.getChild("multi-transaction", CORE_EE_NAMESPACE);
        String txAction = mapTransactionalAction(multiTx.getAttributeValue("action"), report, multiTx, object);
        object.setAttribute("transactionalAction", txAction);
        object.removeChild("multi-transaction", CORE_EE_NAMESPACE);
    }
    getApplicationModel().addNameSpace(JMS_NAMESPACE, "http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd", object.getDocument());
    object.setNamespace(JMS_NAMESPACE);
    object.setName("listener");
    Optional<Element> connector = resolveJmsConnector(object, getApplicationModel());
    String configName = migrateJmsConfig(object, report, connector, getApplicationModel());
    connector.ifPresent(m3c -> {
        migrateReconnect(m3c, object, report, object);
        if (m3c.getAttributeValue("acknowledgementMode") != null) {
            switch(m3c.getAttributeValue("acknowledgementMode")) {
                case "CLIENT_ACKNOWLEDGE":
                    object.setAttribute("ackMode", "MANUAL");
                    break;
                case "DUPS_OK_ACKNOWLEDGE":
                    object.setAttribute("ackMode", "DUPS_OK");
                    break;
                default:
            }
        }
        if (m3c.getAttributeValue("numberOfConsumers") != null) {
            object.setAttribute("numberOfConsumers", m3c.getAttributeValue("numberOfConsumers"));
        }
        handleConnectorChildElements(m3c, getApplicationModel().getNode("*/*[namespace-uri()='" + JMS_NAMESPACE_URI + "' and local-name()='config' and @name='" + configName + "']"), new Element("connection", CORE_NAMESPACE), report);
    });
    String destination = processAddress(object, report).map(address -> {
        String path = address.getPath();
        if ("topic".equals(path)) {
            configureTopicListener(object, JMS_NAMESPACE, connector);
            return address.getPort();
        } else {
            return path;
        }
    }).orElseGet(() -> {
        if (object.getAttributeValue("queue") != null) {
            return object.getAttributeValue("queue");
        } else {
            configureTopicListener(object, JMS_NAMESPACE, connector);
            return object.getAttributeValue("topic");
        }
    });
    if (object.getAttribute("exchange-pattern") == null || object.getAttributeValue("exchange-pattern").equals("request-response")) {
        Element outboundBuilder = new Element("response", JMS_NAMESPACE);
        outboundBuilder.addContent(compatibilityProperties(getApplicationModel()));
        outboundBuilder.setAttribute("correlationId", "#[migration::JmsTransport::jmsCorrelationId(correlationId, vars)]");
        report.report("jms.propertiesListener", object, object);
        connector.ifPresent(m3c -> {
            if (m3c.getAttributeValue("persistentDelivery") != null) {
                outboundBuilder.setAttribute("persistentDelivery", m3c.getAttributeValue("persistentDelivery"));
            }
        });
        object.addContent(outboundBuilder);
    }
    if (object.getChild("selector", JMS_NAMESPACE) != null) {
        object.setAttribute("selector", object.getChild("selector", JMS_NAMESPACE).getAttributeValue("expression"));
        object.removeChild("selector", JMS_NAMESPACE);
    }
    object.setAttribute("config-ref", configName);
    if (destination != null) {
        object.setAttribute("destination", destination);
    }
    object.removeAttribute("queue");
    object.removeAttribute("topic");
    object.removeAttribute("name");
    object.removeAttribute("responseTimeout");
    // TODO
    object.removeAttribute("xaPollingTimeout");
    if (object.getAttribute("exchange-pattern") == null || object.getAttributeValue("exchange-pattern").equals("request-response")) {
        migrateInboundEndpointStructure(getApplicationModel(), object, report, true);
    } else {
        migrateInboundEndpointStructure(getApplicationModel(), object, report, false);
    }
    addAttributesToInboundProperties(object, getApplicationModel(), report);
}
Also used : XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) CORE_EE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_EE_NAMESPACE) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) Attribute(org.jdom2.Attribute) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TransportsUtils.handleConnectorChildElements(com.mulesoft.tools.migration.step.util.TransportsUtils.handleConnectorChildElements) TransportsUtils.migrateInboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateInboundEndpointStructure) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) Optional(java.util.Optional) Namespace(org.jdom2.Namespace) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) XmlDslUtils.migrateReconnect(com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateReconnect) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) Element(org.jdom2.Element)

Example 2 with CORE_EE_NAMESPACE

use of com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_EE_NAMESPACE in project mule-migration-assistant by mulesoft.

the class VmInboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    Element tx = object.getChild("transaction", VM_NAMESPACE);
    while (tx != null) {
        String txAction = mapTransactionalAction(tx.getAttributeValue("action"), report, tx, object);
        object.setAttribute("transactionalAction", txAction);
        if (!"NONE".equals(txAction)) {
            if (object.getChild("redelivery-policy", CORE_NAMESPACE) == null) {
                object.addContent(new Element("redelivery-policy", CORE_NAMESPACE));
            }
        }
        object.removeChild("transaction", VM_NAMESPACE);
        tx = object.getChild("transaction", VM_NAMESPACE);
    }
    while (object.getChild("xa-transaction", CORE_NAMESPACE) != null) {
        Element xaTx = object.getChild("xa-transaction", CORE_NAMESPACE);
        String txAction = mapTransactionalAction(xaTx.getAttributeValue("action"), report, xaTx, object);
        object.setAttribute("transactionalAction", txAction);
        object.setAttribute("transactionType", "XA");
        if (!"NONE".equals(txAction)) {
            if (object.getChild("redelivery-policy", CORE_NAMESPACE) == null) {
                object.addContent(new Element("redelivery-policy", CORE_NAMESPACE));
            }
        }
        if ("true".equals(xaTx.getAttributeValue("interactWithExternal"))) {
            report.report("vm.externalTx", xaTx, object);
        }
        object.removeChild("xa-transaction", CORE_NAMESPACE);
    }
    while (object.getChild("multi-transaction", CORE_EE_NAMESPACE) != null) {
        Element multiTx = object.getChild("multi-transaction", CORE_EE_NAMESPACE);
        String txAction = mapTransactionalAction(multiTx.getAttributeValue("action"), report, multiTx, object);
        object.setAttribute("transactionalAction", txAction);
        if (!"NONE".equals(txAction)) {
            if (object.getChild("redelivery-policy", CORE_NAMESPACE) == null) {
                object.addContent(new Element("redelivery-policy", CORE_NAMESPACE));
            }
        }
        object.removeChild("multi-transaction", CORE_EE_NAMESPACE);
    }
    getApplicationModel().addNameSpace(VM_NAMESPACE, "http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd", object.getDocument());
    object.setNamespace(VM_NAMESPACE);
    object.setName("listener");
    Optional<Element> connector = resolveVmConector(object, getApplicationModel());
    String configName = getVmConfigName(object, connector);
    Element vmConfig = migrateVmConfig(object, connector, configName, getApplicationModel());
    String path = processAddress(object, report).map(address -> address.getPath()).orElseGet(() -> obtainPath(object));
    addQueue(VM_NAMESPACE, connector, vmConfig, path);
    connector.ifPresent(conn -> {
        handleServiceOverrides(conn, report);
        Integer consumers = null;
        if (conn.getAttribute("numberOfConcurrentTransactedReceivers") != null) {
            consumers = parseInt(conn.getAttributeValue("numberOfConcurrentTransactedReceivers"));
        } else if (conn.getChild("receiver-threading-profile", CORE_NAMESPACE) != null && conn.getChild("receiver-threading-profile", CORE_NAMESPACE).getAttribute("maxThreadsActive") != null) {
            consumers = parseInt(conn.getChild("receiver-threading-profile", CORE_NAMESPACE).getAttributeValue("maxThreadsActive"));
        }
        if (consumers != null) {
            getContainerElement(object).setAttribute("maxConcurrency", "" + consumers);
            object.setAttribute("numberOfConsumers", "" + consumers);
        }
        handleConnectorChildElements(conn, vmConfig, new Element("connection", CORE_NAMESPACE), report);
    });
    if (object.getAttribute("mimeType") != null) {
        Element setMimeType = new Element("set-payload", CORE_NAMESPACE).setAttribute("value", "#[output " + object.getAttributeValue("mimeType") + " --- payload]");
        addElementAfter(setMimeType, object);
        object.removeAttribute("mimeType");
    }
    if (object.getAttribute("responseTimeout") != null) {
        object.setAttribute("timeout", object.getAttributeValue("responseTimeout"));
        object.setAttribute("timeoutUnit", "MILLISECONDS");
        object.removeAttribute("responseTimeout");
    }
    object.setAttribute("config-ref", configName);
    object.setAttribute("queueName", path);
    object.removeAttribute("path");
    object.removeAttribute("name");
    object.removeAttribute("disableTransportTransformer");
    Element content = buildContent(VM_NAMESPACE);
    object.addContent(new Element("response", VM_NAMESPACE).addContent(content));
    report.report("vm.sessionVars", content, content);
    if (object.getAttribute("exchange-pattern") == null || object.getAttributeValue("exchange-pattern").equals("one-way")) {
        migrateInboundEndpointStructure(getApplicationModel(), object, report, false, true);
    } else {
        migrateInboundEndpointStructure(getApplicationModel(), object, report, true, true);
    }
}
Also used : XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) CORE_EE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_EE_NAMESPACE) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Integer.parseInt(java.lang.Integer.parseInt) TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) Attribute(org.jdom2.Attribute) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TransportsUtils.handleConnectorChildElements(com.mulesoft.tools.migration.step.util.TransportsUtils.handleConnectorChildElements) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) TransportsUtils.migrateInboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateInboundEndpointStructure) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) Optional(java.util.Optional) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) TransportsUtils.handleServiceOverrides(com.mulesoft.tools.migration.step.util.TransportsUtils.handleServiceOverrides) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) Element(org.jdom2.Element)

Aggregations

Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)2 TransportsUtils.handleConnectorChildElements (com.mulesoft.tools.migration.step.util.TransportsUtils.handleConnectorChildElements)2 TransportsUtils.migrateInboundEndpointStructure (com.mulesoft.tools.migration.step.util.TransportsUtils.migrateInboundEndpointStructure)2 TransportsUtils.processAddress (com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress)2 CORE_EE_NAMESPACE (com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_EE_NAMESPACE)2 CORE_NAMESPACE (com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE)2 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)2 Optional (java.util.Optional)2 Attribute (org.jdom2.Attribute)2 Element (org.jdom2.Element)2 TransportsUtils.handleServiceOverrides (com.mulesoft.tools.migration.step.util.TransportsUtils.handleServiceOverrides)1 XmlDslUtils.addElementAfter (com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter)1 XmlDslUtils.copyAttributeIfPresent (com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent)1 XmlDslUtils.getContainerElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement)1 XmlDslUtils.migrateReconnect (com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateReconnect)1 Integer.parseInt (java.lang.Integer.parseInt)1 Namespace (org.jdom2.Namespace)1