Search in sources :

Example 26 with MigrationReport

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

the class ApikitRouterConfig method migrateFlowMappings.

private void migrateFlowMappings(Element config, MigrationReport report) {
    final List<Element> flowMappings = config.getChildren().stream().filter(child -> APIKIT_NS_PREFIX.equals(child.getNamespacePrefix()) && FLOW_MAPPING_TAG_NAME.equals(child.getName())).collect(toList());
    if (!flowMappings.isEmpty()) {
        final Element flowMappingParent = getFlowMappingsParent(config);
        flowMappings.forEach(flowMapping -> {
            flowMapping.detach();
            flowMapping.setNamespace(APIKIT_NAMESPACE);
            flowMappingParent.addContent(flowMapping);
        });
    }
}
Also used : Attribute(org.jdom2.Attribute) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) WARN(com.mulesoft.tools.migration.step.category.MigrationReport.Level.WARN) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 27 with MigrationReport

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

the class PreprocessNamespaces method addReportEntries.

public void addReportEntries(Document document, MigrationReport report, ApplicationModel applicationModel) {
    List<Namespace> unsupportedNamespaces = document.getRootElement().getAdditionalNamespaces().stream().filter(n -> !getElementsWithNamespace(document, n, applicationModel).isEmpty() && !containsNamespace(n, applicationModel.getSupportedNamespaces())).collect(toList());
    AtomicInteger processedElements = new AtomicInteger(0);
    unsupportedNamespaces.forEach(ns -> {
        // Ignore nested elements of the same pass to not distort statistics or clutter the report
        applicationModel.getNodes("//*[namespace-uri() = '" + ns.getURI() + "' and namespace-uri(..) != '" + ns.getURI() + "']").forEach(node -> {
            processedElements.incrementAndGet();
            if (ns.getURI().startsWith("http://www.mulesoft.org")) {
                report.report("components.unsupported", node, node, ns.getPrefix());
            } else {
                report.report("components.unknown", node, node, ns.getPrefix(), ns.getURI(), ADDITIONAL_SPRING_NAMESPACES_PROP);
            }
            report.addComponentFailure(node);
        });
    });
    report.addProcessedElements(processedElements.get());
}
Also used : Document(org.jdom2.Document) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ADDITIONAL_SPRING_NAMESPACES_PROP(com.mulesoft.tools.migration.library.mule.steps.spring.SpringContributions.ADDITIONAL_SPRING_NAMESPACES_PROP) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ApplicationModel.getElementsWithNamespace(com.mulesoft.tools.migration.project.model.ApplicationModel.getElementsWithNamespace) NamespaceContribution(com.mulesoft.tools.migration.step.category.NamespaceContribution) Namespace(org.jdom2.Namespace) AdditionalNamespacesFactory.containsNamespace(com.mulesoft.tools.migration.xml.AdditionalNamespacesFactory.containsNamespace) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ApplicationModel.getElementsWithNamespace(com.mulesoft.tools.migration.project.model.ApplicationModel.getElementsWithNamespace) Namespace(org.jdom2.Namespace) AdditionalNamespacesFactory.containsNamespace(com.mulesoft.tools.migration.xml.AdditionalNamespacesFactory.containsNamespace)

Example 28 with MigrationReport

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

the class DbStoredProcedure method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    migrateSql(object);
    migrateInputParamTypes(object);
    migrateInputParams(object);
    List<Element> outParams = object.getChildren("out-param", DB_NAMESPACE).stream().map(ip -> new Element("output-parameter", DB_NAMESPACE).setAttribute("key", ip.getAttributeValue("name"))).collect(toList());
    if (!outParams.isEmpty()) {
        object.addContent(new Element("output-parameters", DB_NAMESPACE).addContent(outParams));
    }
    object.removeChildren("out-param", DB_NAMESPACE);
    List<Element> inoutParams = object.getChildren("inout-param", DB_NAMESPACE).stream().map(ip -> new Element("in-out-parameter", DB_NAMESPACE).setAttribute("key", ip.getAttributeValue("name")).setAttribute("value", ip.getAttributeValue("value"))).collect(toList());
    if (!inoutParams.isEmpty()) {
        object.addContent(new Element("in-out-parameters", DB_NAMESPACE).addContent(inoutParams));
    }
    object.removeChildren("inout-param", DB_NAMESPACE);
    if (object.getAttribute("streaming") == null || "false".equals(object.getAttributeValue("streaming"))) {
        report.report("db.streaming", object, object);
    }
    object.removeAttribute("streaming");
    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 29 with MigrationReport

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

