Compare commits

...

2 Commits

Author SHA1 Message Date
Roman Voievidko
fee4a9fea1 fix(TDI-39240): improve exception message, minor fixes 2018-03-30 14:05:03 +03:00
Roman Voievidko
4d5a389e80 fix(TDI-39240): add logic to check if component use paralel vars 2018-03-29 18:36:10 +03:00

View File

@@ -3,8 +3,18 @@ imports="
org.talend.core.model.process.INode
org.talend.core.model.process.ElementParameterParser
org.talend.designer.codegen.config.CodeGeneratorArgument
org.talend.core.model.process.IElementParameter
org.talend.core.model.process.IConnection
org.talend.core.model.process.EComponentCategory
org.talend.core.model.process.EParameterFieldType
org.talend.designer.core.ui.editor.nodes.Node
org.talend.designer.core.model.components.ElementParameter
org.talend.core.model.utils.ContextParameterUtils
java.util.List
java.util.ArrayList
java.util.Map
java.util.Iterator
"
%>
@@ -13,15 +23,79 @@ CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
INode node = (INode)codeGenArgument.getArgument();
String cid = node.getUniqueName();
List<Map<String, String>> variables =
(List<Map<String,String>>)ElementParameterParser.getObjectValue(
node,
"__VARIABLES__"
);
boolean flag = false;
List<String> parallelizationConnections = new ArrayList();
List< ? extends INode> nodes = node.getProcess().getGeneratingNodes();
for (INode generatedNode : nodes){
for (Map<String, String> variable : variables) {
%>
globalMap.put(<%=variable.get("KEY")%>, <%=variable.get("VALUE")%>);
<%
if (generatedNode.getUniqueName().startsWith("tRecollector")){
flag = false;
}
if (generatedNode.getUniqueName().startsWith("tPartitioner") || flag) {
flag = true;
List< ? extends IConnection> nodeConnections = generatedNode.getOutgoingConnections();
for (IConnection con : nodeConnections){
//remove technical connection names
if (con.getName().equals("Starts")) continue;
parallelizationConnections.add(con.getName());
}
}
}
List< ? extends IElementParameter> elements = node.getElementParametersWithChildrens();
Iterator< ? extends IElementParameter> iterator = elements.iterator();
while (iterator.hasNext()){
IElementParameter elementParameter = iterator.next();
if (elementParameter.getCategory() != EComponentCategory.ADVANCED && elementParameter.getCategory() != EComponentCategory.BASIC){
iterator.remove();
}
}
List<String> componentVariables = new ArrayList();
for (IElementParameter ielement : elements){
if (ielement.getListItemsValue()!= null && ielement.getFieldType() == EParameterFieldType.TABLE) {
List<java.util.Map<String, String>> tableValues = ElementParameterParser.createTableValues((List<Map<String, Object>>) ielement.getValue(), ielement);
for(Map<String, String> map : tableValues) {
componentVariables.add(map.get("KEY"));
componentVariables.add(map.get("VALUE"));
}
}
}
List<String> componentsVarsThatRefersToParallel = new ArrayList();
for (String var : componentVariables){
for (String connectionName : parallelizationConnections){
String shortVar = var.replaceAll("\"","");
connectionName = connectionName.replaceAll("\"","") + ".";
if (ContextParameterUtils.containCodeVariable(shortVar, connectionName)) {
componentsVarsThatRefersToParallel.add(var);
}
}
}
boolean hasVariablesRefToParallel = !componentsVarsThatRefersToParallel.isEmpty();
String exceptionMessage = "Variables " + componentsVarsThatRefersToParallel + " of " + node.getUniqueName() + " refers to connections from parallelization";
%>
if (<%=hasVariablesRefToParallel%>) throw new IllegalArgumentException("<%=exceptionMessage%>");
<%
if (!hasVariablesRefToParallel) {
List<Map<String, String>> variables =
(List<Map<String,String>>)ElementParameterParser.getObjectValue(
node,
"__VARIABLES__"
);
for (Map<String, String> variable : variables) {
%>
globalMap.put(<%=variable.get("KEY")%>, <%=variable.get("VALUE")%>);
<%
}
}
%>