Search in sources :

Example 1 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class JmsOutboundEndpoint method migrateOutboundJmsEndpoint.

public static void migrateOutboundJmsEndpoint(Element object, MigrationReport report, Optional<Element> connector, String configName, ApplicationModel appModel) {
    String destination = processAddress(object, report).map(address -> {
        String path = address.getPath();
        if ("topic".equals(path)) {
            configureTopicPublisher(object);
            return address.getPort();
        } else {
            return path;
        }
    }).orElseGet(() -> {
        if (object.getAttributeValue("queue") != null) {
            return object.getAttributeValue("queue");
        } else {
            configureTopicPublisher(object);
            return object.getAttributeValue("topic");
        }
    });
    report.report("jms.propertiesPublish", object, object);
    Element outboundBuilder = new Element("message", JMS_NAMESPACE);
    Attribute migrationReplyTo = object.getAttribute("reply-to", Namespace.getNamespace("migration", "migration"));
    if (migrationReplyTo != null) {
        if (migrationReplyTo.getValue().startsWith("TOPIC:")) {
            outboundBuilder.addContent(new Element("reply-to", JMS_NAMESPACE).setAttribute("destination", migrationReplyTo.getValue()).setAttribute("destinationType", "TOPIC"));
        } else {
            outboundBuilder.addContent(new Element("reply-to", JMS_NAMESPACE).setAttribute("destination", migrationReplyTo.getValue()));
        }
        migrationReplyTo.detach();
    } else {
        outboundBuilder.addContent(new Element("reply-to", JMS_NAMESPACE).setAttribute("destination", "#[migration::JmsTransport::jmsPublishReplyTo(vars)]"));
    }
    outboundBuilder.addContent(compatibilityProperties(appModel));
    outboundBuilder.setAttribute("correlationId", "#[migration::JmsTransport::jmsCorrelationId(correlationId, vars)]");
    object.setAttribute("sendCorrelationId", "#[migration::JmsTransport::jmsSendCorrelationId(vars)]");
    object.addContent(outboundBuilder);
    connector.ifPresent(m3c -> {
        if (m3c.getAttributeValue("persistentDelivery") != null) {
            object.setAttribute("persistentDelivery", m3c.getAttributeValue("persistentDelivery"));
        }
        // This logic comes from JmsMessageDispatcher#dispatchMessage in Mule 3
        if ("true".equals(m3c.getAttributeValue("honorQosHeaders"))) {
            report.report("jms.inboundProperties", m3c, object);
            String defaultDeliveryMode = "true".equals(m3c.getAttributeValue("persistentDelivery")) ? "2" : "1";
            object.setAttribute("persistentDelivery", "#[(vars.compatibility_inboundProperties.JMSDeliveryMode default " + defaultDeliveryMode + ") == 2]");
            object.setAttribute("priority", "#[vars.compatibility_inboundProperties.JMSPriority default 4]");
        }
        handleConnectorChildElements(m3c, appModel.getNode("*/*[namespace-uri()='" + JMS_NAMESPACE_URI + "' and local-name()='config' and @name='" + configName + "']"), new Element("connection", CORE_NAMESPACE), report);
    });
    if (object.getAttribute("responseTimeout") != null) {
        object.addContent(new Element("consume-configuration", JMS_NAMESPACE).setAttribute("maximumWait", object.getAttributeValue("responseTimeout")));
    }
    object.removeAttribute("responseTimeout");
    object.setAttribute("config-ref", configName);
    if (destination != null) {
        object.setAttribute("destination", destination);
    }
    object.removeAttribute("queue");
    object.removeAttribute("topic");
    object.removeAttribute("name");
    object.removeAttribute("exchange-pattern");
}
Also used : 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) CORE_EE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_EE_NAMESPACE) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) Optional(java.util.Optional) Namespace(org.jdom2.Namespace) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) TransportsUtils.migrateOutboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 2 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class MUnitNamespaces method execute.

@Override
public void execute(ApplicationModel applicationModel, MigrationReport report) throws RuntimeException {
    try {
        applicationModel.removeNameSpace(MUNIT_MOCK_NAME, MUNIT_MOCK_URI, MUNIT_MOCK_SCHEMA);
        Namespace namespace = Namespace.getNamespace(MUNIT_TOOLS_NAME, MUNIT_TOOLS_URI);
        applicationModel.getApplicationDocuments().values().stream().filter(d -> isMUnitFile(d)).forEach(e -> applicationModel.addNameSpace(namespace, MUNIT_TOOLS_SCHEMA, e));
    } catch (Exception e) {
        throw new MigrationStepException("Fail to apply step. " + e.getMessage(), e);
    }
}
Also used : Document(org.jdom2.Document) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) NamespaceContribution(com.mulesoft.tools.migration.step.category.NamespaceContribution) Namespace(org.jdom2.Namespace) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) Namespace(org.jdom2.Namespace) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Example 3 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class MigrationJob method execute.

