use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class RepositoryValueUtils method updateRepositoryList.
private void updateRepositoryList() {
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
tableIdAndDbTypeMap = new HashMap<String, String>();
tableIdAndDbSchemaMap = new HashMap<String, String>();
repositoryTableMap = new HashMap<String, IMetadataTable>();
repositoryQueryStoreMap = new HashMap<String, Query>();
repositoryConnectionItemMap = new HashMap<String, ConnectionItem>();
List<ConnectionItem> metadataConnectionsItem = null;
try {
metadataConnectionsItem = factory.getMetadataConnectionsItem();
} catch (PersistenceException e) {
throw new RuntimeException(e);
}
if (metadataConnectionsItem != null) {
repositoryTableMap.clear();
repositoryQueryStoreMap.clear();
repositoryConnectionItemMap.clear();
tablesMap.clear();
queriesMap.clear();
List<String> tableNamesList = new ArrayList<String>();
List<String> tableValuesList = new ArrayList<String>();
List<String> queryStoreNameList = new ArrayList<String>();
List<String> queryStoreValuesList = new ArrayList<String>();
for (ConnectionItem connectionItem : metadataConnectionsItem) {
Connection connection = connectionItem.getConnection();
if (!connection.isReadOnly()) {
//$NON-NLS-1$
repositoryConnectionItemMap.put(connectionItem.getProperty().getId() + "", connectionItem);
repositoryDBIdAndNameMap.put(connectionItem.getProperty().getId(), getRepositoryAliasName(connectionItem) + //$NON-NLS-1$
":" + connectionItem.getProperty().getLabel());
for (Object tableObj : ConnectionHelper.getTables(connection)) {
org.talend.core.model.metadata.builder.connection.MetadataTable table;
table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
if (!factory.isDeleted(table)) {
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel() + " - " + //$NON-NLS-1$
table.getLabel();
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
IMetadataTable newTable = ConvertionHelper.convert(table);
repositoryTableMap.put(value, newTable);
if (connection instanceof DatabaseConnection) {
String dbType = ((DatabaseConnection) connection).getDatabaseType();
String schema = ((DatabaseConnection) connection).getUiSchema();
tableIdAndDbTypeMap.put(newTable.getId(), dbType);
if (schema != null && !schema.equals("")) {
//$NON-NLS-1$
tableIdAndDbSchemaMap.put(newTable.getId(), schema);
}
}
tableNamesList.add(name);
tableValuesList.add(value);
}
}
}
}
tablesMap.put(connectionItem.getProperty().getId(), tableValuesList);
if (connection instanceof DatabaseConnection && !connection.isReadOnly()) {
DatabaseConnection dbConnection = (DatabaseConnection) connection;
QueriesConnection queriesConnection = dbConnection.getQueries();
if (queriesConnection != null) {
List<Query> qs = queriesConnection.getQuery();
for (Query query : qs) {
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel() + " - " + //$NON-NLS-1$
query.getLabel();
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + query.getLabel();
repositoryQueryStoreMap.put(value, query);
queryStoreNameList.add(name);
queryStoreValuesList.add(value);
}
}
}
queriesMap.put(connectionItem.getProperty().getId(), queryStoreValuesList);
}
}
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class DynamicTabbedPropertySection method updateRepositoryList.
/**
* ftang Comment method "updateRepositoryList".
*/
@SuppressWarnings("unchecked")
public void updateRepositoryList() {
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
tableIdAndDbTypeMap = new HashMap<String, String>();
tableIdAndDbSchemaMap = new HashMap<String, String>();
List<ConnectionItem> metadataConnectionsItem = null;
String[] repositoryTableNameList = new String[] {};
String[] repositoryTableValueList = new String[] {};
String[] repositoryConnectionNameList = new String[] {};
String[] repositoryConnectionValueList = new String[] {};
String[] repositoryQueryNameList = new String[] {};
String[] repositoryQueryValueList = new String[] {};
try {
metadataConnectionsItem = factory.getMetadataConnectionsItem();
} catch (PersistenceException e) {
throw new RuntimeException(e);
}
if (metadataConnectionsItem != null) {
repositoryTableMap.clear();
repositoryQueryStoreMap.clear();
repositoryConnectionItemMap.clear();
tablesMap.clear();
queriesMap.clear();
List<String> tableNamesList = new ArrayList<String>();
List<String> tableValuesList = new ArrayList<String>();
List<String> queryStoreNameList = new ArrayList<String>();
List<String> queryStoreValuesList = new ArrayList<String>();
for (ConnectionItem connectionItem : metadataConnectionsItem) {
Connection connection = connectionItem.getConnection();
if (!connection.isReadOnly()) {
//$NON-NLS-1$
repositoryConnectionItemMap.put(connectionItem.getProperty().getId() + "", connectionItem);
for (Object tableObj : ConnectionHelper.getTables(connection)) {
org.talend.core.model.metadata.builder.connection.MetadataTable table;
table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
if (!factory.isDeleted(table)) {
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel() + " - " + //$NON-NLS-1$
table.getLabel();
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
IMetadataTable newTable = ConvertionHelper.convert(table);
repositoryTableMap.put(value, newTable);
if (connection instanceof DatabaseConnection) {
String dbType = ((DatabaseConnection) connection).getDatabaseType();
String schema = ((DatabaseConnection) connection).getUiSchema();
tableIdAndDbTypeMap.put(newTable.getId(), dbType);
if (schema != null && !schema.equals("")) {
//$NON-NLS-1$
tableIdAndDbSchemaMap.put(newTable.getId(), schema);
}
}
addOrderDisplayNames(tableValuesList, tableNamesList, value, name);
// tableNamesList.add(name);
// tableValuesList.add(value);
}
}
}
}
tablesMap.put(connectionItem.getProperty().getId(), tableValuesList);
if (connection instanceof DatabaseConnection && !connection.isReadOnly()) {
DatabaseConnection dbConnection = (DatabaseConnection) connection;
QueriesConnection queriesConnection = dbConnection.getQueries();
if (queriesConnection != null) {
List<Query> qs = queriesConnection.getQuery();
for (Query query : qs) {
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel() + " - " + //$NON-NLS-1$
query.getLabel();
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + query.getLabel();
repositoryQueryStoreMap.put(value, query);
addOrderDisplayNames(queryStoreValuesList, queryStoreNameList, value, name);
// queryStoreNameList.add(name);
// queryStoreValuesList.add(value);
}
}
}
queriesMap.put(connectionItem.getProperty().getId(), queryStoreValuesList);
}
repositoryTableNameList = tableNamesList.toArray(new String[0]);
repositoryTableValueList = tableValuesList.toArray(new String[0]);
repositoryQueryNameList = queryStoreNameList.toArray(new String[0]);
repositoryQueryValueList = queryStoreValuesList.toArray(new String[0]);
}
initMaps();
for (int i = 0; i < elem.getElementParameters().size(); i++) {
IElementParameter param = elem.getElementParameters().get(i);
if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) || param.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE)) {
IElementParameter repositorySchemaType = param.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
repositorySchemaType.setListItemsDisplayName(repositoryTableNameList);
repositorySchemaType.setListItemsValue(repositoryTableValueList);
if (!repositoryTableMap.keySet().contains(repositorySchemaType.getValue())) {
List<String> list2 = tablesMap.get(elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()));
boolean isNeeded = list2 != null && !list2.isEmpty();
if (repositoryTableNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
repositorySchemaType.setValue(getDefaultRepository(param, true, repositoryConnectionValueList[0]));
// elem.setPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName(),
// getDefaultRepository(
// true, repositoryConnectionValueList[0]));
}
}
}
if (param.getName().equals(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName())) {
param.setListItemsDisplayName(repositoryQueryNameList);
param.setListItemsValue(repositoryQueryValueList);
if (!repositoryQueryStoreMap.keySet().contains(param.getValue())) {
List<String> list2 = queriesMap.get(elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()));
boolean isNeeded = list2 != null && !list2.isEmpty();
if (repositoryQueryNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
elem.setPropertyValue(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName(), getDefaultRepository(elem.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE), false, repositoryConnectionValueList[0]));
}
}
}
if (param.getName().equals(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())) {
updateRepositoryListExtra(param, repositoryConnectionNameList, repositoryConnectionValueList, false);
}
// // for job settings extra (feature 2710)
// if (param.getName().equals(extraRepositoryPropertyTypeName)) {
// updateRepositoryListExtra(param, repositoryConnectionNameList, repositoryConnectionValueList, true);
// }
}
updateQuery();
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class JavaSampleCodeFactory method generateJavaRowCode.
/**
*
* DOC YeXiaowei Comment method "generateJavaRowCode". Generates Java code for the tJavaRow component in DI and BD.
*
* @param node
* @return
*/
private String generateJavaRowCode(final Node node) {
boolean isSparkNode = false;
//$NON-NLS-1$
String sparkMapType = "MAP";
ComponentCategory componentCategory = ComponentCategory.getComponentCategoryFromName(node.getComponent().getType());
String primeVlue = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"// code sample:\r\n" + "//\r\n" + "// multiply by 2 the row identifier\r\n" + "// output_row.id = input_row.id * 2;\r\n" + "//\r\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"// lowercase the name\r\n" + //$NON-NLS-1$
"// output_row.name = input_row.name.toLowerCase();";
if (ComponentCategory.CATEGORY_4_SPARK == componentCategory || ComponentCategory.CATEGORY_4_SPARKSTREAMING == componentCategory) {
isSparkNode = true;
//$NON-NLS-1$
sparkMapType = node.getPropertyValue("MAPTYPE").toString();
//$NON-NLS-1$
primeVlue = "// Please add an input to the component to generate a sample code\r\n";
}
if (node.getMetadataList() == null || node.getMetadataList().get(0) == null) {
return primeVlue;
}
if (node.getIncomingConnections() == null || node.getIncomingConnections().isEmpty() || node.getIncomingConnections().get(0).getMetadataTable() == null) {
return primeVlue;
}
IMetadataTable inputTable = node.getIncomingConnections().get(0).getMetadataTable();
List<IMetadataColumn> inputColumns = inputTable.getListColumns();
IMetadataTable outputTable = node.getMetadataList().get(0);
List<IMetadataColumn> outputColumns = outputTable.getListColumns();
if (inputColumns == null || inputColumns.isEmpty() || outputColumns == null || outputColumns.isEmpty()) {
return primeVlue;
}
//$NON-NLS-1$
String javaEnding = ";";
//$NON-NLS-1$
String lineSeparator = System.getProperty("line.separator");
StringBuilder builder = new StringBuilder();
//$NON-NLS-1$
boolean isSelect = MessageDialog.openQuestion(null, null, Messages.getString("JavaSampleCodeFactory.askRegenerateCode"));
if (isSelect) {
// Add simple comment
//$NON-NLS-1$
builder.append(Messages.getString("JavaSampleCodeFactory.schema")).append(lineSeparator);
int inputRowsLength = inputColumns.size();
int ouputRowsLength = outputColumns.size();
if (inputRowsLength == 0 || ouputRowsLength == 0) {
return null;
}
if (isSparkNode && (sparkMapType.equalsIgnoreCase("FLATMAP"))) {
//$NON-NLS-1$
//$NON-NLS-1$
builder.append("Output output = new Output();\r\n");
}
if (inputRowsLength >= ouputRowsLength) {
for (int i = 0; i < inputRowsLength; i++) {
String inputLabel = inputColumns.get(i).getLabel();
String outputLabel = null;
if (i > ouputRowsLength - 1) {
outputLabel = outputColumns.get(ouputRowsLength - 1).getLabel();
} else {
outputLabel = outputColumns.get(i).getLabel();
}
if (isSparkNode) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
builder.append("output.").append(outputLabel).append(" = ").append("input.").append(inputLabel).append(javaEnding);
} else {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
builder.append("output_row.").append(outputLabel).append(" = ").append("input_row.").append(inputLabel).append(javaEnding);
}
builder.append(lineSeparator);
}
} else {
for (int i = 0; i < ouputRowsLength; i++) {
String outputLabel = outputColumns.get(i).getLabel();
String inputLabel = null;
if (i > inputRowsLength - 1) {
inputLabel = inputColumns.get(inputRowsLength - 1).getLabel();
} else {
inputLabel = inputColumns.get(i).getLabel();
}
if (isSparkNode) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
builder.append("output.").append(outputLabel).append(" = ").append("input.").append(inputLabel).append(javaEnding);
} else {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
builder.append("output_row.").append(outputLabel).append(" = ").append("input_row.").append(inputLabel).append(javaEnding);
}
builder.append(lineSeparator);
}
}
if (isSparkNode && (sparkMapType.equalsIgnoreCase("FLATMAP"))) {
//$NON-NLS-1$
//$NON-NLS-1$
builder.append("outputList.add(output);\r\n");
}
return builder.toString();
} else {
return null;
}
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class HL7OutputManager method initModel.
public void initModel() {
List<? extends IConnection> incomingConnections = NodeUtil.getIncomingConnections(hl7Component, IConnectionCategory.FLOW);
// HL7Root root = new HL7Root("root");
List<Map<String, String>> maps = (List<Map<String, String>>) ElementParameterParser.getObjectValue(hl7Component, //$NON-NLS-1$
"__SCHEMAS__");
List<String> schemaList = new ArrayList<String>();
for (IMetadataTable table : hl7Component.getMetadataList()) {
if (table.getLabel() != null) {
schemaList.add(table.getLabel());
}
}
List<Map<String, String>> rootTable = hl7Component.getTableList(HL7InputComponent.ROOT);
Map<String, IMetadataTable> schemaNameToInputTable = new HashMap<String, IMetadataTable>();
if (!maps.isEmpty()) {
for (Map<String, String> map : maps) {
String schemaName = map.get("SCHEMA");
int first = schemaName.indexOf("_");
int second = schemaName.lastIndexOf("_");
if (first > 0 && first < second) {
schemaName = schemaName.substring(first + 1, second);
}
IMetadataTable metadataTable = null;
for (IConnection connection : incomingConnections) {
if (connection.getUniqueName().equals(map.get("PARENT_ROW"))) {
metadataTable = connection.getMetadataTable();
metadataTable.setLabel(connection.getUniqueName());
schemaNameToInputTable.put(schemaName, metadataTable);
break;
}
}
}
} else {
for (String schemaName : schemaList) {
IMetadataTable metadataTable = null;
for (IConnection connection : incomingConnections) {
if (connection.getUniqueName().equals(schemaName)) {
metadataTable = connection.getMetadataTable();
metadataTable.setLabel(connection.getUniqueName());
schemaNameToInputTable.put(schemaName, metadataTable);
}
}
}
}
Map<String, HL7TreeNode> mapNodes = new HashMap<String, HL7TreeNode>();
treeData = new ArrayList<HL7TreeNode>();
HL7TreeNode rootNode = null;
HL7TreeNode current = null;
HL7TreeNode temp = null;
String currentPath = null;
String defaultValue = null;
int nodeOrder = 0;
boolean haveOrder = true;
// build root tree
for (Map<String, String> rootMap : rootTable) {
String newPath = rootMap.get(HL7InputComponent.PATH);
String columnName = rootMap.get(HL7InputComponent.COLUMN);
defaultValue = rootMap.get(HL7InputComponent.VALUE);
String orderValue = rootMap.get(HL7InputComponent.ORDER);
boolean repeatable = Boolean.valueOf(rootMap.get("REPEATABLE"));
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
String rowName = columnName;
if (columnName != null && columnName.contains(":")) {
String[] names = columnName.split(":");
rowName = names[0];
columnName = names[1];
} else {
columnName = null;
}
temp = this.addElement(current, currentPath, newPath, defaultValue, mapNodes);
if (temp == null) {
// should not happen
continue;
}
if (rootNode == null) {
rootNode = temp;
}
if (rootMap.get(HL7InputComponent.ATTRIBUTE).equals("main")) {
//$NON-NLS-1$
temp.setMain(true);
}
current = temp;
currentPath = newPath;
temp.setRepetable(repeatable);
if (haveOrder) {
temp.setOrder(nodeOrder);
}
if (rowName != null && rowName.length() > 0) {
temp.setRow(rowName);
}
if (columnName != null) {
IMetadataTable metadataTable = schemaNameToInputTable.get(rowName);
// group node can not get the metadata table
if (metadataTable == null) {
IMetadataTable metadataTableTemp = null;
for (IConnection connection : incomingConnections) {
metadataTableTemp = connection.getMetadataTable();
String connectionName = metadataTableTemp.getLabel();
if (connectionName == null) {
connectionName = connection.getUniqueName();
}
if (columnName.startsWith(connectionName)) {
break;
}
}
temp.setColumnName(columnName);
if (metadataTableTemp != null) {
temp.setColumn(metadataTableTemp.getColumn(columnName));
temp.setTable(metadataTableTemp);
}
} else {
temp.setColumnName(columnName);
temp.setColumn(metadataTable.getColumn(columnName));
temp.setTable(metadataTable);
}
}
}
if (rootNode == null) {
rootNode = new Element("rootTag");
}
if (haveOrder) {
orderNode(rootNode);
}
// the root node should not set the ColumnLabel
if (rootNode.getRow() != null) {
rootNode.setRow(null);
}
treeData.add(rootNode);
contents.put(rootNode.getColumnLabel(), treeData);
initCurrentSchema();
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class UIManager method refreshInOutTableAndMetaTable.
/**
* DOC amaumont Comment method "refreshInOutTableAndMetaTable".
*
* @param currentModifiedTableEntry can be null
*/
private void refreshInOutTableAndMetaTable(AbstractInOutTableEntry currentModifiedTableEntry) {
DataMapTableView dataMapTableView = mapperManager.retrieveDataMapTableView(currentModifiedTableEntry);
IMetadataTable metadataTableTarget = ((AbstractInOutTable) dataMapTableView.getDataMapTable()).getMetadataTable();
dataMapTableView.getTableViewerCreatorForColumns().getTableViewer().refresh(currentModifiedTableEntry);
MetadataTableEditorView metadataEditorView = getMetadataEditorView(dataMapTableView.getZone());
if (metadataEditorView != null && metadataEditorView.getMetadataTableEditor() != null && metadataEditorView.getMetadataTableEditor().getMetadataTable() == metadataTableTarget) {
metadataEditorView.getTableViewerCreator().getTableViewer().refresh(currentModifiedTableEntry.getMetadataColumn());
metadataEditorView.getTableViewerCreator().refreshTableEditorControls();
}
}
Aggregations