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));
}
Aggregations