@Override
public void execute(MigrationReport report) throws Exception {
    ApplicationModel applicationModel = generateSourceApplicationModel(project);
    report.initialize(applicationModel.getProjectType(), project.getFileName().toString());
    Path sourceProjectBasePath = applicationModel.getProjectBasePath();
    persistApplicationModel(applicationModel);
    ProjectType targetProjectType = applicationModel.getProjectType().getTargetType();
    applicationModel = generateTargetApplicationModel(outputProject, targetProjectType, sourceProjectBasePath, projectParentGAV, projectGAV);
    try {
        for (AbstractMigrationTask task : migrationTasks) {
            if (task.getApplicableProjectTypes().contains(targetProjectType)) {
                task.setApplicationModel(applicationModel);
                task.setExpressionMigrator(new MelToDwExpressionMigrator(report, applicationModel));
                try {
                    task.execute(report);
                    persistApplicationModel(applicationModel);
                    applicationModel = generateTargetApplicationModel(outputProject, targetProjectType, sourceProjectBasePath, projectParentGAV, projectGAV);
                } catch (MigrationTaskException ex) {
                    if (cancelOnError) {
                        throw ex;
                    } else {
                        logger.error("Failed to apply task, rolling back and continuing with the next one.", ex);
                    }
                } catch (RuntimeException e) {
                    throw new MigrationJobException("Failed to continue executing migration: " + e.getClass().getName() + ": " + e.getMessage(), e);
                }
            }
        }
    } finally {
        generateReport(report, applicationModel);
    }
}
Also used : Path(java.nio.file.Path) MelToDwExpressionMigrator(com.mulesoft.tools.migration.library.tools.MelToDwExpressionMigrator) MigrationJobException(com.mulesoft.tools.migration.engine.exception.MigrationJobException) AbstractMigrationTask(com.mulesoft.tools.migration.task.AbstractMigrationTask) ProjectType(com.mulesoft.tools.migration.project.ProjectType) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException)

Example 4 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class SpringImportTest method setUp.

@Before
public void setUp() throws Exception {
    ApplicationModel appModel = mock(ApplicationModel.class);
    springImport = new SpringImport();
    springImport.setApplicationModel(appModel);
    File projectBaseFolder = temp.newFolder();
    write(new File(projectBaseFolder, "import.xml"), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<mule xmlns=\"http://www.mulesoft.org/schema/mule/core\"\n" + "      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "      xsi:schemaLocation=\"http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd\">\n" + "</mule>\n" + "", UTF_8);
    when(appModel.getProjectBasePath()).thenReturn(projectBaseFolder.toPath());
}
Also used : ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) File(java.io.File) Before(org.junit.Before)

Example 5 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class MetadataTest method setUp.

@Before
public void setUp() throws Exception {
    ApplicationModel appModel = mock(ApplicationModel.class);
    setPayload = new SetPayload();
    setPayload.setExpressionMigrator(new MelToDwExpressionMigrator(report.getReport(), appModel));
    dwTransform = new EETransform();
    dwTransform.setApplicationModel(appModel);
    metadata = new RemoveMetadataAttributes();
}
Also used : MelToDwExpressionMigrator(com.mulesoft.tools.migration.library.tools.MelToDwExpressionMigrator) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) EETransform(com.mulesoft.tools.migration.library.mule.steps.ee.EETransform) Before(org.junit.Before)

Aggregations

ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)28 Path (java.nio.file.Path)9 Namespace (org.jdom2.Namespace)9 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)8 Document (org.jdom2.Document)8 Before (org.junit.Before)8 Test (org.junit.Test)7 Element (org.jdom2.Element)6 PomModel (com.mulesoft.tools.migration.project.model.pom.PomModel)5 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)4 ExpressionMigratorAware (com.mulesoft.tools.migration.step.ExpressionMigratorAware)4 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)4 List (java.util.List)4 Optional (java.util.Optional)4 XMLOutputter (org.jdom2.output.XMLOutputter)4 ApplicationModelBuilder (com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder)3 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)3 NamespaceContribution (com.mulesoft.tools.migration.step.category.NamespaceContribution)3 Map (java.util.Map)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2