Search in sources :

Example 46 with TdColumn

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);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Example 47 with TdColumn

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());
                    }
                }
            }
        }
    }
}
Also used : TdTable(org.talend.cwm.relational.TdTable) Resource(org.eclipse.emf.ecore.resource.Resource) Connection(org.talend.core.model.metadata.builder.connection.Connection) ConnectionSwitch(org.talend.core.model.metadata.builder.connection.util.ConnectionSwitch) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Catalog(orgomg.cwm.resource.relational.Catalog) TdColumn(org.talend.cwm.relational.TdColumn) EMFUtil(org.talend.commons.emf.EMFUtil) TdView(org.talend.cwm.relational.TdView) EObject(org.eclipse.emf.ecore.EObject) File(java.io.File) Test(org.junit.Test)

Example 48 with TdColumn

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);
    }
}
Also used : DBConnectionRepNode(org.talend.dq.nodes.DBConnectionRepNode) DBSchemaRepNode(org.talend.dq.nodes.DBSchemaRepNode) TdTable(org.talend.cwm.relational.TdTable) Schema(orgomg.cwm.resource.relational.Schema) ArrayList(java.util.ArrayList) Connection(org.talend.core.model.metadata.builder.connection.Connection) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) RepositoryNode(org.talend.repository.model.RepositoryNode) Catalog(orgomg.cwm.resource.relational.Catalog) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) TdColumn(org.talend.cwm.relational.TdColumn) DBCatalogRepNode(org.talend.dq.nodes.DBCatalogRepNode) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Property(org.talend.core.model.properties.Property) IFolder(org.eclipse.core.resources.IFolder)

Example 49 with TdColumn

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);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) TdView(org.talend.cwm.relational.TdView) TdExpression(org.talend.cwm.relational.TdExpression) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(orgomg.cwm.resource.relational.Schema) MetadataTable(org.talend.core.model.metadata.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 50 with TdColumn

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);
        }
    }
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) Connection(org.talend.core.model.metadata.builder.connection.Connection) List(java.util.List) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

TdColumn (org.talend.cwm.relational.TdColumn)182 ArrayList (java.util.ArrayList)49 TdTable (org.talend.cwm.relational.TdTable)49 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)40 Test (org.junit.Test)37 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)35 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)28 RepositoryNode (org.talend.repository.model.RepositoryNode)26 IRepositoryNode (org.talend.repository.model.IRepositoryNode)23 Indicator (org.talend.dataquality.indicators.Indicator)20 Catalog (orgomg.cwm.resource.relational.Catalog)19 Connection (org.talend.core.model.metadata.builder.connection.Connection)17 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)16 TdSqlDataType (org.talend.cwm.relational.TdSqlDataType)16 Analysis (org.talend.dataquality.analysis.Analysis)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)14 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)14 Package (orgomg.cwm.objectmodel.core.Package)14 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)13