use of com.mindbright.security.x509.Attribute 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.mindbright.security.x509.Attribute in project mule-migration-assistant by mulesoft.
the class FileInboundEndpoint method buildNewMatcher.
private static Element buildNewMatcher(Element object, Namespace ns, ApplicationModel appModel) {
Element newMatcher;
newMatcher = new Element("matcher", ns);
List<Element> referencedMatcher = appModel.getNodes("/*/" + ns.getPrefix() + ":matcher[@name='" + object.getAttributeValue("matcher") + "']");
if (!referencedMatcher.isEmpty()) {
for (Attribute attribute : referencedMatcher.get(0).getAttributes()) {
newMatcher.setAttribute(attribute.getName(), attribute.getValue());
}
}
String newMatcherName = (object.getAttributeValue("connector-ref") != null ? object.getAttributeValue("connector-ref") + "-" : "") + object.getParentElement().getAttributeValue("name") + "Matcher";
newMatcher.setAttribute("name", newMatcherName);
object.setAttribute("matcher", newMatcherName);
int idx = object.getDocument().getRootElement().indexOf(object.getParentElement());
object.getDocument().getRootElement().addContent(idx, newMatcher);
return newMatcher;
}
use of com.mindbright.security.x509.Attribute in project mule-migration-assistant by mulesoft.
the class FtpOutboundEndpoint method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
object.setName("write");
object.setNamespace(FTP_NAMESPACE);
String configName = object.getAttributeValue("connector-ref");
Optional<Element> config;
if (configName != null) {
config = getApplicationModel().getNodeOptional("/*/*[namespace-uri() = '" + FTP_NS_URI + "' and local-name() = 'config' and @name = '" + configName + "']");
} else {
config = getApplicationModel().getNodeOptional("/*/*[namespace-uri() = '" + FTP_NS_URI + "' and local-name() = 'config']");
}
Element ftpConfig = migrateFtpConfig(object, config, configName, config, report);
Element connection = ftpConfig.getChild("connection", FTP_NAMESPACE);
processAddress(object, report).ifPresent(address -> {
connection.setAttribute("host", address.getHost());
connection.setAttribute("port", address.getPort());
if (address.getCredentials() != null) {
String[] credsSplit = address.getCredentials().split(":");
connection.setAttribute("username", credsSplit[0]);
connection.setAttribute("password", credsSplit[1]);
}
object.setAttribute("path", address.getPath() != null ? address.getPath() : "/");
});
copyAttributeIfPresent(object, connection, "host");
copyAttributeIfPresent(object, connection, "port");
copyAttributeIfPresent(object, connection, "user", "username");
copyAttributeIfPresent(object, connection, "password");
Attribute pathAttr = object.getAttribute("path");
if (pathAttr != null) {
pathAttr.setValue(resolveDirectory(pathAttr.getValue()));
// pathAttr.setName("directory");
}
copyAttributeIfPresent(object, connection, "path", "workingDir");
if (object.getAttribute("connector-ref") != null) {
object.getAttribute("connector-ref").setName("config-ref");
} else {
object.setAttribute("config-ref", ftpConfig.getAttributeValue("name"));
}
object.removeAttribute("name");
if (object.getAttribute("responseTimeout") != null) {
copyAttributeIfPresent(object, connection, "responseTimeout", "connectionTimeout");
connection.setAttribute("connectionTimeoutUnit", "MILLISECONDS");
}
extractInboundChildren(object, getApplicationModel());
migrateOperationStructure(getApplicationModel(), object, report);
object.setAttribute("path", compatibilityOutputFile("{" + " outputPattern: " + propToDwExpr(object, "outputPattern") + "," + " outputPatternConfig: " + getExpressionMigrator().unwrap(propToDwExpr(object, "outputPatternConfig")) + "}"));
if (object.getAttribute("exchange-pattern") != null) {
object.removeAttribute("exchange-pattern");
}
}
use of com.mindbright.security.x509.Attribute in project mule-migration-assistant by mulesoft.
the class HttpConnectorListener method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
httpListenerLib(getApplicationModel());
addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
object.setNamespace(HTTP_NAMESPACE);
if (object.getAttribute("parseRequest") != null && !"false".equals(object.getAttributeValue("parseRequest"))) {
report.report("http.parseRequest", object, object);
}
object.removeAttribute("parseRequest");
migrateSourceStructure(getApplicationModel(), object, report);
addAttributesToInboundProperties(object, getApplicationModel(), report);
object.getChildren().forEach(c -> {
if (HTTP_NAMESPACE_URI.equals(c.getNamespaceURI())) {
executeChild(c, report, HTTP_NAMESPACE);
}
});
if (object.getChild("response", HTTP_NAMESPACE) == null) {
Element response = new Element("response", HTTP_NAMESPACE);
// if (rb.getAttribute("disablePropertiesAsHeaders") == null
// || "false".equals(rb.getAttributeValue("disablePropertiesAsHeaders"))) {
object.addContent(0, response.addContent(compatibilityHeaders(getApplicationModel(), HTTP_NAMESPACE)));
// }
}
Element response = object.getChild("response", HTTP_NAMESPACE);
if (response.getAttribute("statusCode") == null) {
response.setAttribute("statusCode", "#[migration::HttpListener::httpListenerResponseSuccessStatusCode(vars)]");
report.report("http.statusCode", response, response);
}
if (object.getChild("error-response", HTTP_NAMESPACE) == null) {
Element errorResponse = new Element("error-response", HTTP_NAMESPACE);
// if (rb.getAttribute("disablePropertiesAsHeaders") == null
// || "false".equals(rb.getAttributeValue("disablePropertiesAsHeaders"))) {
object.addContent(errorResponse.addContent(compatibilityHeaders(getApplicationModel(), HTTP_NAMESPACE)));
// }
}
Element errorResponse = object.getChild("error-response", HTTP_NAMESPACE);
if (errorResponse.getAttribute("statusCode") == null) {
errorResponse.setAttribute("statusCode", "#[vars.statusCode default migration::HttpListener::httpListenerResponseErrorStatusCode(vars)]");
report.report("http.statusCode", errorResponse, errorResponse);
}
}
use of com.mindbright.security.x509.Attribute in project mule-migration-assistant by mulesoft.
the class FtpInboundEndpoint method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
object.setName("listener");
object.setNamespace(FTP_NAMESPACE);
addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
String configName = object.getAttributeValue("connector-ref");
Optional<Element> config;
if (configName != null) {
config = getApplicationModel().getNodeOptional("/*/*[namespace-uri() = '" + FTP_NS_URI + "' and local-name() = 'config' and @name = '" + configName + "']");
} else {
config = getApplicationModel().getNodeOptional("/*/*[namespace-uri() = '" + FTP_NS_URI + "' and local-name() = 'config']");
}
Element ftpConfig = migrateFtpConfig(object, config, configName, config, report);
Element connection = ftpConfig.getChild("connection", FTP_NAMESPACE);
addAttributesToInboundProperties(object, report);
Element redelivery = object.getChild("idempotent-redelivery-policy", CORE_NAMESPACE);
if (redelivery != null) {
redelivery.setName("redelivery-policy");
Attribute exprAttr = redelivery.getAttribute("idExpression");
if (exprAttr != null) {
// TODO MMT-128
exprAttr.setValue(exprAttr.getValue().replaceAll("#\\[header\\:inbound\\:originalFilename\\]", "#[attributes.name]"));
if (getExpressionMigrator().isWrapped(exprAttr.getValue())) {
exprAttr.setValue(getExpressionMigrator().wrap(getExpressionMigrator().migrateExpression(exprAttr.getValue(), true, object)));
}
}
migrateRedeliveryPolicyChildren(redelivery, report);
}
migrateSchedulingStrategy(object, OptionalInt.of(1000));
doExecute(object, report);
migrateFileFilters(object, report, FTP_NAMESPACE, getApplicationModel());
processAddress(object, report).ifPresent(address -> {
connection.setAttribute("host", address.getHost());
connection.setAttribute("port", address.getPort());
if (address.getCredentials() != null) {
String[] credsSplit = address.getCredentials().split(":");
connection.setAttribute("username", credsSplit[0]);
connection.setAttribute("password", credsSplit[1]);
}
object.setAttribute("directory", address.getPath() != null ? address.getPath() : "/");
});
copyAttributeIfPresent(object, connection, "host");
copyAttributeIfPresent(object, connection, "port");
copyAttributeIfPresent(object, connection, "user", "username");
copyAttributeIfPresent(object, connection, "password");
if (object.getAttribute("path") != null) {
object.getAttribute("path").setName("directory");
}
if (object.getAttribute("connector-ref") != null) {
object.getAttribute("connector-ref").setName("config-ref");
} else {
object.setAttribute("config-ref", ftpConfig.getAttributeValue("name"));
}
object.removeAttribute("name");
copyAttributeIfPresent(object, connection, "passive");
if (object.getAttribute("binary") != null) {
connection.setAttribute("transferMode", "true".equals(object.getAttributeValue("binary")) ? "BINARY" : "ASCII");
object.removeAttribute("binary");
}
if (object.getAttribute("encoding") != null) {
object.getParent().addContent(3, new Element("set-payload", CORE_NAMESPACE).setAttribute("value", "#[payload]").setAttribute("encoding", object.getAttributeValue("encoding")));
object.removeAttribute("encoding");
}
if (object.getAttribute("responseTimeout") != null) {
copyAttributeIfPresent(object, connection, "responseTimeout", "connectionTimeout");
connection.setAttribute("connectionTimeoutUnit", "MILLISECONDS");
}
if (object.getAttribute("exchange-pattern") != null) {
object.removeAttribute("exchange-pattern");
}
}
Aggregations