use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class ImportHL7StructureAction method initXmlTreeData.
private void initXmlTreeData(List<String> schemaList, List<HL7FileNode> root, List<HL7TreeNode> treeData) {
Map<String, HL7TreeNode> mapNodes = new HashMap<String, HL7TreeNode>();
List<? extends IConnection> incomingConnections = new ArrayList<IConnection>();
if (hl7ui != null) {
if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
((HL7OutputManager) hl7ui.gethl7Manager()).getContents().clear();
incomingConnections = NodeUtil.getIncomingConnections(hl7ui.gethl7Manager().getHl7Component(), IConnectionCategory.FLOW);
}
}
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
List<MetadataTable> iMetadataTables = new ArrayList<MetadataTable>();
HL7TreeNode rootNode = null;
Map<String, IMetadataTable> schemaNameToInputTable = new HashMap<String, IMetadataTable>();
Map<String, MetadataTable> schemaNameToOutputTable = new HashMap<String, MetadataTable>();
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);
break;
}
}
MetadataTable targetMetadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
targetMetadataTable.setId(factory.getNextId());
schemaNameToOutputTable.put(schemaName, targetMetadataTable);
targetMetadataTable.setLabel(schemaName);
iMetadataTables.add(targetMetadataTable);
}
HL7TreeNode current = null;
HL7TreeNode temp = null;
String currentPath = null;
String defaultValue = null;
int nodeOrder = 0;
boolean haveOrder = true;
// build root tree
for (int i = 0; i < root.size(); i++) {
HL7FileNode node = root.get(i);
String newPath = node.getFilePath();
defaultValue = node.getDefaultValue();
String columnName = node.getRelatedColumn();
// String type = node.getType();
String orderValue = String.valueOf(node.getOrder());
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = node.getOrder();
}
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;
}
// temp.setDataType(type);
if (rootNode == null) {
rootNode = temp;
}
if (node.getAttribute().equals("main")) {
temp.setMain(true);
}
current = temp;
currentPath = newPath;
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 (!temp.isMain()) {
MetadataColumn newColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
newColumn.setLabel(columnName);
newColumn.setName(temp.getLabel());
newColumn.setLength(226);
newColumn.setTalendType("id_String");
schemaNameToOutputTable.get(rowName).getColumns().add(newColumn);
}
}
}
if (rootNode == null) {
rootNode = new Element("rootTag");
}
if (haveOrder) {
orderNode(rootNode);
}
if (rootNode != null) {
treeData.add(rootNode);
}
if (hl7ui != null) {
if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
((HL7OutputManager) hl7ui.gethl7Manager()).getContents().put(rootNode.getColumnLabel(), treeData);
}
} else if (form != null) {
for (HL7TreeNode hl7Node : treeData) {
form.getContents().put(rootNode.getColumnLabel(), hl7Node);
}
}
if (hl7ui != null) {
// execute the commands,initialize the propertiesView .
List<Command> commands = new ArrayList<Command>();
for (MetadataTable tableTemp : iMetadataTables) {
Command hl7Cmd = new RepositoryChangeMetadataForHL7Command(hl7ui.gethl7Manager().getHl7Component(), IHL7Constant.TABLE_SCHEMAS, tableTemp.getLabel(), ConvertionHelper.convert(tableTemp));
commands.add(hl7Cmd);
}
for (Command command : commands) {
command.execute();
}
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class HL7Manager method convertMetadataColumns2Propertis.
public List<Map<String, String>> convertMetadataColumns2Propertis() {
List<Map<String, String>> schemas = new ArrayList<Map<String, String>>();
Iterator<String> it = schemaRelationMap.keySet().iterator();
while (it.hasNext()) {
MetadataTable metatable = ConnectionFactory.eINSTANCE.createMetadataTable();
String schemaKey = it.next().toString();
List<MetadataColumn> columns = new ArrayList<MetadataColumn>();
columns.addAll(schemaRelationMap.get(schemaKey));
Map<String, String> oneSchema = new HashMap<String, String>();
//$NON-NLS-N$
String displayName = "";
for (int i = 0; i < columns.size(); i++) {
MetadataColumn column = columns.get(i);
String original = columns.get(i).getOriginalField();
if (original != null && !"".equals(original)) {
if (original.indexOf(TalendTextUtils.LBRACKET) > 0) {
original = original.substring(0, original.indexOf(TalendTextUtils.LBRACKET));
}
}
if (i != columns.size() - 1) {
displayName = displayName + TalendTextUtils.QUOTATION_MARK + original + TalendTextUtils.QUOTATION_MARK + ",";
} else {
displayName = displayName + TalendTextUtils.QUOTATION_MARK + original + TalendTextUtils.QUOTATION_MARK;
}
if (column.getSourceType() == null) {
column.setSourceType("id_String");
}
if (column.getTalendType() == null) {
column.setTalendType("id_String");
}
// column.setLabel(column.getOriginalField()); // display user defined column name
metatable.getColumns().add(column);
}
metatable.setLabel(schemaKey);
schemaKey = mapSchemaKeyFromNode(schemaKey);
IMetadataTable table = ConvertionHelper.convert(metatable);
table.setTableName(schemaKey);
if (displayName != null && !"".equals(displayName)) {
//$NON-NLS-N$
oneSchema.put("SCHEMA", schemaKey);
//$NON-NLS-N$
oneSchema.put("MAPPING", displayName);
schemas.add(oneSchema);
}
if (table != null && !table.getListColumns().isEmpty()) {
//
boolean find = false;
int index = 0;
for (int i = 0; i < hl7Component.getMetadataList().size(); i++) {
if (table.getLabel().equals(hl7Component.getMetadataList().get(i).getLabel())) {
find = true;
index = i;
break;
}
}
if (find) {
hl7Component.getMetadataList().remove(index);
} else {
schemaKey = hl7Component.getProcess().generateUniqueConnectionName(MultiSchemasUtil.getConnectionBaseName(schemaKey));
table.setTableName(schemaKey);
}
hl7Component.getMetadataList().add(table);
} else if (table != null && table.getListColumns().isEmpty()) {
boolean find = false;
int index = 0;
for (int i = 0; i < hl7Component.getMetadataList().size(); i++) {
if (table.getLabel().equals(hl7Component.getMetadataList().get(i).getLabel())) {
find = true;
index = i;
break;
}
}
if (find) {
hl7Component.getMetadataList().remove(index);
hl7Component.getMetadataList().add(table);
}
}
}
return schemas;
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class HL7MultiSchemaUI method buildCurrentTable.
private MetadataTable buildCurrentTable(MetadataColumn[] beans, String schemaKey) {
MetadataTable metatable = ConnectionFactory.eINSTANCE.createMetadataTable();
//$NON-NLS-N$
String displayName = "";
for (int i = 0; i < beans.length; i++) {
MetadataColumn column = beans[i];
String original = beans[i].getOriginalField();
if (original != null && !"".equals(original)) {
if (original.indexOf(TalendTextUtils.LBRACKET) > 0) {
original = original.substring(0, original.indexOf(TalendTextUtils.LBRACKET));
}
}
if (i != beans.length - 1) {
displayName = displayName + TalendTextUtils.QUOTATION_MARK + original + TalendTextUtils.QUOTATION_MARK + ",";
} else {
displayName = displayName + TalendTextUtils.QUOTATION_MARK + original + TalendTextUtils.QUOTATION_MARK;
}
if (column.getSourceType() == null) {
column.setSourceType("id_String");
}
if (column.getTalendType() == null) {
column.setTalendType("id_String");
}
// column.setLabel(column.getOriginalField()); // display user defined column name
metatable.getColumns().add(column);
}
metatable.setLabel(schemaKey);
return metatable;
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class ComponentChooseDialog method getChangeMetadataCommand.
/**
* DOC bqian Comment method "getChangeMetadataCommand".
*
* @param selectedNode
* @param node
* @param list
* @param connectionItem
*/
private void getChangeMetadataCommand(CompoundCommand cc, RepositoryNode selectedNode, Node node, ConnectionItem connectionItem) {
if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_COLUMN) {
RepositoryNode columnParentNode = selectedNode.getParent().getParent();
if (columnParentNode != null) {
selectedNode = columnParentNode;
}
}
if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_TABLE || selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_SAP_FUNCTION || selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_SALESFORCE_MODULE) {
String etlSchema = null;
if (connectionItem.getConnection() instanceof DatabaseConnection) {
DatabaseConnection connection = (DatabaseConnection) connectionItem.getConnection();
if (connection instanceof DatabaseConnection) {
etlSchema = connection.getUiSchema();
}
if (!"".equals(etlSchema)) {
//$NON-NLS-1$
//$NON-NLS-1$
IElementParameter e = node.getElementParameter("ELT_SCHEMA_NAME");
if (e != null) {
if (connection.isContextMode() && ContextParameterUtils.isContainContextParam(etlSchema)) {
e.setValue(etlSchema);
} else {
e.setValue(TalendTextUtils.addQuotes(etlSchema));
}
}
// node.getElementParameter("ELT_SCHEMA_NAME").setValue("\"" + etlSchema + "\"");
}
}
IRepositoryViewObject object = selectedNode.getObject();
MetadataTable table = null;
if (object instanceof MetadataTableRepositoryObject) {
table = ((MetadataTableRepositoryObject) object).getTable();
} else if (object instanceof SalesforceModuleRepositoryObject) {
table = ((SalesforceModuleRepositoryObject) object).getDefaultTable();
IRepositoryViewObject obj = null;
if (selectedNode.getChildren() != null) {
for (IRepositoryNode repositoryNode : selectedNode.getChildren()) {
obj = repositoryNode.getObject();
if (obj instanceof MetadataTableRepositoryObject) {
table = ((MetadataTableRepositoryObject) obj).getTable();
break;
}
}
}
}
// for SAP
if (PluginChecker.isSAPWizardPluginLoaded() && connectionItem instanceof SAPConnectionItem) {
getSAPCommand(cc, object, connectionItem, table, node);
return;
}
if (table != null) {
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
IElementParameter schemaParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
if (schemaParam == null) {
schemaParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
}
IElementParameter queryParam = node.getElementParameterFromField(EParameterFieldType.QUERYSTORE_TYPE);
if (queryParam != null) {
queryParam = queryParam.getChildParameters().get(EParameterName.QUERYSTORE_TYPE.getName());
if (queryParam != null) {
queryParam.setValue(EmfComponent.BUILTIN);
}
}
// }
if (PluginChecker.isHL7PluginLoaded() && connectionItem instanceof HL7ConnectionItem) {
Command hl7Cmd = new RepositoryChangeMetadataForHL7Command(node, IEbcdicConstant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
cc.add(hl7Cmd);
return;
}
if (schemaParam == null) {
return;
}
if (node.isELTComponent()) {
//$NON-NLS-1$
node.setPropertyValue(EParameterName.LABEL.getName(), "__ELT_TABLE_NAME__");
}
schemaParam.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
RepositoryChangeMetadataCommand command2 = new RepositoryChangeMetadataCommand(node, //$NON-NLS-1$
schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, ConvertionHelper.convert(table), null, connectionItem.getConnection());
cc.add(command2);
return;
}
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class GenericDragAndDropHandler method isValid.
private boolean isValid(RepositoryNode seletetedNode, IComponent component) {
// TUP-4151
IRepositoryViewObject object = seletetedNode.getObject();
if (component == null || object == null) {
return false;
}
ComponentProperties currentComponentProperties = null;
if (object instanceof RepositoryViewObject) {
RepositoryViewObject repositoryViewObj = (RepositoryViewObject) object;
Connection connection = ((ConnectionItem) repositoryViewObj.getProperty().getItem()).getConnection();
if (canHandle(connection)) {
GenericConnection genericConnection = (GenericConnection) connection;
currentComponentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(genericConnection.getCompProperties(), connection);
}
} else if (object instanceof MetadataTableRepositoryObject) {
MetadataTableRepositoryObject metaTableRepObj = (MetadataTableRepositoryObject) object;
currentComponentProperties = SchemaUtils.getCurrentComponentProperties(metaTableRepObj);
} else if (object instanceof MetadataColumnRepositoryObject) {
MetadataColumnRepositoryObject metaColumnRepObj = (MetadataColumnRepositoryObject) object;
ModelElement element = metaColumnRepObj.getTdColumn();
if (element != null && element.eContainer() instanceof MetadataTable) {
MetadataTable metadataTable = (MetadataTable) element.eContainer();
IMetadataTable newTable = MetadataToolHelper.convert(metadataTable);
currentComponentProperties = SchemaUtils.getCurrentComponentProperties(newTable);
}
}
if (currentComponentProperties != null) {
try {
List<ComponentDefinition> possibleComponents = ComponentsUtils.getComponentService().getPossibleComponents(currentComponentProperties);
if (component instanceof Component) {
ComponentDefinition componentDefinition = ((Component) component).getComponentDefinition();
return possibleComponents.contains(componentDefinition);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
return false;
}
Aggregations