use of org.talend.core.repository.utils.AbstractResourceChangesService in project tdq-studio-se by Talend.
the class AElementPersistance method saveWithDependencies.
/**
* Save item with dependencies.
*
* @param element
* @throws PersistenceException
*/
protected ReturnCode saveWithDependencies(Item item, ModelElement element) throws PersistenceException {
ReturnCode rc = new ReturnCode();
removeDependencies(item);
addDependencies(element);
addResourceContent(element.eResource(), element);
Map<EObject, Collection<Setting>> find = EcoreUtil.ExternalCrossReferencer.find(element.eResource());
Set<EObject> needSaves = new HashSet<EObject>();
for (EObject object : find.keySet()) {
Resource re = object.eResource();
if (re == null) {
continue;
}
// only do save when the dependency is not reference project node, and do not do resolve
if (!re.getURI().segment(1).equals(ProjectManager.getInstance().getCurrentProject().getTechnicalLabel())) {
continue;
}
// MOD sizhaoliu TDQ-6296 the resource should be resolved before saving the item to make sure the references
// are updated.
EcoreUtil.resolveAll(re);
needSaves.add(object);
}
// Set the TDQ item file name.
if (item instanceof TDQItem) {
setTDQItemFileName(element, item);
}
ProxyRepositoryFactory.getInstance().save(item);
AbstractResourceChangesService resChangeService = TDQServiceRegister.getInstance().getResourceChangeService(AbstractResourceChangesService.class);
if (resChangeService != null) {
for (EObject toSave : needSaves) {
// only do save when the dependency is not reference project node
toSave = EObjectHelper.resolveObject(toSave);
if (!toSave.eResource().getURI().segment(1).equals(ProjectManager.getInstance().getCurrentProject().getTechnicalLabel())) {
continue;
}
resChangeService.saveResourceByEMFShared(toSave.eResource());
}
}
return rc;
}
Aggregations