use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class FileSystemImportWriter method updateAnalysisClientDependence.
/**
* remove the old client dependency add a new one in Anlaysis.
*
* @param supplierItem
* @param modelElement
* @throws PersistenceException
*/
private void updateAnalysisClientDependence(TDQItem supplierItem, Property property) throws PersistenceException {
ModelElement anaModelElement = PropertyHelper.getModelElement(property);
if (anaModelElement != null) {
Analysis analysis = (Analysis) anaModelElement;
EList<Dependency> clientDependency = anaModelElement.getClientDependency();
Iterator<Dependency> it = clientDependency.iterator();
ModelElement supplierModelElement = RepositoryNodeHelper.getResourceModelElement(supplierItem);
Resource supModeResource = supplierModelElement.eResource();
while (it.hasNext()) {
Dependency clientDep = it.next();
// systemSupplyModelElement,remove it.
if (clientDep.eResource() == null) {
URI clientDepURI = ((InternalEObject) clientDep).eProxyURI();
boolean isUDI = clientDepURI.path().contains(ResourceManager.getUDIFolder().getProjectRelativePath().toString());
boolean isPattern = clientDepURI.path().contains(ResourceManager.getPatternFolder().getProjectRelativePath().toString());
if (supModeResource != null && (isUDI || isPattern) && clientDepURI.lastSegment().equals(supModeResource.getURI().lastSegment())) {
it.remove();
break;
}
}
}
DependenciesHandler.getInstance().setUsageDependencyOn(anaModelElement, supplierModelElement);
// TDQ-8436 remove the old pattern and add the new pattern in analysis Indicator Parameters.
if (isPattern(supplierModelElement)) {
updatePatternInAnaParams(supplierModelElement, analysis);
ElementWriterFactory.getInstance().createPatternWriter().save(supplierItem, true);
}
// remove old udi and set a new one in the analysis indicators.
if (supplierModelElement instanceof UDIndicatorDefinition) {
if (analysis.getResults() != null) {
EList<Indicator> indicators = analysis.getResults().getIndicators();
Iterator<Indicator> itIndicators = indicators.iterator();
while (itIndicators.hasNext()) {
Indicator indicator = itIndicators.next();
IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
if (indicatorDefinition.eResource() == null) {
URI indicatorDefURI = ((InternalEObject) indicatorDefinition).eProxyURI();
if (supModeResource != null && UDIHelper.isUDI(indicator) && indicatorDefURI.lastSegment().equals(supModeResource.getURI().lastSegment())) {
indicator.setIndicatorDefinition((UDIndicatorDefinition) supplierModelElement);
break;
}
}
}
ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().save(supplierItem, true);
}
}
// only save analysis item at here.
ProxyRepositoryFactory.getInstance().save(property.getItem(), true);
}
}
use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class ColumnSetAnalysisHandler method addIndicator.
/**
* The resources that are connected to this analysis and that are potentially modified.
*/
// private Collection<Resource> modifiedResources = new HashSet<Resource>();
/**
* Method "addColumnToAnalyze".
*
* @param column
* @return
*/
public boolean addIndicator(List<ModelElement> columns, Indicator indicator) {
for (ModelElement tdColumn : columns) {
if (!analysis.getContext().getAnalysedElements().contains(tdColumn)) {
analysis.getContext().getAnalysedElements().add(tdColumn);
}
}
// store first level of indicators in result.
analysis.getResults().getIndicators().add(indicator);
initializeIndicator(indicator);
DataManager connection = analysis.getContext().getConnection();
if (connection == null) {
// try to get one
for (ModelElement element : columns) {
TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(element);
// $NON-NLS-1$
log.error(Messages.getString("ColumnCorrelationAnalysisHandler.CONNNOTBEENSETINANALYSIS"));
connection = ConnectionHelper.getTdDataProvider(tdColumn);
if (connection != null) {
analysis.getContext().setConnection(connection);
break;
}
}
}
TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(analysis, connection);
return rc.isOk();
}
use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class DependenciesHandler method clearDependencies.
/**
* Method "clearDependencies" is to be used before a file is deleted. The root element is given as argument and the
* dependencies on this element are removed in all resources that depend on this element.
*
* @param elementToDelete a root element which file will be deleted.
* @return the list of modified dependencies
*/
public List<Resource> clearDependencies(ModelElement elementToDelete) {
EList<Dependency> clientDependencies;
// get the client dependencies (
clientDependencies = elementToDelete.getClientDependency();
// locate resource of each Dependency object
List<Resource> modifiedResources = new ArrayList<Resource>();
Iterator<Dependency> it = clientDependencies.iterator();
while (it.hasNext()) {
Dependency dependency = it.next();
// MOD qiongli bug 15587.if dependcy is Proxy,reload it and remove the client element
if (dependency.eIsProxy()) {
dependency = (Dependency) EObjectHelper.resolveObject(dependency);
}
// ~
Resource dependencyResource = dependency.eResource();
if (dependencyResource != null) {
modifiedResources.add(dependencyResource);
}
}
// this clears also the reverse dependencies: remove the elementToDelete
// from
// Dependency.getClient()
clientDependencies.clear();
// now get the objects that depend on the elementToDelete
EList<Dependency> supplierDependencies = elementToDelete.getSupplierDependency();
for (Dependency dependency : supplierDependencies) {
EList<ModelElement> client = dependency.getClient();
// get the resource of each client
for (ModelElement modelElement : client) {
Resource clientResource = modelElement.eResource();
if (clientResource != null) {
modifiedResources.add(clientResource);
}
}
// clear the dependencies of all clients
// this clear the corresponding getClientDependency() of each client
// (objects that requires the
// elementToDelete)
client.clear();
}
// }
return modifiedResources;
}
use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class DependenciesHandler method removeSupplierDependenciesBetweenModels.
/**
* This method removes supplier dependencies. See
* {@link DependenciesHandler#removeDependenciesBetweenModels(ModelElement, List)}
*
* @param rule
* @param analyses
* @return
*/
public boolean removeSupplierDependenciesBetweenModels(ModelElement rule, List<? extends ModelElement> analyses) {
List<Resource> toRemoveResources = new ArrayList<Resource>();
for (ModelElement modelElement : analyses) {
toRemoveResources.add(modelElement.eResource());
}
// get the client dependencies (
EList<Dependency> supplierDependencies = rule.getSupplierDependency();
for (Dependency dependency : supplierDependencies) {
EList<ModelElement> client = dependency.getClient();
// get the resource of each client
Iterator<ModelElement> dependencyIterator = client.iterator();
while (dependencyIterator.hasNext()) {
Resource clientResource = dependencyIterator.next().eResource();
if (clientResource != null) {
if (toRemoveResources.contains(clientResource)) {
dependencyIterator.remove();
}
}
}
}
return true;
}
use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class DependenciesHandler method setUsageDependencyOn.
/**
* Method "setUsageDependencyOn".
*
* @param client the element which depends on the supplier
* @param supplier the element needed by the client element
* @return the dependency object between the two given elements
*/
public TypedReturnCode<Dependency> setUsageDependencyOn(ModelElement client, ModelElement supplier) {
// get the supplier's usage dependencies
EList<Dependency> supplierDependencies = supplier.getSupplierDependency();
// search for clients into them
for (Dependency dependency : supplierDependencies) {
if (dependency.getKind() != null && USAGE.compareTo(dependency.getKind()) == 0) {
// if exist return true with the dependency
EObject resolvedObject = ResourceHelper.resolveObject(dependency.getClient(), client);
// check whether the client contains relation dependency, if yes remove the dependency firstly
if (resolvedObject == null) {
if (checkClientDependencyExist(client, supplier)) {
// normal case the code should not come here, except import same project with the second time
removeClientDependency(client, supplier);
}
// if not add analysis to the dependency
dependency.getClient().add(client);
}
TypedReturnCode<Dependency> rc = new TypedReturnCode<Dependency>();
rc.setObject(dependency);
return rc;
}
}
// if not exist create a usage dependency
return createUsageDependencyOn(client, supplier);
}
Aggregations