Search in sources :

Example 6 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class InvokeApexRestMethodOperation method execute.

@Override
public void execute(Element mule3Operation, MigrationReport report) throws RuntimeException {
    super.execute(mule3Operation, report);
    resolveAttributes(mule3Operation, mule4Operation);
    StringBuilder requestContents = new StringBuilder();
    String body = mule3Operation.getAttributeValue("input-ref");
    if (body != null && !body.isEmpty()) {
        // ?
        String expression = expressionMigrator.migrateExpression(body, true, mule3Operation);
        requestContents.append("body: " + expressionMigrator.unwrap(expression));
    }
    String headers = mule3Operation.getAttributeValue("requestHeaders-ref");
    if (headers != null && !headers.isEmpty()) {
        String expression = expressionMigrator.migrateExpression(headers, true, mule3Operation);
        if (requestContents != null && !requestContents.equals("")) {
            requestContents.append(", \n");
        }
        requestContents.append("headers: " + expressionMigrator.unwrap(expression));
    }
    Optional<Element> mule3QueryParams = Optional.ofNullable(mule3Operation.getChild("query-parameters", SalesforceUtils.MULE3_SALESFORCE_NAMESPACE));
    mule3QueryParams.ifPresent(queryParams -> {
        String refHeaders = queryParams.getAttributeValue("ref");
        if (refHeaders != null) {
            String expression = expressionMigrator.migrateExpression(refHeaders, true, queryParams);
            if (requestContents != null && !requestContents.equals("")) {
                requestContents.append(", \n");
            }
            requestContents.append("queryParams: " + expressionMigrator.unwrap(expression));
        }
        List<Element> children = queryParams.getChildren();
        if (children.size() > 0) {
            String queryParam = children.stream().map(object -> object.getContent().stream().map(innerObject -> object.getAttributeValue("key") + ": " + "\"" + innerObject.getValue() + "\"").collect(Collectors.joining(""))).collect(Collectors.joining(", "));
            if (requestContents != null && !requestContents.equals("")) {
                requestContents.append(", \n");
            }
            requestContents.append("queryParams: { " + queryParam + " }");
        }
    });
    if (requestContents != null && requestContents.length() != 0) {
        Element request = new Element("request", SalesforceUtils.MULE4_SALESFORCE_NAMESPACE);
        request.setContent(new CDATA(START_TRANSFORM_BODY_TYPE_JSON + requestContents.toString() + SalesforceUtils.CLOSE_TRANSFORM_BODY_TYPE_JSON));
        mule4Operation.addContent(request);
    }
    XmlDslUtils.addElementAfter(mule4Operation, mule3Operation);
    mule3Operation.getParentElement().removeContent(mule3Operation);
}
Also used : CDATA(org.jdom2.CDATA) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) START_TRANSFORM_BODY_TYPE_JSON(com.mulesoft.tools.migration.library.tools.SalesforceUtils.START_TRANSFORM_BODY_TYPE_JSON) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) XmlDslUtils(com.mulesoft.tools.migration.step.util.XmlDslUtils) Optional(java.util.Optional) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Collectors(java.util.stream.Collectors) SalesforceUtils(com.mulesoft.tools.migration.library.tools.SalesforceUtils) Element(org.jdom2.Element) Element(org.jdom2.Element) CDATA(org.jdom2.CDATA)

Example 7 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport 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 MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class TransportUtilsAddressTest method doProcessAddress.

private EndpointAddress doProcessAddress(String address) {
    MigrationReport report = mock(MigrationReport.class);
    doAnswer(invocation -> {
        fail("Couldn't parse address");
        return null;
    }).when(report).report(eq("transports.cantParseAddress"), any(), any());
    return processAddress(new Element("endpoint", COMPATIBILITY_NAMESPACE).setAttribute("address", address), report).get();
}
Also used : Element(org.jdom2.Element) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport)

Example 9 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class XmlDslUtils method migrateRedeliveryPolicyChildren.

/**
 * Migrate redelivery policy of Mule 3 into the new REDELIVERY_EXHAUSTED method on Mule 4
 *
 * @param redeliveryPolicy the Mule 3 redelivery policy element
 * @param report the migration report
 */
