use of orgomg.cwm.objectmodel.core.Dependency 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;
}
use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class RedundancyAnalysisDetailsPage method saveAnalysis.
@Override
protected void saveAnalysis() throws DataprofilerCoreException {
for (Domain domain : getCurrentModelElement().getParameters().getDataFilter()) {
domain.setName(getCurrentModelElement().getName());
}
IRepositoryViewObject reposObject = null;
getAnalysisHandler().clearAnalysis();
List<ModelElement> analysedElements = new ArrayList<ModelElement>();
anaColumnCompareViewer.setColumnABForMatchingIndicator(rowMatchingIndicatorA, anaColumnCompareViewer.getColumnListA(), anaColumnCompareViewer.getColumnListB());
anaColumnCompareViewer.setColumnABForMatchingIndicator(rowMatchingIndicatorB, anaColumnCompareViewer.getColumnListB(), anaColumnCompareViewer.getColumnListA());
Connection tdDataProvider = null;
for (int i = 0; i < anaColumnCompareViewer.getColumnListA().size(); i++) {
reposObject = anaColumnCompareViewer.getColumnListA().get(i).getObject();
analysedElements.add(((MetadataColumnRepositoryObject) reposObject).getTdColumn());
}
for (int i = 0; i < anaColumnCompareViewer.getColumnListB().size(); i++) {
reposObject = anaColumnCompareViewer.getColumnListB().get(i).getObject();
analysedElements.add(((MetadataColumnRepositoryObject) reposObject).getTdColumn());
}
if (analysedElements.size() > 0) {
tdDataProvider = ConnectionHelper.getTdDataProvider((TdColumn) analysedElements.get(0));
// 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);
}
AnalysisBuilder anaBuilder = new AnalysisBuilder();
anaBuilder.setAnalysis(getCurrentModelElement());
if (anaColumnCompareViewer.getCheckComputeButton().getSelection()) {
getCurrentModelElement().getParameters().getDeactivatedIndicators().add(rowMatchingIndicatorB);
} else {
getCurrentModelElement().getParameters().getDeactivatedIndicators().clear();
}
anaBuilder.addElementsToAnalyze(analysedElements.toArray(new ModelElement[analysedElements.size()]), new Indicator[] { rowMatchingIndicatorA, rowMatchingIndicatorB });
// 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);
// ADD xqliu 2012-04-19 TDQ-5005
anaColumnCompareViewer.setDirty(false);
dataFilterCompA.setDirty(false);
dataFilterCompB.setDirty(false);
}
use of orgomg.cwm.objectmodel.core.Dependency 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 orgomg.cwm.objectmodel.core.Dependency 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 orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class DependenciesHandlerTest method testRemoveDependenciesBetweenModel.
/**
* Test method for
* {@link org.talend.cwm.dependencies.DependenciesHandler#removeDependenciesBetweenModel(orgomg.cwm.objectmodel.core.ModelElement, orgomg.cwm.objectmodel.core.ModelElement)}
* .
*/
@Test
public void testRemoveDependenciesBetweenModel() {
// $NON-NLS-1$
ModelElement ana = AnalysisHelper.createAnalysis("ana1");
// $NON-NLS-1$
ModelElement conn = ConnectionHelper.createDatabaseConnection("conn1");
EList<Dependency> clientDependencyFirst = ana.getClientDependency();
assertEquals(0, clientDependencyFirst.size());
TypedReturnCode<Dependency> setUsageDependencyOn = DependenciesHandler.getInstance().setUsageDependencyOn(ana, conn);
assertEquals(1, clientDependencyFirst.size());
EList<ModelElement> supplier = clientDependencyFirst.get(0).getSupplier();
assertEquals(1, supplier.size());
assertEquals(conn, supplier.get(0));
if (setUsageDependencyOn.isOk()) {
DependenciesHandler.getInstance().removeDependenciesBetweenModel(ana, conn);
}
assertEquals(0, clientDependencyFirst.size());
EList<Dependency> clientDependencyTwo = conn.getClientDependency();
assertEquals(0, clientDependencyTwo.size());
setUsageDependencyOn = DependenciesHandler.getInstance().setUsageDependencyOn(conn, ana);
assertEquals(1, clientDependencyTwo.size());
supplier = clientDependencyTwo.get(0).getSupplier();
assertEquals(1, supplier.size());
assertEquals(ana, supplier.get(0));
if (setUsageDependencyOn.isOk()) {
DependenciesHandler.getInstance().removeDependenciesBetweenModel(ana, conn);
}
assertEquals(0, clientDependencyTwo.size());
}
Aggregations