Search in sources :

Example 11 with AnalysisContext

use of org.talend.dataquality.analysis.AnalysisContext 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 12 with AnalysisContext

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

the class RespositoryDetailView method createAnaysisDetail.

private void createAnaysisDetail(Analysis ana) {
    if (ana == null) {
        return;
    }
    createName(ana);
    createPurpose(ana);
    createDescription(ana);
    AnalysisParameters parameters = ana.getParameters();
    String description = parameters == null ? null : parameters.getAnalysisType().getLiteral();
    // $NON-NLS-1$
    newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.otherType"), description);
    AnalysisContext context = ana.getContext();
    int numn = context == null ? 0 : context.getAnalysedElements().size();
    newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.numberOfAnalyzedElements"), // $NON-NLS-1$
    String.valueOf(numn));
    DataManager connection = context == null ? null : context.getConnection();
    if (connection == null) {
        description = null;
    } else {
        description = connection.getName();
    }
    // $NON-NLS-1$
    newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.connection"), description);
}
Also used : AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext)

Example 13 with AnalysisContext

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

the class AnalysisSubFolderRepNode method getCount.

public String getCount() {
    IRepositoryViewObject anaViewObject = this.getParent().getObject();
    if (anaViewObject.getProperty() != null) {
        TDQAnalysisItem item = (TDQAnalysisItem) anaViewObject.getProperty().getItem();
        Analysis analysis = item.getAnalysis();
        AnalysisContext context = analysis.getContext();
        EList<ModelElement> analysedElements = context.getAnalysedElements();
        if (analysedElements.size() == 1) {
            ModelElement modelElement = analysedElements.get(0);
            if (modelElement instanceof DatabaseConnection) {
                EList<Package> dataPackage = ((DatabaseConnection) modelElement).getDataPackage();
                // $NON-NLS-1$ //$NON-NLS-2$
                return "(" + dataPackage.size() + ")";
            }
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        return "(" + analysedElements.size() + ")";
    }
    // $NON-NLS-1$
    return "(0)";
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Package(orgomg.cwm.objectmodel.core.Package) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 14 with AnalysisContext

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

the class AnalysisBaseBuilder method setAnalysisConnection.

public boolean setAnalysisConnection(DataManager dataManager) {
    if (!initialized) {
        log.error(ANALYSIS_NOT_INITIALIZED);
        return false;
    }
    AnalysisContext context = analysis.getContext();
    if (context == null) {
        // $NON-NLS-1$
        log.error(Messages.getString("AnalysisBuilder.CONTEXTISNULL"));
        return false;
    }
    context.setConnection(dataManager);
    return true;
}
Also used : AnalysisContext(org.talend.dataquality.analysis.AnalysisContext)

Example 15 with AnalysisContext

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

the class EObjectHelper method getFirstDependency.

/**
 * get the first Dependency of node(only used for METADATA_CON_TABLE and METADATA_CON_VIEW).
 *
 * @param node
 * @return
 */
public static List<ModelElement> getFirstDependency(IRepositoryNode node) {
    List<ModelElement> result = new ArrayList<ModelElement>();
    if (node == null) {
        return result;
    }
    // use the connection supplier to get analyses, and then check them when they use the droped table
    // get the connection
    ModelElement deleteModel = RepositoryNodeHelper.getMetadataElement(node);
    Connection connection = ModelElementHelper.getConnection(deleteModel);
    if (connection == null) {
        return result;
    }
    // get the supplier Dependency of the connection
    EList<Dependency> supplierDependency = connection.getSupplierDependency();
    if (supplierDependency != null && supplierDependency.size() > 0) {
        EList<ModelElement> clients = supplierDependency.get(0).getClient();
        for (ModelElement client : clients) {
            if (!(client instanceof Analysis)) {
                continue;
            }
            Analysis analysis = (Analysis) client;
            if (analysis.eIsProxy()) {
                analysis = (Analysis) EObjectHelper.resolveObject(analysis);
            }
            AnalysisContext context = analysis.getContext();
            EList<ModelElement> analysedElements = context.getAnalysedElements();
            if (analysedElements != null && analysedElements.size() > 0) {
                ModelElement analysisModel = null;
                ModelElement firstAnalysisElement = analysedElements.get(0);
                if (firstAnalysisElement instanceof MetadataColumn) {
                    analysisModel = ModelElementHelper.getContainer(firstAnalysisElement);
                } else if (firstAnalysisElement instanceof MetadataTable) {
                    analysisModel = firstAnalysisElement;
                }
                if (compareModelElement(deleteModel, analysisModel)) {
                    result.add(analysis);
                    break;
                }
            }
        }
    }
    return result;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Analysis(org.talend.dataquality.analysis.Analysis) ArrayList(java.util.ArrayList) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Dependency(orgomg.cwm.objectmodel.core.Dependency) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext)

Aggregations

AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)40 Analysis (org.talend.dataquality.analysis.Analysis)30 Test (org.junit.Test)17 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)15 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)13 AnalysisParameters (org.talend.dataquality.analysis.AnalysisParameters)13 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)12 TdColumn (org.talend.cwm.relational.TdColumn)11 TdTable (org.talend.cwm.relational.TdTable)11 ArrayList (java.util.ArrayList)9 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)8 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)7 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)7 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)7 DataManager (orgomg.cwm.foundation.softwaredeployment.DataManager)7 Catalog (orgomg.cwm.resource.relational.Catalog)7 IPath (org.eclipse.core.runtime.IPath)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Property (org.talend.core.model.properties.Property)6 TdExpression (org.talend.cwm.relational.TdExpression)6