use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ChangeMultiSchemasCommand method initNew.
private void initNew(Object object) {
if (fakeConnection != null) {
this.newFieldSeperator = fakeConnection.getFieldSeparatorValue();
this.newRowSeperator = fakeConnection.getRowSeparatorValue();
this.newEncoding = TalendTextUtils.addQuotes(fakeConnection.getEncoding());
IElementParameter encodingType = node.getElementParameter(EParameterName.ENCODING_TYPE.getName());
if (encodingType != null) {
String[] codes = encodingType.getListItemsDisplayCodeName();
if (codes != null) {
List<String> list = Arrays.asList(codes);
if (list.indexOf(fakeConnection.getEncoding()) > -1) {
this.newEncodingType = fakeConnection.getEncoding();
} else {
// custom
this.newEncodingType = list.get(list.size() - 1);
}
}
}
this.newFilePath = fakeConnection.getFilePath();
this.newTextEnclosure = fakeConnection.getTextEnclosure();
this.newEscapeChar = fakeConnection.getEscapeChar();
this.newCsvOption = fakeConnection.isCsvOption();
this.newSelectedColumnIndex = TalendTextUtils.QUOTATION_MARK + String.valueOf(object) + TalendTextUtils.QUOTATION_MARK;
} else if (params != null) {
this.newFieldSeperator = params.get(EParameterName.FIELDSEPARATOR);
this.newRowSeperator = params.get(EParameterName.ROWSEPARATOR);
this.newEncoding = params.get(EParameterName.ENCODING);
this.newEncodingType = params.get(EParameterName.ENCODING_TYPE);
this.newFilePath = params.get(EParameterName.FILENAME);
this.newTextEnclosure = params.get(EParameterName.TEXT_ENCLOSURE);
this.newEscapeChar = params.get(EParameterName.ESCAPE_CHAR);
this.newCsvOption = Boolean.valueOf(params.get(EParameterName.CSV_OPTION));
this.newUseMultiSaparator = Boolean.valueOf(params.get(EParameterName.USE_MULTISEPARATORS));
this.newSaparators = params.get(EParameterName.MULTI_SEPARATORS);
this.newSelectedColumnIndex = params.get(EParameterName.COLUMNINDEX);
this.newKeyValues = params.get(EParameterName.MULTI_KEYVALUES);
}
// map
this.newSchemasListMap = new ArrayList<Map<String, String>>();
// metadata table
this.newMetadataTable = new ArrayList<IMetadataTable>();
// hywang add for feature7373
addSchemasMap(newSchemasListMap, newMetadataTable, this.rootSchemaData);
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ChangeMultiSchemasCommand method addMetadataTable.
private void addMetadataTable(List<IMetadataTable> newTables) {
// remove
IProcess process = this.node.getProcess();
List<IMetadataTable> needAddedTables = new ArrayList<IMetadataTable>();
List<String> schemaNames = new ArrayList<String>();
// record added table, and update the existed table.
for (IMetadataTable table : newTables) {
final String tableLabel = table.getLabel();
schemaNames.add(tableLabel);
IMetadataTable mappingTable = MetadataToolHelper.getMetadataTableFromNode(node, tableLabel);
if (mappingTable == null) {
// added
needAddedTables.add(table);
process.addUniqueConnectionName(table.getTableName());
} else {
MetadataToolHelper.copyTable(table, mappingTable);
}
}
// record removed table
List<IMetadataTable> needRemovedTables = new ArrayList<IMetadataTable>();
for (IMetadataTable table : node.getMetadataList()) {
if (!schemaNames.contains(table.getLabel())) {
needRemovedTables.add(table);
process.removeUniqueConnectionName(table.getTableName());
}
}
node.getMetadataList().removeAll(needRemovedTables);
node.getMetadataList().addAll(needAddedTables);
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ChangeMultiSchemasCommand method addSchemasMap.
private void addSchemasMap(List<Map<String, String>> newValueList, List<IMetadataTable> newTables, SchemasKeyData keyData) {
if (keyData == null) {
return;
}
if (keyData.getParent() != null) {
// not root
//
Map<String, String> map = new HashMap<String, String>();
final String uniqueRecord = keyData.getUniqueRecord();
final String recordType = keyData.getRecordType();
map.put(IMultiSchemaConstant.SCHEMA, uniqueRecord);
map.put(IMultiSchemaConstant.RECORD, TalendTextUtils.addQuotes(recordType));
map.put(IMultiSchemaConstant.PARENT_RECORD, TalendTextUtils.addQuotes(keyData.getParent().getRecordType()));
map.put(IMultiSchemaConstant.CARDINALITY, keyData.getCard());
map.put(IMultiSchemaConstant.FIELDDELIMITED, TalendTextUtils.addQuotes(keyData.getSeparator()));
newValueList.add(map);
//
String connectionBaseName = MetadataToolHelper.validateColumnName(MultiSchemasUtil.getConnectionBaseName(uniqueRecord), 0);
String uniqueConnName = node.getProcess().generateUniqueConnectionName(connectionBaseName);
MetadataTable table = new MetadataTable();
table.setLabel(uniqueRecord);
table.setTableName(uniqueConnName);
//$NON-NLS-1$
String keyIndex = "";
boolean first = true;
List<MultiMetadataColumn> metadataColumnsInModel = keyData.getMetadataColumnsInModel();
for (int i = 0; i < metadataColumnsInModel.size(); i++) {
MultiMetadataColumn column = metadataColumnsInModel.get(i);
table.getListColumns().add(column.clone(true));
if (column.isKey()) {
if (first) {
keyIndex += i;
} else {
//$NON-NLS-1$
keyIndex += "," + i;
}
first = false;
}
}
map.put(IMultiSchemaConstant.KEY_COLUMN_INDEX, TalendTextUtils.addQuotes(keyIndex));
newTables.add(table);
}
for (SchemasKeyData child : keyData.getChildren()) {
addSchemasMap(newValueList, newTables, child);
}
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ChangeMultiSchemasCommand method initOld.
private void initOld() {
if (node == null) {
return;
}
IElementParameter elementParameter = this.node.getElementParameter(EParameterName.FILENAME.getName());
if (elementParameter != null) {
this.oldFilePath = elementParameter.getValue();
}
elementParameter = this.node.getElementParameter(EParameterName.ENCODING_TYPE.getName());
if (elementParameter != null) {
this.oldEncodingType = elementParameter.getValue();
}
elementParameter = this.node.getElementParameter(EParameterName.ENCODING.getName());
if (elementParameter != null) {
this.oldEncoding = elementParameter.getValue();
}
elementParameter = this.node.getElementParameter(EParameterName.ROWSEPARATOR.getName());
if (elementParameter != null) {
this.oldRowSeperator = elementParameter.getValue();
}
elementParameter = this.node.getElementParameter(EParameterName.FIELDSEPARATOR.getName());
if (elementParameter != null) {
this.oldFieldSeperator = elementParameter.getValue();
}
elementParameter = this.node.getElementParameter(EParameterName.TEXT_ENCLOSURE.getName());
if (elementParameter != null) {
this.oldTextEnclosure = elementParameter.getValue();
}
elementParameter = this.node.getElementParameter(EParameterName.ESCAPE_CHAR.getName());
if (elementParameter != null) {
this.oldEscapeChar = elementParameter.getValue();
}
elementParameter = this.node.getElementParameter(EParameterName.CSV_OPTION.getName());
if (elementParameter != null) {
this.oldCsvOption = (Boolean) elementParameter.getValue();
}
// hywang add for feature7373
elementParameter = this.node.getElementParameter(EParameterName.COLUMNINDEX.getName());
if (elementParameter != null) {
this.oldSelectedColumnIndex = String.valueOf(elementParameter.getValue());
}
elementParameter = this.node.getElementParameter(EParameterName.MULTI_SEPARATORS.getName());
if (elementParameter != null) {
this.oldSaparators = String.valueOf(elementParameter.getValue());
}
elementParameter = this.node.getElementParameter(EParameterName.USE_MULTISEPARATORS.getName());
if (elementParameter != null) {
this.oldUseMultiSaparator = (Boolean) elementParameter.getValue();
}
elementParameter = this.node.getElementParameter(EParameterName.MULTI_KEYVALUES.getName());
if (elementParameter != null) {
this.oldKeyValues = String.valueOf(elementParameter.getValue());
}
// schema table
elementParameter = this.node.getElementParameter(EParameterName.SCHEMAS.getName());
if (elementParameter != null) {
Object value = elementParameter.getValue();
List<Map<String, String>> oldvalueList = new ArrayList<Map<String, String>>();
if (value != null) {
List<Map<String, String>> valueList = (List<Map<String, String>>) value;
for (Map<String, String> map : valueList) {
Map<String, String> valueMap = new HashMap<String, String>();
for (String key : map.keySet()) {
valueMap.put(key, map.get(key));
}
oldvalueList.add(valueMap);
}
}
this.oldSchemasListMap = oldvalueList;
}
// metadata
List<IMetadataTable> oldMetadataTable = new ArrayList<IMetadataTable>();
for (IMetadataTable table : this.node.getMetadataList()) {
oldMetadataTable.add(table.clone(true));
}
this.oldMetadataTable = oldMetadataTable;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class HL7UI method initTableViewer.
private void initTableViewer() {
List<IMetadataTable> tables = externalNode.getMetadataList();
for (IMetadataTable table : tables) {
MetadataTable loaded = ConvertionHelper.convert(table);
List<MetadataColumn> columns = loaded.getColumns();
String trueTableName = table.getLabel();
if (trueTableName.split("_").length > 2) {
// get true table name from node draged from repository
//$NON-NLS-N$
trueTableName = trueTableName.split("_")[1];
}
if (hl7Manager.getSchemaRelationMap().get(trueTableName) != null) {
hl7Manager.getSchemaRelationMap().remove(trueTableName);
hl7Manager.getSchemaRelationMap().put(trueTableName, columns);
} else {
hl7Manager.getSchemaRelationMap().put(trueTableName, columns);
}
MetadataColumn[] array = new MetadataColumn[columns.size()];
int i = 0;
for (MetadataColumn column : columns) {
MetadataColumn newColumn = copyColumn(column);
array[i] = newColumn;
i++;
}
if (this.getMetaTableViewer().getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) this.getMetaTableViewer().getSelection();
if (selection.getFirstElement() != null) {
String name = ((IModel) selection.getFirstElement()).getDisplayName();
if (name.equals(trueTableName)) {
for (int j = 0; j < array.length; j++) {
hl7SchemaEditorView.getMetadataEditor().add(array[j]);
}
// hl7SchemaEditorView.getMetadataEditor().addAll(columns);
}
}
}
}
}
Aggregations