Search in sources :

Example 91 with MetadataColumn

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

the class MapRDBMetadataProvider method isMetadataExsit.

@Override
public boolean isMetadataExsit(Object node, DatabaseConnection connection) {
    TableNode columnNode = null;
    if (node == null) {
        return false;
    }
    if (node instanceof TableNode) {
        columnNode = (TableNode) node;
    }
    if (columnNode.getType() == TableNode.COLUMN) {
        TableNode columnFamilyNode = columnNode.getParent();
        TableNode tableNode = null;
        String tableName = null;
        String columnFamilyName = null;
        String columnName = columnNode.getValue();
        if (columnFamilyNode != null) {
            columnFamilyName = columnFamilyNode.getValue();
            tableNode = columnFamilyNode.getParent();
            if (tableNode != null) {
                tableName = tableNode.getValue();
            }
        }
        List<MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
        for (MetadataTable table : tables) {
            if (table instanceof TdTable) {
                TdTable tdTable = (TdTable) table;
                if (tdTable.getLabel().equals(tableName)) {
                    List<MetadataColumn> columns = tdTable.getColumns();
                    for (MetadataColumn column : columns) {
                        if (column.getLabel().equals(columnName)) {
                            List<TaggedValue> tagValues = column.getTaggedValue();
                            for (TaggedValue tv : tagValues) {
                                String tag = tv.getTag();
                                String value = tv.getValue();
                                if (tag != null && tag.equals(COLUMN_FAMILY)) {
                                    if (value != null && value.equals(columnFamilyName)) {
                                        // columns.remove(column);
                                        return true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else if (columnNode.getType() == TableNode.COLUMN_FAMILY) {
        String columnFamilyName = columnNode.getValue();
        String tableName = null;
        TableNode tableNode = columnNode.getParent();
        if (tableNode != null) {
            tableName = tableNode.getValue();
        }
        List<MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
        for (MetadataTable table : tables) {
            if (table instanceof TdTable) {
                TdTable tdTable = (TdTable) table;
                if (tdTable.getLabel().equals(tableName)) {
                    List<MetadataColumn> columns = tdTable.getColumns();
                    for (MetadataColumn column : columns) {
                        List<TaggedValue> tagValues = column.getTaggedValue();
                        for (TaggedValue tv : tagValues) {
                            String tag = tv.getTag();
                            String value = tv.getValue();
                            if (tag != null && tag.equals(COLUMN_FAMILY)) {
                                if (value != null && value.equals(columnFamilyName)) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdTable(org.talend.cwm.relational.TdTable) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) TableNode(org.talend.core.model.metadata.builder.database.TableNode) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) List(java.util.List) ArrayList(java.util.ArrayList)

Example 92 with MetadataColumn

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

the class ExtractAVROFileSchemaService method extractColumns.

private List<MetadataColumn> extractColumns(HDFSConnection connection, InputStream inputStream, String tmpFileName, String fullPathName) throws CoreException {
    List<MetadataColumn> columns = new ArrayList<MetadataColumn>();
    if (connection == null || inputStream == null || tmpFileName == null || fullPathName == null) {
        return columns;
    }
    File tmpFile = createTmpFile(inputStream, tmpFileName);
    try {
        ReflectedAVROSchema storedSchema = new ReflectedAVROSchema(fullPathName, tmpFile, classLoader);
        if (storedSchema != null) {
            columns = guessSchemaFromAVRO(storedSchema.getFields());
        }
    } catch (Exception e) {
        IStatus template = Status.CANCEL_STATUS;
        Status expStatus = new Status(template.getSeverity(), template.getPlugin(), e.getMessage(), e);
        throw new CoreException(expStatus);
    }
    return columns;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) File(java.io.File) HDFSFile(org.talend.designer.hdfsbrowse.model.HDFSFile) CoreException(org.eclipse.core.runtime.CoreException) HadoopServerException(org.talend.designer.hdfsbrowse.exceptions.HadoopServerException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 93 with MetadataColumn

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

the class ExtractHDFSSchemaManager method extractColumns.

public List<MetadataColumn> extractColumns(HDFSConnection connection, ClassLoader classLoader, MetadataTable metadataTable) throws Exception {
    List<MetadataColumn> columns = new ArrayList<MetadataColumn>();
    if (connection == null || metadataTable == null) {
        return columns;
    }
    EMap<String, String> additionalProperties = metadataTable.getAdditionalProperties();
    String hdfsPath = additionalProperties.get(HDFSConstants.HDFS_PATH);
    if (StringUtils.isEmpty(hdfsPath)) {
        return columns;
    }
    HDFSConnectionBean connectionBean = HDFSModelUtil.convert2HDFSConnectionBean(connection);
    Object filePath = getHDFSFilePath(connectionBean, classLoader, hdfsPath);
    IExtractSchemaService<HDFSConnection> service = ExtractHDFSMetaServiceFactory.getService(connectionBean, classLoader, filePath);
    return service.extractColumns(connection, metadataTable);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) HDFSConnectionBean(org.talend.designer.hdfsbrowse.model.HDFSConnectionBean) ArrayList(java.util.ArrayList) HDFSConnection(org.talend.repository.model.hdfs.HDFSConnection)

Example 94 with MetadataColumn

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

the class FixCassandraDataStaxDbtypesProblemMigrationTask method execute.

/*
     * (non-Javadoc)
     *
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    if (item instanceof NoSQLConnectionItem) {
        boolean modify = false;
        Connection connection = ((NoSQLConnectionItem) item).getConnection();
        if (connection instanceof NoSQLConnection) {
            NoSQLConnection noSqlConn = (NoSQLConnection) connection;
            EMap<String, String> attributes = noSqlConn.getAttributes();
            String dbVersion = attributes.get(INoSQLCommonAttributes.DB_VERSION);
            if (!CASSANDRA_2_0_0.equals(dbVersion)) {
                return ExecutionResult.NOTHING_TO_DO;
            }
            boolean isDatastaxApiType = ICassandraConstants.API_TYPE_DATASTAX.equals(attributes.get(INoSQLCommonAttributes.API_TYPE));
            if (!isDatastaxApiType) {
                return ExecutionResult.NOTHING_TO_DO;
            }
            Set<MetadataTable> tables = ConnectionHelper.getTables(noSqlConn);
            if (tables == null || tables.isEmpty()) {
                return ExecutionResult.NOTHING_TO_DO;
            }
            MappingTypeRetriever mappingTypeRetriever = MetadataTalendType.getMappingTypeRetriever(ICassandraConstants.DBM_DATASTAX_ID);
            for (MetadataTable table : tables) {
                EList<MetadataColumn> columns = table.getColumns();
                if (columns == null || columns.isEmpty()) {
                    continue;
                }
                for (MetadataColumn column : columns) {
                    String sourceType = column.getSourceType();
                    if (sourceType == null || sourceType.isEmpty()) {
                        continue;
                    }
                    modify = true;
                    sourceType = sourceType.toLowerCase();
                    column.setSourceType(sourceType);
                    String talendType = mappingTypeRetriever.getDefaultSelectedTalendType(sourceType);
                    if (talendType == null) {
                        talendType = JavaTypesManager.STRING.getId();
                    }
                    column.setTalendType(talendType);
                }
            }
        }
        if (modify) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                factory.save(item, true);
                return ExecutionResult.SUCCESS_WITH_ALERT;
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : MappingTypeRetriever(org.talend.core.model.metadata.MappingTypeRetriever) NoSQLConnection(org.talend.repository.model.nosql.NoSQLConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) NoSQLConnection(org.talend.repository.model.nosql.NoSQLConnection) NoSQLConnectionItem(org.talend.repository.model.nosql.NoSQLConnectionItem)

Example 95 with MetadataColumn

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

the class AbstractNoSQLSchemaForm method initMetadataForm.

private void initMetadataForm() {
    if (metadataTable == null) {
        return;
    }
    metadataEditor.setMetadataTable(metadataTable);
    boolean flag = CoreRuntimePlugin.getInstance().getProjectPreferenceManager().isAllowSpecificCharacters();
    if (!flag) {
        List<MetadataColumn> list = metadataEditor.getMetadataColumnList();
        for (MetadataColumn column : list) {
            if (!isCnorEn(column.getLabel())) {
                // $NON-NLS-1$
                String label = metadataEditor.getNextGeneratedColumnName("newColumn");
                column.setLabel(label);
            }
        }
    }
    tableEditorView.setMetadataEditor(metadataEditor);
    tableEditorView.getTableViewerCreator().layout();
    // add listener to tableMetadata (listen the event of the toolbars)
    metadataEditor.addAfterOperationListListener(new IListenableListListener() {

        @Override
        public void handleEvent(ListenableListEvent event) {
            changeTableNavigatorStatus(checkFieldsValue());
        }
    });
    // init the fields
    String label = MetadataToolHelper.validateValue(metadataTable.getLabel());
    nameText.setText(label);
    commentText.setText(metadataTable.getComment());
    if (tableCombo != null) {
        String currentTableName = getCurrentTableName();
        if (currentTableName != null) {
            tableCombo.setText(currentTableName);
        }
    }
    if (guessSchemaButton != null) {
        updateGuessSchemaButton();
    }
    nameText.forceFocus();
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener)

Aggregations

MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)203 ArrayList (java.util.ArrayList)98 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)51 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)37 TdColumn (org.talend.cwm.relational.TdColumn)28 List (java.util.List)24 HashMap (java.util.HashMap)20 Test (org.junit.Test)15 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)14 EList (org.eclipse.emf.common.util.EList)12 Indicator (org.talend.dataquality.indicators.Indicator)12 IRepositoryNode (org.talend.repository.model.IRepositoryNode)12 File (java.io.File)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 NoSQLExtractSchemaException (org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)10 Map (java.util.Map)9 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 Iterator (java.util.Iterator)8 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8