Search in sources :

Example 1 with DelimitedFileConnectionItem

use of org.talend.core.model.properties.DelimitedFileConnectionItem 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 2 with DelimitedFileConnectionItem

use of org.talend.core.model.properties.DelimitedFileConnectionItem in project tdq-studio-se by Talend.

the class PropertyHelper method getModelElement.

/**
 * DOC bZhou Comment method "getModelElement".
 *
 * Get model element from property recognized by current system.
 *
 * @param property
 * @return
 */
public static ModelElement getModelElement(Property property) {
    Item item = property.getItem();
    assert item != null;
    ModelElement element = (ModelElement) new org.talend.core.model.properties.util.PropertiesSwitch() {

        @Override
        public Object caseDatabaseConnectionItem(DatabaseConnectionItem object) {
            return object.getConnection();
        }

        @Override
        public Object caseMDMConnectionItem(MDMConnectionItem object) {
            return object.getConnection();
        }

        @Override
        public Object caseDelimitedFileConnectionItem(DelimitedFileConnectionItem object) {
            return object.getConnection();
        }
    }.doSwitch(item);
    if (element == null) {
        element = new org.talend.dataquality.properties.util.PropertiesSwitch<ModelElement>() {

            @Override
            public ModelElement caseTDQReportItem(TDQReportItem object) {
                return object.getReport();
            }

            @Override
            public ModelElement caseTDQAnalysisItem(TDQAnalysisItem object) {
                return object.getAnalysis();
            }

            @Override
            public ModelElement caseTDQBusinessRuleItem(TDQBusinessRuleItem object) {
                return object.getDqrule();
            }

            /*
                 * (non-Javadoc)
                 * 
                 * @see
                 * org.talend.dataquality.properties.util.PropertiesSwitch#caseTDQMatchRuleItem(org.talend.dataquality
                 * .properties.TDQMatchRuleItem)
                 */
            @Override
            public ModelElement caseTDQMatchRuleItem(TDQMatchRuleItem object) {
                return object.getMatchRule();
            }

            @Override
            public ModelElement caseTDQIndicatorDefinitionItem(TDQIndicatorDefinitionItem object) {
                return object.getIndicatorDefinition();
            }

            @Override
            public ModelElement caseTDQPatternItem(TDQPatternItem object) {
                return object.getPattern();
            }
        }.doSwitch(item);
    }
    return element;
}
Also used : TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) DelimitedFileConnectionItem(org.talend.core.model.properties.DelimitedFileConnectionItem) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) TDQItem(org.talend.core.model.properties.TDQItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) DelimitedFileConnectionItem(org.talend.core.model.properties.DelimitedFileConnectionItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 3 with DelimitedFileConnectionItem

use of org.talend.core.model.properties.DelimitedFileConnectionItem in project tdq-studio-se by Talend.

the class WorkbenchUtilsTest method testUpdateDependAnalysisOfDelimitedFile.

// test for 2 remained columns
@Test
public void testUpdateDependAnalysisOfDelimitedFile() 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("file1");
    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("name");
    name.setLabel("name");
    tempNewColumns.add(name);
    MetadataColumn country = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
    country.setName("country");
    country.setLabel("country");
    tempNewColumns.add(country);
    MetadataColumn country1 = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
    country1.setName("country1");
    country1.setLabel("country1");
    tempNewColumns.add(country1);
    MetadataColumn company = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
    company.setName("new column");
    company.setLabel("new column");
    tempNewColumns.add(company);
    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(4, afterCompareColumns.size());
    Assert.assertEquals("name", afterCompareColumns.get(0).getLabel());
    Assert.assertEquals("country", afterCompareColumns.get(1).getLabel());
    Assert.assertEquals("country1", afterCompareColumns.get(2).getLabel());
    Assert.assertEquals("new column", afterCompareColumns.get(3).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(2, ana.getContext().getAnalysedElements().size());
            Assert.assertEquals("name", ana.getContext().getAnalysedElements().get(0).getName());
            Assert.assertEquals("country", ana.getContext().getAnalysedElements().get(1).getName());
        }
    }
}
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 4 with DelimitedFileConnectionItem

use of org.talend.core.model.properties.DelimitedFileConnectionItem in project tdq-studio-se by Talend.

the class WorkbenchUtilsTest method testUpdateDependAnalysisOfDelimitedFile_2.

// test for last column remained
@Test
public void testUpdateDependAnalysisOfDelimitedFile_2() 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("file2");
    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);
    MetadataColumn company = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
    company.setName("name");
    company.setLabel("name");
    tempNewColumns.add(company);
    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(4, afterCompareColumns.size());
    Assert.assertEquals("name", afterCompareColumns.get(0).getLabel());
    Assert.assertEquals("country2", afterCompareColumns.get(2).getLabel());
    Assert.assertEquals("country1", afterCompareColumns.get(3).getLabel());
    Assert.assertEquals("name2", afterCompareColumns.get(1).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(1, ana.getContext().getAnalysedElements().size());
            Assert.assertEquals("name", ana.getContext().getAnalysedElements().get(0).getName());
        }
    }
}
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 5 with DelimitedFileConnectionItem

use of org.talend.core.model.properties.DelimitedFileConnectionItem in project tdq-studio-se by Talend.

the class DFConnectionRepNode method getDfConnection.

public DelimitedFileConnection getDfConnection() {
    DelimitedFileConnection dfConnection = null;
    Property property = getObject().getProperty();
    Item item = property.getItem();
    if (item instanceof DelimitedFileConnectionItem) {
        dfConnection = (DelimitedFileConnection) ((DelimitedFileConnectionItem) item).getConnection();
    }
    return dfConnection;
}
Also used : Item(org.talend.core.model.properties.Item) DelimitedFileConnectionItem(org.talend.core.model.properties.DelimitedFileConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) Property(org.talend.core.model.properties.Property) DelimitedFileConnectionItem(org.talend.core.model.properties.DelimitedFileConnectionItem)

Aggregations

DelimitedFileConnectionItem (org.talend.core.model.properties.DelimitedFileConnectionItem)5 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)4 Property (org.talend.core.model.properties.Property)4 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)4 File (java.io.File)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 IPath (org.eclipse.core.runtime.IPath)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)3 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)3 Analysis (org.talend.dataquality.analysis.Analysis)3 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)3 Dependency (orgomg.cwm.objectmodel.core.Dependency)3 Item (org.talend.core.model.properties.Item)2 ConnectionItem (org.talend.core.model.properties.ConnectionItem)1 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)1