Example 30 with MigrationReport

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

the class OAuth2ProviderConfig method migrateTokenConfig.

private void migrateTokenConfig(Element element, MigrationReport report) {
    final Element tokenConfig = new Element("token-config", OAUTH2_PROVIDER_NAMESPACE);
    final String path = element.getAttributeValue("accessTokenEndpointPath");
    if (path != null) {
        tokenConfig.setAttribute("path", path.startsWith("/") ? path : "/" + path);
        element.removeAttribute("accessTokenEndpointPath");
    }
    AtomicReference<Element> refreshTokens = new AtomicReference<>();
    if ("true".equals(element.getAttributeValue("enableRefreshToken"))) {
        if ("true".equals(element.getAttributeValue("issueNewRefreshToken"))) {
            refreshTokens.set(new Element("multiple-refresh-tokens", OAUTH2_PROVIDER_NAMESPACE));
        } else {
            refreshTokens.set(new Element("single-refresh-tokens", OAUTH2_PROVIDER_NAMESPACE));
        }
        element.removeAttribute("issueNewRefreshToken");
        tokenConfig.addContent(new Element("refresh-token-strategy", OAUTH2_PROVIDER_NAMESPACE).addContent(refreshTokens.get()));
        if (element.getAttributeValue("refreshTokenTtlSeconds") != null) {
            report.report("oauth2Provider.refreshTokenTtl", element, tokenConfig);
            element.removeAttribute("refreshTokenTtlSeconds");
        }
    }
    element.removeAttribute("enableRefreshToken");
    getApplicationModel().getNodeOptional("//*[namespace-uri() = '" + SPRING_BEANS_NS_URI + "' and local-name() = 'bean' and @name='" + element.getAttributeValue("tokenStore-ref") + "']").ifPresent(b -> {
        tokenConfig.setAttribute("tokenStore", b.getAttributes().stream().filter(att -> "accessTokenObjectStore-ref".equals(att.getName())).map(att -> att.getValue()).findFirst().get());
        if (refreshTokens.get() != null) {
            refreshTokens.get().setAttribute("objectStore", b.getAttributes().stream().filter(att -> "refreshTokenObjectStore-ref".equals(att.getName())).map(att -> att.getValue()).findFirst().get());
        }
    });
    if (element.getAttributeValue("tokenStore-ref") != null) {
        element.removeAttribute("tokenStore-ref");
        if (element.getAttributeValue("tokenTtlSeconds") != null) {
            report.report("oauth2Provider.tokenTtl", element, tokenConfig);
            element.removeAttribute("tokenTtlSeconds");
        }
    }
    element.addContent(tokenConfig);
}
Also used : HTTP_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE_URI) SPRING_BEANS_NS_URI(com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI) HttpInboundEndpoint.extractListenerConfig(com.mulesoft.tools.migration.library.mule.steps.http.HttpInboundEndpoint.extractListenerConfig) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors.joining(java.util.stream.Collectors.joining) Collections.singletonList(java.util.Collections.singletonList) HTTPS_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE_URI) HttpsInboundEndpoint.handleHttpsListenerConfig(com.mulesoft.tools.migration.library.mule.steps.http.HttpsInboundEndpoint.handleHttpsListenerConfig) HTTP_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) HTTPS_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) Arrays.stream(java.util.Arrays.stream) Element(org.jdom2.Element) Element(org.jdom2.Element) AtomicReference(java.util.concurrent.atomic.AtomicReference)

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