Search in sources :

Example 41 with Attribute

use of com.mindbright.security.x509.Attribute in project mule-migration-assistant by mulesoft.

the class Pop3InboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    object.setName("listener-pop3");
    object.setNamespace(EMAIL_NAMESPACE);
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    addAttributesToInboundProperties(object, report);
    Optional<Element> pop3Connector = resolveConnector(object, getApplicationModel());
    getApplicationModel().addNameSpace(EMAIL_NAMESPACE.getPrefix(), EMAIL_NAMESPACE.getURI(), EMAIL_SCHEMA_LOC);
    migrateSchedulingStrategy(object, OptionalInt.empty());
    Element fixedFrequency = object.getChild("scheduling-strategy", CORE_NAMESPACE).getChild("fixed-frequency", CORE_NAMESPACE);
    pop3Connector.ifPresent(c -> {
        handleServiceOverrides(c, report);
        migrateReconnection(c, object, report);
        if (c.getAttribute("moveToFolder") != null) {
            // TODO https://www.mulesoft.org/jira/browse/MULE-15721
            report.report("email.moveToFolder", object, c);
        }
        if (c.getAttribute("mailboxFolder") != null) {
            object.setAttribute("folder", c.getAttributeValue("mailboxFolder"));
        }
        if (c.getAttribute("backupEnabled") != null || c.getAttribute("backupFolder") != null) {
            report.report("email.pop3Backup", object, object);
        }
        if (c.getAttribute("deleteReadMessages") != null) {
            object.setAttribute("deleteAfterRetrieve", c.getAttributeValue("deleteReadMessages"));
        }
        if (c.getAttribute("defaultProcessMessageAction") != null) {
            object.removeAttribute("defaultProcessMessageAction");
            report.report("email.pop3DefaultProcessMessageAction", object, object);
        }
        if (c.getAttribute("checkFrequency") != null) {
            fixedFrequency.setAttribute("frequency", c.getAttributeValue("checkFrequency"));
        }
    });
    Element m4Config = migratePop3Config(object, report, pop3Connector);
    Element connection = getConnection(m4Config);
    if (pop3Connector.isPresent() && "gmail-connector".equals(pop3Connector.get().getName())) {
        connection.setName("pop3s-connection");
        connection.addContent(new Element("context", TLS_NAMESPACE).addContent(new Element("trust-store", TLS_NAMESPACE).setAttribute("insecure", "true")));
        connection.setAttribute("host", "pop.gmail.com");
        connection.setAttribute("port", "995");
        object.removeAttribute("host");
        object.removeAttribute("port");
        getApplicationModel().addNameSpace(TLS_NAMESPACE.getPrefix(), TLS_NAMESPACE.getURI(), "http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd");
        report.report("email.gmail", pop3Connector.get(), connection);
    } else {
        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("user", credsSplit[0]);
                connection.setAttribute("password", credsSplit[1]);
            }
        });
        copyAttributeIfPresent(object, connection, "host");
        copyAttributeIfPresent(object, connection, "port");
    }
    copyAttributeIfPresent(object, connection, "user");
    copyAttributeIfPresent(object, connection, "password");
    if (object.getAttribute("connector-ref") != null) {
        object.getAttribute("connector-ref").setName("config-ref");
    } else {
        object.removeAttribute("name");
        object.setAttribute("config-ref", m4Config.getAttributeValue("name"));
    }
    if (object.getAttribute("responseTimeout") != null) {
        connection.setAttribute("readTimeout", object.getAttributeValue("responseTimeout"));
        connection.setAttribute("writeTimeout", object.getAttributeValue("responseTimeout"));
        connection.setAttribute("timeoutUnit", "MILLISECONDS");
        object.removeAttribute("responseTimeout");
    }
}
Also used : Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Example 42 with Attribute

