use of org.talend.cwm.relational.TdColumn 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);
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class ReadItemConnectionFile method test.
@Test
public void test() {
EMFUtil emfUtil = new EMFUtil();
File file = new File("data/my_0.1.item");
System.out.println("Loading file " + file.getAbsolutePath());
ResourceSet rs = emfUtil.getResourceSet();
Resource r = rs.getResource(URI.createFileURI(file.getAbsolutePath()), true);
// TreeIterator<EObject> allContents = r.getAllContents();
// while (allContents.hasNext()) {
// EObject metadata = allContents.next();
// System.out.println(metadata);
// }
// should contain the connection, then catalog/schema, then tables, then columns
EList<EObject> contents = r.getContents();
// switch class that returns a connection when it finds one.
ConnectionSwitch<Connection> connectionFinder = new ConnectionSwitch<Connection>() {
/*
* (non-Javadoc)
*
* @see
* org.talend.core.model.metadata.builder.connection.util.ConnectionSwitch#caseConnection(org.talend.core
* .model.metadata.builder.connection.Connection)
*/
@Override
public Connection caseConnection(Connection object) {
return object;
}
};
// loop on all the content of the resource
for (EObject eObject : contents) {
Connection connection = connectionFinder.doSwitch(eObject);
if (connection != null) {
Set<Catalog> allCatalogs = ConnectionHelper.getAllCatalogs(connection);
for (Catalog catalog : allCatalogs) {
System.out.println("## Catalog: " + catalog.getName());
System.out.println("\t## Tables");
List<TdTable> tables = CatalogHelper.getTables(catalog);
for (TdTable tdTable : tables) {
System.out.println("\t\t" + tdTable.getName());
List<TdColumn> columns = TableHelper.getColumns(tdTable);
if (!columns.isEmpty()) {
System.out.println("\t\t\t## Columns");
}
for (TdColumn tdColumn : columns) {
System.out.println("\t\t\t\t" + tdColumn.getName());
}
}
System.out.println("\t## Views");
List<TdView> views = CatalogHelper.getViews(catalog);
for (TdView tdView : views) {
System.out.println("\t\t" + tdView.getName());
List<TdColumn> columns = ViewHelper.getColumns(tdView);
if (!columns.isEmpty()) {
System.out.println("\t\t\t## Columns");
}
for (TdColumn tdColumn : columns) {
System.out.println("\t\t\t\t" + tdColumn.getName());
}
}
}
}
}
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class SelectedCompareUIProvider method fillContextMenu.
@Override
public void fillContextMenu(IMenuManager menu) {
// TDQ-9394 hide all "Reload" menu.
if (!isShowMenu()) {
return;
}
if (isShowMenu()) {
return;
}
Iterator<?> iter = ((TreeSelection) this.getContext().getSelection()).iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (!(obj instanceof RepositoryNode)) {
return;
}
}
TreeSelection treeSelection = (TreeSelection) getContext().getSelection();
if (treeSelection == null) {
return;
}
Object firstElement = treeSelection.getFirstElement();
RepositoryNode rNode = (RepositoryNode) firstElement;
IFolder folder = WorkbenchUtils.getFolder(rNode);
IFolder metadataFolder = ResourceManager.getMetadataFolder();
if (!folder.getFullPath().toOSString().startsWith(metadataFolder.getFullPath().toOSString())) {
return;
}
Object[] selectedObj = treeSelection.toArray();
if (selectedObj.length < 2) {
return;
}
List<Object> objects = new ArrayList<Object>();
for (Object obj : selectedObj) {
Connection conn = getConnection(obj);
if (!MetadataConnectionUtils.isTDQSupportDBTemplate(conn)) {
return;
}
RepositoryNode node = (RepositoryNode) obj;
if (node instanceof DBConnectionRepNode) {
Property property = ((DBConnectionRepNode) node).getObject().getProperty();
DatabaseConnectionItem databaseConnectionItem = (DatabaseConnectionItem) property.getItem();
Connection databaseConnection = databaseConnectionItem.getConnection();
objects.add(databaseConnection);
} else if (node instanceof DBCatalogRepNode) {
Catalog catalog = ((DBCatalogRepNode) node).getCatalog();
objects.add(catalog);
} else if (node instanceof DBSchemaRepNode) {
Schema schema = ((DBSchemaRepNode) node).getSchema();
objects.add(schema);
} else if (node instanceof DBTableRepNode) {
TdTable tdTable = ((DBTableRepNode) node).getTdTable();
objects.add(tdTable);
} else if (node instanceof DBColumnRepNode) {
TdColumn tdColumn = ((DBColumnRepNode) node).getTdColumn();
objects.add(tdColumn);
}
}
// MOD yyi 2011-03-22 17871:hide compare action for flat file column
if (2 == objects.size()) {
selectionCompareAction.refreshSelectedObj(objects.get(0), objects.get(1));
menu.add(selectionCompareAction);
}
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class ModelElementEditonDistance method distance.
/*
* (non-Javadoc)
*
* @see org.eclipse.emf.compare.match.eobject.EditionDistance#distance(org.eclipse.emf.compare.Comparison,
* org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
*/
@Override
public double distance(Comparison inProgress, EObject a, EObject b) {
boolean isSame = false;
if (a instanceof DatabaseConnection) {
return 0;
}
if (a instanceof Catalog && b instanceof Catalog) {
Catalog catalog1 = (Catalog) a;
Catalog catalog2 = (Catalog) b;
isSame = StringUtils.equalsIgnoreCase(catalog1.getName(), catalog2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof Schema && b instanceof Schema) {
Schema schema1 = (Schema) a;
Schema schema2 = (Schema) b;
isSame = StringUtils.equalsIgnoreCase(schema1.getName(), schema2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdTable && b instanceof TdTable) {
TdTable tdTable1 = (TdTable) a;
TdTable tdTable2 = (TdTable) b;
isSame = StringUtils.equalsIgnoreCase(tdTable1.getName(), tdTable2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdView && b instanceof TdView) {
TdView tdView1 = (TdView) a;
TdView tdView2 = (TdView) b;
isSame = StringUtils.equalsIgnoreCase(tdView1.getName(), tdView2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdColumn && b instanceof TdColumn) {
TdColumn tdColumn1 = (TdColumn) a;
TdColumn tdColumn2 = (TdColumn) b;
isSame = StringUtils.equalsIgnoreCase(tdColumn1.getName(), tdColumn2.getName()) && distance(inProgress, tdColumn1.getSqlDataType(), tdColumn2.getSqlDataType()) == 0;
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TaggedValue && b instanceof TaggedValue) {
TaggedValue taggedValue1 = (TaggedValue) a;
TaggedValue taggedValue2 = (TaggedValue) b;
isSame = StringUtils.equalsIgnoreCase(taggedValue1.getTag(), taggedValue2.getTag()) && StringUtils.equalsIgnoreCase(taggedValue1.getValue(), taggedValue2.getValue());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdExpression && b instanceof TdExpression) {
TdExpression tdExpression1 = (TdExpression) a;
TdExpression tdExpression2 = (TdExpression) b;
isSame = StringUtils.equalsIgnoreCase(tdExpression1.getLanguage(), tdExpression2.getLanguage()) && StringUtils.equalsIgnoreCase(tdExpression1.getBody(), tdExpression2.getBody());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdSqlDataType && b instanceof TdSqlDataType) {
TdSqlDataType tdExpression1 = (TdSqlDataType) a;
TdSqlDataType tdExpression2 = (TdSqlDataType) b;
isSame = StringUtils.equalsIgnoreCase(tdExpression1.getName(), tdExpression2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof MetadataColumn && b instanceof MetadataColumn) {
// Added yyin TDQ-8360
MetadataColumn metaColumn1 = (MetadataColumn) a;
MetadataColumn metaColumn2 = (MetadataColumn) b;
isSame = StringUtils.equalsIgnoreCase(metaColumn1.getLabel(), metaColumn2.getLabel());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof MetadataTable && b instanceof MetadataTable) {
MetadataTable mTable1 = (MetadataTable) a;
MetadataTable mTable2 = (MetadataTable) b;
isSame = StringUtils.equalsIgnoreCase(mTable1.getLabel(), mTable2.getLabel());
return isSame ? 0 : Double.MAX_VALUE;
}
return super.distance(inProgress, a, b);
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class AbstractPagePart method updateBindConnection.
/**
* ADD mzhao 2009-05-05 bug:6587.
*/
protected void updateBindConnection(AbstractAnalysisMetadataPage masterPage, List<TableViewer> tableViewerPosStack) {
boolean isEmpty1 = tableViewerPosStack.get(0) == null || tableViewerPosStack.get(0).getInput() == null || ((List) tableViewerPosStack.get(0).getInput()).size() == 0;
boolean isEmpty2 = tableViewerPosStack.get(1) == null || tableViewerPosStack.get(1).getInput() == null || ((List) tableViewerPosStack.get(1).getInput()).size() == 0;
if (isEmpty1 && isEmpty2) {
return;
} else {
TableViewer columnsElementViewer = null;
if (!isEmpty1) {
columnsElementViewer = tableViewerPosStack.get(0);
} else {
columnsElementViewer = tableViewerPosStack.get(1);
}
Connection tdProvider = null;
Object input = columnsElementViewer.getInput();
List<DBColumnRepNode> columnSet = (List<DBColumnRepNode>) input;
if (columnSet != null && columnSet.size() != 0) {
TdColumn column = (TdColumn) ((MetadataColumnRepositoryObject) columnSet.get(0).getObject()).getTdColumn();
if (column != null && column.eIsProxy()) {
column = (TdColumn) EObjectHelper.resolveObject(column);
}
tdProvider = ConnectionHelper.getTdDataProvider(column);
setConnectionState(masterPage, tdProvider);
}
}
}
Aggregations