use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.
the class RequestReply method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
final Element request = object.getChildren().get(0);
final Element reply = object.getChildren().get(1);
if (object.getAttribute("storePrefix") != null) {
report.report("transports.requestReplyStorePrefix", object, request);
object.removeAttribute("storePrefix");
}
if (RequestReplyMigrableConnector.JMS.equals(resolveEndpointConnector(request)) && RequestReplyMigrableConnector.JMS.equals(resolveEndpointConnector(reply))) {
handleGlobalEndpointsRefs(request, reply);
final Optional<Element> requestConnector = resolveJmsConnector(request, getApplicationModel());
final Optional<Element> replyConnector = resolveJmsConnector(reply, getApplicationModel());
if (!requestConnector.equals(replyConnector)) {
restoreConnectorRef(request, reply, requestConnector, replyConnector);
String destination = processAddress(reply, report).map(address -> {
String path = address.getPath();
if ("topic".equals(path)) {
return "TOPIC:" + address.getPort();
} else {
return path;
}
}).orElseGet(() -> {
if (reply.getAttributeValue("queue") != null) {
return reply.getAttributeValue("queue");
} else {
return "TOPIC:" + reply.getAttributeValue("topic");
}
});
request.setAttribute("reply-to", destination, Namespace.getNamespace("migration", "migration"));
migrateToReplyFlow(object, report, request, reply);
return;
}
migrateJmsRequestReply(object, report, request, reply, requestConnector);
} else if (RequestReplyMigrableConnector.VM.equals(resolveEndpointConnector(request)) && RequestReplyMigrableConnector.VM.equals(resolveEndpointConnector(reply))) {
handleGlobalEndpointsRefs(request, reply);
final Optional<Element> requestConnector = resolveVmConector(request, getApplicationModel());
final Optional<Element> replyConnector = resolveVmConector(reply, getApplicationModel());
if (!requestConnector.equals(replyConnector)) {
restoreConnectorRef(request, reply, requestConnector, replyConnector);
migrateToReplyFlow(object, report, request, reply);
return;
}
migrateVmRequestReply(object, report, request, reply, requestConnector);
} else {
migrateToReplyFlow(object, report, request, reply);
}
}
use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.
the class DbConfig method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
if ("template-query".equals(object.getName())) {
List<Element> templateRefs = getApplicationModel().getNodes("//*[namespace-uri() = '" + DB_NAMESPACE_URI + "' and local-name() = 'template-query-ref' and @name = '" + object.getAttributeValue("name") + "']");
for (Element templateRef : new ArrayList<>(templateRefs)) {
List<Content> migratedChildren = object.cloneContent();
for (Content migratedChild : migratedChildren) {
if (Element == migratedChild.getCType() && "in-param".equals(((Element) migratedChild).getName())) {
Element migratedChildElement = (Element) migratedChild;
if (migratedChildElement.getAttribute("defaultValue") != null) {
migratedChildElement.getAttribute("defaultValue").setName("value");
}
}
}
templateRef.getParent().addContent(templateRef.getParent().indexOf(templateRef), migratedChildren);
templateRef.detach();
}
object.detach();
return;
}
Element dataTypes = object.getChild("data-types", DB_NAMESPACE);
if (dataTypes != null) {
dataTypes.setName("column-types");
for (Element dataType : dataTypes.getChildren("data-type", DB_NAMESPACE)) {
dataType.setName("column-type");
dataType.getAttribute("name").setName("typeName");
}
}
Element connection = null;
if (object.getAttribute("dataSource-ref") != null) {
report.report("db.referencedDataSource", object, object, object.getName());
connection = new Element("data-source-connection", DB_NAMESPACE);
object.addContent(connection);
copyAttributeIfPresent(object, connection, "dataSource-ref", "dataSourceRef");
List<Attribute> otherAttributes = object.getAttributes().stream().filter(att -> !"name".equals(att.getName())).collect(toList());
if (!otherAttributes.isEmpty()) {
report.report("db.configAttributesOverlap", connection, connection, otherAttributes.toString());
}
} else if (object.getAttribute("url") != null) {
connection = new Element("generic-connection", DB_NAMESPACE);
object.addContent(connection);
copyAttributeIfPresent(object, connection, "user");
copyAttributeIfPresent(object, connection, "password");
copyAttributeIfPresent(object, connection, "url");
copyAttributeIfPresent(object, connection, "useXaTransactions");
copyAttributeIfPresent(object, connection, "transactionIsolation");
if (!copyAttributeIfPresent(object, connection, "driverClassName")) {
if ("derby-config".equals(object.getName())) {
connection.setAttribute("driverClassName", "org.apache.derby.jdbc.EmbeddedDriver");
} else if ("mysql-config".equals(object.getName())) {
connection.setAttribute("driverClassName", "com.mysql.jdbc.Driver");
report.report("db.jdbcDriverDependency", connection, connection);
} else if ("oracle-config".equals(object.getName())) {
connection.setAttribute("driverClassName", "oracle.jdbc.driver.OracleDriver");
report.report("db.jdbcDriverDependency", connection, connection);
} else {
report.report("db.jdbcDriverDependency", connection, connection);
}
}
report.report("db.jdbcUrlForSpecificEngine", connection, connection);
Element connectionProps = object.getChild("connection-properties", DB_NAMESPACE);
if (connectionProps != null) {
// Have to use isPresent() because connection cannot be final
Optional<Element> userProp = connectionProps.getChildren("property", DB_NAMESPACE).stream().filter(p -> "user".equals(p.getAttributeValue("key"))).findFirst();
if (userProp.isPresent()) {
connection.setAttribute("user", userProp.get().getAttributeValue("value"));
connectionProps.removeContent(userProp.get());
}
if (connectionProps.getChildren().isEmpty()) {
object.removeContent(connectionProps);
}
}
} else if ("derby-config".equals(object.getName())) {
connection = new Element("derby-connection", DB_NAMESPACE);
object.addContent(connection);
copyAttributeIfPresent(object, connection, "user");
copyAttributeIfPresent(object, connection, "password");
copyAttributeIfPresent(object, connection, "useXaTransactions");
copyAttributeIfPresent(object, connection, "transactionIsolation");
} else if ("mysql-config".equals(object.getName())) {
connection = new Element("my-sql-connection", DB_NAMESPACE);
object.addContent(connection);
copyAttributeIfPresent(object, connection, "database");
copyAttributeIfPresent(object, connection, "host");
copyAttributeIfPresent(object, connection, "port");
copyAttributeIfPresent(object, connection, "user");
copyAttributeIfPresent(object, connection, "password");
copyAttributeIfPresent(object, connection, "useXaTransactions");
copyAttributeIfPresent(object, connection, "transactionIsolation");
report.report("db.jdbcDriverDependency", connection, connection);
} else if ("oracle-config".equals(object.getName())) {
connection = new Element("oracle-connection", DB_NAMESPACE);
object.addContent(connection);
copyAttributeIfPresent(object, connection, "host");
copyAttributeIfPresent(object, connection, "port");
copyAttributeIfPresent(object, connection, "instance");
copyAttributeIfPresent(object, connection, "user");
copyAttributeIfPresent(object, connection, "password");
copyAttributeIfPresent(object, connection, "useXaTransactions");
copyAttributeIfPresent(object, connection, "transactionIsolation");
report.report("db.jdbcDriverDependency", connection, connection);
}
migrateReconnection(connection, object, report);
final List<Element> configChildren = new ArrayList<>(object.getChildren());
Collections.reverse(configChildren);
for (Element element : configChildren) {
if (element != connection) {
element.detach();
if (!"reconnect-forever".equals(element.getName()) && !"reconnect".equals(element.getName())) {
connection.addContent(0, element);
}
}
}
object.setName("config");
}
use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.
the class DbDelete method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
migrateSql(object);
if ("true".equals(object.getAttributeValue("bulkMode"))) {
object.setName("bulk-delete");
object.removeAttribute("bulkMode");
migrateBulkInputParams(object);
} else {
List<Element> paramTypes = object.getChildren("in-param", DB_NAMESPACE).stream().filter(ip -> ip.getAttribute("type") != null).map(ip -> new Element("parameter-type", DB_NAMESPACE).setAttribute("key", ip.getAttributeValue("name")).setAttribute("type", ip.getAttributeValue("type"))).collect(toList());
if (!paramTypes.isEmpty()) {
object.addContent(new Element("parameter-types", DB_NAMESPACE).addContent(paramTypes));
}
migrateInputParams(object);
}
if (object.getAttribute("source") != null) {
report.report("db.source", object, object);
object.removeAttribute("source");
}
migrateOperationStructure(getApplicationModel(), object, report, false, getExpressionMigrator(), new DefaultMelCompatibilityResolver());
}
use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.
the class ImapInboundEndpoint method migrateImapConfig.
public Element migrateImapConfig(Element object, MigrationReport report, Optional<Element> connector) {
String configName = connector.map(conn -> conn.getAttributeValue("name")).orElse((object.getAttribute("name") != null ? object.getAttributeValue("name") : (object.getAttribute("ref") != null ? object.getAttributeValue("ref") : "")).replaceAll("\\\\", "_") + "ImapConfig");
Optional<Element> config = getApplicationModel().getNodeOptional("*/*[namespace-uri() = '" + EMAIL_NAMESPACE.getURI() + "' and local-name() = 'imap-config' and @name='" + configName + "']");
return config.orElseGet(() -> {
final Element imapCfg = new Element("imap-config", EMAIL_NAMESPACE);
imapCfg.setAttribute("name", configName);
Element connection = createConnection();
imapCfg.addContent(connection);
addTopLevelElement(imapCfg, connector.map(c -> c.getDocument()).orElse(object.getDocument()));
return imapCfg;
});
}
use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.
the class NotFilter method negateValidator.
public Element negateValidator(Element validator, MigrationReport report, Element original) {
if ("is-true".equals(validator.getName())) {
validator.setName("is-false");
} else if ("is-false".equals(validator.getName())) {
validator.setName("is-true");
} else if ("matches-regex".equals(validator.getName())) {
Attribute regexAttr = validator.getAttribute("regex");
if (regexAttr.getValue().startsWith("(?!") && regexAttr.getValue().endsWith(")")) {
regexAttr.setValue(StringUtils.substring(regexAttr.getValue(), 3, -1));
} else {
regexAttr.setValue("(?!" + regexAttr.getValue() + ")");
}
} else if ("any".equals(validator.getName())) {
validator.setName("all");
validator.getChildren().forEach(c -> negateValidator(c, report, original));
} else if ("all".equals(validator.getName())) {
validator.setName("any");
validator.getChildren().forEach(c -> negateValidator(c, report, original));
} else {
report.report("filters.negated", original, validator);
}
return validator;
}
Aggregations