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