Search in sources :

Example 16 with ApplicationModel

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

the class HttpMigrationTask method getSteps.

@Override
public List<MigrationStep> getSteps() {
    ApplicationModel applicationModel = getApplicationModel();
    ResponseBuilderMigrationStep responseBuilderMigrationStep = new ResponseBuilderMigrationStep();
    responseBuilderMigrationStep.setApplicationModel(applicationModel);
    ErrorResponseBuilderMigrationStep errorResponseBuilderMigrationStep = new ErrorResponseBuilderMigrationStep();
    errorResponseBuilderMigrationStep.setApplicationModel(applicationModel);
    return Arrays.asList(responseBuilderMigrationStep, errorResponseBuilderMigrationStep);
}
Also used : ErrorResponseBuilderMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.http.ErrorResponseBuilderMigrationStep) ResponseBuilderMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.http.ResponseBuilderMigrationStep) ErrorResponseBuilderMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.http.ErrorResponseBuilderMigrationStep) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel)

Example 17 with ApplicationModel

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

the class AbstractJmsEndpoint method addConnectionToConfig.

public static void addConnectionToConfig(final Element m4JmsConfig, final Element m3Connector, ApplicationModel appModel, MigrationReport report) {
    Element connection;
    switch(m3Connector.getName()) {
        case "activemq-connector":
            connection = addActiveMqConnection(m4JmsConfig, m3Connector, appModel);
            break;
        case "activemq-xa-connector":
            connection = addActiveMqConnection(m4JmsConfig, m3Connector, appModel);
            Element factoryConfig = connection.getChild("factory-configuration", JMS_NAMESPACE);
            if (factoryConfig == null) {
                factoryConfig = new Element("factory-configuration", JMS_NAMESPACE);
                connection.addContent(factoryConfig);
            }
            factoryConfig.setAttribute("enable-xa", "true");
            break;
        case "connector":
        case "custom-connector":
            report.report("jms.customConnector", m3Connector, m4JmsConfig);
            connection = new Element("generic-connection", JMS_NAMESPACE);
            m4JmsConfig.addContent(connection);
            break;
        case "weblogic-connector":
            report.report("jms.weblogicMqConnector", m3Connector, m4JmsConfig);
            connection = new Element("generic-connection", JMS_NAMESPACE);
            m4JmsConfig.addContent(connection);
            break;
        case "websphere-connector":
            // TODO MMT-202
            report.report("jms.,websphereMqConnector", m3Connector, m4JmsConfig);
            connection = new Element("generic-connection", JMS_NAMESPACE);
            m4JmsConfig.addContent(connection);
            break;
        default:
            connection = new Element("generic-connection", JMS_NAMESPACE);
            m4JmsConfig.addContent(connection);
    }
    String m4Specification = changeDefault("1.0.2b", "1.1", m3Connector.getAttributeValue("specification"));
    if (m4Specification != null && m4Specification.equals("1.0.2b")) {
        connection.setAttribute("specification", "JMS_1_0_2b");
    }
    copyAttributeIfPresent(m3Connector, connection, "username");
    copyAttributeIfPresent(m3Connector, connection, "password");
    copyAttributeIfPresent(m3Connector, connection, "clientId");
    if (m3Connector.getAttribute("connectionFactory-ref") != null) {
        Element defaultCaching = new Element("default-caching", JMS_NAMESPACE);
        Optional<Element> conFactoryOptional = appModel.getNodeOptional("/*/*[@name='" + m3Connector.getAttributeValue("connectionFactory-ref") + "']");
        if (conFactoryOptional.isPresent()) {
            Element connFactory = conFactoryOptional.get();
            copyAttributeIfPresent(connFactory, defaultCaching, "sessionCacheSize");
            copyAttributeIfPresent(connFactory, defaultCaching, "cacheConsumers");
            copyAttributeIfPresent(connFactory, defaultCaching, "cacheProducers");
            connection.addContent(0, new Element("caching-strategy", JMS_NAMESPACE).addContent(defaultCaching));
            connFactory.detach();
        } else {
            report.report("jms.beanConnectionFactory", m3Connector, m4JmsConfig);
        }
    } else {
        connection.addContent(0, new Element("caching-strategy", JMS_NAMESPACE).addContent(new Element("no-caching", JMS_NAMESPACE)));
    }
    if (m3Connector.getAttribute("connectionFactoryJndiName") != null) {
        Element jndiConnFactory = new Element("jndi-connection-factory", JMS_NAMESPACE);
        copyAttributeIfPresent(m3Connector, jndiConnFactory, "connectionFactoryJndiName");
        Element nameResolverBuilder = new Element("name-resolver-builder", JMS_NAMESPACE);
        copyAttributeIfPresent(m3Connector, nameResolverBuilder, "jndiInitialFactory", "jndiInitialContextFactory");
        copyAttributeIfPresent(m3Connector, nameResolverBuilder, "jndiProviderUrl");
        copyAttributeIfPresent(m3Connector, nameResolverBuilder, "jndiProviderUrl");
        processProviderProperties(m3Connector, appModel, nameResolverBuilder);
        Element m3defaultJndiNameResolver = m3Connector.getChild("default-jndi-name-resolver", JMS_NAMESPACE);
        if (m3defaultJndiNameResolver != null) {
            copyAttributeIfPresent(m3defaultJndiNameResolver, nameResolverBuilder, "jndiInitialFactory", "jndiInitialContextFactory");
            copyAttributeIfPresent(m3defaultJndiNameResolver, nameResolverBuilder, "jndiProviderUrl");
            processProviderProperties(m3defaultJndiNameResolver, appModel, nameResolverBuilder);
        }
        Element m3customJndiNameResolver = m3Connector.getChild("custom-jndi-name-resolver", JMS_NAMESPACE);
        if (m3customJndiNameResolver != null) {
            copyAttributeIfPresent(m3customJndiNameResolver.getChildren().stream().filter(p -> "jndiInitialFactory".equals(p.getAttributeValue("key"))).findFirst().get(), nameResolverBuilder, "value", "jndiInitialContextFactory");
            copyAttributeIfPresent(m3customJndiNameResolver.getChildren().stream().filter(p -> "jndiProviderUrl".equals(p.getAttributeValue("key"))).findFirst().get(), nameResolverBuilder, "value", "jndiProviderUrl");
            m3customJndiNameResolver.getChildren("property", CORE_NAMESPACE).forEach(prop -> {
                if ("jndiProviderProperties".equals(prop.getAttributeValue("key"))) {
                    processProviderPropertiesRef(prop.getAttributeValue("value-ref"), appModel, nameResolverBuilder);
                }
            });
        }
        if ("true".equals(m3Connector.getAttributeValue("jndiDestinations"))) {
            if ("true".equals(m3Connector.getAttributeValue("forceJndiDestinations"))) {
                jndiConnFactory.setAttribute("lookupDestination", "ALWAYS");
            } else {
                jndiConnFactory.setAttribute("lookupDestination", "TRY_ALWAYS");
            }
        }
        jndiConnFactory.addContent(nameResolverBuilder);
        Element connFactory = new Element("connection-factory", JMS_NAMESPACE).addContent(jndiConnFactory);
        connection.addContent(connFactory);
    }
}
Also used : System.lineSeparator(java.lang.System.lineSeparator) Optional.of(java.util.Optional.of) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) InboundPropertiesHelper.addAttributesMapping(com.mulesoft.tools.migration.library.mule.steps.core.properties.InboundPropertiesHelper.addAttributesMapping) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) LinkedHashMap(java.util.LinkedHashMap) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) Map(java.util.Map) Namespace(org.jdom2.Namespace) TransportsUtils.handleServiceOverrides(com.mulesoft.tools.migration.step.util.TransportsUtils.handleServiceOverrides) SPRING_BEANS_NS_URI(com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI) XmlDslUtils.setText(com.mulesoft.tools.migration.step.util.XmlDslUtils.setText) PomModelUtils.addSharedLibs(com.mulesoft.tools.migration.project.model.pom.PomModelUtils.addSharedLibs) IOException(java.io.IOException) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) DataWeaveHelper.getMigrationScriptFolder(com.mulesoft.tools.migration.library.mule.steps.core.dw.DataWeaveHelper.getMigrationScriptFolder) DependencyBuilder(com.mulesoft.tools.migration.project.model.pom.Dependency.DependencyBuilder) DataWeaveHelper.library(com.mulesoft.tools.migration.library.mule.steps.core.dw.DataWeaveHelper.library) Dependency(com.mulesoft.tools.migration.project.model.pom.Dependency) XPATH_SELECTOR(com.mulesoft.tools.migration.library.mule.steps.jms.JmsConnector.XPATH_SELECTOR) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Optional(java.util.Optional) XmlDslUtils.changeDefault(com.mulesoft.tools.migration.step.util.XmlDslUtils.changeDefault) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Example 18 with ApplicationModel

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

