Search in sources :

Example 1 with SftpInboundEndpoint

use of com.mulesoft.tools.migration.library.mule.steps.sftp.SftpInboundEndpoint in project mule-migration-assistant by mulesoft.

the class InboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    object.getChildren("property", CORE_NAMESPACE).forEach(p -> {
        object.setAttribute(p.getAttributeValue("key"), p.getAttributeValue("value"));
    });
    object.removeChildren("property", CORE_NAMESPACE);
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    AbstractApplicationModelMigrationStep migrator = null;
    if (object.getAttribute("address") != null) {
        String address = object.getAttributeValue("address");
        // TODO MMT-132 make available migrators discoverable
        if (address.startsWith("file://")) {
            migrator = new FileInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(FILE_NS_PREFIX, FILE_NS_URI));
        } else if (address.startsWith("ftp://")) {
            migrator = new FtpEeInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(FTP_NS_PREFIX, FTP_NS_URI));
        } else if (address.startsWith("sftp://")) {
            migrator = new SftpInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(SFTP_NS_PREFIX, SFTP_NS_URI));
        } else if (address.startsWith("http://")) {
            migrator = new HttpInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(HTTP_NS_PREFIX, HTTP_NS_URI));
        } else if (address.startsWith("https://")) {
            migrator = new HttpsInboundEndpoint();
            object.setNamespace(Namespace.getNamespace("https", "http://www.mulesoft.org/schema/mule/https"));
        } else if (address.startsWith("imap://")) {
            migrator = new ImapInboundEndpoint();
            object.setNamespace(Namespace.getNamespace("imap", "http://www.mulesoft.org/schema/mule/imap"));
        } else if (address.startsWith("imaps://")) {
            migrator = new ImapsInboundEndpoint();
            object.setNamespace(Namespace.getNamespace("imaps", "http://www.mulesoft.org/schema/mule/imaps"));
        } else if (address.startsWith("pop3://")) {
            migrator = new Pop3InboundEndpoint();
            object.setNamespace(Namespace.getNamespace("pop3", "http://www.mulesoft.org/schema/mule/pop3"));
        } else if (address.startsWith("pop3s://")) {
            migrator = new Pop3sInboundEndpoint();
            object.setNamespace(Namespace.getNamespace("pop3s", "http://www.mulesoft.org/schema/mule/pop3s"));
        } else if (address.startsWith("jms://")) {
            migrator = new JmsInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(JMS_NS_PREFIX, JMS_NS_URI));
        } else if (address.startsWith("vm://")) {
            migrator = new VmInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(VM_NS_PREFIX, VM_NS_URI));
        }
        if (migrator != null) {
            migrator.setApplicationModel(getApplicationModel());
            if (migrator instanceof ExpressionMigratorAware) {
                ((ExpressionMigratorAware) migrator).setExpressionMigrator(getExpressionMigrator());
            }
            migrator.execute(object, report);
        }
        object.removeAttribute("address");
    } else if (object.getAttribute("ref") != null) {
        Element globalEndpoint = getApplicationModel().getNode("/*/*[@name = '" + object.getAttributeValue("ref") + "']");
        // TODO MMT-132 make available migrators discoverable
        if (globalEndpoint.getAttribute("address") != null) {
            String address = globalEndpoint.getAttributeValue("address");
            if (address.startsWith("file://")) {
                migrator = new FileInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(FILE_NS_PREFIX, FILE_NS_URI));
            } else if (address.startsWith("ftp://")) {
                migrator = new FtpEeInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(FTP_NS_PREFIX, FTP_NS_URI));
            } else if (address.startsWith("sftp://")) {
                migrator = new SftpInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(SFTP_NS_PREFIX, SFTP_NS_URI));
            } else if (address.startsWith("http://")) {
                migrator = new HttpInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(HTTP_NS_PREFIX, HTTP_NS_URI));
            } else if (address.startsWith("https://")) {
                migrator = new HttpsInboundEndpoint();
                object.setNamespace(Namespace.getNamespace("https", "http://www.mulesoft.org/schema/mule/https"));
            } else if (address.startsWith("imap://")) {
                migrator = new ImapInboundEndpoint();
                object.setNamespace(Namespace.getNamespace("imap", "http://www.mulesoft.org/schema/mule/imap"));
            } else if (address.startsWith("imaps://")) {
                migrator = new ImapsInboundEndpoint();
                object.setNamespace(Namespace.getNamespace("imaps", "http://www.mulesoft.org/schema/mule/imaps"));
            } else if (address.startsWith("pop3://")) {
                migrator = new Pop3InboundEndpoint();
                object.setNamespace(Namespace.getNamespace("pop3", "http://www.mulesoft.org/schema/mule/pop3"));
            } else if (address.startsWith("pop3s://")) {
                migrator = new Pop3sInboundEndpoint();
                object.setNamespace(Namespace.getNamespace("pop3s", "http://www.mulesoft.org/schema/mule/pop3s"));
            } else if (address.startsWith("jms://")) {
                migrator = new JmsInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(JMS_NS_PREFIX, JMS_NS_URI));
            } else if (address.startsWith("vm://")) {
                migrator = new VmInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(VM_NS_PREFIX, VM_NS_URI));
            }
            if (migrator != null) {
                migrator.setApplicationModel(getApplicationModel());
                if (migrator instanceof ExpressionMigratorAware) {
                    ((ExpressionMigratorAware) migrator).setExpressionMigrator(getExpressionMigrator());
                }
                for (Attribute attribute : globalEndpoint.getAttributes()) {
                    if (object.getAttribute(attribute.getName()) == null) {
                        object.setAttribute(attribute.getName(), attribute.getValue());
                    }
                }
                migrator.execute(object, report);
            }
        }
    }
    if (object.getAttribute("exchange-pattern") != null) {
        object.removeAttribute("exchange-pattern");
    }
}
Also used : ImapsInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.email.ImapsInboundEndpoint) ImapInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.email.ImapInboundEndpoint) Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) Element(org.jdom2.Element) HttpsInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.http.HttpsInboundEndpoint) HttpInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.http.HttpInboundEndpoint) FileInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.file.FileInboundEndpoint) Pop3InboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.email.Pop3InboundEndpoint) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) FtpEeInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.ftp.FtpEeInboundEndpoint) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) SftpInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.sftp.SftpInboundEndpoint) JmsInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.jms.JmsInboundEndpoint) VmInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.vm.VmInboundEndpoint) Pop3sInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.email.Pop3sInboundEndpoint)

Aggregations

ImapInboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.email.ImapInboundEndpoint)1 ImapsInboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.email.ImapsInboundEndpoint)1 Pop3InboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.email.Pop3InboundEndpoint)1 Pop3sInboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.email.Pop3sInboundEndpoint)1 FileInboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.file.FileInboundEndpoint)1 FtpEeInboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.ftp.FtpEeInboundEndpoint)1 HttpInboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.http.HttpInboundEndpoint)1 HttpsInboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.http.HttpsInboundEndpoint)1 JmsInboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.jms.JmsInboundEndpoint)1 SftpInboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.sftp.SftpInboundEndpoint)1 VmInboundEndpoint (com.mulesoft.tools.migration.library.mule.steps.vm.VmInboundEndpoint)1 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)1 ExpressionMigratorAware (com.mulesoft.tools.migration.step.ExpressionMigratorAware)1 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)1 Attribute (org.jdom2.Attribute)1 Element (org.jdom2.Element)1