Search in sources :

Example 1 with VM_NAMESPACE

use of com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.VM_NAMESPACE in project mule-migration-assistant by mulesoft.

the class QuartzInboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    if (object.removeAttribute("repeatCount")) {
        report.report("quartz.repeatCount", object, object);
    }
    object.setName("scheduler");
    object.setNamespace(CORE_NAMESPACE);
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    String configName = object.getAttributeValue("connector-ref");
    Optional<Element> config;
    if (configName != null) {
        config = getApplicationModel().getNodeOptional("/*/*[namespace-uri() = '" + QUARTZ_NS_URI + "' and local-name() = 'connector' and @name = '" + configName + "']");
    } else {
        config = getApplicationModel().getNodeOptional("/*/*[namespace-uri() = '" + QUARTZ_NS_URI + "' and local-name() = 'connector']");
    }
    config.ifPresent(cfg -> {
        Element receiverThreadingProfile = cfg.getChild("receiver-threading-profile", CORE_NAMESPACE);
        if (receiverThreadingProfile != null) {
            if (receiverThreadingProfile.getAttribute("maxThreadsActive") != null) {
                getContainerElement(object).setAttribute("maxConcurrency", receiverThreadingProfile.getAttributeValue("maxThreadsActive"));
            }
        }
    });
    Element schedulingStrategy = new Element("scheduling-strategy", CORE_NAMESPACE);
    Element fixedFrequecy = null;
    Element cron = null;
    if (object.getAttribute("repeatInterval") != null) {
        if (fixedFrequecy == null) {
            fixedFrequecy = new Element("fixed-frequency", CORE_NAMESPACE);
            schedulingStrategy.addContent(fixedFrequecy);
        }
        fixedFrequecy.setAttribute("frequency", object.getAttributeValue("repeatInterval"));
        object.removeAttribute("repeatInterval");
    }
    if (object.getAttribute("startDelay") != null) {
        if (fixedFrequecy == null) {
            fixedFrequecy = new Element("fixed-frequency", CORE_NAMESPACE);
            schedulingStrategy.addContent(fixedFrequecy);
        }
        fixedFrequecy.setAttribute("startDelay", object.getAttributeValue("startDelay"));
        object.removeAttribute("startDelay");
    }
    if (object.getAttribute("cronExpression") != null) {
        if (cron == null) {
            cron = new Element("cron", CORE_NAMESPACE);
            schedulingStrategy.addContent(cron);
        }
        cron.setAttribute("expression", object.getAttributeValue("cronExpression"));
        object.removeAttribute("cronExpression");
    }
    if (object.getAttribute("cronTimeZone") != null) {
        if (cron == null) {
            cron = new Element("cron", CORE_NAMESPACE);
            schedulingStrategy.addContent(cron);
        }
        cron.setAttribute("timeZone", object.getAttributeValue("cronTimeZone"));
        object.removeAttribute("cronTimeZone");
    }
    Element eventGeneratorJob = object.getChild("event-generator-job", QUARTZ_NS);
    if (eventGeneratorJob != null) {
        String payload = eventGeneratorJob.getChildText("payload", QUARTZ_NS);
        if (payload != null) {
            addElementAfter(new Element("set-payload", CORE_NAMESPACE).setAttribute("value", payload), object);
        }
    }
    Element endpointPollingJob = object.getChild("endpoint-polling-job", QUARTZ_NS);
    if (endpointPollingJob != null) {
        Element jobEndpoint = endpointPollingJob.getChild("job-endpoint", QUARTZ_NS);
        addMigrationAttributeToElement(jobEndpoint, new Attribute("isPolledConsumer", "true"));
        if (JobEndpointMigrableConnector.JMS.equals(resolveEndpointConnector(jobEndpoint))) {
            handleGlobalEndpointsRefs(jobEndpoint);
            final Optional<Element> jobEndpointConnector = resolveJmsConnector(jobEndpoint, getApplicationModel());
            jobEndpointConnector.ifPresent(c -> jobEndpoint.setAttribute("connector-ref", c.getAttributeValue("name")));
            getApplicationModel().addNameSpace(JMS_NAMESPACE, "http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd", object.getDocument());
            jobEndpoint.setNamespace(JMS_NAMESPACE);
            jobEndpoint.setName("consume");
            String jmsConfig = migrateJmsConfig(jobEndpoint, report, jobEndpointConnector, getApplicationModel());
            migrateOutboundJmsEndpoint(jobEndpoint, report, jobEndpointConnector, jmsConfig, getApplicationModel());
            jobEndpoint.detach();
            addElementAfter(jobEndpoint, object);
            if (object.getAttribute("timeout") != null) {
                jobEndpoint.addContent(new Element("consume-configuration", JMS_NAMESPACE).setAttribute("maximumWait", object.getAttributeValue("timeout")));
            }
            migrateOutboundEndpointStructure(getApplicationModel(), jobEndpoint, report, true);
            extractInboundChildren(jobEndpoint, jobEndpoint.getParentElement().indexOf(jobEndpoint) + 2, jobEndpoint.getParentElement(), getApplicationModel());
            addAttributesToInboundProperties(jobEndpoint, getApplicationModel(), report);
            object.addContent(schedulingStrategy);
        } else if (JobEndpointMigrableConnector.VM.equals(resolveEndpointConnector(jobEndpoint))) {
            handleGlobalEndpointsRefs(jobEndpoint);
            final Optional<Element> jobEndpointConnector = resolveVmConector(jobEndpoint, getApplicationModel());
            jobEndpointConnector.ifPresent(c -> jobEndpoint.setAttribute("connector-ref", c.getAttributeValue("name")));
            getApplicationModel().addNameSpace(VM_NAMESPACE, "http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd", object.getDocument());
            jobEndpoint.setNamespace(VM_NAMESPACE);
            jobEndpoint.setName("consume");
            final String vmConfigName = getVmConfigName(object, jobEndpointConnector);
            Element vmConfig = migrateVmConfig(object, jobEndpointConnector, vmConfigName, getApplicationModel());
            migrateVmEndpointConsumer(jobEndpoint, report, jobEndpointConnector, vmConfigName, vmConfig);
            jobEndpoint.detach();
            addElementAfter(jobEndpoint, object);
            if (object.getAttribute("timeout") != null) {
                jobEndpoint.setAttribute("timeout", object.getAttributeValue("timeout"));
                jobEndpoint.setAttribute("timeoutUnit", "MILLISECONDS");
                object.removeAttribute("timeout");
            }
            migrateOutboundEndpointStructure(getApplicationModel(), jobEndpoint, report, true, true);
            extractInboundChildren(jobEndpoint, jobEndpoint.getParentElement().indexOf(jobEndpoint) + 2, jobEndpoint.getParentElement(), getApplicationModel());
            object.addContent(schedulingStrategy);
        } else if (JobEndpointMigrableConnector.POLLING.equals(resolveEndpointConnector(jobEndpoint))) {
            // This handles a Mule 4 connector source that is a polling source
            jobEndpoint.setName("inbound-endpoint");
            jobEndpoint.setNamespace(CORE_NAMESPACE);
            jobEndpoint.detach();
            addElementBefore(jobEndpoint, object);
            jobEndpoint.addContent(schedulingStrategy);
            object.detach();
        } else {
            object.addContent(schedulingStrategy);
            report.report("quartz.unsupportedSource", jobEndpoint, object);
        }
    } else {
        object.addContent(schedulingStrategy);
    }
    object.removeAttribute("connector-ref");
    object.removeAttribute("name");
    object.removeAttribute("jobName");
    object.removeContent(new ElementFilter(QUARTZ_NS));
}
Also used : XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) ElementFilter(org.jdom2.filter.ElementFilter) AbstractGlobalEndpointMigratorStep.copyAttributes(com.mulesoft.tools.migration.step.AbstractGlobalEndpointMigratorStep.copyAttributes) XmlDslUtils.addElementBefore(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementBefore) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) JMS_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.JMS_NAMESPACE) 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) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) VmOutboundEndpoint.migrateVmEndpointConsumer(com.mulesoft.tools.migration.library.mule.steps.vm.VmOutboundEndpoint.migrateVmEndpointConsumer) 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) 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) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) AbstractJmsEndpoint.resolveJmsConnector(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.resolveJmsConnector) Attribute(org.jdom2.Attribute) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) Optional(java.util.Optional) Element(org.jdom2.Element) Optional(java.util.Optional) 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) ElementFilter(org.jdom2.filter.ElementFilter)