use of com.mindbright.security.x509.Attribute 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;
}
Also used : Collectors.toList(java.util.stream.Collectors.toList) Attribute(org.jdom2.Attribute) List(java.util.List) XmlDslUtils.getCoreXPathSelector(com.mulesoft.tools.migration.step.util.XmlDslUtils.getCoreXPathSelector) XmlDslUtils.addElementsAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementsAfter) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) StringUtils(org.apache.commons.lang3.StringUtils) Content(org.jdom2.Content) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute)

Example 43 with Attribute

use of com.mindbright.security.x509.Attribute in project mule-migration-assistant by mulesoft.

the class EETransform method addSessionVariable.

private void addSessionVariable(Element element, MigrationReport report) {
    addCompatibilityNamespace(element.getDocument());
    Element sessionVar = new Element("set-session-variable", COMPATIBILITY_NAMESPACE);
    Attribute varName = element.getAttribute("variableName");
    sessionVar.setAttribute(new Attribute(varName.getName(), varName.getValue()));
    sessionVar.setAttribute(new Attribute("value", "#[vars." + varName.getValue() + "]"));
    addElementAfter(sessionVar, element.getParentElement());
    report.report("transform.sessionVars", sessionVar, sessionVar);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 44 with Attribute

use of com.mindbright.security.x509.Attribute in project mule-migration-assistant by mulesoft.

the class Poll method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        changeNodeName("", POLL_NEW_NAME).apply(element);
        addMigrationAttributeToElement(element, new Attribute("isMessageSource", "true"));
        List<Element> childElementsToMove = element.getChildren().stream().filter(s -> !StringUtils.equals(s.getName(), FIXED_FREQ_SCHEDULER) && !StringUtils.equals(s.getName(), CRON_FREQ_SCHEDULER) && !StringUtils.equals(s.getName(), WATERMARK)).collect(toList());
        movePollChildsToParent(childElementsToMove, element.getParentElement(), element.getParentElement().indexOf(element) + 1);
        if (element.getChild(FIXED_FREQ_SCHEDULER, CORE_NAMESPACE) == null && element.getChild(CRON_FREQ_SCHEDULER, SCHEDULERS_NAMESPACE) == null) {
            Element schedulingStrategy = new Element("scheduling-strategy", element.getNamespace());
            final Element fixedFrequency = new Element("fixed-frequency", element.getNamespace());
            schedulingStrategy.addContent(fixedFrequency);
            element.addContent(schedulingStrategy);
            // support the `frequency` attribute that was deprecated in 3.5.0
            final String newFrequency = changeDefault("1000", "60000", element.getAttributeValue("frequency"));
            if (newFrequency != null) {
                fixedFrequency.setAttribute("frequency", newFrequency);
            }
            element.removeAttribute("frequency");
        } else {
            updateCronScheduler(element);
            updateFixedFrequencyScheduler(element);
        }
        if (element.getChild(WATERMARK, CORE_NAMESPACE) != null) {
            Element watermark = element.getChild(WATERMARK, CORE_NAMESPACE);
            Element osStore = new Element("store", NEW_OS_NAMESPACE);
            Element osRetrieve = new Element("retrieve", NEW_OS_NAMESPACE);
            addMigrationAttributeToElement(osStore, new Attribute("lastElement", "true"));
            osStore.setAttribute("failIfPresent", "false");
            osStore.setAttribute("failOnNullValue", "false");
            if (watermark.getAttribute("variable") != null) {
                osStore.setAttribute("key", watermark.getAttributeValue("variable"));
                osRetrieve.setAttribute("key", watermark.getAttributeValue("variable"));
                osRetrieve.setAttribute("target", watermark.getAttributeValue("variable"));
            }
            if (watermark.getAttribute("default-expression") != null) {
                String defaultExpression = getExpressionMigrator().migrateExpression(watermark.getAttributeValue("default-expression"), true, element);
                setOSValue(osRetrieve, defaultExpression, "default-value");
            }
            if (watermark.getAttribute("update-expression") != null) {
                String updateExpression = getExpressionMigrator().migrateExpression(watermark.getAttributeValue("update-expression"), true, element);
                setOSValue(osStore, updateExpression, "value");
            } else if (watermark.getAttribute("selector-expression") != null || watermark.getAttribute("selector") != null) {
                String selectorExpression = watermark.getAttributeValue("selector-expression");
                String selector = watermark.getAttributeValue("selector");
                if (selectorExpression == null) {
                    setOSValue(osStore, getExpressionFromSelector(selector), "value");
                } else if (selector == null) {
                    selectorExpression = getExpressionMigrator().migrateExpression(selectorExpression, true, element);
                    setOSValue(osStore, selectorExpression, "value");
                } else {
                    selectorExpression = watermarkSelectorMigrator.migrateSelector(selectorExpression, selector.toLowerCase(), element, report, getExpressionMigrator());
                    setOSValue(osStore, selectorExpression, "value");
                }
            }
            if (watermark.getAttribute("object-store-ref") != null) {
                osStore.setAttribute("objectStore", watermark.getAttributeValue("object-store-ref"));
                osRetrieve.setAttribute("objectStore", watermark.getAttributeValue("object-store-ref"));
            }
            addElementAfter(osRetrieve, element);
            addElementToBottom(getContainerElement(element), osStore);
            watermark.detach();
            addOSModule();
        }
    } catch (Exception ex) {
        throw new MigrationStepException("Failed to migrate poll." + ex.getMessage() + ex.getStackTrace());
    }
}
Also used : XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) AbstractOSMigrator(com.mulesoft.tools.migration.library.mule.steps.os.AbstractOSMigrator) ApplicationModelUtils.addChildNode(com.mulesoft.tools.migration.project.model.ApplicationModelUtils.addChildNode) WatermarkSelectorMigrator(com.mulesoft.tools.migration.library.tools.mel.WatermarkSelectorMigrator) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ApplicationModelUtils.changeNodeName(com.mulesoft.tools.migration.project.model.ApplicationModelUtils.changeNodeName) Collectors.toList(java.util.stream.Collectors.toList) Attribute(org.jdom2.Attribute) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) XmlDslUtils.getCoreXPathSelector(com.mulesoft.tools.migration.step.util.XmlDslUtils.getCoreXPathSelector) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) Namespace(org.jdom2.Namespace) XmlDslUtils.addElementToBottom(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementToBottom) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) XmlDslUtils.changeDefault(com.mulesoft.tools.migration.step.util.XmlDslUtils.changeDefault) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) Element(org.jdom2.Element) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Example 45 with Attribute

