Skip to content

Commit

Permalink
Sanitize sub-flow names (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
svacas authored Jun 7, 2022
1 parent c105621 commit 523b7e2
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</batch:commit>
</batch:step>
<batch:step name="secondStep">
<flow-ref name="upperCasePipe"/>
<flow-ref name="/upperCasePipe"/>
<logger message="something"/>
</batch:step>
</batch:process-records>
Expand All @@ -32,7 +32,7 @@
</batch:on-complete>
</batch:job>

<sub-flow name="upperCasePipe">
<sub-flow name="/upperCasePipe">
<set-payload value="#[payload + '|' + payload.toUpperCase()]"/>
</sub-flow>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"projectType": "MULE_THREE_APPLICATION",
"projectName": "input",
"connectorsMigrated": [],
"numberOfMuleComponents": 15,
"numberOfMuleComponentsMigrated": 15,
"numberOfMuleComponents": 16,
"numberOfMuleComponentsMigrated": 16,
"componentDetails": {
"mule": {
"success": 1,
Expand All @@ -17,6 +17,10 @@
"success": 2,
"failure": 0
},
"sub-flow": {
"success": 1,
"failure": 0
},
"flow-ref": {
"success": 2,
"failure": 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</batch:aggregator>
</batch:step>
<batch:step name="secondStep">
<flow-ref name="upperCasePipe" />
<flow-ref name="\upperCasePipe" />
<logger message="something" />
</batch:step>
</batch:process-records>
Expand All @@ -33,7 +33,7 @@

</flow>

<sub-flow name="upperCasePipe">
<sub-flow name="\upperCasePipe">
<set-payload value="#[mel:payload + '|' + payload.toUpperCase()]">
<!--Migration WARN: The MEL expression could not be migrated to a DataWeave expression.-->
<!-- For more information refer to:-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"projectType": "MULE_THREE_APPLICATION",
"projectName": "input",
"connectorsMigrated": [],
"numberOfMuleComponents": 28,
"numberOfMuleComponentsMigrated": 28,
"numberOfMuleComponents": 29,
"numberOfMuleComponentsMigrated": 29,
"componentDetails": {
"mule": {
"success": 1,
Expand All @@ -17,6 +17,10 @@
"success": 4,
"failure": 0
},
"sub-flow": {
"success": 1,
"failure": 0
},
"flow-ref": {
"success": 2,
"failure": 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"projectType": "MULE_THREE_POLICY",
"projectName": "input",
"connectorsMigrated": [],
"numberOfMuleComponents": 11,
"numberOfMuleComponentsMigrated": 11,
"numberOfMuleComponents": 12,
"numberOfMuleComponentsMigrated": 12,
"componentDetails": {
"mule:sub-flow": {
"success": 1,
"failure": 0
},
"mule:set-payload": {
"success": 2,
"failure": 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
package com.mulesoft.tools.migration.library.mule.steps.core;

import static com.mulesoft.tools.migration.library.mule.steps.core.Flow.migrateFlowName;
import static com.mulesoft.tools.migration.step.util.XmlDslUtils.getTopLevelCoreXPathSelector;

import com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep;
import com.mulesoft.tools.migration.step.category.MigrationReport;

Expand All @@ -18,7 +21,7 @@
*/
public class SubFlow extends AbstractApplicationModelMigrationStep {

public static final String XPATH_SELECTOR = "/*/mule:sub-flow";
public static final String XPATH_SELECTOR = getTopLevelCoreXPathSelector("sub-flow");

@Override
public String getDescription() {
Expand All @@ -31,12 +34,13 @@ public SubFlow() {

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
element.setAttribute("name", element.getAttributeValue("name")
.replaceAll("\\/", "\\\\")
.replaceAll("\\[|\\{", "(")
.replaceAll("\\]|\\}", ")")
.replaceAll("#", "_"));
}
String name = element.getAttributeValue("name");

// do not replace special chars for sub-flows in policy templates
if (!name.matches(".*\\{\\{\\w+}}.*")) {
element.setAttribute("name", migrateFlowName(name));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.mulesoft.tools.migration.library.mule.steps.core.SetPayload;
import com.mulesoft.tools.migration.library.mule.steps.core.SetVariable;
import com.mulesoft.tools.migration.library.mule.steps.core.SpringImport;
import com.mulesoft.tools.migration.library.mule.steps.core.SubFlow;
import com.mulesoft.tools.migration.library.mule.steps.core.TransactionalScope;
import com.mulesoft.tools.migration.library.mule.steps.core.UntilSuccessful;
import com.mulesoft.tools.migration.library.mule.steps.ee.CacheHttpCachingStrategy;
Expand Down Expand Up @@ -88,6 +89,7 @@ public List<MigrationStep> getSteps() {
new ScatterGather(),
new Enricher(),
new Flow(),
new SubFlow(),
new FlowRef(),
new CompositeSource(),
new Async(),
Expand Down

0 comments on commit 523b7e2

Please sign in to comment.