Search in sources :

Example 16 with TDQAnalysisItem

use of org.talend.dataquality.properties.TDQAnalysisItem in project tdq-studio-se by Talend.

the class UnitTestBuildHelper method createRealAnalysis.

/**
 * DOC qiongli Comment method "createRealAnalysis".
 *
 * @param name
 * @param folder
 * @param isDelete
 * @return
 */
public static Analysis createRealAnalysis(String name, IFolder folder, Boolean isDelete) {
    IPath createPath = Path.EMPTY;
    if (folder != null) {
        createPath = new Path(folder.getFullPath().lastSegment());
    }
    Analysis analysis1 = AnalysisHelper.createAnalysis(name);
    TDQAnalysisItem item1 = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
    org.talend.core.model.properties.Property property1 = PropertiesFactory.eINSTANCE.createProperty();
    property1.setId(EcoreUtil.generateUUID());
    property1.setItem(item1);
    property1.setLabel(analysis1.getName());
    item1.setProperty(property1);
    item1.setAnalysis(analysis1);
    ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(isDelete);
    item1.setState(itemState);
    AnalysisResult analysisResult1 = AnalysisFactory.eINSTANCE.createAnalysisResult();
    analysis1.setResults(analysisResult1);
    try {
        ProxyRepositoryFactory.getInstance().create(item1, createPath, false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    return analysis1;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) Analysis(org.talend.dataquality.analysis.Analysis) ItemState(org.talend.core.model.properties.ItemState) PersistenceException(org.talend.commons.exception.PersistenceException) Property(org.talend.core.model.properties.Property) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 17 with TDQAnalysisItem

use of org.talend.dataquality.properties.TDQAnalysisItem in project tdq-studio-se by Talend.

the class DependenciesHandlerTest method testSetUsageDependencyOnModelElementModelElementCase2.

/**
 * Test method for
 * {@link org.talend.cwm.dependencies.DependenciesHandler#setUsageDependencyOn(ModelElement, ModelElement)} . 、
 * case2 supplier side is lost
 */
@Test
public void testSetUsageDependencyOnModelElementModelElementCase2() {
    // analysis init
    TDQAnalysisItem analysisItem = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    // $NON-NLS-1$
    analysis.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase2Analysis");
    analysisItem.setAnalysis(analysis);
    Property propertyAna = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyAna.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyAna.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase2Analysis");
    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.testSetUsageDependencyOnModelElementModelElementCase2UDI");
    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.testSetUsageDependencyOnModelElementModelElementCase2UDI");
    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 (!createIndicatorDefinition.getSupplierDependency().isEmpty()) {
        createIndicatorDefinition.getSupplierDependency().get(0).getClient().clear();
    }
    Analysis analysisFromFile = AnalysisFactory.eINSTANCE.createAnalysis();
    try {
        analysis.eResource().unload();
        IRepositoryViewObject lastVersion = ProxyRepositoryFactory.getInstance().getLastVersion(propertyAna.getId());
        analysisFromFile = ((TDQAnalysisItem) lastVersion.getProperty().getItem()).getAnalysis();
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // call the test method
    TypedReturnCode<Dependency> setUsageDependencyOn = DependenciesHandler.getInstance().setUsageDependencyOn(analysisFromFile, createIndicatorDefinition);
    // $NON-NLS-1$
    Assert.assertEquals("call setUsageDependencyOn method should return ok stauts", true, setUsageDependencyOn.isOk());
    Assert.assertEquals(analysisFromFile, setUsageDependencyOn.getObject().getClient().get(0));
    Assert.assertEquals(1, setUsageDependencyOn.getObject().getClient().size());
    Assert.assertEquals(createIndicatorDefinition, 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 18 with TDQAnalysisItem

use of org.talend.dataquality.properties.TDQAnalysisItem in project tdq-studio-se by Talend.

the class DependenciesHandlerTest method testSetUsageDependencyOnModelElementModelElementCase1.

/**
 * Test method for
 * {@link org.talend.cwm.dependencies.DependenciesHandler#setUsageDependencyOn(ModelElement, ModelElement)} . case1
 * noraml case the dependency has been set between clint and supplier
 */
@Test
public void testSetUsageDependencyOnModelElementModelElementCase1() {
    // analysis init
    TDQAnalysisItem analysisItem = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    // $NON-NLS-1$
    analysis.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase1Analysis");
    analysisItem.setAnalysis(analysis);
    Property propertyAna = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyAna.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyAna.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase1Analysis");
    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.testSetUsageDependencyOnModelElementModelElementCase1UDI");
    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.testSetUsageDependencyOnModelElementModelElementCase1UDI");
    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 (!createIndicatorDefinition.getSupplierDependency().isEmpty()) {
        createIndicatorDefinition.getSupplierDependency().get(0).getClient().clear();
    }
    // call the test method
    TypedReturnCode<Dependency> setUsageDependencyOn = DependenciesHandler.getInstance().setUsageDependencyOn(analysis, createIndicatorDefinition);
    // $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(createIndicatorDefinition, 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) Analysis(org.talend.dataquality.analysis.Analysis) ItemState(org.talend.core.model.properties.ItemState) PersistenceException(org.talend.commons.exception.PersistenceException) Dependency(orgomg.cwm.objectmodel.core.Dependency) Property(org.talend.core.model.properties.Property) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Test(org.junit.Test)

Example 19 with TDQAnalysisItem

use of org.talend.dataquality.properties.TDQAnalysisItem 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 20 with TDQAnalysisItem

use of org.talend.dataquality.properties.TDQAnalysisItem 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

TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)33 Analysis (org.talend.dataquality.analysis.Analysis)26 PersistenceException (org.talend.commons.exception.PersistenceException)17 Property (org.talend.core.model.properties.Property)14 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)14 Item (org.talend.core.model.properties.Item)11 ItemState (org.talend.core.model.properties.ItemState)11 Path (org.eclipse.core.runtime.Path)9 Test (org.junit.Test)9 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)9 TDQReportItem (org.talend.dataquality.properties.TDQReportItem)9 IPath (org.eclipse.core.runtime.IPath)7 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)7 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)7 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)6 ReturnCode (org.talend.utils.sugars.ReturnCode)6 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)6 TDQBusinessRuleItem (org.talend.dataquality.properties.TDQBusinessRuleItem)5 TdReport (org.talend.dataquality.reports.TdReport)5