Search in sources :

Example 11 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class UpdateDependenciesFileTask method updateDependencies.

/**
 * Method "updateDependencies" updates dependencies between elements in TOP.
 *
 * @param analysesSubFolder
 * @throws CoreException
 */
private void updateDependencies(IFolder analysesSubFolder) throws CoreException {
    for (IResource resource : analysesSubFolder.members()) {
        if (resource instanceof IFolder) {
            IFolder folder = (IFolder) resource;
            updateDependencies(folder);
        }
        if (resource instanceof IFile) {
            IFile file = (IFile) resource;
            final Analysis analysis = AnaResourceFileHelper.getInstance().findAnalysis(file);
            // update dependency between analyses and patterns
            if (analysis != null) {
                final List<Pattern> patterns = AnalysisHelper.getPatterns(analysis);
                for (Pattern pattern : patterns) {
                    DependenciesHandler.getInstance().setDependencyOn(analysis, pattern);
                    AnaResourceFileHelper.getInstance().save(analysis);
                }
                // update dependency between analyses and dq rules
                final List<IndicatorDefinition> userDefinedIndicators = AnalysisHelper.getUserDefinedIndicators(analysis);
                for (IndicatorDefinition indicatorDefinition : userDefinedIndicators) {
                    DependenciesHandler.getInstance().setDependencyOn(analysis, indicatorDefinition);
                    AnaResourceFileHelper.getInstance().save(analysis);
                }
            }
        }
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IFile(org.eclipse.core.resources.IFile) Analysis(org.talend.dataquality.analysis.Analysis) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class DependenciesHandlerTest method testRemoveConnDependencyAndSave.

@Test
public void testRemoveConnDependencyAndSave() {
    TDQAnalysisItem analysisItem = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    // $NON-NLS-1$
    analysis.setName("testDependAnalysis");
    analysisItem.setAnalysis(analysis);
    Property propertyAna = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyAna.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyAna.setLabel("ana");
    analysisItem.setProperty(propertyAna);
    ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(false);
    analysisItem.setState(itemState);
    AnalysisResult analysisResult1 = AnalysisFactory.eINSTANCE.createAnalysisResult();
    analysis.setResults(analysisResult1);
    AnalysisContext analysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
    analysis.setContext(analysisContext);
    try {
        ProxyRepositoryFactory.getInstance().create(analysisItem, Path.EMPTY, false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    DatabaseConnectionItem connectionItem = UnitTestBuildHelper.createDatabaseConnectionItem("testDependeceConnection", null, // $NON-NLS-1$
    false);
    DependenciesHandler.getInstance().setUsageDependencyOn(analysis, connectionItem.getConnection());
    analysisContext.setConnection(connectionItem.getConnection());
    ElementWriterFactory.getInstance().createDataProviderWriter().save(connectionItem, true);
    Assert.assertNotNull(analysis.getContext().getConnection());
    Assert.assertEquals(false, analysis.getClientDependency().isEmpty());
    DependenciesHandler.getInstance().removeConnDependencyAndSave(analysisItem);
    Assert.assertNull(analysis.getContext().getConnection());
    Assert.assertEquals(true, analysis.getClientDependency().isEmpty());
}
Also used : Analysis(org.talend.dataquality.analysis.Analysis) ItemState(org.talend.core.model.properties.ItemState) PersistenceException(org.talend.commons.exception.PersistenceException) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Property(org.talend.core.model.properties.Property) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Test(org.junit.Test)

Example 13 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class AnalysisHandlerTest method testChangeDefaultRowLoaded.

/**
 * Test method for {@link org.talend.dq.analysis.AnalysisHandler#changeDefaultRowLoaded(java.lang.String)}.
 */
@Test
public void testChangeDefaultRowLoaded() {
    int rowCountValue = 100;
    Analysis createAna = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    createAna.setResults(createAnalysisResult);
    ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
    createAnalysisResult.setResultMetadata(createExecutionInformations);
    AnalysisHandler createHandler = AnalysisHandler.createHandler(createAna);
    createHandler.changeDefaultRowLoaded(String.valueOf(rowCountValue));
    String defaultLoadedRowCount = createHandler.getDefaultLoadedRowCount();
    Assert.assertEquals(Integer.valueOf(rowCountValue), Integer.valueOf(defaultLoadedRowCount));
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Test(org.junit.Test)

Example 14 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class ColumnAnalysisExecutorTest method testCreateSqlStatement_1.

/**
 * when there are some catelog
 * {@link org.talend.dq.analysis.ColumnAnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)}
 * .
 */
@Test
public void testCreateSqlStatement_1() {
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
    analysis.setContext(context);
    TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
    TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tdTable.setName("tableName");
    tdColumn.setOwner(tdTable);
    // $NON-NLS-1$
    tdColumn.setName("columnName");
    AnalysisParameters analysisPara = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    analysisPara.setStoreData(false);
    analysis.setParameters(analysisPara);
    context.getAnalysedElements().add(tdColumn);
    AnalysisResult analysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations info = AnalysisFactory.eINSTANCE.createExecutionInformations();
    analysisResult.setResultMetadata(info);
    analysis.setResults(analysisResult);
    // mock(Catalog.class);
    Package catalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    catalog.setName("catalogName");
    tdTable.setNamespace(catalog);
    DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    createConnection.getTaggedValue().add(TaggedValueHelper.createTaggedValue(TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.MYSQLDEFAULTURL.getLanguage()));
    analysis.getContext().setConnection(createConnection);
    ColumnAnalysisExecutor columnAnalysisExecutor = new ColumnAnalysisExecutor();
    // $NON-NLS-1$
    assertEquals("SELECT `columnName` FROM `catalogName`.`tableName`", columnAnalysisExecutor.createSqlStatement(analysis));
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdColumn(org.talend.cwm.relational.TdColumn) TdTable(org.talend.cwm.relational.TdTable) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Package(orgomg.cwm.objectmodel.core.Package) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Test(org.junit.Test)

Example 15 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class ColumnAnalysisExecutorTest method testCreateSqlStatement_2.

/**
 * when there are some schema.
 * {@link org.talend.dq.analysis.ColumnAnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)}
 * .
 */
@Test
public void testCreateSqlStatement_2() {
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
    analysis.setContext(context);
    TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
    TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tdTable.setName("tableName");
    tdColumn.setOwner(tdTable);
    // $NON-NLS-1$
    tdColumn.setName("columnName");
    AnalysisParameters analysisPara = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    analysisPara.setStoreData(false);
    analysis.setParameters(analysisPara);
    context.getAnalysedElements().add(tdColumn);
    AnalysisResult analysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations info = AnalysisFactory.eINSTANCE.createExecutionInformations();
    analysisResult.setResultMetadata(info);
    analysis.setResults(analysisResult);
    // mock(Schema.class);
    Package schema = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createSchema();
    // $NON-NLS-1$
    schema.setName("schemaName");
    tdTable.setNamespace(schema);
    // mock(Catalog.class);
    Package catalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    catalog.setName("catalogName");
    schema.setNamespace(catalog);
    DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    createConnection.getTaggedValue().add(TaggedValueHelper.createTaggedValue(TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.MSSQLDEFAULTURL.getLanguage()));
    analysis.getContext().setConnection(createConnection);
    ColumnAnalysisExecutor columnAnalysisExecutor = new ColumnAnalysisExecutor();
    assertEquals("SELECT columnName FROM catalogName.schemaName.tableName", // $NON-NLS-1$
    columnAnalysisExecutor.createSqlStatement(analysis));
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdColumn(org.talend.cwm.relational.TdColumn) TdTable(org.talend.cwm.relational.TdTable) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Package(orgomg.cwm.objectmodel.core.Package) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Test(org.junit.Test)

Aggregations

Analysis (org.talend.dataquality.analysis.Analysis)137 Test (org.junit.Test)36 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)36 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)30 ArrayList (java.util.ArrayList)28 Property (org.talend.core.model.properties.Property)28 Indicator (org.talend.dataquality.indicators.Indicator)27 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)27 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)26 PersistenceException (org.talend.commons.exception.PersistenceException)19 Connection (org.talend.core.model.metadata.builder.connection.Connection)18 ReturnCode (org.talend.utils.sugars.ReturnCode)18 Dependency (orgomg.cwm.objectmodel.core.Dependency)18 TdColumn (org.talend.cwm.relational.TdColumn)16 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)16 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)15 Pattern (org.talend.dataquality.domain.pattern.Pattern)15 IFile (org.eclipse.core.resources.IFile)14 File (java.io.File)12 IPath (org.eclipse.core.runtime.IPath)12