use of com.mulesoft.tools.migration.library.mule.steps.validation.ValidationMigration.VALIDATION_NAMESPACE in project mule-migration-assistant by mulesoft.
the class HttpTransformers method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
if ("request-wildcard-filter".equals(object.getName())) {
addValidationDependency(getApplicationModel().getPomModel().get());
addValidationNamespace(object.getDocument());
Element wildcardFilterTryScope = new Element("try", CORE_NAMESPACE);
Element matchValidator = new Element("matches-regex", VALIDATION_NAMESPACE);
String regex;
Element parent = object.getParentElement();
if ("not-filter".equals(parent.getName()) && parent.getNamespace().equals(CORE_NAMESPACE)) {
addElementAfter(wildcardFilterTryScope, object.getParentElement());
object.getParentElement().detach();
regex = "^(?!" + object.getAttributeValue("pattern").replaceAll("\\*", ".*") + ").*$";
} else {
regex = "^" + object.getAttributeValue("pattern").replaceAll("\\*", ".*") + "$";
addElementAfter(wildcardFilterTryScope, object);
object.detach();
}
matchValidator.setAttribute("value", "#[message.attributes.requestPath]");
matchValidator.setAttribute("regex", regex);
matchValidator.removeAttribute("pattern");
wildcardFilterTryScope.addContent(matchValidator);
wildcardFilterTryScope.addContent(new Element("error-handler", CORE_NAMESPACE).addContent(new Element("on-error-propagate", CORE_NAMESPACE).addContent(new Element("set-variable", CORE_NAMESPACE).setAttribute("variableName", "statusCode").setAttribute("value", "406")).setAttribute("type", "MULE:VALIDATION")));
} else if ("body-to-parameter-map-transformer".equals(object.getName())) {
Element bodyToParamMap = new Element("set-payload", CORE_NAMESPACE).setAttribute("value", "#[output application/java --- payload]");
if (object.getParentElement() == object.getDocument().getRootElement()) {
getApplicationModel().getNodes("//mule:transformer[@ref='" + object.getAttributeValue("name") + "']").forEach(t -> {
addElementAfter(bodyToParamMap, t);
t.detach();
});
} else {
addElementAfter(bodyToParamMap, object);
}
object.detach();
} else {
if (object.getAttribute("name") != null) {
getApplicationModel().getNodes("//mule:transformer[@ref = '" + object.getAttributeValue("name") + "']").forEach(t -> t.detach());
}
object.detach();
}
}
Aggregations