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;
}
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());
}
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());
}
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());
}
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;
}
Aggregations