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