use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class ConnectionManager method canConnect.
/**
*
* Will return true if the connection can connect or not between source & target.
*
* @param source
* @param target
* @param connType
* @param connectionName
* @return
*/
private static boolean canConnect(INode source, INode target, EConnectionType connType, String connectionName) {
if (source.equals(target)) {
return false;
}
if (!target.isActivate() || !source.isActivate()) {
return false;
}
boolean skipSameProcessTest = false;
if (newlineStyle.equals(EConnectionType.FLOW_MAIN)) {
int nbMain = 0;
for (IConnection connec : target.getIncomingConnections()) {
if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
nbMain++;
}
}
int maxFlowInput = 0;
if (target.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()) != null) {
maxFlowInput = target.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()).getMaxLinkInput();
}
if (maxFlowInput > 1 && nbMain >= 1 && (nbMain <= maxFlowInput || maxFlowInput == -1)) {
// if the component accept several connections on the input, all inputs must come from the same process
boolean isExtensionComponent = false;
AbstractProcessProvider findProcessProviderFromPID = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
if (findProcessProviderFromPID != null) {
isExtensionComponent = findProcessProviderFromPID.isExtensionComponent(target);
}
if (!isExtensionComponent && !source.sameProcessAs(target, false)) {
return false;
}
skipSameProcessTest = true;
}
}
if (!skipSameProcessTest && source.sameProcessAs(target, false)) {
return false;
}
// Check existing connections to avoid to have more than one link
// no matter the type of the connection and the direction
List<Connection> connections = new ArrayList<Connection>((List<Connection>) source.getOutgoingConnections());
connections.removeAll(source.getOutgoingConnections(EConnectionType.FLOW_MAIN));
// connections = source.getOutgoingConnections();
for (int i = 0; i < connections.size(); i++) {
if ((connections.get(i)).getTarget().equals(target)) {
return false;
}
}
connections = new ArrayList<Connection>((List<Connection>) source.getIncomingConnections());
connections.removeAll(source.getIncomingConnections(EConnectionType.FLOW_MAIN));
// connections = source.getIncomingConnections();
for (int i = 0; i < connections.size(); i++) {
if ((connections.get(i)).getSource().equals(target)) {
return false;
}
}
if (connType.hasConnectionCategory(IConnectionCategory.DEPENDENCY)) {
if (!(Boolean) target.getPropertyValue(EParameterName.STARTABLE.getName())) {
return false;
}
boolean isJoblet = false;
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null) {
if (service.isJobletComponent(target) && !connType.hasConnectionCategory(IConnectionCategory.FLOW)) {
List<INodeConnector> freeTriggerBuiltConnectors = service.getFreeTriggerBuiltConnectors(target, connType, true);
if (freeTriggerBuiltConnectors.isEmpty()) {
return false;
}
isJoblet = true;
}
// for bug 10973
if (service.isTriggerNode(target) && target.getIncomingConnections() != null && target.getIncomingConnections().size() >= 1) {
return false;
}
}
}
if (!isJoblet && !target.isELTComponent() && !target.isSubProcessStart()) {
return false;
}
}
connections = (List<Connection>) target.getIncomingConnections();
for (int i = 0; i < connections.size(); i++) {
if (connType == EConnectionType.TABLE || connType == EConnectionType.TABLE_REF) {
if ((connections.get(i)).isActivate()) {
if ((connections.get(i)).getName().equals(connectionName)) {
return false;
}
}
}
}
boolean targetHasHashLinks = ((Process) target.getProcess()).isThereLinkWithHash(target) | newlineStyle.hasConnectionCategory(IConnectionCategory.USE_HASH);
if (connType.hasConnectionCategory(IConnectionCategory.CONDITION)) {
if (targetHasHashLinks) {
return false;
}
}
if (targetHasHashLinks && source.hasRunIfLink()) {
return false;
}
return true;
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class ConnectionManager method canConnectToTarget.
/**
* Will return true if the connection can connect or not between source & target.
*
* @param source
* @param oldTarget
* @param newTarget
* @param connType
* @param connectionName
* @return
*/
public static boolean canConnectToTarget(INode source, INode oldTarget, INode newTarget, EConnectionType lineStyle, String connectorName, String connectionName) {
newlineStyle = lineStyle;
boolean isMainConn = lineStyle == EConnectionType.FLOW_MAIN;
if (source.equals(newTarget)) {
return false;
}
final INode designSubjobStartNode = source.getDesignSubjobStartNode();
if ((designSubjobStartNode.getOutgoingConnections(EConnectionType.ON_SUBJOB_OK).size() != 0 || designSubjobStartNode.getOutgoingConnections(EConnectionType.ON_SUBJOB_ERROR).size() != 0) && !newTarget.checkIfCanBeStart() && isMainConn && !((Node) newTarget).isJoblet()) {
return false;
}
if ((designSubjobStartNode.getIncomingConnections(EConnectionType.ON_SUBJOB_OK).size() != 0 || designSubjobStartNode.getIncomingConnections(EConnectionType.ON_SUBJOB_ERROR).size() != 0) && !newTarget.checkIfCanBeStart() && isMainConn && !((Node) newTarget).isJoblet()) {
return false;
}
if (newTarget.getJobletNode() != null) {
return false;
}
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null) {
if (service.isTriggerNode(newTarget) && !service.canConnectTriggerNode(newTarget, lineStyle)) {
return false;
}
// can't connect from joblet's node, bug 21411
if (service.isJobletComponent(source.getJobletNode())) {
return false;
}
}
}
INode processStartNode = source.getProcessStartNode(true);
// if the target is the start of the (source) process, then can't connect.
if (processStartNode.equals(newTarget)) {
return false;
}
// to avoid different db elt input link to map.
if (newTarget.isELTComponent() && newTarget.getComponent().getName().endsWith("Map")) {
//$NON-NLS-1$
String targetName = newTarget.getComponent().getOriginalFamilyName();
String sourceName = processStartNode.getComponent().getOriginalFamilyName();
if (!targetName.equals(sourceName) && !(lineStyle.hasConnectionCategory(IConnectionCategory.DEPENDENCY))) {
return false;
}
if (source.isELTComponent() && source.getComponent().getName().endsWith("Map")) {
//$NON-NLS-1$
List<? extends IConnection> tableLines = source.getOutgoingConnections(EConnectionType.TABLE);
if (null != tableLines && 0 < tableLines.size()) {
// node, so could not have table_ref out line
return false;
}
newlineStyle = EConnectionType.TABLE_REF;
}
}
// fix bug 0004935: Error on job save
if (checkCircle(source, newTarget)) {
return false;
}
if (newTarget.isFileScaleComponent()) {
if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && !connectorName.equals("FSCOMBINE")) {
//$NON-NLS-1$
return false;
}
}
// TDI-25765 : avoid any connection for components not accepting PIG
if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && "PIGCOMBINE".equals(connectorName)) {
//$NON-NLS-1$
if (!newTarget.getComponent().getName().startsWith("tPig")) {
//$NON-NLS-1$
return false;
}
}
if (newTarget.getComponent() != null && newTarget.getComponent().getName().startsWith("tPig")) {
//$NON-NLS-1$
if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && !"PIGCOMBINE".equals(connectorName)) {
//$NON-NLS-1$
return false;
}
}
// TDI-29775 : avoid any connection for components not accepting SPARK
if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && "SPARKCOMBINE".equals(connectorName)) {
//$NON-NLS-1$
if (!newTarget.getComponent().getName().startsWith("tSpark")) {
//$NON-NLS-1$
return false;
}
}
if (newTarget.getComponent() != null && newTarget.getComponent().getName().startsWith("tSpark")) {
//$NON-NLS-1$
if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && !"SPARKCOMBINE".equals(connectorName)) {
//$NON-NLS-1$
return false;
}
}
// Modify Connection Type depending old and new target.
if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW)) {
// if the connection type is not the default one, then we don't change automatically.
// && newlineStyle.getName().equals(newConnectionType)) {
newlineStyle = EConnectionType.FLOW_MAIN;
if (newTarget.getComponent().useLookup()) {
int nbMain = 0;
for (IConnection connec : newTarget.getIncomingConnections()) {
if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
nbMain++;
}
}
if (nbMain >= 1) {
newlineStyle = EConnectionType.FLOW_REF;
} else {
newlineStyle = EConnectionType.FLOW_MAIN;
}
} else if (newTarget.getComponent().useMerge()) {
newlineStyle = EConnectionType.FLOW_MERGE;
}
}
boolean isJoblet = false;
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null && service.isJobletComponent(newTarget) && !lineStyle.hasConnectionCategory(IConnectionCategory.FLOW)) {
List<INodeConnector> inputConnector = service.getFreeTriggerBuiltConnectors(newTarget, lineStyle, true);
if (inputConnector.isEmpty()) {
return false;
}
isJoblet = true;
}
}
if (!isJoblet) {
INodeConnector connectorFromType = newTarget.getConnectorFromType(newlineStyle);
int maxInput = connectorFromType.getMaxLinkInput();
if (maxInput != -1 && (connectorFromType.getCurLinkNbInput() >= maxInput)) {
return false;
}
}
if (!canConnect(source, newTarget, lineStyle, connectionName)) {
return false;
}
// if (!newConnectionType.equals(EConnectionType.LOOKUP)) {
// INodeConnector nodeConnectorTarget;
// nodeConnectorTarget = newTarget.getConnectorFromType(newConnectionType);
// if (nodeConnectorTarget.getMaxLinkInput() != -1) {
// if (nodeConnectorTarget.getCurLinkNbInput() >= nodeConnectorTarget.getMaxLinkInput()) {
// return false;
// }
// }
// }
// check extensionPoints
Set<IConnectionValidator> connectionValidators = ConnectionValidatorManager.getConnectionValidators();
for (IConnectionValidator validator : connectionValidators) {
boolean canConnectToTarget = validator.canConnectToTarget(source, oldTarget, newTarget, lineStyle, connectorName, connectionName);
if (!canConnectToTarget) {
return false;
}
}
return true;
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class NodesPasteCommand method createNodeContainerList.
@SuppressWarnings("unchecked")
private void createNodeContainerList() {
int firstIndex = 0;
int index = 0;
nodeContainerList = new ArrayList<NodeContainer>();
jobletNodeToExpand = new ArrayList<NodeContainer>();
connections = new ArrayList<IConnection>();
createdNames = new ArrayList<String>();
Map<String, String> oldNameTonewNameMap = new HashMap<String, String>();
Map<String, String> oldMetaToNewMeta = new HashMap<String, String>();
// see bug 0004882: Subjob title is not copied when copying/pasting subjobs from one job to another
Map<INode, SubjobContainer> mapping = new HashMap<INode, SubjobContainer>();
ITestContainerGEFService testContainerService = null;
Map<SubjobContainer, List<Node>> junitGroup = null;
if (isJunitCreate()) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerGEFService.class)) {
testContainerService = (ITestContainerGEFService) GlobalServiceRegister.getDefault().getService(ITestContainerGEFService.class);
if (testContainerService != null) {
junitGroup = testContainerService.caculateJunitGroup(nodeParts);
}
}
if (nodeMap == null) {
nodeMap = new HashMap<IGraphicalNode, IGraphicalNode>();
}
}
// create the nodes
for (NodePart copiedNodePart : nodeParts) {
IGraphicalNode copiedNode = (IGraphicalNode) copiedNodePart.getModel();
if (!containNodeInProcess(copiedNode)) {
continue;
}
IComponent component = ComponentsFactoryProvider.getInstance().get(copiedNode.getComponent().getName(), process.getComponentsType());
if (component == null) {
boolean isJobletInOutComponent = false;
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null && service.isJobletInOutComponent(copiedNode)) {
isJobletInOutComponent = true;
}
}
if (isJobletInOutComponent) {
component = copiedNode.getComponent();
} else {
component = new DummyComponent(copiedNode.getComponent().getName());
}
}
IGraphicalNode pastedNode = new Node(component, process);
if (nodeMap != null) {
nodeMap.put(copiedNode, pastedNode);
}
if (isJobletRefactor() || isJunitCreate()) {
// keep original for joblet refactor.
process.removeUniqueNodeName(pastedNode.getUniqueName());
pastedNode.setPropertyValue(EParameterName.UNIQUE_NAME.getName(), copiedNode.getUniqueName());
process.addUniqueNodeName(copiedNode.getUniqueName());
}
// for bug 0004882: Subjob title is not copied when copying/pasting subjobs from one job to another
makeCopyNodeAndSubjobMapping(copiedNode, pastedNode, mapping);
Point location = null;
if (getCursorLocation() == null) {
location = copiedNode.getLocation();
} else {
location = getCursorLocation();
index = nodeParts.indexOf(copiedNodePart);
}
if (process.isGridEnabled()) {
// replace the component to set it on the grid if it's enabled
int tempVar = location.x / TalendEditor.GRID_SIZE;
location.x = tempVar * TalendEditor.GRID_SIZE;
tempVar = location.y / TalendEditor.GRID_SIZE;
location.y = tempVar * TalendEditor.GRID_SIZE;
}
pastedNode.setLocation(findLocationForNode(location, copiedNode.getSize(), index, firstIndex, copiedNodePart));
pastedNode.setSize(copiedNode.getSize());
INodeConnector mainConnector;
if (pastedNode.isELTComponent()) {
mainConnector = pastedNode.getConnectorFromType(EConnectionType.TABLE);
} else {
mainConnector = pastedNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
}
if (!mainConnector.isMultiSchema()) {
if (copiedNode.getMetadataList().size() != 0) {
pastedNode.getMetadataList().clear();
for (IMetadataTable metaTable : copiedNode.getMetadataList()) {
IMetadataTable newMetaTable = metaTable.clone();
if (metaTable.getTableName().equals(copiedNode.getUniqueName())) {
newMetaTable.setTableName(pastedNode.getUniqueName());
}
for (IMetadataColumn column : metaTable.getListColumns()) {
if (column.isCustom()) {
IMetadataColumn newColumn = newMetaTable.getColumn(column.getLabel());
newColumn.setReadOnly(column.isReadOnly());
newColumn.setCustom(column.isCustom());
}
}
pastedNode.getMetadataList().add(newMetaTable);
}
}
} else {
List<IMetadataTable> copyOfMetadataList = new ArrayList<IMetadataTable>();
for (IMetadataTable metaTable : copiedNode.getMetadataList()) {
IMetadataTable newTable = metaTable.clone();
if (copiedNode.isELTComponent()) {
newTable.setTableName(createNewConnectionName(metaTable.getTableName(), IProcess.DEFAULT_TABLE_CONNECTION_NAME));
} else {
if (metaTable.getTableName().equals(copiedNode.getUniqueName())) {
newTable.setTableName(createNewConnectionName(pastedNode.getUniqueName(), null));
} else {
newTable.setTableName(createNewConnectionName(metaTable.getTableName(), null));
}
}
//$NON-NLS-1$
oldMetaToNewMeta.put(pastedNode.getUniqueName() + ":" + metaTable.getTableName(), newTable.getTableName());
for (IMetadataColumn column : metaTable.getListColumns()) {
if (column.isCustom()) {
IMetadataColumn newColumn = newTable.getColumn(column.getLabel());
newColumn.setReadOnly(column.isReadOnly());
newColumn.setCustom(column.isCustom());
}
}
newTable.sortCustomColumns();
copyOfMetadataList.add(newTable);
}
pastedNode.setMetadataList(copyOfMetadataList);
}
// TDQ-10039 extract this code from above "else",aslo consider tMatchGroup.
if (mainConnector.isMultiSchema() || copiedNode.getComponent().getName().startsWith("tMatchGroup")) {
//$NON-NLS-1$
IExternalNode externalNode = pastedNode.getExternalNode();
if (externalNode != null) {
if (copiedNode.getExternalData() != null) {
try {
externalNode.setExternalData(copiedNode.getExternalData().clone());
} catch (CloneNotSupportedException e) {
ExceptionHandler.process(e);
}
((Node) pastedNode).setExternalData(externalNode.getExternalData());
}
if (copiedNode.getExternalNode().getExternalEmfData() != null) {
externalNode.setExternalEmfData(EcoreUtil.copy(copiedNode.getExternalNode().getExternalEmfData()));
}
for (IMetadataTable metaTable : copiedNode.getMetadataList()) {
String oldName = metaTable.getTableName();
//$NON-NLS-1$
String newName = oldMetaToNewMeta.get(pastedNode.getUniqueName() + ":" + metaTable.getTableName());
externalNode.renameOutputConnection(oldName, newName);
CorePlugin.getDefault().getMapperService().renameJoinTable(process, externalNode.getExternalData(), createdNames);
}
// when copy a external node, should also copy screeshot
if (copiedNode.getExternalNode() != null) {
ImageDescriptor screenshot = copiedNode.getExternalNode().getScreenshot();
if (screenshot != null) {
externalNode.setScreenshot(screenshot);
}
}
}
}
((Node) pastedNode).getNodeLabel().setOffset(new Point(((Node) copiedNode).getNodeLabel().getOffset()));
oldNameTonewNameMap.put(copiedNode.getUniqueName(), pastedNode.getUniqueName());
if (copiedNode.getElementParametersWithChildrens() != null) {
for (ElementParameter param : (List<ElementParameter>) copiedNode.getElementParametersWithChildrens()) {
if (!EParameterName.UNIQUE_NAME.getName().equals(param.getName())) {
IElementParameter elementParameter = pastedNode.getElementParameter(param.getName());
if (elementParameter != null) {
if (param.getFieldType() == EParameterFieldType.TABLE) {
List<Map<String, Object>> tableValues = (List<Map<String, Object>>) param.getValue();
ArrayList newValues = new ArrayList();
for (Map<String, Object> map : tableValues) {
Map<String, Object> newMap = new HashMap<String, Object>();
newMap.putAll(map);
// rename schemas
if (!oldMetaToNewMeta.isEmpty()) {
boolean isSAPBapiInputSchema = //$NON-NLS-1$
"MAPPING_INPUT".equals(param.getName()) && //$NON-NLS-1$
"tSAPBapi".equals(copiedNode.getComponent().getName());
if (EParameterName.SCHEMAS.name().equals(param.getName()) || isSAPBapiInputSchema) {
String newSchemaName = oldMetaToNewMeta.get(pastedNode.getUniqueName() + ":" + map.get(EParameterName.SCHEMA.getName()));
if (newSchemaName != null) {
newMap.put(EParameterName.SCHEMA.getName(), newSchemaName);
}
}
}
newValues.add(newMap);
}
// fix for TDI-7988 paste tFixedFlowInput inline table
Object[] copiedListItem = param.getListItemsValue();
if (copiedListItem != null) {
Object[] pasetedListItem = elementParameter.getListItemsValue();
if (pasetedListItem == null || pasetedListItem.length != copiedListItem.length) {
elementParameter.setListItemsValue(copiedListItem);
elementParameter.setListItemsDisplayCodeName(param.getListItemsDisplayCodeName());
elementParameter.setListItemsDisplayName(param.getListItemsDisplayName());
}
}
elementParameter.setValue(newValues);
} else {
if (param.getParentParameter() != null) {
String parentName = param.getParentParameter().getName();
//$NON-NLS-1$
pastedNode.setPropertyValue(parentName + ":" + param.getName(), param.getValue());
} else if (param.getName().equals("SOURCE_GENERATED_TDM_STRUCT_PATH") || param.getName().equals("TARGET_GENERATED_TDM_STRUCT_PATH") || param.getName().equals("SOURCE_TDM_STRUCT_INCARNATION") || param.getName().equals("TARGET_TDM_STRUCT_INCARNATION")) {
elementParameter.setReadOnly(param.getOriginalityReadOnly());
elementParameter.setRepositoryValueUsed(param.isRepositoryValueUsed());
} else {
pastedNode.setPropertyValue(param.getName(), param.getValue());
// See Bug 0005722: the pasted component don't keep the same read-only mode and
// didn;t
// hide
// the password.
elementParameter.setReadOnly(param.getOriginalityReadOnly());
elementParameter.setRepositoryValueUsed(param.isRepositoryValueUsed());
}
}
}
}
}
}
List<Node> pastedNodeList = null;
if (junitGroup != null) {
pastedNodeList = junitGroup.get(((Node) copiedNode).getNodeContainer().getSubjobContainer());
}
NodeContainer nc = ((Process) pastedNode.getProcess()).loadNodeContainer((Node) pastedNode, ((Node) copiedNode).isJunitStart() && isJunitCreate());
if (pastedNodeList != null) {
pastedNodeList.remove(copiedNode);
pastedNodeList.add((Node) pastedNode);
}
nodeContainerList.add(nc);
if (selectedExpandedJoblet != null && selectedExpandedJoblet.contains(copiedNodePart)) {
jobletNodeToExpand.add(nc);
}
}
((Process) process).setCopyPasteSubjobMappings(mapping);
Map<String, String> oldToNewConnVarMap = new HashMap<String, String>();
// add the connections
for (NodePart copiedNodePart : nodeParts) {
INode copiedNode = (INode) copiedNodePart.getModel();
for (IConnection connection : (List<IConnection>) copiedNode.getOutgoingConnections()) {
INode pastedTargetNode = null, pastedSourceNode = null;
String nodeSource = oldNameTonewNameMap.get(copiedNode.getUniqueName());
for (NodeContainer nodeContainer : nodeContainerList) {
INode node = nodeContainer.getNode();
if (node.getUniqueName().equals(nodeSource)) {
pastedSourceNode = node;
}
}
INode targetNode = connection.getTarget();
// test if the target is in the nodes to paste to add the
// connection
// if the targeted node is not in the nodes to paste, then the
// string will be null
String nodeToConnect = oldNameTonewNameMap.get(targetNode.getUniqueName());
if (nodeToConnect != null) {
for (NodeContainer nodeContainer : nodeContainerList) {
INode node = nodeContainer.getNode();
if (node.getUniqueName().equals(nodeToConnect)) {
pastedTargetNode = node;
}
}
}
if ((pastedSourceNode != null) && (pastedTargetNode != null)) {
String newConnectionName;
String metaTableName;
if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.UNIQUE_NAME) && connection.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
String newNameBuiltIn = oldMetaToNewMeta.get(//$NON-NLS-1$
pastedSourceNode.getUniqueName() + ":" + connection.getMetaName());
if (newNameBuiltIn == null) {
IElementParameter formatParam = pastedSourceNode.getElementParameter(EParameterName.CONNECTION_FORMAT.getName());
String baseName = IProcess.DEFAULT_ROW_CONNECTION_NAME;
if (formatParam != null) {
String value = (String) formatParam.getValue();
if (value != null && !"".equals(value)) {
//$NON-NLS-1$
baseName = value;
}
}
if (process.checkValidConnectionName(connection.getName(), true)) {
// keep the name, bug 5086
baseName = null;
}
newConnectionName = createNewConnectionName(connection.getName(), baseName);
} else {
newConnectionName = newNameBuiltIn;
}
} else {
newConnectionName = connection.getName();
}
//$NON-NLS-1$
String meta = oldMetaToNewMeta.get(pastedSourceNode.getUniqueName() + ":" + connection.getMetaName());
if (meta != null) {
if (pastedSourceNode.getConnectorFromType(connection.getLineStyle()).isMultiSchema() && !connection.getLineStyle().equals(EConnectionType.TABLE)) {
newConnectionName = meta;
}
metaTableName = meta;
} else {
if (pastedSourceNode.getConnectorFromType(connection.getLineStyle()).isMultiSchema()) {
metaTableName = pastedSourceNode.getMetadataList().get(0).getTableName();
} else {
// connection.getMetaName();
metaTableName = pastedSourceNode.getUniqueName();
}
}
IConnection pastedConnection;
if (!pastedTargetNode.isELTComponent()) {
pastedConnection = new Connection(pastedSourceNode, pastedTargetNode, connection.getLineStyle(), connection.getConnectorName(), metaTableName, newConnectionName, connection.isMonitorConnection());
} else {
pastedConnection = new Connection(pastedSourceNode, pastedTargetNode, connection.getLineStyle(), connection.getConnectorName(), metaTableName, newConnectionName, metaTableName, connection.isMonitorConnection());
}
connections.add(pastedConnection);
oldNameTonewNameMap.put(connection.getUniqueName(), pastedConnection.getUniqueName());
// pastedConnection.setActivate(pastedSourceNode.isActivate());
for (ElementParameter param : (List<ElementParameter>) connection.getElementParameters()) {
// pastedConnection.getElementParameter(param.getName())
// .setValue(param.getValue());
pastedConnection.setPropertyValue(param.getName(), param.getValue());
}
// reset unique name param
IElementParameter uniqueNameParam = pastedConnection.getElementParameter(EParameterName.UNIQUE_NAME.getName());
String newName = oldNameTonewNameMap.get(connection.getUniqueName());
if (uniqueNameParam != null && newName != null) {
if (!newName.equals(uniqueNameParam.getValue())) {
pastedConnection.setPropertyValue(EParameterName.UNIQUE_NAME.getName(), newName);
}
}
// // keep the label (bug 3778)
// if (pastedConnection != null) {
// if (pastedConnection.getSourceNodeConnector().isBuiltIn()
// && pastedConnection.getLineStyle().hasConnectionCategory(EConnectionType.FLOW)) {
// pastedConnection.setPropertyValue(EParameterName.LABEL.getName(), connection.getName());
// } else {
// pastedConnection.setPropertyValue(EParameterName.LABEL.getName(), newConnectionName);
// }
// }
((Connection) pastedConnection).getConnectionLabel().setOffset(new Point(((Connection) connection).getConnectionLabel().getOffset()));
INodeConnector connector = pastedConnection.getSourceNodeConnector();
connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() + 1);
connector = pastedConnection.getTargetNodeConnector();
connector.setCurLinkNbInput(connector.getCurLinkNbInput() + 1);
IExternalNode externalNode = pastedTargetNode.getExternalNode();
if (externalNode != null) {
externalNode.renameInputConnection(connection.getName(), newConnectionName);
}
// (feature 2962)
if (pastedConnection.getMetadataTable() == null) {
continue;
}
for (IMetadataColumn column : pastedConnection.getMetadataTable().getListColumns()) {
//$NON-NLS-1$
String oldConnVar = connection.getName() + "." + column.getLabel();
//$NON-NLS-1$
String newConnVar = newConnectionName + "." + column.getLabel();
// String newConnVar = newConnectionName;
if (!oldToNewConnVarMap.containsKey(oldConnVar)) {
oldToNewConnVarMap.put(oldConnVar, newConnVar);
}
}
}
}
}
// rename the connection data for node parameters. (feature 2962)
for (NodeContainer nodeContainer : nodeContainerList) {
Node node = nodeContainer.getNode();
for (String oldConnVar : oldToNewConnVarMap.keySet()) {
String newConnVar = oldToNewConnVarMap.get(oldConnVar);
if (newConnVar != null) {
node.renameData(oldConnVar, newConnVar);
}
}
}
// check if the new components use the old components name.
Map<String, Set<String>> usedDataMap = new HashMap<String, Set<String>>();
for (NodeContainer nodeContainer : nodeContainerList) {
Node currentNode = nodeContainer.getNode();
String uniqueName = currentNode.getUniqueName();
for (String oldName : oldNameTonewNameMap.keySet()) {
if (!oldName.equals(oldNameTonewNameMap.get(oldName)) && currentNode.useData(oldName)) {
Set<String> oldNameSet = usedDataMap.get(uniqueName);
if (oldNameSet == null) {
oldNameSet = new HashSet<String>();
usedDataMap.put(uniqueName, oldNameSet);
}
oldNameSet.add(oldName);
}
}
}
// check if the new connections use the old components name.
Map<String, Set<String>> usedDataMapForConnections = new HashMap<String, Set<String>>();
for (IConnection connection : connections) {
String uniqueName = connection.getUniqueName();
for (String oldName : oldNameTonewNameMap.keySet()) {
if (oldName != null && !oldName.equals(oldNameTonewNameMap.get(oldName)) && UpgradeElementHelper.isUseData(connection, oldName)) {
Set<String> oldNameSet = usedDataMapForConnections.get(uniqueName);
if (oldNameSet == null) {
oldNameSet = new HashSet<String>();
usedDataMapForConnections.put(uniqueName, oldNameSet);
}
oldNameSet.add(oldName);
}
}
}
if (!usedDataMap.isEmpty() || !usedDataMapForConnections.isEmpty()) {
MessageBox msgBox = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.YES | SWT.NO | SWT.ICON_WARNING);
//$NON-NLS-1$
msgBox.setMessage(Messages.getString("NodesPasteCommand.renameMessages"));
if (msgBox.open() == SWT.YES) {
for (NodeContainer nodeContainer : nodeContainerList) {
Node currentNode = nodeContainer.getNode();
Set<String> oldNameSet = usedDataMap.get(currentNode.getUniqueName());
if (oldNameSet != null && !oldNameSet.isEmpty()) {
for (String oldName : oldNameSet) {
currentNode.renameData(oldName, oldNameTonewNameMap.get(oldName));
}
}
}
// Rename connections
for (IConnection connection : connections) {
Set<String> oldNameSet = usedDataMapForConnections.get(connection.getUniqueName());
if (oldNameSet != null && !oldNameSet.isEmpty()) {
for (String oldName : oldNameSet) {
UpgradeElementHelper.renameData(connection, oldName, oldNameTonewNameMap.get(oldName));
}
}
}
}
}
if (isJunitCreate()) {
if (testContainerService != null) {
testContainerService.setTestNodes(nodeMap, junitGroup, nodeContainerList);
}
}
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class DeleteNodeContainerCommand method execute.
@Override
@SuppressWarnings("unchecked")
public void execute() {
connectionDeletedInfosMap = new MultiKeyMap();
process.setActivate(false);
List uniqueNameList = new ArrayList();
for (INode node : nodeList) {
if (node.getJobletNode() != null) {
continue;
}
uniqueNameList.add(node.getUniqueName());
NodeContainer nodeContainer = ((Node) node).getNodeContainer();
((Process) process).removeNodeContainer(nodeContainer);
List<IConnection> inputList = (List<IConnection>) node.getIncomingConnections();
List<IConnection> outputList = (List<IConnection>) node.getOutgoingConnections();
boolean builtIn = node.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
for (IConnection connection : inputList) {
// see bug 0002633: "rejects" link disappears at times.
if (connection != null && connection.getSourceNodeConnector() != null) {
connection.getSourceNodeConnector().setCurLinkNbOutput(connection.getSourceNodeConnector().getCurLinkNbOutput() - 1);
}
INode prevNode = connection.getSource();
if ((prevNode instanceof Node) && ((Node) prevNode).getJobletNode() != null) {
Node jobletnode = (Node) prevNode.getJobletNode();
((AbstractJobletContainer) jobletnode.getNodeContainer()).getOutputs().remove(connection);
if (!nodeList.contains(jobletnode)) {
boolean builtInJobletNode = jobletnode.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
storeMetadata(connection, jobletnode, true);
jobletnode.removeOutput(connection);
if (!builtInJobletNode) {
process.removeUniqueConnectionName(connection.getUniqueName());
}
}
}
if (!nodeList.contains(prevNode)) {
boolean builtInPrevNode = prevNode.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
boolean remove = true;
if ((prevNode instanceof Node) && ((Node) prevNode).isELTMapComponent()) {
remove = false;
}
storeMetadata(connection, prevNode, remove);
prevNode.removeOutput(connection);
if (!builtInPrevNode && remove) {
process.removeUniqueConnectionName(connection.getUniqueName());
}
}
}
for (IConnection connection : outputList) {
INode nextNode = connection.getTarget();
if ((nextNode instanceof Node) && ((Node) nextNode).getJobletNode() != null) {
Node jobletnode = (Node) nextNode.getJobletNode();
((AbstractJobletContainer) jobletnode.getNodeContainer()).getInputs().remove(connection);
if (!nodeList.contains(jobletnode)) {
jobletnode.removeInput(connection);
boolean builtInJobletNode = jobletnode.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
if (!builtInJobletNode) {
process.removeUniqueConnectionName(connection.getUniqueName());
}
}
}
if (!nodeList.contains(nextNode)) {
INodeConnector nodeConnector = nextNode.getConnectorFromType(connection.getLineStyle());
nodeConnector.setCurLinkNbInput(nodeConnector.getCurLinkNbInput() - 1);
nextNode.removeInput(connection);
if (nextNode != null) {
for (int i = 0; i < nextNode.getIncomingConnections().size(); i++) {
Connection nextNodeConnection = (Connection) nextNode.getIncomingConnections().get(i);
nextNodeConnection.updateName();
}
}
if (nextNode.getExternalNode() instanceof AbstractNode) {
((AbstractNode) nextNode.getExternalNode()).removeInput(connection);
}
}
if (!builtIn) {
process.removeUniqueConnectionName(connection.getUniqueName());
}
}
if (builtIn) {
for (IMetadataTable meta : node.getMetadataList()) {
String metaName = meta.getTableName();
process.removeUniqueConnectionName(metaName);
}
// for tmap remove join table names
final List<String> names = CorePlugin.getDefault().getMapperService().getJoinTableNames(node.getExternalData());
if (!names.isEmpty()) {
joinTableNames.addAll(names);
for (String name : joinTableNames) {
process.removeUniqueConnectionName(name);
}
}
}
}
process.setActivate(true);
process.checkStartNodes();
process.checkProcess();
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class DeleteNodeContainerCommand method undo.
@Override
@SuppressWarnings("unchecked")
public void undo() {
process.setActivate(false);
for (INode node : nodeList) {
if (node.getJobletNode() != null) {
continue;
}
NodeContainer nodeContainer = ((Node) node).getNodeContainer();
this.process.addUniqueNodeName(node.getUniqueName());
((Process) process).addNodeContainer(nodeContainer);
List<Connection> inputList = (List<Connection>) node.getIncomingConnections();
List<Connection> outputList = (List<Connection>) node.getOutgoingConnections();
boolean builtIn = node.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
for (Connection connection : inputList) {
// see bug 0004514: need to undo for 0002633
if (connection != null && connection.getSourceNodeConnector() != null) {
connection.getSourceNodeConnector().setCurLinkNbOutput(connection.getSourceNodeConnector().getCurLinkNbOutput() + 1);
}
INode prevNode = connection.getSource();
if ((prevNode instanceof Node) && ((Node) prevNode).getJobletNode() != null) {
Node jobletnode = (Node) prevNode.getJobletNode();
((AbstractJobletContainer) jobletnode.getNodeContainer()).getOutputs().add(connection);
restoreMetadata(connection, jobletnode);
}
if (!nodeList.contains(prevNode)) {
if (!prevNode.getOutgoingConnections().contains(connection)) {
prevNode.addOutput(connection);
}
restoreMetadata(connection, prevNode);
connection.reconnect();
connection.updateAllId();
boolean builtInPrevNode = prevNode.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.UNIQUE_NAME) && !builtInPrevNode) {
// for bug 10024
// see 10583
String name = connection.getUniqueName();
if (connection.getConnectorName().startsWith("TRIGGER_OUTPUT")) {
if (process.checkValidConnectionName(name)) {
process.addUniqueConnectionName(name);
}
} else {
process.addUniqueConnectionName(name);
}
}
}
}
for (IConnection connection : outputList) {
INode nextNode = connection.getTarget();
if ((nextNode instanceof Node) && ((Node) nextNode).getJobletNode() != null) {
Node jobletnode = (Node) nextNode.getJobletNode();
((AbstractJobletContainer) jobletnode.getNodeContainer()).getInputs().add(connection);
}
if (!nodeList.contains(nextNode)) {
if (!nextNode.getIncomingConnections().contains(connection)) {
nextNode.addInput(connection);
}
INodeConnector nodeConnector = nextNode.getConnectorFromType(connection.getLineStyle());
nodeConnector.setCurLinkNbInput(nodeConnector.getCurLinkNbInput() + 1);
connection.reconnect();
if (nextNode.getExternalNode() instanceof AbstractNode) {
((AbstractNode) nextNode.getExternalNode()).addInput(connection);
}
}
if (!builtIn) {
if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.UNIQUE_NAME)) {
// for bug 10024
// see 10583
String name = connection.getUniqueName();
// name = process.generateUniqueConnectionName(name);
process.addUniqueConnectionName(name);
}
}
}
if (builtIn) {
for (IMetadataTable meta : node.getMetadataList()) {
String metaName = meta.getTableName();
process.addUniqueConnectionName(metaName);
}
// tmap join table
for (String name : joinTableNames) {
process.addUniqueConnectionName(name);
}
}
}
process.setActivate(true);
process.checkStartNodes();
process.checkProcess();
}
Aggregations