Aggregations

JMS_NAMESPACE (com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.JMS_NAMESPACE)1 AbstractJmsEndpoint.addAttributesToInboundProperties (com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.addAttributesToInboundProperties)1 AbstractJmsEndpoint.migrateJmsConfig (com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.migrateJmsConfig)1 AbstractJmsEndpoint.resolveJmsConnector (com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.resolveJmsConnector)1 JmsOutboundEndpoint.migrateOutboundJmsEndpoint (com.mulesoft.tools.migration.library.mule.steps.jms.JmsOutboundEndpoint.migrateOutboundJmsEndpoint)1 VM_NAMESPACE (com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.VM_NAMESPACE)1 AbstractVmEndpoint.getVmConfigName (com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.getVmConfigName)1 AbstractVmEndpoint.migrateVmConfig (com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.migrateVmConfig)1 AbstractVmEndpoint.resolveVmConector (com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.resolveVmConector)1 VmOutboundEndpoint.migrateVmEndpointConsumer (com.mulesoft.tools.migration.library.mule.steps.vm.VmOutboundEndpoint.migrateVmEndpointConsumer)1 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)1 AbstractGlobalEndpointMigratorStep.copyAttributes (com.mulesoft.tools.migration.step.AbstractGlobalEndpointMigratorStep.copyAttributes)1 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)1 TransportsUtils.extractInboundChildren (com.mulesoft.tools.migration.step.util.TransportsUtils.extractInboundChildren)1 TransportsUtils.migrateOutboundEndpointStructure (com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure)1 CORE_NAMESPACE (com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE)1 XmlDslUtils.addElementAfter (com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter)1 XmlDslUtils.addElementBefore (com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementBefore)1 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)1 XmlDslUtils.getContainerElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement)1