Search in sources :

Example 11 with MigrationStepException

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

the class AbstractMigrationTask method fetchAndProcessNodes.

private void fetchAndProcessNodes(MigrationReport report, ApplicationModelContribution s, List<Element> alreadyProcessed) {
    AtomicInteger processedElements = new AtomicInteger(0);
    List<Element> nodes = applicationModel.getNodes(s.getAppliedTo());
    nodes.stream().filter(n -> !alreadyProcessed.contains(n)).forEach(n -> {
        try {
            processedElements.incrementAndGet();
            s.execute(n, report);
        } catch (Exception e) {
            throw new MigrationStepException("Task execution exception (" + e.getMessage() + ") migrating node:" + lineSeparator() + outp.outputString(n), e);
        }
    });
    alreadyProcessed.addAll(nodes);
    nodes.removeAll(applicationModel.getNodes(s.getAppliedTo()));
    if (!nodes.isEmpty()) {
        // This recursive calls is here so if any task adds nodes to the config that would be processed by this task, those are
        // processed.
        // Also, this is recursive rather than iterative so in the case of a bug, we get a StackOverflow rather than an infinite
        // loop.
        fetchAndProcessNodes(report, s, alreadyProcessed);
    }
    report.addProcessedElements(processedElements.get());
}
Also used : System.lineSeparator(java.lang.System.lineSeparator) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Collectors(java.util.stream.Collectors) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Preconditions.checkState(com.google.common.base.Preconditions.checkState) XMLOutputter(org.jdom2.output.XMLOutputter) ArrayList(java.util.ArrayList) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) List(java.util.List) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException) ReportingStep(com.mulesoft.tools.migration.step.ReportingStep) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) ApplicationModelContribution(com.mulesoft.tools.migration.step.category.ApplicationModelContribution) Element(org.jdom2.Element) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Element(org.jdom2.Element) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException)

Example 12 with MigrationStepException

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

the class AbstractSpringMigratorStep method resolveSpringDocument.

protected Document resolveSpringDocument(Document currentDoc) {
    Document springDocument = null;
    springDocument = resolveSpringFile(currentDoc, springDocument, getApplicationModel().getApplicationDocuments());
    if (springDocument == null) {
        springDocument = resolveSpringFile(currentDoc, springDocument, getApplicationModel().getDomainDocuments());
        if (springDocument == null) {
            throw new MigrationStepException("The document of the passed element was not present in the application model");
        }
    }
    return springDocument;
}
Also used : MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) Document(org.jdom2.Document)

Example 13 with MigrationStepException

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

the class AssertTrue method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        changeNodeName("munit-tools", "assert-that").andThen(changeAttribute("condition", of("expression"), empty())).andThen(addAttribute("is", "#[MunitTools::equalTo(true)]")).apply(element);
        migrateExpression(element);
    } catch (Exception e) {
        throw new MigrationStepException("Fail to apply step. " + e.getMessage());
    }
}
Also used : MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Example 14 with MigrationStepException

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

the class Mock method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        changeNodeName(MUNIT_TOOLS_PREFIX, "mock-when").andThen(changeAttribute("messageProcessor", of("processor"), empty())).apply(element);
        updateChildElementsNamespace(element.getChildren());
        Element attributesNode = element.getChild("with-attributes", element.getNamespace());
        attributesNode.getChildren().forEach(n -> changeAttribute("name", of("attributeName"), empty()).apply(n));
        movePayloadToChildNode(element.getChild("then-return", element.getNamespace()));
    } 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 15 with MigrationStepException

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

the class AssertNotEquals method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        changeNodeName("munit-tools", "assert-that").andThen(changeAttribute("expectedValue", of("expression"), empty())).andThen(changeAttribute("actualValue", of("is"), empty())).apply(element);
        updateMUnitAssertionNotEqualsExpression("is").apply(element);
        migrateExpression(element);
    } catch (Exception e) {
        throw new MigrationStepException("Fail to apply step. " + e.getMessage());
    }
}
Also used : 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