Search in sources :

Example 1 with VALIDATION_NAMESPACE

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();
    }
}
Also used : HTTP_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE_URI) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) ValidationMigration.addValidationNamespace(com.mulesoft.tools.migration.library.mule.steps.validation.ValidationMigration.addValidationNamespace) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ValidationPomContribution.addValidationDependency(com.mulesoft.tools.migration.library.mule.steps.validation.ValidationPomContribution.addValidationDependency) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) VALIDATION_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.validation.ValidationMigration.VALIDATION_NAMESPACE) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Element(org.jdom2.Element) Element(org.jdom2.Element)

Aggregations

HTTP_NAMESPACE_URI (com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE_URI)1 VALIDATION_NAMESPACE (com.mulesoft.tools.migration.library.mule.steps.validation.ValidationMigration.VALIDATION_NAMESPACE)1 ValidationMigration.addValidationNamespace (com.mulesoft.tools.migration.library.mule.steps.validation.ValidationMigration.addValidationNamespace)1 ValidationPomContribution.addValidationDependency (com.mulesoft.tools.migration.library.mule.steps.validation.ValidationPomContribution.addValidationDependency)1 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)1 ExpressionMigratorAware (com.mulesoft.tools.migration.step.ExpressionMigratorAware)1 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)1 CORE_NAMESPACE (com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE)1 XmlDslUtils.addElementAfter (com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter)1 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)1 Element (org.jdom2.Element)1