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;
}
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;
}
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);
}
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;
}
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();
}
Aggregations