use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class DependenciesHandler method getClintDependency.
/**
* @param property
* @return SupplierDependency
*
* getClintDependency
*/
public List<Property> getClintDependency(Property property) {
List<Property> listProperty = new ArrayList<Property>();
if (property == null) {
return listProperty;
}
ModelElement modelElement = PropertyHelper.getModelElement(property);
// MOD qiongli 2012-5-15 TDQ-5259,avoid NPE.
if (modelElement == null) {
return listProperty;
}
if (property.getItem() instanceof TDQSourceFileItem) {
return listProperty;
}
EList<Dependency> clientDependency = modelElement.getClientDependency();
for (Dependency clienter : clientDependency) {
for (ModelElement depencyModelElement : clienter.getSupplier()) {
Property dependencyProperty = PropertyHelper.getProperty(depencyModelElement);
// IRepositoryViewObject repositoryViewObject = new RepositoryViewObject(property);
if (dependencyProperty != null) {
listProperty.add(dependencyProperty);
}
}
}
return listProperty;
}
use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class DependenciesHandler method createDependencyOn.
/**
* Method "createUsageDependencyOn".
*
* Example Analysis depends on the exitence of a DataProvider. This method must be called
* createUsageDependencyOn(Analysis, DataProvider). The created dependency is added to the DataProvider in its
* "client dependencies" and to the Analysis in its "supplier dependencies". See OMG CWM spec paragraph 4.3.2.7.
*
* The resource in which the dependency is stored is the supplier's resource.
*
* @param kind the kind of dependency
* @param clientElement the element that requires the requiredElement
* @param supplierElement the required element
* @return the Dependency of clientElement on requiredElement
*/
Dependency createDependencyOn(String kind, ModelElement clientElement, ModelElement supplierElement) {
Dependency dependency = ModelElementHelper.createDependencyOn(kind, clientElement, supplierElement);
Resource supplierResource = supplierElement.eResource();
if (supplierResource != null) {
supplierResource.getContents().add(dependency);
}
return dependency;
}
use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class DependenciesHandler method removeDependenciesBetweenModel.
/**
* Comment method "removeDependenciesBetweenModel".
*
* @param supplier
* @param client
* @return
*/
public boolean removeDependenciesBetweenModel(ModelElement supplier, ModelElement client) {
// get the supplier's usage dependencies
boolean hasFind = false;
EList<Dependency> supplierDependencies = supplier.getSupplierDependency();
Iterator<Dependency> suppiterator = supplierDependencies.iterator();
while (suppiterator.hasNext()) {
Dependency supplierDep = suppiterator.next();
if (supplierDep.getClient().contains(client)) {
supplierDep.getClient().remove(client);
hasFind = true;
break;
}
}
// for the argument
if (!hasFind) {
EList<Dependency> clientDependency = supplier.getClientDependency();
Iterator<Dependency> clientiterator = clientDependency.iterator();
while (clientiterator.hasNext()) {
Dependency clientDep = clientiterator.next();
if (clientDep.getSupplier().contains(client)) {
clientiterator.remove();
hasFind = true;
break;
}
}
}
return hasFind;
}
use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class DependenciesHandler method findClientAndRemoveDependencyInLocalProject.
private static void findClientAndRemoveDependencyInLocalProject(ModelElement modelElement, ModelElement analysis) {
URI uri = EObjectHelper.getURI(modelElement).trimFileExtension().appendFileExtension(FactoriesUtil.PROPERTIES_EXTENSION);
// get file from filename
String fileName = uri.lastSegment();
File foundFile = null;
EResourceConstant[] topConstants = EResourceConstant.getTopConstants();
for (EResourceConstant resource : topConstants) {
File reportFolder = ResourceManager.getRootProject().getLocation().append(resource.getPath()).toFile();
List<File> fileList = FileUtils.getFilesByExtension(reportFolder, FactoriesUtil.PROPERTIES_EXTENSION);
for (File file : fileList) {
if (file.getName().equals(fileName)) {
foundFile = file;
break;
}
}
if (foundFile != null) {
break;
}
}
// from file to get model and change it
if (foundFile != null) {
Property property = PropertyHelper.getProperty(foundFile);
// change the cache content also
Item item = property.getItem();
Resource itemResource = ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().getItemResource(item);
List<EObject> toRemoveObjList = new ArrayList<EObject>();
for (EObject obj : itemResource.getContents()) {
if (obj != null && obj instanceof Dependency) {
EList<ModelElement> clients = ((Dependency) obj).getClient();
for (ModelElement model : clients) {
if (model.getName() == null) {
toRemoveObjList.add(obj);
} else {
if (StringUtils.equals(model.getName(), analysis.getName())) {
toRemoveObjList.add(obj);
break;
}
}
}
EList<ModelElement> supplier = ((Dependency) obj).getSupplier();
for (ModelElement model : supplier) {
if (model.getName() == null) {
toRemoveObjList.add(obj);
} else {
if (StringUtils.equals(model.getName(), item.getProperty().getLabel())) {
toRemoveObjList.add(obj);
break;
}
}
}
} else {
// modify where rule
EList<Dependency> supplierDependency = ((ModelElement) obj).getSupplierDependency();
Iterator<Dependency> iterator = supplierDependency.iterator();
while (iterator.hasNext()) {
Dependency model = iterator.next();
EList<ModelElement> clients = model.getClient();
for (ModelElement client : clients) {
if (StringUtils.equals(client.getName(), analysis.getName())) {
iterator.remove();
break;
}
}
}
}
}
for (EObject removeObj : toRemoveObjList) {
if (removeObj != null) {
itemResource.getContents().remove(removeObj);
}
}
// save the node
AElementPersistance writer = ElementWriterFactory.getInstance().create(item);
writer.save(item, true);
}
}
use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.
the class DependenciesHandler method removeUselessDependencies.
public static ReturnCode removeUselessDependencies(Item localItem, Item remoteItem) {
ReturnCode rc = new ReturnCode();
ModelElement remoteModelElement = PropertyHelper.getModelElement(remoteItem.getProperty());
ModelElement localModelElement = PropertyHelper.getModelElement(localItem.getProperty());
for (Dependency remoteClientDependency : remoteModelElement.getClientDependency()) {
// rule2, remote-ana
// rule1 list
List<Dependency> localClients = localModelElement.getClientDependency();
Iterator<Dependency> localClientDependency = localClients.iterator();
boolean isContains = false;
while (localClientDependency.hasNext()) {
// rule2,rule1
Dependency next = localClientDependency.next();
URI uri = EObjectHelper.getURI(remoteClientDependency);
String fileName = uri.lastSegment();
URI nexturi = EObjectHelper.getURI(next);
String nextfileName = nexturi.lastSegment();
if (StringUtils.equals(fileName, nextfileName)) {
isContains = true;
break;
}
}
if (isContains == false) {
findClientAndRemoveDependencyInLocalProject(remoteClientDependency, localModelElement);
}
}
return rc;
}
Aggregations