use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdq-studio-se by Talend.
the class OverviewResultPage method wapperInput.
/**
* DOC klliu Comment method "wapperInput". relations
*
* @param indicatorTableList
* @param parentNode
* @return
*/
private List<OverviewIndUIElement> wapperInput(EList<TableIndicator> indicatorTableList, IRepositoryNode parentNode) {
List<OverviewIndUIElement> cataUIEleList = new ArrayList<OverviewIndUIElement>();
List<IRepositoryNode> children = parentNode.getChildren();
for (IRepositoryNode folderNode : children) {
if (folderNode instanceof DBTableFolderRepNode) {
List<IRepositoryNode> tableNodes = folderNode.getChildren();
// MOD 20120315 klliu&yyin TDQ-2391, avoid getting many times for table nodes.
for (TableIndicator indicator : indicatorTableList) {
boolean equals = false;
for (IRepositoryNode tableNode : tableNodes) {
MetadataTable table = ((MetadataTableRepositoryObject) tableNode.getObject()).getTable();
String name = table.getName();
String tableName = indicator.getTableName();
// String connUuid = ResourceHelper.getUUID(table);
// String anaUuid = ResourceHelper.getUUID(indicator.getAnalyzedElement());
equals = name.equals(tableName);
if (equals) {
OverviewIndUIElement tableUIEle = new OverviewIndUIElement();
tableUIEle.setNode(tableNode);
tableUIEle.setOverviewIndicator(indicator);
if (DqRepositoryViewService.isComeFromRefrenceProject(getTdDataProvider()) && ColumnSetHelper.getColumns((ColumnSet) table).isEmpty()) {
tableUIEle.setVirtualNode(true);
}
cataUIEleList.add(tableUIEle);
break;
}
}
if (!equals) {
OverviewIndUIElement tableUIEle = new OverviewIndUIElement();
tableUIEle.setOverviewIndicator(indicator);
tableUIEle.setVirtualNode(true);
cataUIEleList.add(tableUIEle);
}
}
}
}
return cataUIEleList;
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method initFileConnection.
/**
* create a real file connection witl file url
*
* @param fileUrl
* @param delimitedFileconnection
* @return
*/
public MetadataTable initFileConnection(URL fileUrl, DelimitedFileConnection delimitedFileconnection) {
try {
delimitedFileconnection.setFilePath(FileLocator.toFileURL(fileUrl).toURI().getPath().toString());
// $NON-NLS-1$
delimitedFileconnection.setRowSeparatorValue("\n");
// $NON-NLS-1$
delimitedFileconnection.setEncoding("UTF-8");
// $NON-NLS-1$
delimitedFileconnection.setFieldSeparatorValue(",");
delimitedFileconnection.setName(ERepositoryObjectType.METADATA_FILE_DELIMITED.getKey());
MetadataTable metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
// IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
// metadataTable.setId(factory.getNextId());
RecordFile record = (RecordFile) ConnectionHelper.getPackage(delimitedFileconnection.getName(), delimitedFileconnection, RecordFile.class);
if (record != null) {
// hywang
PackageHelper.addMetadataTable(metadataTable, record);
} else {
RecordFile newrecord = RecordFactory.eINSTANCE.createRecordFile();
newrecord.setName(delimitedFileconnection.getName());
ConnectionHelper.addPackage(newrecord, delimitedFileconnection);
PackageHelper.addMetadataTable(metadataTable, newrecord);
}
return metadataTable;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method initFileConnection.
/**
* create a real file connection witl file url
*
* @param fileUrl
* @param delimitedFileconnection
* @return
*/
public static MetadataTable initFileConnection(URL fileUrl, DelimitedFileConnection delimitedFileconnection) {
try {
delimitedFileconnection.setFilePath(FileLocator.toFileURL(fileUrl).toURI().getPath().toString());
delimitedFileconnection.setRowSeparatorValue("\n");
delimitedFileconnection.setEncoding("UTF-8");
delimitedFileconnection.setFieldSeparatorValue(",");
delimitedFileconnection.setName(ERepositoryObjectType.METADATA_FILE_DELIMITED.getKey());
MetadataTable metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
metadataTable.setId(factory.getNextId());
RecordFile record = (RecordFile) ConnectionHelper.getPackage(delimitedFileconnection.getName(), delimitedFileconnection, RecordFile.class);
if (record != null) {
// hywang
PackageHelper.addMetadataTable(metadataTable, record);
} else {
RecordFile newrecord = RecordFactory.eINSTANCE.createRecordFile();
newrecord.setName(delimitedFileconnection.getName());
ConnectionHelper.addPackage(newrecord, delimitedFileconnection);
PackageHelper.addMetadataTable(metadataTable, newrecord);
}
return metadataTable;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdq-studio-se by Talend.
the class WorkbenchUtilsTest method testUpdateDependAnalysisOfDelimitedFile_3.
// test for no column remained
@Test
public void testUpdateDependAnalysisOfDelimitedFile_3() throws IOException, URISyntaxException, PartInitException, BusinessException {
// create a file connection
DelimitedFileConnection fileConnection = ConnectionPackage.eINSTANCE.getConnectionFactory().createDelimitedFileConnection();
// $NON-NLS-1$
URL fileUrl = this.getClass().getResource("file1");
MetadataTable metadataTable = UnitTestBuildHelper.initFileConnection(fileUrl, fileConnection);
UnitTestBuildHelper.initColumns(metadataTable);
IFile file = WorkspaceUtils.fileToIFile(new File(FileLocator.toFileURL(fileUrl).toURI()));
IPath itemPath = file.getFullPath();
Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
connectionProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
// $NON-NLS-1$
connectionProperty.setStatusCode("");
connectionProperty.setLabel("file3");
DelimitedFileConnectionItem connectionItem = PropertiesFactory.eINSTANCE.createDelimitedFileConnectionItem();
connectionItem.setProperty(connectionProperty);
connectionItem.setConnection(fileConnection);
try {
ProxyRepositoryFactory.getInstance().create(connectionItem, itemPath.removeFirstSegments(3).removeLastSegments(1));
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
// create an analysis which use the columns in the file connection
Analysis analysis = UnitTestBuildHelper.createRealAnalysis("Ana01", null, false);
AnalysisContext context = AnalysisPackage.eINSTANCE.getAnalysisFactory().createAnalysisContext();
context.setConnection(fileConnection);
analysis.setContext(context);
context.getAnalysedElements().addAll(metadataTable.getColumns());
DependenciesHandler.getInstance().setDependencyOn(analysis, fileConnection);
ElementWriterFactory.getInstance().createAnalysisWrite().save(analysis);
// change the file's schema
List<MetadataColumn> tempNewColumns = new ArrayList<MetadataColumn>();
MetadataColumn name = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
name.setName("name2");
name.setLabel("name2");
tempNewColumns.add(name);
MetadataColumn country = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
country.setName("country2");
country.setLabel("country2");
tempNewColumns.add(country);
MetadataColumn country1 = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
country1.setName("country1");
country1.setLabel("country1");
tempNewColumns.add(country1);
metadataTable.getFeature().clear();
metadataTable.getFeature().addAll(tempNewColumns);
// before compare, the analysis has 5 analyzed elements
Assert.assertEquals(5, analysis.getContext().getAnalysedElements().size());
// call the tested method
WorkbenchUtils.reloadMetadataOfDelimitedFile(metadataTable);
List<MetadataColumn> afterCompareColumns = metadataTable.getColumns();
// check the columns
Assert.assertEquals(3, afterCompareColumns.size());
Assert.assertEquals("name2", afterCompareColumns.get(0).getLabel());
Assert.assertEquals("country2", afterCompareColumns.get(1).getLabel());
Assert.assertEquals("country1", afterCompareColumns.get(2).getLabel());
metadataTable.getColumns().clear();
metadataTable.getColumns().addAll(afterCompareColumns);
WorkbenchUtils.impactExistingAnalyses(fileConnection);
// check the depended analysis
EList<Dependency> clientDependencies = fileConnection.getSupplierDependency();
for (Dependency dep : clientDependencies) {
for (ModelElement mod : dep.getClient()) {
if (!(mod instanceof Analysis)) {
continue;
}
Analysis ana = (Analysis) mod;
// assert the column with same name still in the analysis
Assert.assertNotNull(ana.getContext().getAnalysedElements());
// should be: only 2 with same name remained
Assert.assertEquals(0, ana.getContext().getAnalysedElements().size());
}
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdq-studio-se by Talend.
the class RegexpMatchingIndicatorImplTest method testGetRegexFail1NotJavaRegex.
/**
* Test method for {@link org.talend.dataquality.indicators.impl.RegexpMatchingIndicatorImpl#getJavaRegex()}.
*/
@Test
public void testGetRegexFail1NotJavaRegex() {
// RegexpMatchingIndicator
RegexpMatchingIndicator createRegexpMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
// ~RegexpMatchingIndicator
// IndicatorParameters
IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
// ~IndicatorParameters
// Domain
Domain createDomain = DomainFactory.eINSTANCE.createDomain();
EList<Pattern> patterns = createDomain.getPatterns();
// ~Domain
// Pattern
Pattern createJavaPattern = PatternFactory.eINSTANCE.createPattern();
Pattern createSQLPattern = PatternFactory.eINSTANCE.createPattern();
Pattern createMSSQLPattern = PatternFactory.eINSTANCE.createPattern();
patterns.add(createJavaPattern);
patterns.add(createSQLPattern);
patterns.add(createMSSQLPattern);
// ~Pattern
// init java Pattern data
RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
createJavaTdExpression.setBody(JavaRegex);
createJavaTdExpression.setLanguage("Microsoft SQL Server");
createJavaRegularExpression.setExpression(createJavaTdExpression);
createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
EList<PatternComponent> components = createJavaPattern.getComponents();
components.add(createJavaRegularExpression);
// ~init java Pattern data
createIndicatorParameters.setDataValidDomain(createDomain);
createRegexpMatchingIndicator.setParameters(createIndicatorParameters);
TdColumn column = RelationalFactory.eINSTANCE.createTdColumn();
MetadataTable mdColumn = RelationalFactory.eINSTANCE.createTdTable();
column.setTable(mdColumn);
createRegexpMatchingIndicator.setAnalyzedElement(column);
// call getRegex()
String regexResult = createRegexpMatchingIndicator.getRegex();
// ~call getRegex()
Assert.assertTrue(regexResult == null);
}
Aggregations