use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class DCSchemaController method createButtonCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createButtonCommand(org
* .eclipse.swt.widgets.Button)
*/
@SuppressWarnings("unchecked")
protected Command createButtonCommand(Button button) {
Button inputButton = button;
Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
Node node;
if (elem instanceof Node) {
node = (Node) elem;
} else {
// else instanceof Connection
node = (Node) ((Connection) elem).getSource();
}
String componentName = node.getComponent().getName();
initConnectionParameters();
IContextManager manager;
if (part == null) {
manager = new EmptyContextManager();
} else {
manager = part.getProcess().getContextManager();
}
IElement oldElement = elem;
if (isUseExistingConnection()) {
this.elem = connectionNode;
initConnectionParametersWithContext(connectionNode, manager.getDefaultContext());
} else {
initConnectionParametersWithContext(elem, manager.getDefaultContext());
}
this.elem = oldElement;
if (!GlobalServiceRegister.getDefault().isServiceRegistered(IDCService.class)) {
return null;
}
IDCService restService = (IDCService) GlobalServiceRegister.getDefault().getService(IDCService.class);
restService.setupRestHelperInstance(connParameters.getHost(), connParameters.getPort(), connParameters.getUserName(), connParameters.getPassword(), connParameters.getDirectory(), connParameters.isHttps());
String entityName = elem.getPropertyValue("ENTITY").toString().replaceAll("\"", "");
IMetadataTable inputMetadata = null, inputMetaCopy = null;
Connection inputConec = null;
String propertyName = (String) inputButton.getData(PARAMETER_NAME);
IElementParameter param = node.getElementParameter(propertyName);
IElementParameter connectionParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
String connectionName = null;
if (connectionParam != null) {
connectionName = (String) connectionParam.getValue();
}
boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
if (connec.isActivate() && (EConnectionType.FLOW_MAIN.equals(connec.getLineStyle()) || EConnectionType.TABLE.equals(connec.getLineStyle()) || EConnectionType.FLOW_MERGE.equals(connec.getLineStyle()) || EConnectionType.FLOW_REF.equals(connec.getLineStyle()))) {
if (connectionName != null && !connec.getName().equals(connectionName)) {
continue;
}
inputMetadata = connec.getMetadataTable();
inputMetaCopy = inputMetadata.clone();
inputConec = connec;
if (connec.getSource().isReadOnly()) {
inputReadOnlyNode = true;
} else {
for (IElementParameter curParam : connec.getSource().getElementParameters()) {
if (curParam.getFieldType() == EParameterFieldType.SCHEMA_TYPE || curParam.getFieldType() == EParameterFieldType.DCSCHEMA) {
if (curParam.isReadOnly()) {
inputReadOnlyParam = true;
}
}
}
}
// check if the inputMetadata is readonly
if (inputMetadata != null) {
for (IMetadataColumn column : inputMetadata.getListColumns()) {
IMetadataColumn columnCopied = inputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
}
inputMetaCopy.setReadOnly(inputMetadata.isReadOnly());
inputReadOnly = prepareReadOnlyTable(inputMetaCopy, inputReadOnlyParam, inputReadOnlyNode);
}
// store the value for Dialog
Map<IMetadataTable, Boolean> oneInput = new HashMap<IMetadataTable, Boolean>();
oneInput.put(inputMetaCopy, inputReadOnly);
inputInfos.put(connec.getSource(), oneInput);
}
}
if (connectionParam != null && inputMetadata == null) {
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
button.getShell(), //$NON-NLS-1$
Messages.getString("SchemaTypeController.inputNotSet"), //$NON-NLS-1$
Messages.getString("SchemaTypeController.connectionNotAvaliable"));
return null;
}
IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
// check if the outputMetadata is readonly
IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
IMetadataTable outputMetaCopy = originaleOutputTable.clone();
for (IMetadataColumn column : originaleOutputTable.getListColumns()) {
IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
}
outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
outputMetaCopy.sortCustomColumns();
// create the MetadataDialog
MetadataDialog metaDialog = null;
if (inputMetadata != null) {
if (inputInfos != null && inputInfos.size() > 1 && connectionName == null) {
MetadataDialogForMerge metaDialogForMerge = new MetadataDialogForMerge(composite.getShell(), inputInfos, outputMetaCopy, node, getCommandStack());
//$NON-NLS-1$
metaDialogForMerge.setText(Messages.getString("SchemaController.schemaOf") + node.getLabel());
metaDialogForMerge.setInputReadOnly(inputReadOnly);
metaDialogForMerge.setOutputReadOnly(outputReadOnly);
if (metaDialogForMerge.open() == MetadataDialogForMerge.OK) {
outputMetaCopy = metaDialogForMerge.getOutputMetaData();
// check if the metadata is modified
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
} else {
if (inputMetadata != null) {
// Notice: the Map inputInfos maybe is modified by the dialog.
Set<INode> inputNodes = inputInfos.keySet();
for (INode inputNode : inputNodes) {
Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
if (!inputMetaCopy.sameMetadataAs(inputNode.getMetadataList().get(0), IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
}
}
}
// create the changeMetadataCommand
if (modified) {
Command changeMetadataCommand = null;
// only output, no input
if (inputInfos.isEmpty()) {
changeMetadataCommand = new ChangeMetadataCommand(node, param, null, null, null, originaleOutputTable, outputMetaCopy);
} else {
Set<INode> inputNodes = inputInfos.keySet();
int count = 0;
for (INode inputNode : inputNodes) {
Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
if (count == 0) {
changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy);
} else {
changeMetadataCommand = changeMetadataCommand.chain(new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy));
}
count++;
}
}
return changeMetadataCommand;
}
}
} else {
Node inputNode = (Node) (inputConec.getSource());
if (inputMetaCopy.getAttachedConnector() == null) {
INodeConnector mainConnector;
if (inputNode.isELTComponent()) {
mainConnector = inputNode.getConnectorFromType(EConnectionType.TABLE);
} else {
mainConnector = inputNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
}
inputMetaCopy.setAttachedConnector(mainConnector.getName());
}
metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode, outputMetaCopy, node, getCommandStack());
}
} else {
metaDialog = new MetadataDialog(composite.getShell(), outputMetaCopy, node, getCommandStack());
}
/*
* Datacert: Populating data in the edit schema dialog
*
* @author : virtusa
*/
List<IMetadataColumn> columnList = new ArrayList<IMetadataColumn>();
String prefix = "";
if (componentName.equalsIgnoreCase(Messages.getString("DataCertController.tDataCertDenormalize.componentName"))) {
String denorCol = elem.getPropertyValue("DC_COLUMN_DENORMALIZE").toString().replaceAll("\"", "");
;
prefix = denorCol;
IMetadataTable inputTable = null;
if (node.getIncomingConnections() != null && node.getIncomingConnections().size() > 0) {
IConnection inputConn = node.getIncomingConnections().get(0);
if (inputConn != null) {
inputTable = inputConn.getMetadataTable();
}
}
if (inputTable != null) {
for (IMetadataColumn inCol : inputTable.getListColumns()) {
if (!inCol.getLabel().equals(denorCol)) {
columnList.add(inCol);
}
}
}
}
restService.addColumnsToSchema(entityName, componentName, prefix, columnList);
outputMetaCopy.setListColumns(columnList);
outputMetaCopy.setComment("Attribute Metadata");
outputMetaCopy.setLabel("Attribute Metadata");
outputMetaCopy.setTableName(entityName);
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", node.getLabel()));
metaDialog.setInputReadOnly(false);
metaDialog.setOutputReadOnly(false);
if (metaDialog.open() == MetadataDialog.OK) {
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
if (modified) {
Node inputNode = null;
if (inputConec != null) {
inputNode = (Node) inputConec.getSource();
}
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
return changeMetadataCommand;
}
}
}
return null;
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class DbTypeListController method getCurrentDbms.
private static String getCurrentDbms(INode node) {
boolean hasMappingType = false;
String currentDbms = null;
for (IElementParameter currentParam : node.getElementParameters()) {
if (currentParam.getFieldType().equals(EParameterFieldType.MAPPING_TYPE) && currentParam.isShow(node.getElementParameters())) {
currentDbms = (String) currentParam.getValue();
hasMappingType = true;
}
}
if (!hasMappingType) {
// if there is no mapping type, then check if a db repository schema is used
//$NON-NLS-1$
IElementParameter schemaTypeParameter = node.getElementParameter("SCHEMA_TYPE");
if (schemaTypeParameter == null) {
return null;
}
String schemaType = (String) schemaTypeParameter.getValue();
if (schemaType.equals("REPOSITORY")) {
//$NON-NLS-1$
// repository mode
//$NON-NLS-1$
String metaRepositoryName = (String) node.getElementParameter("REPOSITORY_SCHEMA_TYPE").getValue();
Connection connection = MetadataToolHelper.getConnectionFromRepository(metaRepositoryName);
if (connection instanceof DatabaseConnection) {
// bug 13200
if (((DatabaseConnection) connection).getDatabaseType().equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
// bug 7618 modify
currentDbms = (DBConnectionContextUtils.cloneOriginalValueConnection((DatabaseConnection) connection, true, null)).getDbmsId();
} else {
currentDbms = ((DatabaseConnection) connection).getDbmsId();
}
}
} else {
//$NON-NLS-1$
String componentDbType = "";
for (IElementParameter param : (List<IElementParameter>) node.getElementParameters()) {
if (param.getRepositoryValue() != null) {
if (param.getRepositoryValue().equals("TYPE")) {
//$NON-NLS-1$
componentDbType = (String) param.getValue();
}
}
}
String componentProduct = EDatabaseTypeName.getTypeFromDbType(componentDbType).getProduct();
if (EDatabaseTypeName.supportDbType(componentDbType)) {
currentDbms = MetadataTalendType.getDefaultDbmsFromProduct(componentProduct).getId();
}
}
}
return currentDbms;
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class GuessSchemaController method useMockJob.
private void useMockJob() {
/*
* get the select node,it's the input node of the process. then transfer selected context varriable to
* openContextChooseDialog, added by hyWang
*/
final IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
final Shell parentShell = this.composite.getShell();
final Node inputNode = (Node) this.curParameter.getElement();
if (connParameters == null) {
initConnectionParameters();
}
final String tmpMemoSql = this.memoSQL;
final DatabaseConnection connt = TracesConnectionUtils.createConnection(connParameters);
IMetadataConnection iMetadataConnection = null;
boolean isStatus = false;
try {
if (connt != null) {
iMetadataConnection = ConvertionHelper.convert(connt);
isStatus = checkConnection(iMetadataConnection);
}
if (isStatus) {
if (EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(iMetadataConnection.getDbType())) {
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getAdditionalParams());
} else if (EDatabaseTypeName.HIVE.getDisplayName().equals(iMetadataConnection.getDbType())) {
String jobTracker = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_JOB_TRACKER_URL)));
String nameNode = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_NAME_NODE_URL)));
String thrifturi = null;
if (HiveModeInfo.get(iMetadataConnection.getDbVersionString()) == HiveModeInfo.EMBEDDED) {
thrifturi = "thrift://" + iMetadataConnection.getServerName() + ":" + iMetadataConnection.getPort();
}
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), jobTracker, nameNode, thrifturi, iMetadataConnection.getDriverJarPath());
String hiveServerVersion = String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.HIVE_SERVER_VERSION));
//$NON-NLS-1$
String driverClass = "";
if (HiveServerVersionInfo.HIVE_SERVER_2.getKey().equals(hiveServerVersion)) {
driverClass = EDatabase4DriverClassName.HIVE2.getDriverClass();
} else {
driverClass = EDatabase4DriverClassName.HIVE.getDriverClass();
}
info.setDriverClassName(driverClass);
} else {
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverJarPath());
}
final Property property = GuessSchemaProcess.getNewmockProperty();
List<IContext> allcontexts = inputNode.getProcess().getContextManager().getListContext();
OpenContextChooseComboDialog dialog = new OpenContextChooseComboDialog(parentShell, allcontexts);
dialog.create();
dialog.getShell().setText(CONTEXT_CHOOSE_DIALOG_TITLE);
IContext selectContext = null;
// job only have defoult context,or the query isn't context mode
if (allcontexts.size() == 1 || TalendTextUtils.isCommonString(tmpMemoSql)) {
selectContext = inputNode.getProcess().getContextManager().getDefaultContext();
} else if (Window.OK == dialog.open()) {
selectContext = dialog.getSelectedContext();
}
final IContext context = selectContext;
if (context != null) {
//
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(this.composite.getShell());
pmd.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
runShadowProcess(property, inputNode, context, switchParam);
}
});
}
});
}
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//$NON-NLS-1$
String pid = "org.talend.sqlbuilder";
//$NON-NLS-1$
String mainMsg = Messages.getString("GuessSchemaController.connectionFailed");
ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
if (dialog.getCodeOfButton() == Window.OK) {
openParamemerDialog(composite.getShell(), part.getProcess().getContextManager());
}
}
});
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
// else {
// try {
// pmd2.run(true, true, new IRunnableWithProgress() {
// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// Display.getDefault().asyncExec(new Runnable() {
//
// public void run() {
// String pid = SqlBuilderPlugin.PLUGIN_ID;
// String mainMsg = Messages.getString("GuessSchemaController.connectionFailed"); //$NON-NLS-1$
// ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite
// .getShell(), pid, mainMsg, connParameters.getConnectionComment());
// if (dialog.getCodeOfButton() == Window.OK) {
// openParamemerDialog(composite.getShell(), part.getTalendEditor().getProcess().getContextManager());
// }
// }
// });
// }
// });
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class GuessSchemaController method createButtonCommand.
/**
* This method is used for "Guess Query" button.
*
* @return
*/
// modified by hyWang
private Command createButtonCommand(Button btn, IContextManager manager) {
this.btn = btn;
IElementParameter elementParameterFromField = elem.getElementParameterFromField(EParameterFieldType.MEMO_SQL);
memoSQL = (String) elementParameterFromField.getValue();
initConnectionParameters();
if (this.connParameters != null && memoSQL != null) {
initConnectionParametersWithContext(elem, manager.getDefaultContext());
// runShadowProcess();
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
useMockJob();
} else if (LanguageManager.getCurrentLanguage() == ECodeLanguage.PERL) {
IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
//$NON-NLS-1$ //$NON-NLS-2$
memoSQL = memoSQL.substring(1, memoSQL.length() - 1).trim().replace("\\'", "\'");
runShadowProcessForPerl();
if (columns != null && columns.size() > 0) {
Node node = (Node) elem;
IMetadataTable tempMetatable = new MetadataTable();
IMetadataTable inputMetaCopy, inputMetadata, outputMetaCopy, originaleOutputTable;
String propertyName = (String) btn.getData(PARAMETER_NAME);
IElementParameter param = node.getElementParameter(propertyName);
for (IElementParameter eParam : elem.getElementParameters()) {
if (eParam.getContext() != null) {
param = eParam;
}
}
originaleOutputTable = node.getMetadataFromConnector(param.getContext());
if (originaleOutputTable != null) {
outputMetaCopy = originaleOutputTable.clone();
}
tempMetatable.setListColumns(columns);
MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), tempMetatable, node, getCommandStack());
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", node.getLabel()));
if (metaDialog.open() == MetadataDialog.OK) {
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
if (modified) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, originaleOutputTable, outputMetaCopy);
return changeMetadataCommand;
}
}
}
}
}
if (changeMetadataCommand != null) {
return changeMetadataCommand;
}
}
return null;
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class FileController method setDragAndDropActionBool.
private void setDragAndDropActionBool() {
IElementParameter propertyParam = elem.getElementParameter("PROPERTY:REPOSITORY_PROPERTY_TYPE");
try {
if (propertyParam != null && propertyParam.getValue() != null && !"".equals(propertyParam.getValue())) {
Item linkedRepositoryItem = null;
IRepositoryViewObject repository = DesignerPlugin.getDefault().getProxyRepositoryFactory().getLastVersion(propertyParam.getValue().toString());
if (repository != null && repository.getProperty() != null) {
linkedRepositoryItem = repository.getProperty().getItem();
}
if (linkedRepositoryItem != null && linkedRepositoryItem instanceof XmlFileConnectionItem) {
XmlFileConnectionItem xci = (XmlFileConnectionItem) linkedRepositoryItem;
XmlFileConnection cc = (XmlFileConnection) xci.getConnection();
String xmlFilePath = cc.getXmlFilePath();
if (xmlFilePath != null && XmlUtil.isXSDFile(TalendQuoteUtils.removeQuotes(xmlFilePath))) {
dragAndDropActionBool = true;
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
Aggregations