Search in sources :

Example 36 with Dependency

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;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TDQSourceFileItem(org.talend.dataquality.properties.TDQSourceFileItem) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency) Property(org.talend.core.model.properties.Property)

Example 37 with Dependency

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;
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 38 with 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;
}
Also used : Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 39 with Dependency

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);
    }
}
Also used : EResourceConstant(org.talend.resource.EResourceConstant) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency) URI(org.eclipse.emf.common.util.URI) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Item(org.talend.core.model.properties.Item) TDQSourceFileItem(org.talend.dataquality.properties.TDQSourceFileItem) TDQFileItem(org.talend.dataquality.properties.TDQFileItem) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EObject(org.eclipse.emf.ecore.EObject) AElementPersistance(org.talend.dq.writer.AElementPersistance) File(java.io.File) Property(org.talend.core.model.properties.Property)

Example 40 with Dependency

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;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) Dependency(orgomg.cwm.objectmodel.core.Dependency) URI(org.eclipse.emf.common.util.URI)

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