use of com.mindbright.security.x509.Attribute in project mule-migration-assistant by mulesoft.

the class PropertyPlaceholder method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    Attribute propsLocation = element.getAttribute("location");
    if (propsLocation != null) {
        Element configProperties = new Element("configuration-properties", CORE_NAMESPACE);
        configProperties.setAttribute("file", propsLocation.getValue());
        addTopLevelElement(configProperties, element.getDocument());
    }
    getApplicationModel().removeNameSpace(Namespace.getNamespace(SPRING_CONTEXT_NS_PREFIX, SPRING_CONTEXT_NS_URI), SPRING_CONTEXT_SCHEMA, element.getDocument());
    element.detach();
}
Also used : Attribute(org.jdom2.Attribute) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Aggregations

Attribute (org.jdom2.Attribute)316 Element (org.jdom2.Element)210 Attribute (ucar.nc2.Attribute)65 IOException (java.io.IOException)55 ArrayList (java.util.ArrayList)51 Document (org.jdom2.Document)43 Variable (ucar.nc2.Variable)39 List (java.util.List)31 HashMap (java.util.HashMap)25 Namespace (org.jdom2.Namespace)24 File (java.io.File)21 Array (ucar.ma2.Array)21 DataConversionException (org.jdom2.DataConversionException)19 Test (org.junit.Test)19 Dimension (ucar.nc2.Dimension)19 Map (java.util.Map)17 JDOMException (org.jdom2.JDOMException)16 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)15 Editor (jmri.jmrit.display.Editor)15 NamedIcon (jmri.jmrit.catalog.NamedIcon)13