Search in sources :

Example 1 with Dependency

use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.

the class FunctionalDependencyAnalysisDetailsPage method saveAnalysis.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#saveAnalysis()
     */
@Override
protected void saveAnalysis() throws DataprofilerCoreException {
    analysisHandler.changeDefaultRowLoaded(rowLoadedText.getText());
    analysisHandler.changeSampleDataShowWay(sampleDataShowWayCombo.getText());
    for (Domain domain : getCurrentModelElement().getParameters().getDataFilter()) {
        domain.setName(getCurrentModelElement().getName());
    }
    IRepositoryViewObject reposObject = null;
    getAnalysisHandler().clearAnalysis();
    List<RepositoryNode> columnListAANode = anaColumnCompareViewer.getColumnListA();
    List<RepositoryNode> columnListBBNode = anaColumnCompareViewer.getColumnListB();
    AnalysisBuilder anaBuilder = new AnalysisBuilder();
    anaBuilder.setAnalysis(getCurrentModelElement());
    Connection tdDataProvider = null;
    for (int i = 0; i < columnListAANode.size(); i++) {
        if (columnListBBNode.size() > i) {
            ColumnDependencyIndicator indicator = ColumnsetFactory.eINSTANCE.createColumnDependencyIndicator();
            TdColumn columnA = (TdColumn) ((MetadataColumnRepositoryObject) columnListAANode.get(i).getObject()).getTdColumn();
            TdColumn columnB = (TdColumn) ((MetadataColumnRepositoryObject) columnListBBNode.get(i).getObject()).getTdColumn();
            indicator.setColumnA(columnA);
            indicator.setColumnB(columnB);
            indicator.setIndicatorDefinition(DefinitionHandler.getInstance().getFDRuleDefaultIndicatorDefinition());
            getCurrentModelElement().getResults().getIndicators().add(indicator);
            anaBuilder.addElementToAnalyze(columnA, indicator);
            // ADD this line qiongli 2010-6-8
            anaBuilder.addElementToAnalyze(columnB, indicator);
        }
    }
    if (columnListAANode.size() > 0) {
        reposObject = columnListAANode.get(0).getObject();
        tdDataProvider = ((ConnectionItem) reposObject.getProperty().getItem()).getConnection();
        // MOD qiongli bug 14437:Add dependency
        getCurrentModelElement().getContext().setConnection(tdDataProvider);
        TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(getCurrentModelElement(), tdDataProvider);
        if (!rc.isOk()) {
            // $NON-NLS-1$
            log.info("fail to save dependency analysis:" + getCurrentModelElement().getFileName());
        }
    } else {
        getCurrentModelElement().getContext().setConnection(null);
    }
    // save the number of connections per analysis
    this.saveNumberOfConnectionsPerAnalysis();
    // 2011.1.12 MOD by zhsne to unify anlysis and connection id when saving.
    this.nameText.setText(getCurrentModelElement().getName());
    // MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
    ReturnCode saved = ElementWriterFactory.getInstance().createAnalysisWrite().save(getCurrentRepNode().getObject().getProperty().getItem(), true);
    // MOD yyi 2012-02-03 TDQ-3602:Avoid to rewriting all analyzes after saving, no reason to update all analyzes
    // which is depended in the referred connection.
    // Extract saving log function.
    // @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#logSaved(ReturnCode)
    logSaved(saved);
    anaColumnCompareViewer.setDirty(false);
    dataFilterComp.setDirty(false);
}
Also used : ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator) TdColumn(org.talend.cwm.relational.TdColumn) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Connection(org.talend.core.model.metadata.builder.connection.Connection) AnalysisBuilder(org.talend.dq.analysis.AnalysisBuilder) Dependency(orgomg.cwm.objectmodel.core.Dependency) Domain(org.talend.dataquality.domain.Domain) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 2 with Dependency

use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.

the class AbstractAnalysisMetadataPage method updateDQRuleDependency.

/**
 * ADD gdbu 2011-6-1 bug : 19833
 *
 * DOC gdbu Comment method "updateDQRuleDependency".
 *
 * @param dqRules
 */
