Search in sources :

Example 6 with MigrationStepException

use of com.mulesoft.tools.migration.exception.MigrationStepException in project mule-migration-assistant by mulesoft.

the class MUnitConfig method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        File munitFile = new File(element.getDocument().getBaseURI());
        changeAttribute(ATTRIBUTE_NAME, empty(), of(FilenameUtils.getBaseName(munitFile.getName()))).apply(element);
    } catch (Exception e) {
        throw new MigrationStepException("Fail to apply step. " + e.getMessage());
    }
    if (element.getAttribute(ATTRIBUTE_MOCK_CONNECTORS) != null) {
        if (element.getAttributeValue(ATTRIBUTE_MOCK_CONNECTORS).equals("true")) {
            report.report("munit.mockConnectors", element, element.getParentElement());
        }
        element.removeAttribute(ATTRIBUTE_MOCK_CONNECTORS);
    }
    if (element.getAttribute(ATTRIBUTE_MOCK_INBOUNDS) != null) {
        if (element.getAttributeValue(ATTRIBUTE_MOCK_INBOUNDS).equals("true")) {
            report.report("munit.mockInbounds", element, element.getParentElement());
        }
        element.removeAttribute(ATTRIBUTE_MOCK_INBOUNDS);
    }
}
Also used : MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) File(java.io.File) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Example 7 with MigrationStepException

use of com.mulesoft.tools.migration.exception.MigrationStepException in project mule-migration-assistant by mulesoft.

the class MUnitNamespaces method execute.

@Override
public void execute(ApplicationModel applicationModel, MigrationReport report) throws RuntimeException {
    try {
        applicationModel.removeNameSpace(MUNIT_MOCK_NAME, MUNIT_MOCK_URI, MUNIT_MOCK_SCHEMA);
        Namespace namespace = Namespace.getNamespace(MUNIT_TOOLS_NAME, MUNIT_TOOLS_URI);
        applicationModel.getApplicationDocuments().values().stream().filter(d -> isMUnitFile(d)).forEach(e -> applicationModel.addNameSpace(namespace, MUNIT_TOOLS_SCHEMA, e));
    } catch (Exception e) {
        throw new MigrationStepException("Fail to apply step. " + e.getMessage(), e);
    }
}
Also used : Document(org.jdom2.Document) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) NamespaceContribution(com.mulesoft.tools.migration.step.category.NamespaceContribution) Namespace(org.jdom2.Namespace) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) Namespace(org.jdom2.Namespace) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Example 8 with MigrationStepException

use of com.mulesoft.tools.migration.exception.MigrationStepException in project mule-migration-assistant by mulesoft.

the class MUnitTest method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        element.setAttribute("name", element.getAttributeValue("name").replaceAll("/", "\\\\").replaceAll("\\[|\\{", "(").replaceAll("\\]|\\}", ")").replaceAll("#", "_"));
        List<Element> childNodes = element.getChildren();
        createBehaviorSection(childNodes, element);
        createExecutionSection(childNodes, element);
        createValidationSection(childNodes, element);
    } catch (Exception e) {
        throw new MigrationStepException("Fail to apply step. " + e.getMessage());
    }
}
Also used : Element(org.jdom2.Element) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Example 9 with MigrationStepException

use of com.mulesoft.tools.migration.exception.MigrationStepException 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 10 with MigrationStepException

use of com.mulesoft.tools.migration.exception.MigrationStepException in project mule-migration-assistant by mulesoft.

the class TransactionalScope method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        final boolean xa = element != null && element.getName().equals("xa-transactional");
        final Element transformed = changeNodeName("", "try").andThen(changeAttribute("action", of("transactionalAction"), empty())).apply(element);
        if (xa) {
            transformed.setAttribute("transactionType", "XA");
        }
    } catch (Exception ex) {
        throw new MigrationStepException("Failed to migrate transactional scope.");
    }
}
Also used : Element(org.jdom2.Element) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Aggregations

MigrationStepException (com.mulesoft.tools.migration.exception.MigrationStepException)16 Element (org.jdom2.Element)5 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)3 IOException (java.io.IOException)3 Document (org.jdom2.Document)3 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Attribute (org.jdom2.Attribute)2 Namespace (org.jdom2.Namespace)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 MigrationAbortException (com.mulesoft.tools.migration.exception.MigrationAbortException)1 MigrationTaskException (com.mulesoft.tools.migration.exception.MigrationTaskException)1 AbstractOSMigrator (com.mulesoft.tools.migration.library.mule.steps.os.AbstractOSMigrator)1 WatermarkSelectorMigrator (com.mulesoft.tools.migration.library.tools.mel.WatermarkSelectorMigrator)1 ApplicationModelUtils.addAttribute (com.mulesoft.tools.migration.project.model.ApplicationModelUtils.addAttribute)1 ApplicationModelUtils.addChildNode (com.mulesoft.tools.migration.project.model.ApplicationModelUtils.addChildNode)1 ApplicationModelUtils.changeAttribute (com.mulesoft.tools.migration.project.model.ApplicationModelUtils.changeAttribute)1