public static void migrateRedeliveryPolicyChildren(Element redeliveryPolicy, MigrationReport report) {
    Element dlq = redeliveryPolicy.getChild("dead-letter-queue", CORE_NAMESPACE);
    if (dlq != null) {
        Element flow = getContainerElement(redeliveryPolicy);
        Element errorHandler = getFlowExceptionHandlingElement(flow);
        if (errorHandler == null) {
            errorHandler = new Element("error-handler", CORE_NAMESPACE);
            flow.addContent(errorHandler);
        }
        Optional<Element> redeliveryExhaustedHandler = errorHandler.getChildren().stream().filter(e -> "REDELIVERY_EXHAUSTED".equals(e.getAttributeValue("type"))).findFirst();
        if (redeliveryExhaustedHandler.isPresent()) {
            report.report("flow.redeliveryExhausted", dlq, redeliveryPolicy);
        } else {
            Element handler = new Element("on-error-propagate", CORE_NAMESPACE).setAttribute("type", "REDELIVERY_EXHAUSTED");
            errorHandler.addContent(0, handler);
            handler.addContent(dlq.getChildren().stream().map(c -> c.detach()).collect(toList()));
        }
        dlq.detach();
    }
}
Also used : CompatibilityResolver(com.mulesoft.tools.migration.util.CompatibilityResolver) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) ApplicationModel.addNameSpace(com.mulesoft.tools.migration.project.model.ApplicationModel.addNameSpace) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) COMPATIBILITY_NAMESPACE(com.mulesoft.tools.migration.step.util.TransportsUtils.COMPATIBILITY_NAMESPACE) Namespace(org.jdom2.Namespace) Path(java.nio.file.Path) SAXBuilder(org.jdom2.input.SAXBuilder) Iterator(java.util.Iterator) Comment(org.jdom2.Comment) Collection(java.util.Collection) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) COMPATIBILITY_NS_SCHEMA_LOC(com.mulesoft.tools.migration.step.util.TransportsUtils.COMPATIBILITY_NS_SCHEMA_LOC) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Parent(org.jdom2.Parent) String.format(java.lang.String.format) File(java.io.File) Content(org.jdom2.Content) CDATA(org.jdom2.CDATA) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Attribute(org.jdom2.Attribute) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) LocatedJDOMFactory(org.jdom2.located.LocatedJDOMFactory) Optional(java.util.Optional) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 10 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class AbstractMigrationTask method execute.

@Override
public void execute(MigrationReport report) throws Exception {
    // TODO depending on the project type this may not be true
    checkState(applicationModel != null, "An application model must be provided.");
    List<MigrationStep> steps = enableReporting(getSteps());
    try {
        if (steps != null) {
            MigrationStepSelector stepSelector = new MigrationStepSelector(steps);
            if (shouldExecuteAllSteps(stepSelector)) {
                steps.stream().filter(s -> s instanceof ExpressionMigratorAware).forEach(s -> ((ExpressionMigratorAware) s).setExpressionMigrator(getExpressionMigrator()));
                stepSelector.getNameSpaceContributionSteps().forEach(s -> s.execute(applicationModel, report));
                stepSelector.getApplicationModelContributionSteps().forEach(s -> {
                    s.setApplicationModel(applicationModel);
                    fetchAndProcessNodes(report, s, new ArrayList<>());
                });
                stepSelector.getProjectStructureContributionSteps().forEach(s -> {
                    s.setApplicationModel(applicationModel);
                    s.execute(applicationModel.getProjectBasePath(), report);
                });
                stepSelector.getPomContributionSteps().forEach(s -> {
                    s.setApplicationModel(applicationModel);
                    s.execute(applicationModel.getPomModel().orElse(new PomModel()), report);
                });
            }
        }
    } catch (MigrationAbortException e) {
        throw e;
    } catch (Exception e) {
        throw new MigrationTaskException("Task execution exception. " + e.getMessage(), e);
    }
}
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) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException)

Aggregations

MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)33 Element (org.jdom2.Element)28 Optional (java.util.Optional)16 Namespace (org.jdom2.Namespace)16 CORE_NAMESPACE (com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE)13 List (java.util.List)13 ExpressionMigratorAware (com.mulesoft.tools.migration.step.ExpressionMigratorAware)12 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)12 Attribute (org.jdom2.Attribute)12 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)11 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)11 TransportsUtils.processAddress (com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress)10 XmlDslUtils.copyAttributeIfPresent (com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent)9 XmlDslUtils.addElementAfter (com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter)8 Collectors.toList (java.util.stream.Collectors.toList)8 XmlDslUtils.addTopLevelElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement)7 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)6 TransportsUtils.migrateOutboundEndpointStructure (com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure)6 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)6 StringUtils (org.apache.commons.lang3.StringUtils)6