Search in sources :

Example 1 with AbstractResourceChangesService

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;
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Collection(java.util.Collection) TDQItem(org.talend.core.model.properties.TDQItem) AbstractResourceChangesService(org.talend.core.repository.utils.AbstractResourceChangesService) HashSet(java.util.HashSet)

Aggregations

Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 TDQItem (org.talend.core.model.properties.TDQItem)1 AbstractResourceChangesService (org.talend.core.repository.utils.AbstractResourceChangesService)1 ReturnCode (org.talend.utils.sugars.ReturnCode)1 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)1