Search in sources :

Example 91 with Analysis

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

the class AnalysisExecutorHelperTest method testCheckPatternWithOutDependencyFilesAndBuiltIn.

@Test
public void testCheckPatternWithOutDependencyFilesAndBuiltIn() {
    // Load analysis item/property model from test file.
    // $NON-NLS-1$
    String anaPropertyFile = "/data/builtin/pattern_without_dep_builtin/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
    Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
    Analysis ana = null;
    Property anaProperty = null;
    while (anaPropertyResource.getAllContents().hasNext()) {
        EObject eobj = anaPropertyResource.getAllContents().next();
        if (eobj instanceof Property) {
            anaProperty = (Property) eobj;
            ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
            break;
        }
    }
    if (ana == null) {
        Assert.fail("The analysis is null!");
    }
    if (ana.getResults() == null) {
        Assert.fail("The result of analysis is null!");
    }
    if (ana.getResults().getIndicators() == null) {
        Assert.fail("The indicators of analysis is null!");
    }
    assertTrue(ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getPatterns().get(0).getName() == null);
    ReturnCode rc = AnalysisExecutorHelper.check(ana);
    assertFalse(rc.isOk());
    assertTrue(ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getPatterns().get(0).getName() == null);
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 92 with Analysis

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

the class AnalysisExecutorHelperTest method testCheckPatternDependencyFiles.

@Test
public void testCheckPatternDependencyFiles() {
    // Load analysis item/property model from test file.
    // $NON-NLS-1$
    String anaPropertyFile = "/data/builtin/pattern_with_dep/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
    Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
    Analysis ana = null;
    Property anaProperty = null;
    while (anaPropertyResource.getAllContents().hasNext()) {
        EObject eobj = anaPropertyResource.getAllContents().next();
        if (eobj instanceof Property) {
            anaProperty = (Property) eobj;
            ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
            break;
        }
    }
    if (ana == null) {
        Assert.fail("The analysis is null!");
    }
    if (ana.getResults() == null) {
        Assert.fail("The result of analysis is null!");
    }
    if (ana.getResults().getIndicators() == null) {
        Assert.fail("The indicators of analysis is null!");
    }
    assertTrue(ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getBuiltInPatterns().size() == 0);
    ReturnCode rc = AnalysisExecutorHelper.check(ana);
    assertTrue(rc.isOk());
    assertTrue(ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getBuiltInPatterns().size() > 0);
    ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getBuiltInPatterns().clear();
    EMFUtil.saveResource(ana.eResource());
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 93 with Analysis

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

the class EObjectHelperTest method testGetFirstDependency.

/**
 * Test method for
 * {@link org.talend.dq.helper.EObjectHelper#getFirstDependency(org.talend.repository.model.IRepositoryNode)}.
 */
@Test
public void testGetFirstDependency() {
    // test when the node is null
    List<ModelElement> firstDependency = EObjectHelper.getFirstDependency(null);
    assertTrue(firstDependency.isEmpty());
    IRepositoryNode tableNode = mock(IRepositoryNode.class);
    MetadataTable mod = mock(MetadataTable.class);
    // $NON-NLS-1$
    when(mod.getName()).thenReturn("mod");
    PowerMockito.mockStatic(RepositoryNodeHelper.class);
    when(RepositoryNodeHelper.getMetadataElement(tableNode)).thenReturn(mod);
    Connection connection = mock(Connection.class);
    PowerMockito.mockStatic(ModelElementHelper.class);
    when(ModelElementHelper.getConnection(mod)).thenReturn(connection);
    EList<Dependency> supplierDependency = new BasicEList<Dependency>();
    when(connection.getSupplierDependency()).thenReturn(supplierDependency);
    // when there is no SupplierDependency for this node
    assertTrue(EObjectHelper.getFirstDependency(tableNode).isEmpty());
    // add some analysis to use this table node
    Analysis analysis = mock(Analysis.class);
    Dependency dependency = mock(Dependency.class);
    when(dependency.getKind()).thenReturn(DependenciesHandler.USAGE);
    EList<ModelElement> analysisList = new BasicEList<ModelElement>();
    analysisList.add(analysis);
    when(dependency.getClient()).thenReturn(analysisList);
    when(analysis.eIsProxy()).thenReturn(false);
    supplierDependency.add(dependency);
    when(connection.getSupplierDependency()).thenReturn(supplierDependency);
    AnalysisParameters parameters = mock(AnalysisParameters.class);
    when(parameters.getExecutionLanguage()).thenReturn(ExecutionLanguage.SQL);
    when(analysis.getParameters()).thenReturn(parameters);
    AnalysisContext context = mock(AnalysisContext.class);
    when(analysis.getContext()).thenReturn(context);
    EList<ModelElement> modList = new BasicEList<ModelElement>();
    modList.add(mod);
    when(ModelElementHelper.compareUUID(mod, mod)).thenReturn(true);
    MetadataTable mod1 = mock(MetadataTable.class);
    // $NON-NLS-1$
    when(mod1.getName()).thenReturn("mod1");
    when(mod1.eIsProxy()).thenReturn(false);
    modList.add(mod1);
    MetadataTable mod2 = mock(MetadataTable.class);
    // $NON-NLS-1$
    when(mod2.getName()).thenReturn("mod2");
    when(mod2.eIsProxy()).thenReturn(false);
    modList.add(mod2);
    when(context.getAnalysedElements()).thenReturn(modList);
    assertFalse(EObjectHelper.getFirstDependency(tableNode).isEmpty());
    assertEquals(analysis, EObjectHelper.getFirstDependency(tableNode).get(0));
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) BasicEList(org.eclipse.emf.common.util.BasicEList) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Connection(org.talend.core.model.metadata.builder.connection.Connection) Dependency(orgomg.cwm.objectmodel.core.Dependency) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 94 with Analysis

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

the class SimpleStatisticsExplorerTest method testGetQueryMap.

/**
 * Test method for {@link org.talend.dq.analysis.explore.SimpleStatisticsExplorer#getQueryMap()}.
 */
@Test
public void testGetQueryMap() {
    Analysis ana = UnitTestBuildHelper.createAndInitAnalysis();
    TdTable table = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    table.setName("TDQ_CALENDAR");
    TdColumn column = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    column.setName("CAL_DATE");
    TdSqlDataType tdsql = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdSqlDataType();
    // $NON-NLS-1$
    tdsql.setName("DATE");
    tdsql.setJavaDataType(Types.DATE);
    column.setSqlDataType(tdsql);
    table.getOwnedElement().add(column);
    column.setOwner(table);
    // create user define indicator
    UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
    UDIndicatorDefinition indicatorDefinition = UserdefineFactory.eINSTANCE.createUDIndicatorDefinition();
    // $NON-NLS-1$
    indicatorDefinition.setName("user define");
    userDefIndicator.setName(indicatorDefinition.getName());
    userDefIndicator.setIndicatorDefinition(indicatorDefinition);
    // $NON-NLS-1$
    TdExpression newTdExp = BooleanExpressionHelper.createTdExpression("SQL", body, null);
    newTdExp.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
    indicatorDefinition.getViewRowsExpression().add(newTdExp);
    // $NON-NLS-1$  //$NON-NLS-2$
    ChartDataEntity chartDataEntity = new ChartDataEntity(userDefIndicator, "2012-06-05", "1");
    chartDataEntity.setLabelNull(false);
    // $NON-NLS-1$
    chartDataEntity.setKey("2012-06-05");
    userDefIndicator.setAnalyzedElement(column);
    AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
    createAnalysisResult.setResultMetadata(createExecutionInformations);
    createAnalysisResult.getIndicators().add(userDefIndicator);
    userDefIndicator.setAnalyzedElement(column);
    ana.setResults(createAnalysisResult);
    SimpleStatisticsExplorer simpleStatisticsExplorer = new SimpleStatisticsExplorer();
    Assert.assertTrue(simpleStatisticsExplorer.setAnalysis(ana));
    simpleStatisticsExplorer.setEnitty(chartDataEntity);
    Map<String, String> queryMap = simpleStatisticsExplorer.getQueryMap();
    assertFalse(queryMap.isEmpty());
    assertEquals(1, queryMap.size());
    System.err.println(queryMap.get("View rows"));
    assertEquals(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "-- Analysis: anaA ;\n" + "-- Type of Analysis: Column Analysis ;\n" + "-- Purpose:  ;\n" + "-- Description:  ;\n" + "-- AnalyzedElement: CAL_DATE ;\n" + "-- Indicator: user define ;\n" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "-- Showing: View rows ;\n" + "SELECT * FROM TDQ_CALENDAR ", // $NON-NLS-1$ //$NON-NLS-2$
    queryMap.get("View rows"));
    // test when is not sql engine
    ana.getParameters().setExecutionLanguage(ExecutionLanguage.JAVA);
    Map<String, String> queryMap_java = simpleStatisticsExplorer.getQueryMap();
    assertFalse(queryMap_java.isEmpty());
    assertEquals(1, queryMap_java.size());
    // $NON-NLS-1$
    assertEquals(null, queryMap_java.get("View rows"));
}
Also used : TdTable(org.talend.cwm.relational.TdTable) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdColumn(org.talend.cwm.relational.TdColumn) Analysis(org.talend.dataquality.analysis.Analysis) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Test(org.junit.Test)

Example 95 with Analysis

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

the class AnalysisWriter method save.

/**
 * Save analysis item and update the dependencies(optional). <B>To update dependencies of the analysis the
 * #careDependency must be set as TRUE.</B>
 *
 * @see org.talend.dq.writer.AElementPersistance#save(org.talend.core.model.properties.Item, boolean[])
 */
@Override
public ReturnCode save(final Item item, final boolean careDependency) {
    ReturnCode rc = new ReturnCode();
    RepositoryWorkUnit<Object> repositoryWorkUnit = new // $NON-NLS-1$
    RepositoryWorkUnit<Object>(// $NON-NLS-1$
    "save Analysis item") {

        @Override
        protected void run() throws LoginException, PersistenceException {
            // MOD yyi 2012-02-07 TDQ-4621:Update dependencies(connection) when careDependency is true.
            TDQAnalysisItem anaItem = (TDQAnalysisItem) item;
            Analysis analysis = anaItem.getAnalysis();
            if (careDependency) {
                saveWithDependencies(anaItem, analysis);
            } else {
                saveWithoutDependencies(anaItem, analysis);
            }
        }
    };
    repositoryWorkUnit.setAvoidUnloadResources(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
    try {
        repositoryWorkUnit.throwPersistenceExceptionIfAny();
    } catch (PersistenceException e) {
        log.error(e, e);
        rc.setOk(Boolean.FALSE);
        rc.setMessage(e.getMessage());
    }
    return rc;
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

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