Search in sources :

Example 36 with Attribute

use of com.github.zhenwei.core.asn1.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");
}
Also used : MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Content(org.jdom2.Content) ArrayList(java.util.ArrayList) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) Collectors.toList(java.util.stream.Collectors.toList) Attribute(org.jdom2.Attribute) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Element(org.jdom2.Content.CType.Element) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Optional(java.util.Optional) Namespace(org.jdom2.Namespace) XmlDslUtils.migrateReconnection(com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateReconnection) Collections(java.util.Collections) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) Optional(java.util.Optional) Attribute(org.jdom2.Attribute) Content(org.jdom2.Content) Element(org.jdom2.Content.CType.Element) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList)

Example 37 with Attribute

use of com.github.zhenwei.core.asn1.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;
}
Also used : Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) Element(org.jdom2.Element)

Example 38 with Attribute

use of com.github.zhenwei.core.asn1.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");
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 39 with Attribute

use of com.github.zhenwei.core.asn1.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);
    }
}
Also used : Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) Element(org.jdom2.Element)

Example 40 with Attribute

use of com.github.zhenwei.core.asn1.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");
    }
}
Also used : Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) Element(org.jdom2.Element)

Aggregations

Attribute (org.jdom2.Attribute)316 Element (org.jdom2.Element)210 IOException (java.io.IOException)98 ArrayList (java.util.ArrayList)75 Attribute (ucar.nc2.Attribute)65 List (java.util.List)46 Document (org.jdom2.Document)43 Variable (ucar.nc2.Variable)39 HashMap (java.util.HashMap)26 Extensions (org.bouncycastle.asn1.x509.Extensions)26 X509Certificate (java.security.cert.X509Certificate)24 Namespace (org.jdom2.Namespace)24 File (java.io.File)23 Attribute (org.bouncycastle.asn1.pkcs.Attribute)21 GeneralName (org.bouncycastle.asn1.x509.GeneralName)21 Array (ucar.ma2.Array)21 Test (org.junit.Test)20 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)19 Dimension (ucar.nc2.Dimension)19 Map (java.util.Map)17