use of org.talend.core.service.IDQComponentService in project tdi-studio-se by Talend.
the class ExternalNodeChangeCommand method execute.
@Override
public void execute() {
propagateInput();
// bug 0020749
if (!oldMetaDataList.isEmpty() && !newMetaDataList.isEmpty() && !oldMetaDataList.get(0).sameMetadataAs(newMetaDataList.get(0))) {
node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
}
metadataOutputChanges.clear();
List<IConnection> initTraceList = new ArrayList<IConnection>();
for (IConnection connection : node.getOutgoingConnections()) {
if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
IODataComponent dataComponent = inAndOut.getDataComponent(connection);
boolean sameMetadataAs = connection.getMetadataTable().sameMetadataAs(dataComponent.getTable());
IMetadataTable tempTable = null;
boolean isSchemaAutoPropagated = true;
if (connection.getTarget().getComponent() instanceof EmfComponent) {
EmfComponent component = (EmfComponent) connection.getTarget().getComponent();
isSchemaAutoPropagated = component.isSchemaAutoPropagated();
}
if (sameMetadataAs || !isSchemaAutoPropagated) {
for (IMetadataTable itable : newMetaDataList) {
if (connection.getMetadataTable().getTableName().equals(itable.getTableName())) {
sameMetadataAs = connection.getMetadataTable().sameMetadataAs(itable);
tempTable = itable;
break;
}
}
} else {
IMetadataTable table = connection.getMetadataTable();
if (table == null || table.getListColumns().isEmpty()) {
initTraceList.add(connection);
}
INode connTar = connection.getTarget();
boolean isAllowedPropagated = connTar.getComponent().isAllowedPropagated();
boolean openDialog = false;
Map<String, Boolean> jobletMap = new HashMap<String, Boolean>();
if (isForTemlate()) {
openDialog = true;
} else if (!isAllowedPropagated) {
openDialog = false;
} else {
openDialog = getPropagate(connection, jobletMap);
}
if (openDialog) {
IElementParameter schemaParam = null;
if (connection != null) {
IMetadataTable connTable = connection.getMetadataTable();
IMetadataTable dataTable = dataComponent.getTable();
if (tempTable != null) {
dataTable = tempTable;
}
for (IElementParameter param : ((Node) connection.getTarget()).getElementParameters()) {
if (EParameterFieldType.SCHEMA_TYPE.equals(param.getFieldType()) || EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
INodeConnector connector = connection.getTarget().getConnectorFromName(connection.getConnectorName());
if (connector != null && param.getContext().equals(connector.getBaseSchema())) {
schemaParam = param;
break;
}
}
}
if (schemaParam != null) {
ChangeMetadataCommand cmd = new ChangeMetadataCommand(connection.getTarget(), schemaParam, connTable, dataTable);
cmd.execute(true);
metadataOutputChanges.add(cmd);
}
for (IElementParameter param : ((Node) connection.getSource()).getElementParameters()) {
if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) && param.getContext().equals(connection.getSource().getConnectorFromName(connection.getConnectorName()).getBaseSchema())) {
schemaParam = param;
break;
}
}
if (schemaParam != null) {
ChangeMetadataCommand cmd = new ChangeMetadataCommand(connection.getSource(), schemaParam, connTable, dataTable);
cmd.execute(true);
metadataOutputChanges.add(cmd);
}
if (((Node) connTar).isJoblet()) {
IElementParameter param = connTar.getElementParameter(connection.getTarget().getUniqueName());
if (param != null) {
IMetadataTable originaleOutputTable = connTar.getMetadataFromConnector(param.getContext());
if (originaleOutputTable != null) {
MetadataToolHelper.copyTable(dataTable, originaleOutputTable);
}
}
} else if (((Node) connTar).getJobletNode() != null) {
IElementParameter param = ((Node) connTar).getJobletNode().getElementParameter(connection.getTarget().getUniqueName());
if (param != null) {
IMetadataTable originaleOutputTable = ((Node) connTar).getJobletNode().getMetadataFromConnector(param.getContext());
if (originaleOutputTable != null) {
MetadataToolHelper.copyTable(dataTable, originaleOutputTable);
}
}
}
}
if (((Node) connTar).isJoblet()) {
changeCollapsedState(true, jobletMap, connTar);
}
} else {
// no matter propagate or not the metadata change will be propagate to xmlmap emf data
final Node target = (Node) connection.getTarget();
if (target != null && target.getExternalNode() != null) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IXmlMapService.class)) {
final IXmlMapService service = (IXmlMapService) GlobalServiceRegister.getDefault().getService(IXmlMapService.class);
if (service.isXmlMapComponent(target.getExternalNode())) {
IODataComponent output = new IODataComponent(connection, dataComponent.getTable());
target.metadataInputChanged(output, connection.getUniqueName());
}
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkMapService.class)) {
final ISparkMapService service = (ISparkMapService) GlobalServiceRegister.getDefault().getService(ISparkMapService.class);
if (service.isSparkMapComponent(target.getExternalNode())) {
IODataComponent output = new IODataComponent(connection, dataComponent.getTable());
target.metadataInputChanged(output, connection.getUniqueName());
}
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDQComponentService.class)) {
final IDQComponentService service = (IDQComponentService) GlobalServiceRegister.getDefault().getService(IDQComponentService.class);
service.externalComponentChange(connection, dataComponent.getTable());
}
}
}
}
if (connection instanceof Connection) {
((Connection) connection).updateName();
}
}
}
node.setExternalData(newExternalData);
/*
* It's better to clone, because will change that, if apply, bug 13325
*/
// node.setExternalData(newExternalData.clone()); //should test later.
List<IMetadataTable> cloneNewMetadata = new ArrayList<IMetadataTable>();
if (newMetaDataList != null) {
for (IMetadataTable t : newMetaDataList) {
cloneNewMetadata.add(t.clone(true));
}
}
node.setMetadataList(cloneNewMetadata);
// init trace
for (IConnection conn : initTraceList) {
if (conn instanceof Connection) {
((Connection) conn).initTraceParamters();
}
}
for (Connection connection : connectionsToDelete.keySet()) {
connection.disconnect();
INode prevNode = connection.getSource();
INodeConnector nodeConnectorSource, nodeConnectorTarget;
nodeConnectorSource = prevNode.getConnectorFromType(connection.getLineStyle());
nodeConnectorSource.setCurLinkNbOutput(nodeConnectorSource.getCurLinkNbOutput() - 1);
INode nextNode = connection.getTarget();
nodeConnectorTarget = nextNode.getConnectorFromType(connection.getLineStyle());
nodeConnectorTarget.setCurLinkNbInput(nodeConnectorTarget.getCurLinkNbInput() - 1);
inAndOut.getOuputs().remove(connectionsToDelete.get(connection));
((Process) node.getProcess()).checkStartNodes();
}
((Process) node.getProcess()).checkProcess();
if (!isMetaLanguage) {
refreshCodeView();
ComponentSettings.switchToCurComponentSettingsView();
}
}
Aggregations