use of org.talend.designer.core.ui.editor.process.Process in project tdi-studio-se by Talend.
the class AbstractTalendEditor method getCommonKeyHandler.
/**
* DOC qzhang Comment method "getCommonKeyHandler".
*
* @return
*/
public KeyHandler getCommonKeyHandler() {
if (sharedKeyHandler == null) {
sharedKeyHandler = new KeyHandler();
sharedKeyHandler.put(KeyStroke.getPressed(SWT.F1, 0), new Action() {
@Override
public void run() {
ISelection selection = getGraphicalViewer().getSelection();
if (selection != null) {
if (selection instanceof IStructuredSelection) {
Object input = ((IStructuredSelection) selection).getFirstElement();
Node node = null;
if (input instanceof NodeTreeEditPart) {
NodeTreeEditPart nTreePart = (NodeTreeEditPart) input;
node = (Node) nTreePart.getModel();
} else {
if (input instanceof NodePart) {
EditPart editPart = (EditPart) input;
node = (Node) editPart.getModel();
}
}
if (node != null) {
String helpLink = (String) node.getPropertyValue(EParameterName.HELP.getName());
String requiredHelpLink = ((Process) node.getProcess()).getBaseHelpLink() + node.getComponent().getName();
if (helpLink == null || "".equals(helpLink) || !requiredHelpLink.equals(helpLink)) {
helpLink = ((Process) node.getProcess()).getBaseHelpLink() + node.getComponent().getName();
}
PlatformUI.getWorkbench().getHelpSystem().displayHelp(helpLink);
}
}
}
}
});
sharedKeyHandler.put(KeyStroke.getPressed(SWT.DEL, 0), getActionRegistry().getAction(ActionFactory.DELETE.getId()));
// deactivate the F2 shortcut as it's not used anymore
// sharedKeyHandler.put(KeyStroke.getPressed(SWT.F2, 0),
// getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT));
}
return sharedKeyHandler;
}
use of org.talend.designer.core.ui.editor.process.Process in project tdi-studio-se by Talend.
the class GuessSchemaProcess method buildProcess.
private void buildProcess() {
process = new Process(property);
process.getContextManager().getListContext().addAll(node.getProcess().getContextManager().getListContext());
process.getContextManager().setDefaultContext(this.selectContext);
outputComponent = ComponentsFactoryProvider.getInstance().get(EDatabaseComponentName.FILEDELIMITED.getOutPutComponentName(), ComponentCategory.CATEGORY_4_DI.getName());
if (node.getModulesNeeded().size() > 0 && !node.getComponent().getName().equals("tRedshiftInput")) {
//$NON-NLS-1$
for (ModuleNeeded module : node.getModulesNeeded()) {
if (module.isRequired(node.getElementParameters())) {
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
NodeContainer nc = process.loadNodeContainer(libNode1, false);
process.addNodeContainer(nc);
}
}
} else {
// hywang add for 9594
if (node.getComponent().getName().equals("tJDBCInput") || node.getComponent().getName().equals("tRedshiftInput")) {
List<String> drivers = EDatabaseVersion4Drivers.getDrivers(info.getTrueDBTypeForJDBC(), info.getDbVersion());
String moduleNeedName = "";
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
if (drivers.size() > 0) {
// use the first driver as defalult.
// added for bug 13592
moduleNeedName = drivers.get(0).toString();
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + moduleNeedName + "\"");
}
process.addNodeContainer(new NodeContainer(libNode1));
}
}
INode connectionNode = null;
IElementParameter existConnection = node.getElementParameter("USE_EXISTING_CONNECTION");
boolean useExistConnection = (existConnection == null ? false : (Boolean) existConnection.getValue());
if (useExistConnection) {
IElementParameter connector = node.getElementParameter("CONNECTION");
if (connector != null) {
String connectorValue = connector.getValue().toString();
List<? extends INode> generatingNodes = originalProcess.getGeneratingNodes();
for (INode node : generatingNodes) {
if (node.getUniqueName().equals(connectorValue)) {
connectionNode = node;
break;
}
}
}
}
List<ModuleNeeded> neededLibraries = new ArrayList<ModuleNeeded>();
JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, node);
for (ModuleNeeded module : neededLibraries) {
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
process.addNodeContainer(new NodeContainer(libNode1));
}
if (connectionNode != null) {
neededLibraries = new ArrayList<ModuleNeeded>();
JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, connectionNode);
for (ModuleNeeded module : neededLibraries) {
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
process.addNodeContainer(new NodeContainer(libNode1));
}
}
// create the tLibraryLoad for the output component which is "tFileOutputDelimited"
for (ModuleNeeded module : outputComponent.getModulesNeeded()) {
Node libNode2 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode2.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
process.addNodeContainer(new NodeContainer(libNode2));
}
// for sql statement, feature 6622.
int fetchSize = maximumRowsToPreview;
if (maximumRowsToPreview > 1000) {
fetchSize = 1000;
}
String codeStart, codeMain, codeEnd;
temppath = buildTempCSVFilename();
// Should also replace "/r". NMa.
// ISO-8859-15
memoSQL = memoSQL.replace("\r", " ");
// fix for TDI-26285
//$NON-NLS-1$
String createStatament = "conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY)";
//$NON-NLS-1$
String systemProperty = "";
if (info.isHive()) {
//$NON-NLS-1$
createStatament = "conn.createStatement()";
systemProperty = //$NON-NLS-1$ //$NON-NLS-2$
"System.setProperty(\"mapred.job.tracker\",\"" + info.getJobTracker() + "\");\r\n" + "System.setProperty(\"fs.default.name\", \"" + info.getNameNode() + //$NON-NLS-1$ //$NON-NLS-2$
"\");\r\n";
// only embeded hive need the following params
if (info.getThrifturi() != null) {
systemProperty = //$NON-NLS-1$
systemProperty + " System.setProperty(\"hive.metastore.local\", \"false\");\r\n" + " System.setProperty(\"hive.metastore.uris\", \"" + info.getThrifturi() + //$NON-NLS-1$ //$NON-NLS-2$
"\");\r\n" + //$NON-NLS-1$
"System.setProperty(\"hive.metastore.execute.setugi\", \"true\");\r\n";
}
}
// add for bug TDI-27137 by fwang on 27 August, 2013.
EDatabaseTypeName dbType = EDatabaseTypeName.JAVADB_EMBEDED.getTypeFromDbType(info.getDbType());
if (EDatabaseTypeName.JAVADB_EMBEDED.equals(dbType)) {
IElementParameter dbPathElement = node.getElementParameter("DBPATH");
if (dbPathElement != null) {
String derbyPath = dbPathElement.getValue().toString().replace("\"", "").trim();
systemProperty = systemProperty + "System.setProperty(\"derby.system.home\",\"" + derbyPath + "\");\r\n";
}
}
// the Sqlite
if (EDatabaseTypeName.SQLITE.getXmlName().equals(info.getDbType())) {
createStatament = "conn.createStatement()";
}
// the VERTICA
if (ConnectionUtils.isVertica(info.getUrl())) {
createStatament = "conn.createStatement()";
}
if (EDatabaseTypeName.GENERAL_JDBC.getXmlName().equals(info.getDbType()) && "com.sap.db.jdbc.Driver".equals(info.getDriverClassName()) || EDatabaseTypeName.SAPHana.getXmlName().equals(info.getDbType())) {
createStatament = "conn.createStatement()";
}
codeStart = systemProperty + getCodeStart(connectionNode, createStatament, fetchSize);
codeMain = //$NON-NLS-1$ //$NON-NLS-2$
"String[] dataOneRow = new String[numbOfColumn];\r\n" + "for (int i = 1; i <= numbOfColumn; i++) {\r\n" + " \r\n" + " try{\r\n" + " String tempStr = rs.getString(i);\r\n" + " dataOneRow[i-1] = tempStr;\r\n" + " } catch (java.sql.SQLException e) {\r\n" + "}\r\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"}\r\n" + //$NON-NLS-1$
"csvWriter.writeNext(dataOneRow);";
if (EDatabaseTypeName.REDSHIFT.getXmlName().equals(info.getDbType())) {
codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"nbRows++;\r\n" + " if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
"csvWriter.close();\r\n";
} else {
codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"nbRows++;\r\n" + " if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
"csvWriter.close();\r\n";
}
IComponent component = null;
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
//$NON-NLS-1$
component = ComponentsFactoryProvider.getInstance().get("tJavaFlex");
break;
case PERL:
default:
//$NON-NLS-1$
component = ComponentsFactoryProvider.getInstance().get("tPerlFlex");
break;
}
Node flexNode = new Node(component, process);
//$NON-NLS-1$
flexNode.setPropertyValue("CODE_START", codeStart);
//$NON-NLS-1$
flexNode.setPropertyValue("CODE_MAIN", codeMain);
//$NON-NLS-1$
flexNode.setPropertyValue("CODE_END", codeEnd);
process.addNodeContainer(new NodeContainer(flexNode));
}
use of org.talend.designer.core.ui.editor.process.Process in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method execute.
/**
* this function is moved from the method updateGraphicalNodes.
*/
@SuppressWarnings("unchecked")
@Override
public void execute() {
Object job = result.getJob();
if (job == null) {
return;
}
if (job instanceof Process) {
Process process = (Process) job;
Object parameter = result.getParameter();
// update property change events
if (parameter instanceof PropertyChangeEvent) {
PropertyChangeEvent evt = (PropertyChangeEvent) parameter;
updatePropertyChangeEvents(process, evt);
} else {
//
IUpdateItemType updateType = result.getUpdateType();
if (updateType instanceof EUpdateItemType) {
switch((EUpdateItemType) updateType) {
case JOBLET_RENAMED:
if (!(parameter instanceof List)) {
return;
}
List<Object> params = (List<Object>) parameter;
if (params.size() != 3) {
return;
}
final String oldName = (String) params.get(1);
final String newName = (String) params.get(2);
updateRenaming(process, oldName, newName);
break;
case RELOAD:
List<Node> jobletNodes = (List<Node>) result.getUpdateObject();
if (jobletNodes != null && !jobletNodes.isEmpty()) {
for (Node node : jobletNodes) {
IComponent newComponent = ComponentsFactoryProvider.getInstance().get(node.getComponent().getName(), process.getComponentsType());
if (newComponent == null) {
continue;
}
// node loaded is from loading in the check.
// need to get the instance from process, or this process will be done with wrong
// instance
// of node.
Node currentNode = getOriginalNodeFromProcess(node);
boolean neesPro = needPropagate(currentNode);
if (currentNode.isJoblet() || currentNode.isMapReduce()) {
// maybe no need modify
List<IElementParameter> tempList = new ArrayList<IElementParameter>(currentNode.getElementParameters());
if (result.isNeedReloadJoblet()) {
reloadNode(currentNode, newComponent);
}
if (currentNode.getNodeContainer() instanceof AbstractJobletContainer) {
for (IElementParameter para : tempList) {
currentNode.getElementParameter(para.getName()).setValue(para.getValue());
}
((AbstractJobletContainer) currentNode.getNodeContainer()).updateJobletNodes(true);
}
} else {
reloadNode(currentNode, newComponent);
}
propagate(currentNode, neesPro);
}
process.checkProcess();
}
break;
case JOBLET_SCHEMA:
updateSchema(process, (Node) result.getUpdateObject());
break;
default:
}
}
// else { // for extension
}
}
}
use of org.talend.designer.core.ui.editor.process.Process in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method propagate.
private void propagate(Node jobletNode, boolean needPro) {
if (!needPro) {
return;
}
for (IConnection outConn : jobletNode.getOutgoingConnections()) {
IMetadataTable tab = jobletNode.getMetadataFromConnector(outConn.getConnectorName());
IMetadataTable tmpClone = tab.clone(true);
IMetadataTable newOutputMetadata = jobletNode.getMetadataTable(outConn.getConnectorName());
IMetadataTable toCopy = newOutputMetadata.clone();
Node targetNode = (Node) outConn.getTarget();
String dbmsId = null;
IMetadataTable copy = null;
if (targetNode.getMetadataFromConnector(outConn.getConnectorName()) != null) {
dbmsId = targetNode.getMetadataFromConnector(outConn.getConnectorName()).getDbms();
MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
toCopy = tmpClone;
// only if the target node have exactly the same connector
copy = targetNode.getMetadataFromConnector(outConn.getConnectorName()).clone(true);
} else {
// can only be FLOW right now for this case. //$NON-NLS-1$
final String mainConnector = "FLOW";
dbmsId = targetNode.getMetadataFromConnector(mainConnector).getDbms();
MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
toCopy = tmpClone;
// if don't have the same connector, take the main connector of the component.
copy = targetNode.getMetadataFromConnector(mainConnector).clone(true);
}
MetadataToolHelper.copyTable(dbmsId, toCopy, copy);
// inputSchemaParam);
ChangeMetadataCommand cmd = new ChangeMetadataCommand(targetNode, null, null, copy, null);
cmd.execute(true);
}
try {
ProxyRepositoryFactory.getInstance().save(((Process) jobletNode.getProcess()).getProperty().getItem());
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.designer.core.ui.editor.process.Process in project tdi-studio-se by Talend.
the class UpdateMainParameterCommand method execute.
@Override
public void execute() {
if (result == null) {
return;
}
Object job = result.getJob();
if (job == null) {
return;
}
if (job instanceof IProcess2) {
Process process = (Process) job;
EComponentCategory category = null;
IUpdateItemType updateType = result.getUpdateType();
if (updateType instanceof EUpdateItemType) {
switch((EUpdateItemType) updateType) {
case JOB_PROPERTY_EXTRA:
category = EComponentCategory.EXTRA;
break;
case JOB_PROPERTY_STATS_LOGS:
category = EComponentCategory.STATSANDLOGS;
break;
case JOB_PROPERTY_HEADERFOOTER:
category = EComponentCategory.HEADERFOOTER;
break;
case JOB_PROPERTY_STORM:
if (ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
category = EComponentCategory.SPARK_JOB_CONFIG;
}
break;
case JOB_PROPERTY_MAPREDUCE:
if (ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType())) {
category = EComponentCategory.MAPREDUCE_JOB_CONFIG_FOR_HADOOP;
} else if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType())) {
category = EComponentCategory.SPARK_JOB_CONFIG;
}
break;
default:
}
if (category == EComponentCategory.HEADERFOOTER) {
if (result.getResultType() == EUpdateResult.UPDATE) {
if (result.isChecked()) {
for (IElementParameter param : process.getElementParameters()) {
if (param.getCategory() == EComponentCategory.HEADERFOOTER) {
IElementParameter headerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_HEADERID.getName());
if (headerIDParameter != null) {
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById((String) headerIDParameter.getValue());
HeaderFooterConnection repositoryConnection = null;
if (lastVersion != null) {
final Item item = lastVersion.getProperty().getItem();
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection();
if (repositoryConnection != null) {
Boolean isHeader = repositoryConnection.isIsHeader();
String libraries = repositoryConnection.getLibraries();
String mainCode = repositoryConnection.getMainCode();
String imports = repositoryConnection.getImports();
process.getElementParameter(EParameterName.HEADER_ENABLED.getName()).setValue(isHeader);
process.getElementParameter(EParameterName.HEADER_LIBRARY.getName()).setValue(libraries);
process.getElementParameter(EParameterName.HEADER_CODE.getName()).setValue(mainCode);
process.getElementParameter(EParameterName.HEADER_IMPORT.getName()).setValue(imports);
}
}
}
}
IElementParameter footerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_FOOTERID.getName());
if (footerIDParameter != null) {
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById((String) footerIDParameter.getValue());
HeaderFooterConnection repositoryConnection = null;
if (lastVersion != null) {
final Item item = lastVersion.getProperty().getItem();
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection();
if (repositoryConnection != null) {
Boolean isHeader = repositoryConnection.isIsHeader();
String libraries = repositoryConnection.getLibraries();
String mainCode = repositoryConnection.getMainCode();
String imports = repositoryConnection.getImports();
process.getElementParameter(EParameterName.FOOTER_ENABLED.getName()).setValue(!isHeader);
process.getElementParameter(EParameterName.FOOTER_LIBRARY.getName()).setValue(libraries);
process.getElementParameter(EParameterName.FOOTER_CODE.getName()).setValue(mainCode);
process.getElementParameter(EParameterName.FOOTER_IMPORT.getName()).setValue(imports);
}
}
}
}
}
}
}
}
} else if (category != null) {
boolean repository = false;
if (result.getResultType() == EUpdateResult.UPDATE) {
// upgrade from repository
if (result.isChecked()) {
IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category);
if (property != null) {
Map<String, IElementParameter> childParameters = property.getChildParameters();
if (childParameters != null) {
IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName());
// is repository
if (elementParameter != null && EmfComponent.REPOSITORY.equals(elementParameter.getValue())) {
for (IElementParameter param : process.getElementParameters()) {
if (param.getCategory() != category) {
continue;
}
String repositoryValue = param.getRepositoryValue();
if (param.isShow(process.getElementParameters()) && (repositoryValue != null) && (!param.getName().equals(EParameterName.PROPERTY_TYPE.getName()))) {
Object objectValue = RepositoryToComponentProperty.getValue((org.talend.core.model.metadata.builder.connection.Connection) result.getParameter(), repositoryValue, null);
if (objectValue != null) {
if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && repositoryValue.equals(UpdatesConstants.TYPE)) {
boolean found = false;
String[] items = param.getListRepositoryItems();
for (int i = 0; (i < items.length) && (!found); i++) {
if (objectValue.equals(items[i])) {
found = true;
process.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
}
}
} else if (EParameterName.HADOOP_ADVANCED_PROPERTIES.getName().equals(param.getName()) || EParameterName.SPARK_ADVANCED_PROPERTIES.getName().equals(param.getName())) {
List<Map> list = (ArrayList) param.getValue();
for (Map map : list) {
if (map.get("BUILDIN") != null && map.get("BUILDIN").equals("TRUE")) {
if (objectValue instanceof List) {
((List) objectValue).add(map);
}
}
}
process.setPropertyValue(param.getName(), objectValue);
} else {
process.setPropertyValue(param.getName(), objectValue);
}
param.setRepositoryValueUsed(true);
param.setReadOnly(true);
repository = true;
}
}
}
}
}
}
}
}
IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category);
Map<String, IElementParameter> childParameters = null;
if (property != null) {
childParameters = property.getChildParameters();
}
if (!repository) {
if (childParameters != null) {
IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName());
elementParameter.setValue(EmfComponent.BUILTIN);
}
// built-in
IElementParameter dbTypeParam = null;
IElementParameter impliciteDbType = null;
for (IElementParameter param : process.getElementParameters()) {
if (param.getCategory() != category) {
continue;
}
String repositoryValue = param.getRepositoryValue();
if (param.isShow(process.getElementParameters()) && (repositoryValue != null)) {
// for mysql db verion
if (EParameterName.DB_TYPE.getName().equals(param.getName()) && "TYPE".equals(repositoryValue)) {
dbTypeParam = param;
}
if ("DB_TYPE_IMPLICIT_CONTEXT".equals(param.getName()) && "TYPE".equals(repositoryValue)) {
impliciteDbType = param;
}
if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && dbTypeParam != null && dbTypeParam.getValue() != null) {
final int indexOfItem = dbTypeParam.getIndexOfItemFromList(dbTypeParam.getValue().toString());
String dbType = dbTypeParam.getListItemsDisplayCodeName()[indexOfItem];
setDBVersionForMysql(param, dbType);
} else if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && impliciteDbType != null && impliciteDbType.getValue() != null) {
final int indexOfItem = impliciteDbType.getIndexOfItemFromList(impliciteDbType.getValue().toString());
String dbType = impliciteDbType.getListItemsDisplayCodeName()[indexOfItem];
setDBVersionForMysql(param, dbType);
}
param.setRepositoryValueUsed(false);
param.setReadOnly(false);
}
}
} else {
if (childParameters != null) {
IElementParameter elementParameter = childParameters.get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
ConnectionItem connItem = UpdateRepositoryUtils.getConnectionItemByItemId((String) elementParameter.getValue());
ConnectionContextHelper.addContextForProcessParameter(process, connItem, category, false);
}
}
}
}
// else { // for extension
}
}
Aggregations