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);
}
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);
}
}
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();
}
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();
}
}
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);
}
}
Aggregations