Search in sources :

Example 31 with MetadataTable

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;
}
Also used : DBTableFolderRepNode(org.talend.dq.nodes.DBTableFolderRepNode) TableIndicator(org.talend.dataquality.indicators.schema.TableIndicator) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) OverviewIndUIElement(org.talend.dataprofiler.core.model.OverviewIndUIElement) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)

Example 32 with MetadataTable

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;
}
Also used : RecordFile(orgomg.cwm.resource.record.RecordFile) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) CoreException(org.eclipse.core.runtime.CoreException) SQLException(java.sql.SQLException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 33 with MetadataTable

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;
}
Also used : RecordFile(orgomg.cwm.resource.record.RecordFile) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) CoreException(org.eclipse.core.runtime.CoreException) SQLException(java.sql.SQLException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 34 with MetadataTable

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());
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Dependency(orgomg.cwm.objectmodel.core.Dependency) URL(java.net.URL) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Property(org.talend.core.model.properties.Property) DelimitedFileConnectionItem(org.talend.core.model.properties.DelimitedFileConnectionItem) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with MetadataTable

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

Aggregations

MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)153 ArrayList (java.util.ArrayList)53 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)51 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)25 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)23 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)22 List (java.util.List)18 Test (org.junit.Test)17 PersistenceException (org.talend.commons.exception.PersistenceException)17 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)15 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)14 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)14 Connection (org.talend.core.model.metadata.builder.connection.Connection)12 RepositoryNode (org.talend.repository.model.RepositoryNode)12 ConnectionItem (org.talend.core.model.properties.ConnectionItem)10 TdColumn (org.talend.cwm.relational.TdColumn)9 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 IRepositoryNode (org.talend.repository.model.IRepositoryNode)9 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)8 HashMap (java.util.HashMap)7