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