use of org.talend.core.model.metadata.builder.connection.DelimitedFileConnection in project tdi-studio-se by Talend.
the class DynamicTabbedPropertySection method updateRepositoryListExtra.
private void updateRepositoryListExtra(IElementParameter param, String[] repositoryConnectionNameList, String[] repositoryConnectionValueList, boolean extra) {
String paramName = EParameterName.PROPERTY_TYPE.getName();
// if (extra) {
// paramName = extraPropertyTypeName;
// }
String repositoryValue = elem.getElementParameter(paramName).getRepositoryValue();
if (repositoryValue != null) {
List<String> connectionNamesList = new ArrayList<String>();
List<String> connectionValuesList = new ArrayList<String>();
for (String key : repositoryConnectionItemMap.keySet()) {
ConnectionItem connectionItem = repositoryConnectionItemMap.get(key);
Connection connection = connectionItem.getConnection();
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel();
if ((connection instanceof DelimitedFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.DELIMITED.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof PositionalFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.POSITIONAL.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof RegexpFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.REGEX.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof XmlFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.XML.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof FileExcelConnection) && (repositoryValue.equals(ERepositoryCategoryType.EXCEL.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof GenericSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.GENERIC.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof LDAPSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.LDAP.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof SalesforceSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.SALESFORCE.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof DatabaseConnection) && (repositoryValue.startsWith(ERepositoryCategoryType.DATABASE.getName()))) {
//$NON-NLS-1$
String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
if (repositoryValue.contains(":")) {
// database //$NON-NLS-1$
// is
// specified
// //$NON-NLS-1$
//$NON-NLS-1$
String neededDbType = repositoryValue.substring(repositoryValue.indexOf(":") + 1);
if (neededDbType.equals(currentDbType)) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
} else {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
}
if ((connection instanceof HeaderFooterConnection) && (repositoryValue.equals(ERepositoryCategoryType.HEADERFOOTER.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
}
repositoryConnectionNameList = connectionNamesList.toArray(new String[0]);
repositoryConnectionValueList = connectionValuesList.toArray(new String[0]);
} else {
List<String> connectionValuesList = new ArrayList<String>();
List<String> connectionStringList = new ArrayList<String>();
for (String key : repositoryConnectionItemMap.keySet()) {
ConnectionItem connectionItem = repositoryConnectionItemMap.get(key);
String name = connectionItem.getProperty().getLabel();
addOrderDisplayNames(connectionValuesList, connectionStringList, key, name);
}
repositoryConnectionNameList = connectionStringList.toArray(new String[0]);
repositoryConnectionValueList = connectionValuesList.toArray(new String[0]);
}
param.setListItemsDisplayName(repositoryConnectionNameList);
param.setListItemsValue(repositoryConnectionValueList);
if (!repositoryConnectionItemMap.keySet().contains(param.getValue())) {
if (repositoryConnectionNameList.length > 0) {
// paramName = EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
// if (extra) {
// paramName = extraRepositoryPropertyTypeName;
// }
elem.setPropertyValue(paramName, repositoryConnectionValueList[0]);
}
}
}
use of org.talend.core.model.metadata.builder.connection.DelimitedFileConnection in project tdq-studio-se by Talend.
the class DelimitedFileSQLExecutor method executeQuery.
/*
* (non-Javadoc)
*
* @see org.talend.cwm.db.connection.ISQLExecutor#executeQuery(orgomg.cwm.foundation.softwaredeployment.DataManager,
* java.util.List, java.lang.String)
*/
public List<Object[]> executeQuery(DataManager connection, List<ModelElement> analysedElements, String where) throws SQLException {
getDataFromTable().clear();
try {
beginQuery();
} catch (Exception e1) {
log.error(e1.getMessage(), e1);
return getDataFromTable();
}
DelimitedFileConnection delimitedFileconnection = (DelimitedFileConnection) connection;
String path = JavaSqlFactory.getURL(delimitedFileconnection);
IPath iPath = new Path(path);
try {
File file = iPath.toFile();
if (!file.exists()) {
// $NON-NLS-1$
throw new SQLException("The file does not exist");
}
if (Escape.CSV.equals(delimitedFileconnection.getEscapeType())) {
useCsvReader(file, delimitedFileconnection, analysedElements);
} else {
useFileInputDelimited(analysedElements, delimitedFileconnection);
}
endQuery();
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new SQLException(e.getMessage(), e);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SQLException(e.getMessage(), e);
}
return getDataFromTable();
}
use of org.talend.core.model.metadata.builder.connection.DelimitedFileConnection in project tdq-studio-se by Talend.
the class RunAnalysisAction method addTaggedVaLueIntoConnection.
private void addTaggedVaLueIntoConnection(TDQAnalysisItem runItem) {
DataManager datamanager = runItem.getAnalysis().getContext().getConnection();
if (datamanager instanceof DatabaseConnection) {
TaggedValue productName = TaggedValueHelper.getTaggedValue(TaggedValueHelper.DB_PRODUCT_NAME, datamanager.getTaggedValue());
TaggedValue productVersion = TaggedValueHelper.getTaggedValue(TaggedValueHelper.DB_PRODUCT_VERSION, datamanager.getTaggedValue());
// $NON-NLS-1$
log.info("DB Product Name: " + productName.getValue());
// $NON-NLS-1$
log.info("DB Product Version: " + productVersion.getValue());
} else if (datamanager instanceof DelimitedFileConnection) {
// $NON-NLS-1$
log.info("File Connection path: " + ((DelimitedFileConnection) datamanager).getFilePath());
}
}
use of org.talend.core.model.metadata.builder.connection.DelimitedFileConnection in project tdq-studio-se by Talend.
the class ColumnSetIndicatorEvaluatorTest method testExecuteSqlQuery_file.
/**
* Test method for {@link org.talend.dq.indicators.ColumnSetIndicatorEvaluator#executeSqlQuery(String)} .
*/
@Test
public void testExecuteSqlQuery_file() throws Exception {
Analysis analysis = mock(Analysis.class);
// $NON-NLS-1$
stub(method(DelimitedFileIndicatorEvaluator.class, "handleByARow"));
// $NON-NLS-1$
stub(method(DelimitedFileIndicatorEvaluator.class, "addResultToIndicatorToRowMap", Indicator.class, EMap.class));
AnalysisContext context = mock(AnalysisContext.class);
when(analysis.getContext()).thenReturn(context);
DelimitedFileConnection deliFileConn = mock(DelimitedFileConnection.class);
when(context.getConnection()).thenReturn(deliFileConn);
when(deliFileConn.isContextMode()).thenReturn(true);
when(deliFileConn.getFilePath()).thenReturn(context_fd1_File);
when(deliFileConn.getFieldSeparatorValue()).thenReturn(context_fd1_FieldSeparator);
when(deliFileConn.getEncoding()).thenReturn(context_fd1_Encoding);
IPath iPath = mock(IPath.class);
File file = new File(realFile);
BufferedWriter output = new BufferedWriter(new FileWriter(file));
String str = "id;Cocust(Tests);owner_id\n" + "1;yellow;3301\n" + "2;blue;3302\n" + "4;red;3307\n" + "5;white;4563\n" + "6;pink2;457883\n" + "7;blank;231233\n";
output.write(str);
output.close();
when(iPath.toFile()).thenReturn(file);
assertTrue(file.exists());
PowerMockito.mockStatic(JavaSqlFactory.class);
when(JavaSqlFactory.getURL(deliFileConn)).thenReturn(realFile);
when(JavaSqlFactory.getFieldSeparatorValue(deliFileConn)).thenReturn(realFieldSeparator);
when(JavaSqlFactory.getEncoding(deliFileConn)).thenReturn(realEncoding);
PowerMockito.mockStatic(ResourceBundle.class);
ResourceBundle bundle = mock(ResourceBundle.class);
// $NON-NLS-1$
when(ResourceBundle.getBundle("Messages")).thenReturn(bundle);
PowerMockito.mockStatic(Messages.class);
// $NON-NLS-1$
when(Messages.getString(anyString())).thenReturn("testString");
AnalysisResult results = mock(AnalysisResult.class);
when(analysis.getResults()).thenReturn(results);
EMap<Indicator, AnalyzedDataSet> indicToRowMap = mock(EMap.class);
when(results.getIndicToRowMap()).thenReturn(indicToRowMap);
when(deliFileConn.getHeaderValue()).thenReturn(context_fd1_Header);
when(deliFileConn.getFooterValue()).thenReturn(zero);
when(deliFileConn.getLimitValue()).thenReturn(zero);
when(deliFileConn.getEscapeType()).thenReturn(Escape.DELIMITED);
when(deliFileConn.getRowSeparatorValue()).thenReturn(context_fd1_RowSeparator);
when(deliFileConn.isSplitRecord()).thenReturn(false);
when(deliFileConn.isRemoveEmptyRow()).thenReturn(false);
when(JavaSqlFactory.getHeadValue(deliFileConn)).thenReturn(realHeading);
when(JavaSqlFactory.getRowSeparatorValue(deliFileConn)).thenReturn(realRowSeparator);
PowerMockito.mockStatic(LanguageManager.class);
when(LanguageManager.getCurrentLanguage()).thenReturn(ECodeLanguage.JAVA);
PowerMockito.mockStatic(ParameterUtil.class);
when(ParameterUtil.trimParameter(realFile)).thenReturn(realFile);
when(ParameterUtil.trimParameter(realEncoding)).thenReturn(realEncoding);
PowerMockito.mockStatic(StringUtils.class);
when(StringUtils.loadConvert(realFieldSeparator, ECodeLanguage.JAVA.getName())).thenReturn(realFieldSeparator);
when(ParameterUtil.trimParameter(realFieldSeparator)).thenReturn(realFieldSeparator);
when(StringUtils.loadConvert(realRowSeparator, ECodeLanguage.JAVA.getName())).thenReturn(realRowSeparator);
when(ParameterUtil.trimParameter(realRowSeparator)).thenReturn(realRowSeparator);
List<ModelElement> columnElementList = new BasicEList<ModelElement>();
List<MetadataColumn> columnElementList2 = new BasicEList<MetadataColumn>();
MetadataColumn mc0 = mock(MetadataColumn.class);
MetadataColumn mc1 = mock(MetadataColumn.class);
MetadataColumn mc2 = mock(MetadataColumn.class);
columnElementList.add(mc0);
columnElementList.add(mc1);
columnElementList.add(mc2);
columnElementList2.add(mc0);
columnElementList2.add(mc1);
columnElementList2.add(mc2);
EList<ModelElement> eLs = (EList<ModelElement>) columnElementList;
when(context.getAnalysedElements()).thenReturn(eLs);
PowerMockito.mockStatic(ColumnHelper.class);
MetadataTable mTable = mock(MetadataTable.class);
when(mTable.getColumns()).thenReturn((EList<MetadataColumn>) columnElementList2);
when(ColumnHelper.getColumnOwnerAsMetadataTable(mc0)).thenReturn(mTable);
when(ColumnHelper.getColumnOwnerAsMetadataTable(mc1)).thenReturn(mTable);
when(ColumnHelper.getColumnOwnerAsMetadataTable(mc2)).thenReturn(mTable);
ColumnSetIndicatorEvaluator evaluator = new ColumnSetIndicatorEvaluator(analysis);
ColumnSetIndicatorEvaluator spyEvaluator = Mockito.spy(evaluator);
Mockito.doReturn(true).when(spyEvaluator).continueRun();
ReturnCode rc = spyEvaluator.executeSqlQuery(empty);
assertTrue(rc.isOk());
}
use of org.talend.core.model.metadata.builder.connection.DelimitedFileConnection in project tdq-studio-se by Talend.
the class DelimitedFileIndicatorEvaluatorTest method testExecuteSqlQuery_delimetd.
@Ignore
@Test
public void testExecuteSqlQuery_delimetd() throws Exception {
// $NON-NLS-1$
String empty = "";
Analysis analysis = mock(Analysis.class);
DelimitedFileIndicatorEvaluator delFileIndiEvaluator = new DelimitedFileIndicatorEvaluator(analysis);
DelimitedFileIndicatorEvaluator spyEvaluator = Mockito.spy(delFileIndiEvaluator);
// $NON-NLS-1$
stub(method(DelimitedFileIndicatorEvaluator.class, "handleByARow"));
// $NON-NLS-1$
stub(method(DelimitedFileIndicatorEvaluator.class, "addResultToIndicatorToRowMap", Indicator.class, EMap.class));
AnalysisContext context = mock(AnalysisContext.class);
when(analysis.getContext()).thenReturn(context);
DelimitedFileConnection deliFileConn = mock(DelimitedFileConnection.class);
when(context.getConnection()).thenReturn(deliFileConn);
when(deliFileConn.isContextMode()).thenReturn(false);
// $NON-NLS-1$
String path = "test.txt";
PowerMockito.mockStatic(JavaSqlFactory.class);
when(JavaSqlFactory.getURL(deliFileConn)).thenReturn(path);
IPath iPath = mock(IPath.class);
File file = new File(path);
BufferedWriter output = new BufferedWriter(new FileWriter(file));
String str = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"id;Cocust(Tests);owner_id\n" + "1;yellow;3301\n" + "2;blue;3302\n" + " 4;red;3307\n" + "5;white;4563\n" + "6;pink2;457883\n" + // $NON-NLS-1$ //$NON-NLS-2$
"7;blank;231233\n";
output.write(str);
output.close();
when(iPath.toFile()).thenReturn(file);
// $NON-NLS-1$
when(deliFileConn.getFieldSeparatorValue()).thenReturn(";");
// $NON-NLS-1$
when(deliFileConn.getEncoding()).thenReturn("US-ASCII");
AnalysisResult results = mock(AnalysisResult.class);
when(analysis.getResults()).thenReturn(results);
EMap<Indicator, AnalyzedDataSet> indicToRowMap = mock(EMap.class);
when(results.getIndicToRowMap()).thenReturn(indicToRowMap);
List<ModelElement> columnElementList = new BasicEList<ModelElement>();
List<MetadataColumn> columnElementList2 = new BasicEList<MetadataColumn>();
MetadataColumn mc0 = mock(MetadataColumn.class);
MetadataColumn mc1 = mock(MetadataColumn.class);
MetadataColumn mc2 = mock(MetadataColumn.class);
columnElementList.add(mc0);
columnElementList.add(mc1);
columnElementList.add(mc2);
columnElementList2.add(mc0);
columnElementList2.add(mc1);
columnElementList2.add(mc2);
EList<ModelElement> eLs = (EList<ModelElement>) columnElementList;
when(context.getAnalysedElements()).thenReturn(eLs);
PowerMockito.mockStatic(ColumnHelper.class);
MetadataTable mTable = mock(MetadataTable.class);
when(mTable.getColumns()).thenReturn((EList<MetadataColumn>) columnElementList2);
when(ColumnHelper.getColumnOwnerAsMetadataTable(mc0)).thenReturn(mTable);
when(ColumnHelper.getColumnOwnerAsMetadataTable(mc1)).thenReturn(mTable);
when(deliFileConn.getHeaderValue()).thenReturn(empty);
when(deliFileConn.getFooterValue()).thenReturn(empty);
when(deliFileConn.getLimitValue()).thenReturn(empty);
when(deliFileConn.getEscapeType()).thenReturn(Escape.DELIMITED);
// $NON-NLS-1$
when(deliFileConn.getRowSeparatorValue()).thenReturn("\\n");
when(deliFileConn.isRemoveEmptyRow()).thenReturn(false);
when(deliFileConn.isSplitRecord()).thenReturn(false);
PowerMockito.mockStatic(LanguageManager.class);
when(LanguageManager.getCurrentLanguage()).thenReturn(ECodeLanguage.JAVA);
Mockito.doReturn(true).when(spyEvaluator).continueRun();
spyEvaluator.executeSqlQuery(empty);
}
Aggregations