Search in sources :

Example 1 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable 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);
                }
            }
        }
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IModel(org.talend.designer.hl7.model.IModel) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.

the class JSONRepositoryContentHandler method addNode.

@Override
public void addNode(ERepositoryObjectType type, RepositoryNode recBinNode, IRepositoryViewObject repositoryObject, RepositoryNode node) {
    if (type == JSONRepositoryNodeType.JSON) {
        JSONFileConnection connection = (JSONFileConnection) ((JSONFileConnectionItem) repositoryObject.getProperty().getItem()).getConnection();
        Set<MetadataTable> tableset = ConnectionHelper.getTables(connection);
        for (MetadataTable metadataTable : tableset) {
            if (!SubItemHelper.isDeleted(metadataTable)) {
                RepositoryNode tableNode = RepositoryNodeManager.createMetatableNode(node, repositoryObject, metadataTable);
                node.getChildren().add(tableNode);
                if (metadataTable.getColumns().size() > 0) {
                    RepositoryNodeManager.createColumns(tableNode, repositoryObject, metadataTable);
                }
            }
        }
    }
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 3 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.

the class GenericSchemaWizardPage method createControl.

@Override
public void createControl(final Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    container.setLayout(new GridLayout());
    setControl(container);
    List<MetadataTable> metadataTables = SchemaUtils.getMetadataTables(getConnection(), SubContainer.class);
    List<String> existingTableLabels = new ArrayList<>();
    for (MetadataTable metaTable : metadataTables) {
        String label = metaTable.getLabel();
        if (!label.equals(metadataTable.getLabel())) {
            existingTableLabels.add(label);
        }
    }
    String[] existingTableLabelsArray = existingTableLabels.toArray(new String[0]);
    GenericSchemaForm schemaForm = new GenericSchemaForm(container, connectionItem, metadataTable, existingTableLabelsArray);
    schemaForm.setLayoutData(new GridData(GridData.FILL_BOTH));
    schemaForm.setReadOnly(!isRepositoryObjectEditable);
    addCheckListener(schemaForm.getChecker());
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ArrayList(java.util.ArrayList)

Example 4 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.

the class GenericUpdateManager method getConversionMetadataTables.

public static List<IMetadataTable> getConversionMetadataTables(Connection conn) {
    if (conn == null) {
        return Collections.emptyList();
    }
    List<IMetadataTable> tables = new ArrayList<>();
    List<MetadataTable> metadataTables = SchemaUtils.getMetadataTables(conn, SubContainer.class);
    for (MetadataTable metadataTable : metadataTables) {
        tables.add(ConvertionHelper.convert(metadataTable));
    }
    return tables;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ArrayList(java.util.ArrayList) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable)

Example 5 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.

the class SchemaUtils method createSchema.

public static MetadataTable createSchema(String name, ComponentProperties properties, String schemaPropertyName) {
    if (name == null || properties == null || schemaPropertyName == null) {
        return null;
    }
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    MetadataTable metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
    metadataTable.setId(factory.getNextId());
    metadataTable.setName(name);
    metadataTable.setLabel(name);
    metadataTable.setSourceName(name);
    Object schemaObj = ComponentsUtils.getGenericPropertyValue(properties, schemaPropertyName);
    if (schemaObj instanceof String) {
        Schema avroSchema = new Schema.Parser().parse((String) schemaObj);
        convertComponentSchemaIntoTalendSchema(avroSchema, metadataTable);
    } else if (schemaObj instanceof Schema) {
        convertComponentSchemaIntoTalendSchema((Schema) schemaObj, metadataTable);
    }
    IMetadataTable iMetadataTable = MetadataToolHelper.convert(metadataTable);
    updateComponentSchema(properties, schemaPropertyName, iMetadataTable);
    metadataTable = ConvertionHelper.convert(iMetadataTable);
    properties.setValue(schemaPropertyName, convertTalendSchemaIntoComponentSchema(metadataTable));
    TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
    serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
    serializedPropsTV.setValue(properties.toSerialized());
    metadataTable.getTaggedValue().add(serializedPropsTV);
    TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
    schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
    schemaPropertyTV.setValue(schemaPropertyName);
    metadataTable.getTaggedValue().add(schemaPropertyTV);
    return metadataTable;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)153 ArrayList (java.util.ArrayList)53 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)51 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)25 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)23 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)22 List (java.util.List)18 Test (org.junit.Test)17 PersistenceException (org.talend.commons.exception.PersistenceException)17 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)15 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)14 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)14 Connection (org.talend.core.model.metadata.builder.connection.Connection)12 RepositoryNode (org.talend.repository.model.RepositoryNode)12 ConnectionItem (org.talend.core.model.properties.ConnectionItem)10 TdColumn (org.talend.cwm.relational.TdColumn)9 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 IRepositoryNode (org.talend.repository.model.IRepositoryNode)9 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)8 HashMap (java.util.HashMap)7