the class AbstractJmsEndpoint method migrateJmsConfig.

public static String migrateJmsConfig(Element object, MigrationReport report, Optional<Element> connector, ApplicationModel appModel) {
    String configName = connector.map(conn -> conn.getAttributeValue("name")).orElse((object.getAttribute("name") != null ? object.getAttributeValue("name") : (object.getAttribute("ref") != null ? object.getAttributeValue("ref") : "")).replaceAll("\\\\", "_") + "JmsConfig");
    Optional<Element> config = appModel.getNodeOptional("*/*[namespace-uri()='" + JMS_NAMESPACE_URI + "' and local-name()='config' and @name='" + configName + "']");
    config.orElseGet(() -> {
        final Element jmsCfg = new Element("config", JMS_NAMESPACE);
        jmsCfg.setAttribute("name", configName);
        connector.ifPresent(conn -> {
            handleServiceOverrides(conn, report);
            addConnectionToConfig(jmsCfg, conn, appModel, report);
        });
        addTopLevelElement(jmsCfg, connector.map(c -> c.getDocument()).orElse(object.getDocument()));
        return jmsCfg;
    });
    return configName;
}
Also used : System.lineSeparator(java.lang.System.lineSeparator) Optional.of(java.util.Optional.of) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) InboundPropertiesHelper.addAttributesMapping(com.mulesoft.tools.migration.library.mule.steps.core.properties.InboundPropertiesHelper.addAttributesMapping) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) LinkedHashMap(java.util.LinkedHashMap) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) Map(java.util.Map) Namespace(org.jdom2.Namespace) TransportsUtils.handleServiceOverrides(com.mulesoft.tools.migration.step.util.TransportsUtils.handleServiceOverrides) SPRING_BEANS_NS_URI(com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI) XmlDslUtils.setText(com.mulesoft.tools.migration.step.util.XmlDslUtils.setText) PomModelUtils.addSharedLibs(com.mulesoft.tools.migration.project.model.pom.PomModelUtils.addSharedLibs) IOException(java.io.IOException) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) DataWeaveHelper.getMigrationScriptFolder(com.mulesoft.tools.migration.library.mule.steps.core.dw.DataWeaveHelper.getMigrationScriptFolder) DependencyBuilder(com.mulesoft.tools.migration.project.model.pom.Dependency.DependencyBuilder) DataWeaveHelper.library(com.mulesoft.tools.migration.library.mule.steps.core.dw.DataWeaveHelper.library) Dependency(com.mulesoft.tools.migration.project.model.pom.Dependency) XPATH_SELECTOR(com.mulesoft.tools.migration.library.mule.steps.jms.JmsConnector.XPATH_SELECTOR) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Optional(java.util.Optional) XmlDslUtils.changeDefault(com.mulesoft.tools.migration.step.util.XmlDslUtils.changeDefault) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Example 19 with ApplicationModel

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