protected void updateDQRuleDependency(List<DQRule> dqRules) {
    for (DQRule dqRule : dqRules) {
        List<Dependency> realSupplierDependency = new ArrayList<Dependency>();
        EList<Dependency> supplierDependency = dqRule.getSupplierDependency();
        for (Dependency dependency : supplierDependency) {
            EList<ModelElement> client = dependency.getClient();
            for (ModelElement modelElement : client) {
                if (modelElement instanceof Analysis) {
                    List<DQRule> dqRules2 = getDqRules((Analysis) modelElement);
                    if (dqRules2.contains(dqRule)) {
                        realSupplierDependency.add(dependency);
                    }
                }
            }
        }
        supplierDependency.clear();
        supplierDependency.addAll(realSupplierDependency);
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency) DQRule(org.talend.dataquality.rules.DQRule)

Example 3 with Dependency

use of orgomg.cwm.objectmodel.core.Dependency 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 4 with Dependency

use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.

the class FileSystemImportWriterTest method testMergePattern.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.imex.model.FileSystemImportWriter#mergePattern(org.talend.dataprofiler.core.ui.imex.model.ItemRecord, org.talend.dataquality.domain.pattern.Pattern)}
 * .
 *
 * @throws MalformedURLException
 */
@Test
public void testMergePattern() throws MalformedURLException {
    // import object
    ItemRecord importItem = mock(ItemRecord.class);
    Pattern importPattern = mock(Pattern.class);
    when(importItem.getElement()).thenReturn(importPattern);
    // old object
    TDQPatternItem oldPatternItem = mock(TDQPatternItem.class);
    Pattern oldPattern = mock(Pattern.class);
    when(oldPatternItem.getPattern()).thenReturn(oldPattern);
    // for imported pattern's expression
    InternalEObject eo = mock(InternalEObject.class);
    EList<PatternComponent> importComponents = new EObjectContainmentEList<PatternComponent>(PatternComponent.class, eo, PatternPackage.PATTERN__COMPONENTS);
    RegularExpression re = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td.setBody("sql body");
    // $NON-NLS-1$
    td.setLanguage("SQL");
    // $NON-NLS-1$
    td.setModificationDate("20130101");
    re.setExpression(td);
    importComponents.add(re);
    RegularExpression re3 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td3 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td3.setBody("imported body");
    // $NON-NLS-1$
    td3.setLanguage("MYSQL");
    // $NON-NLS-1$
    td3.setModificationDate("20130101");
    re3.setExpression(td3);
    importComponents.add(re3);
    RegularExpression re4 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td4 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td4.setBody("imported 4 body");
    // $NON-NLS-1$
    td4.setLanguage("Default");
    td4.setModificationDate(null);
    re4.setExpression(td4);
    importComponents.add(re4);
    when(importPattern.getComponents()).thenReturn(importComponents);
    // for imported pattern's supplierDependencies
    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);
    // $NON-NLS-1$
    File file = new File("C://Users//msjian//Desktop//myusetest//AA//TDQ_Data Profiling//Analyses//k_0.1.ana");
    org.eclipse.emf.common.util.URI uri = URI.createFileURI(file.toURL().getPath().substring(1));
    Resource resource = mock(Resource.class);
    when(analysis.eResource()).thenReturn(resource);
    when(resource.getURI()).thenReturn(uri);
    PowerMockito.mockStatic(ResourceManager.class);
    IProject pro = mock(IProject.class);
    when(ResourceManager.getRootProject()).thenReturn(pro);
    // $NON-NLS-1$
    when(pro.getLocation()).thenReturn(new Path("D:\\worspace\\workspace_TDQEE_5.3\\A"));
    EList<ModelElement> patternlist = mock(EObjectContainmentEList.class);
    patternlist.add(importPattern);
    when(dependency.getSupplier()).thenReturn(patternlist);
    EList<Dependency> supplierDependencies_old = new BasicEList<Dependency>();
    when(oldPattern.getSupplierDependency()).thenReturn(supplierDependencies_old);
    Assert.assertEquals(0, oldPattern.getSupplierDependency().size());
    EList<Dependency> supplierDependencies_import = new BasicEList<Dependency>();
    supplierDependencies_import.add(dependency);
    when(importPattern.getSupplierDependency()).thenReturn(supplierDependencies_import);
    Assert.assertEquals(1, importPattern.getSupplierDependency().size());
    PowerMockito.mockStatic(DependenciesHandler.class);
    DependenciesHandler instance = mock(DependenciesHandler.class);
    when(DependenciesHandler.getInstance()).thenReturn(instance);
    TypedReturnCode<Dependency> rc = new TypedReturnCode<Dependency>();
    rc.setObject(dependency);
    when(instance.setUsageDependencyOn(analysis, oldPattern)).thenReturn(rc);
    when(oldPattern.getSupplierDependency()).thenReturn(supplierDependencies_import);
    // for system pattern's expression
    EList<PatternComponent> components = new EObjectContainmentEList<PatternComponent>(PatternComponent.class, eo, PatternPackage.PATTERN__COMPONENTS);
    RegularExpression re2 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td2 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td2.setBody("system 2 body");
    // $NON-NLS-1$
    td2.setLanguage("MYSQL");
    // $NON-NLS-1$
    td2.setModificationDate("20120101");
    re2.setExpression(td2);
    components.add(re2);
    // for re5: should be replace by re4
    RegularExpression re5 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td5 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td5.setBody("system 5 body");
    // $NON-NLS-1$
    td5.setLanguage("Default");
    td5.setModificationDate(null);
    re5.setExpression(td5);
    components.add(re5);
    when(oldPattern.getComponents()).thenReturn(components);
    ElementWriterFactory ewFactory = mock(ElementWriterFactory.class);
    PatternWriter pw = mock(PatternWriter.class);
    when(pw.save(oldPatternItem, true)).thenReturn(null);
    // $NON-NLS-1$
    stub(method(ElementWriterFactory.class, "getInstance")).toReturn(ewFactory);
    when(ewFactory.createPatternWriter()).thenReturn(pw);
    writer.mergePattern(importItem, oldPatternItem);
    for (PatternComponent component : components) {
        TdExpression ex = ((RegularExpression) component).getExpression();
        if (ex.getLanguage().equals("SQL")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("sql body", ex.getBody());
        } else if (ex.getLanguage().equals("MYSQL")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("imported body", ex.getBody());
        } else if (ex.getLanguage().equals("Default")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("imported 4 body", ex.getBody());
        }
    }
    Assert.assertNotNull(oldPattern.getSupplierDependency());
    Assert.assertEquals(1, oldPattern.getSupplierDependency().size());
}
Also used : URI(org.eclipse.emf.common.util.URI) PatternWriter(org.talend.dq.writer.impl.PatternWriter) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) ElementWriterFactory(org.talend.dq.writer.impl.ElementWriterFactory) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EObjectContainmentEList(org.eclipse.emf.ecore.util.EObjectContainmentEList) DependenciesHandler(org.talend.cwm.dependencies.DependenciesHandler) Path(org.eclipse.core.runtime.Path) Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) Resource(org.eclipse.emf.ecore.resource.Resource) Dependency(orgomg.cwm.objectmodel.core.Dependency) IProject(org.eclipse.core.resources.IProject) Analysis(org.talend.dataquality.analysis.Analysis) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) File(java.io.File) InternalEObject(org.eclipse.emf.ecore.InternalEObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with Dependency

use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.

the class ItemRecord method getClintDependency.

public List<File> getClintDependency(ModelElement mElement) {
    List<File> listFile = new ArrayList<File>();
    if (mElement == null) {
        return listFile;
    }
    EList<Dependency> clientDependency = mElement.getClientDependency();
    for (Dependency clienter : clientDependency) {
        for (ModelElement depencyModelElement : clienter.getSupplier()) {
            File depFile = EObjectHelper.modelElement2File(depencyModelElement);
            if (depFile != null) {
                FILE_ELEMENT_MAP.put(depFile, depencyModelElement);
                listFile.add(depFile);
            }
        }
    }
    return listFile;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency) File(java.io.File)

Aggregations

Dependency (orgomg.cwm.objectmodel.core.Dependency)43 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)30 ArrayList (java.util.ArrayList)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)11 Resource (org.eclipse.emf.ecore.resource.Resource)10 Test (org.junit.Test)9 PersistenceException (org.talend.commons.exception.PersistenceException)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)6 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)6 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)6 URI (org.eclipse.emf.common.util.URI)5 EObject (org.eclipse.emf.ecore.EObject)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Connection (org.talend.core.model.metadata.builder.connection.Connection)5 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 TdColumn (org.talend.cwm.relational.TdColumn)5 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)5