Search in sources :

Example 11 with Dependency

use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.

the class ReorderingLibraryFoldersTask method moveItems.

private void moveItems(IFolder oldSubFolder, IFolder newSubfolder) throws CoreException {
    if (!oldSubFolder.exists()) {
        return;
    }
    for (IResource oldResource : oldSubFolder.members()) {
        if (newSubfolder.getName().equals(oldResource.getName())) {
            continue;
        }
        // cannot simply copy EMF files: need to keep the links between files when moving them. See bug 9461
        if (oldResource instanceof IFolder) {
            IFolder oldFolder = (IFolder) oldResource;
            IFolder newFolder = DQStructureManager.getInstance().createNewFolder(newSubfolder, oldFolder.getName());
            moveItems(oldFolder, newFolder);
            // delete folder
            oldFolder.delete(true, null);
        }
        if (oldResource instanceof IFile) {
            IFile file = (IFile) oldResource;
            final ModelElement eltFromLibraryFolder = getModelElement(file);
            final EList<Dependency> supplierDependency = eltFromLibraryFolder.getSupplierDependency();
            if (supplierDependency.isEmpty()) {
                // simple copy of file is enough
                oldResource.copy(newSubfolder.getFolder(oldResource.getName()).getFullPath(), true, null);
            } else {
                // handle dependent analyses
                List<Analysis> analyses = new ArrayList<Analysis>();
                for (Dependency dependency : supplierDependency) {
                    URI newUri = URI.createPlatformResourceURI(newSubfolder.getFullPath().toOSString(), true);
                    // move pattern
                    EMFUtil.changeUri(eltFromLibraryFolder.eResource(), newUri);
                    final EList<ModelElement> clientAnalyses = dependency.getClient();
                    for (ModelElement modelElement : clientAnalyses) {
                        Analysis analysis = DataqualitySwitchHelper.ANALYSIS_SWITCH.doSwitch(modelElement);
                        if (analysis != null) {
                            analyses.add(analysis);
                        }
                    }
                }
                // clean the dependencies that do not refer to an existing object.
                for (Analysis analysis : analyses) {
                    final EList<Dependency> clientDependency = analysis.getClientDependency();
                    List<Dependency> newClientDeps = new ArrayList<Dependency>();
                    for (Dependency dependency : clientDependency) {
                        if (!dependency.eIsProxy()) {
                            newClientDeps.add(dependency);
                        }
                    }
                    clientDependency.clear();
                    clientDependency.addAll(newClientDeps);
                    AnaResourceFileHelper.getInstance().save(analysis);
                }
            }
            remove(file);
        }
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IFile(org.eclipse.core.resources.IFile) Analysis(org.talend.dataquality.analysis.Analysis) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with Dependency

use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.

the class TDQResourceChangeHandler method updateDependeciesWhenVersionChange.

@Override
public void updateDependeciesWhenVersionChange(ConnectionItem connItem, String oldVersion, String newVersion) {
    Connection connection = connItem.getConnection();
    if (connection != null) {
        EList<Dependency> supplierDependencies = connection.getSupplierDependency();
        if (supplierDependencies != null && !supplierDependencies.isEmpty()) {
            Dependency[] arraySupplierDeps = supplierDependencies.toArray(new Dependency[supplierDependencies.size()]);
            for (Dependency supplierDep : arraySupplierDeps) {
                EList<ModelElement> clients = supplierDep.getClient();
                if (clients != null && !clients.isEmpty()) {
                    ModelElement[] arrayClients = clients.toArray(new ModelElement[clients.size()]);
                    for (ModelElement client : arrayClients) {
                        if (client instanceof Analysis) {
                            IFile clientFile = AnaResourceFileHelper.findCorrespondingFile(client);
                            if (clientFile != null) {
                                File file = WorkspaceUtils.ifileToFile(clientFile);
                                if (file != null) {
                                    replaceVersionInfo(connection.getName(), file, oldVersion, newVersion);
                                    reloadFile(file);
                                }
                            }
                        }
                    }
                }
            }
            ResourceService.refreshStructure();
            WorkbenchUtils.refreshAnalysesNode();
            WorkbenchUtils.refreshMetadataNode();
        }
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IFile(org.eclipse.core.resources.IFile) Analysis(org.talend.dataquality.analysis.Analysis) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Dependency(orgomg.cwm.objectmodel.core.Dependency) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 13 with Dependency

use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.

the class DeleteModelElementConfirmDialog method addDenpendencyElements.

static void addDenpendencyElements(ModelElement[] children) {
    for (ModelElement element : children) {
        EList<Dependency> supplierDependencies = element.getSupplierDependency();
        ImpactNode impactNode;
        for (Dependency dependency : supplierDependencies) {
            EList<ModelElement> clients = dependency.getClient();
            for (ModelElement client : clients) {
                // ~
                if (!client.eIsProxy()) {
                    impactNode = new ImpactNode(client);
                    int index = impactNodes.indexOf(impactNode);
                    if (index == -1) {
                        impactNode.addRequireModelElement(element);
                        impactNodes.add(impactNode);
                    } else {
                        ImpactNode existNode = impactNodes.get(index);
                        existNode.addRequireModelElement(element);
                    }
                }
            }
        }
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 14 with Dependency

use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.

the class EObjectHelper method getDependencySuppliers.

public static List<ModelElement> getDependencySuppliers(IFile file) {
    ModelElement findElement = getModelElement(file);
    EList<Dependency> clientDependencys = findElement.getClientDependency();
    // locate resource of each Dependency object
    List<ModelElement> supplierList = new ArrayList<ModelElement>();
    for (Dependency dependency : clientDependencys) {
        EList<ModelElement> supplier = dependency.getSupplier();
        if (supplier != null) {
            supplierList.addAll(supplier);
        }
    }
    return supplierList;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 15 with Dependency

use of orgomg.cwm.objectmodel.core.Dependency in project tdq-studio-se by Talend.

the class EObjectHelper method getDependencyClients.

public static List<ModelElement> getDependencyClients(ModelElement modelElement) {
    if (modelElement == null) {
        return new ArrayList<ModelElement>();
    }
    EList<Dependency> clientDependencys = modelElement.getSupplierDependency();
    // locate resource of each Dependency object
    List<ModelElement> supplierList = new ArrayList<ModelElement>();
    for (Dependency dependency : clientDependencys) {
        EList<ModelElement> clients = dependency.getClient();
        if (clients != null) {
            for (ModelElement client : clients) {
                if (!client.eIsProxy()) {
                    supplierList.add(client);
                }
            }
        }
    }
    return supplierList;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Aggregations

Dependency (orgomg.cwm.objectmodel.core.Dependency)43 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)30 ArrayList (java.util.ArrayList)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)11 Resource (org.eclipse.emf.ecore.resource.Resource)10 Test (org.junit.Test)9 PersistenceException (org.talend.commons.exception.PersistenceException)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)6 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)6 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)6 URI (org.eclipse.emf.common.util.URI)5 EObject (org.eclipse.emf.ecore.EObject)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Connection (org.talend.core.model.metadata.builder.connection.Connection)5 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 TdColumn (org.talend.cwm.relational.TdColumn)5 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)5