the class ProcessorChainTest method setUp.

@Before
public void setUp() throws Exception {
    ApplicationModel appModel = mock(ApplicationModel.class);
    processorChain = new ProcessorChain();
    processorChain.setApplicationModel(appModel);
}
Also used : ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Before(org.junit.Before)

Example 20 with ApplicationModel

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

the class SpringSecurityTest method execute.

@Test
public void execute() throws Exception {
    Path resolvedConfigPath = Paths.get(this.getClass().getClassLoader().getResource(configPath.toString()).toURI());
    ApplicationModel appModel = new ApplicationModelBuilder().withProjectBasePath(Paths.get(this.getClass().getClassLoader().getResource(SPRING_SECURITY_EXAMPLES_PATH.toString()).toURI())).withConfigurationFiles(asList(resolvedConfigPath)).withProjectType(MULE_FOUR_APPLICATION).build();
    Document doc = appModel.getApplicationDocuments().get(configPath.getFileName());
    springConfigInMuleConfig.setApplicationModel(appModel);
    securityManager.setApplicationModel(appModel);
    getElementsFromDocument(doc, springConfigInMuleConfig.getAppliedTo().getExpression()).forEach(node -> springConfigInMuleConfig.execute(node, report.getReport()));
    getElementsFromDocument(doc, securityManager.getAppliedTo().getExpression()).forEach(node -> securityManager.execute(node, report.getReport()));
    getElementsFromDocument(doc, authorizationFilter.getAppliedTo().getExpression()).forEach(node -> authorizationFilter.execute(node, report.getReport()));
    XMLOutputter muleOutputter = new XMLOutputter(Format.getPrettyFormat());
    String muleXmlString = muleOutputter.outputString(doc);
    assertThat(muleXmlString, isSimilarTo(IOUtils.toString(this.getClass().getClassLoader().getResource(targetMulePath.toString()).toURI(), UTF_8)).ignoreComments().normalizeWhitespace());
    Document springDoc = appModel.getApplicationDocuments().get(Paths.get("src/main/resources/spring", targetSpringPath.getFileName().toString()));
    if (this.getClass().getClassLoader().getResource(targetSpringPath.toString()) != null) {
        XMLOutputter springOutputter = new XMLOutputter(Format.getPrettyFormat());
        String springXmlString = springOutputter.outputString(springDoc);
        assertThat(springXmlString, isSimilarTo(IOUtils.toString(this.getClass().getClassLoader().getResource(targetSpringPath.toString()).toURI(), UTF_8)).ignoreComments().normalizeWhitespace());
    } else {
        assertThat(springDoc, nullValue());
    }
}
Also used : Path(java.nio.file.Path) XMLOutputter(org.jdom2.output.XMLOutputter) ApplicationModelBuilder(com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Document(org.jdom2.Document) DocumentHelper.getElementsFromDocument(com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument) Test(org.junit.Test)

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