Search in sources :

Example 21 with Dependency

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

the class DependenciesHandlerTest method testSetUsageDependencyOnModelElementModelElementCase3.

/**
 * Test method for
 * {@link org.talend.cwm.dependencies.DependenciesHandler#setUsageDependencyOn(ModelElement, ModelElement)} . case3
 * client side is lost
 */
@Test
public void testSetUsageDependencyOnModelElementModelElementCase3() {
    // analysis init
    TDQAnalysisItem analysisItem = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    // $NON-NLS-1$
    analysis.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase3Analysis");
    analysisItem.setAnalysis(analysis);
    Property propertyAna = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyAna.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyAna.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase3Analysis");
    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);
    analysis.setContext(AnalysisFactory.eINSTANCE.createAnalysisContext());
    try {
        ProxyRepositoryFactory.getInstance().create(analysisItem, Path.EMPTY, false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // UDI init
    TDQIndicatorDefinitionItem createTDQIndicatorDefinitionItem = PropertiesFactoryImpl.eINSTANCE.createTDQIndicatorDefinitionItem();
    UserDefIndicator createUserDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
    IndicatorDefinition createIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    // $NON-NLS-1$
    createIndicatorDefinition.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase3UDI");
    createTDQIndicatorDefinitionItem.setIndicatorDefinition(createIndicatorDefinition);
    createUserDefIndicator.setIndicatorDefinition(createIndicatorDefinition);
    Property propertyUDI = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyUDI.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyUDI.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase3UDI");
    createTDQIndicatorDefinitionItem.setProperty(propertyUDI);
    try {
        ProxyRepositoryFactory.getInstance().create(createTDQIndicatorDefinitionItem, new Path(EResourceConstant.USER_DEFINED_INDICATORS.getName()), false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // init UDI supplier Dependency
    analysisResult1.getIndicators().add(createUserDefIndicator);
    ElementWriterFactory.getInstance().createAnalysisWrite().save(analysisItem, true);
    if (!analysis.getClientDependency().isEmpty()) {
        analysis.getClientDependency().get(0).getSupplier().clear();
    }
    IndicatorDefinition createIndicatorDefinitionFromFile = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    try {
        createIndicatorDefinition.eResource().unload();
        IRepositoryViewObject lastVersion = ProxyRepositoryFactory.getInstance().getLastVersion(propertyUDI.getId());
        createIndicatorDefinitionFromFile = ((TDQIndicatorDefinitionItem) lastVersion.getProperty().getItem()).getIndicatorDefinition();
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // call the test method
    TypedReturnCode<Dependency> setUsageDependencyOn = DependenciesHandler.getInstance().setUsageDependencyOn(analysis, createIndicatorDefinitionFromFile);
    // $NON-NLS-1$
    Assert.assertEquals("call setUsageDependencyOn method should return ok stauts", true, setUsageDependencyOn.isOk());
    Assert.assertEquals(analysis, setUsageDependencyOn.getObject().getClient().get(0));
    Assert.assertEquals(1, setUsageDependencyOn.getObject().getClient().size());
    Assert.assertEquals(createIndicatorDefinitionFromFile, setUsageDependencyOn.getObject().getSupplier().get(0));
    Assert.assertEquals(1, setUsageDependencyOn.getObject().getSupplier().size());
}
Also used : Path(org.eclipse.core.runtime.Path) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Dependency(orgomg.cwm.objectmodel.core.Dependency) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Analysis(org.talend.dataquality.analysis.Analysis) ItemState(org.talend.core.model.properties.ItemState) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Test(org.junit.Test)

Example 22 with Dependency

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

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

the class AElementPersistance method addResourceContent.

public void addResourceContent(Resource resource, ModelElement element) {
    if (resource != null) {
        EList<EObject> resourceContents = resource.getContents();
        if (!resourceContents.contains(element)) {
            resourceContents.add(element);
        }
        EList<Dependency> supplierDependency = element.getSupplierDependency();
        if (supplierDependency != null) {
            for (Dependency dependency : supplierDependency) {
                if (!resourceContents.contains(dependency)) {
                    resourceContents.add(dependency);
                }
            }
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 24 with Dependency

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

the class AnalysisWriter method addDependencies.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.writer.AElementPersistance#addDependencies(orgomg.cwm.objectmodel.core.ModelElement)
     */
@Override
public void addDependencies(ModelElement element) {
    Analysis analysis = (Analysis) element;
    List<IndicatorDefinition> udis = AnalysisHelper.getUserDefinedIndicators(analysis);
    try {
        for (IndicatorDefinition udi : udis) {
            if (udi == null) {
                continue;
            }
            InternalEObject iudi = (InternalEObject) udi;
            if (!iudi.eIsProxy()) {
                DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(udi);
                // only do save when the dependency is not reference project node
                if (recursiveFind != null && recursiveFind.getProject().isMainProject()) {
                    TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(analysis, udi);
                    if (dependencyReturn.isOk()) {
                        Property property = PropertyHelper.getProperty(udi);
                        if (property != null) {
                            TDQItem udiItem = (TDQItem) property.getItem();
                            if (udiItem instanceof TDQIndicatorDefinitionItem) {
                                ((TDQIndicatorDefinitionItem) udiItem).setIndicatorDefinition(udi);
                            } else if (udiItem instanceof TDQBusinessRuleItem) {
                                ((TDQBusinessRuleItem) udiItem).setDqrule((DQRule) udi);
                            }
                        }
                        ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(udi.eResource());
                    }
                }
            }
        }
        List<Pattern> patterns = AnalysisHelper.getPatterns(analysis);
        for (Pattern pattern : patterns) {
            InternalEObject iptn = (InternalEObject) pattern;
            if (!iptn.eIsProxy()) {
                DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(pattern);
                // only do save when the dependency is not reference project node
                if (recursiveFind != null && recursiveFind.getProject().isMainProject()) {
                    TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(analysis, pattern);
                    if (dependencyReturn.isOk()) {
                        Property property = PropertyHelper.getProperty(pattern);
                        if (property != null && property.getItem() instanceof TDQPatternItem) {
                            TDQPatternItem patternItem = (TDQPatternItem) property.getItem();
                            patternItem.setPattern(pattern);
                        }
                        ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(pattern.eResource());
                    // EMFUtil.saveSingleResource(pattern.eResource());
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        log.error(e, e);
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Dependency(orgomg.cwm.objectmodel.core.Dependency) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DQRule(org.talend.dataquality.rules.DQRule) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) Analysis(org.talend.dataquality.analysis.Analysis) PersistenceException(org.talend.commons.exception.PersistenceException) TDQItem(org.talend.core.model.properties.TDQItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) Property(org.talend.core.model.properties.Property) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 25 with Dependency

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

the class ReportWriter method addDependencies.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.writer.AElementPersistance#addDependencies(orgomg.cwm.objectmodel.core.ModelElement)
     */
@Override
public void addDependencies(ModelElement element) {
    TdReport report = (TdReport) element;
    List<Analysis> analyses = ReportHelper.getAnalyses(report);
    for (Analysis ana : analyses) {
        // TDQ-7999,filter the proxy.
        if (!ana.eIsProxy()) {
            AnalysisRepNode recursiveFindAnalysis = RepositoryNodeHelper.recursiveFindAnalysis(ana);
            // only do save when the dependency is not reference project node
            if (recursiveFindAnalysis != null && recursiveFindAnalysis.getProject().isMainProject()) {
                TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(report, ana);
                if (dependencyReturn.isOk()) {
                    try {
                        Property property = PropertyHelper.getProperty(ana);
                        if (property != null) {
                            Item item = property.getItem();
                            if (item instanceof TDQAnalysisItem) {
                                TDQAnalysisItem anaItem = (TDQAnalysisItem) item;
                                anaItem.setAnalysis(ana);
                            }
                        }
                        ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(ana.eResource());
                    } catch (PersistenceException e) {
                        log.error(e, e);
                    }
                }
            }
        }
    }
}
Also used : TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Item(org.talend.core.model.properties.Item) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) Analysis(org.talend.dataquality.analysis.Analysis) TdReport(org.talend.dataquality.reports.TdReport) PersistenceException(org.talend.commons.exception.PersistenceException) Dependency(orgomg.cwm.objectmodel.core.Dependency) Property(org.talend.core.model.properties.Property) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

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