Search in sources :

Example 6 with Dependency

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

the class FileSystemImportWriter method updateAnalysisClientDependence.

/**
 * remove the old client dependency add a new one in Anlaysis.
 *
 * @param supplierItem
 * @param modelElement
 * @throws PersistenceException
 */
private void updateAnalysisClientDependence(TDQItem supplierItem, Property property) throws PersistenceException {
    ModelElement anaModelElement = PropertyHelper.getModelElement(property);
    if (anaModelElement != null) {
        Analysis analysis = (Analysis) anaModelElement;
        EList<Dependency> clientDependency = anaModelElement.getClientDependency();
        Iterator<Dependency> it = clientDependency.iterator();
        ModelElement supplierModelElement = RepositoryNodeHelper.getResourceModelElement(supplierItem);
        Resource supModeResource = supplierModelElement.eResource();
        while (it.hasNext()) {
            Dependency clientDep = it.next();
            // systemSupplyModelElement,remove it.
            if (clientDep.eResource() == null) {
                URI clientDepURI = ((InternalEObject) clientDep).eProxyURI();
                boolean isUDI = clientDepURI.path().contains(ResourceManager.getUDIFolder().getProjectRelativePath().toString());
                boolean isPattern = clientDepURI.path().contains(ResourceManager.getPatternFolder().getProjectRelativePath().toString());
                if (supModeResource != null && (isUDI || isPattern) && clientDepURI.lastSegment().equals(supModeResource.getURI().lastSegment())) {
                    it.remove();
                    break;
                }
            }
        }
        DependenciesHandler.getInstance().setUsageDependencyOn(anaModelElement, supplierModelElement);
        // TDQ-8436 remove the old pattern and add the new pattern in analysis Indicator Parameters.
        if (isPattern(supplierModelElement)) {
            updatePatternInAnaParams(supplierModelElement, analysis);
            ElementWriterFactory.getInstance().createPatternWriter().save(supplierItem, true);
        }
        // remove old udi and set a new one in the analysis indicators.
        if (supplierModelElement instanceof UDIndicatorDefinition) {
            if (analysis.getResults() != null) {
                EList<Indicator> indicators = analysis.getResults().getIndicators();
                Iterator<Indicator> itIndicators = indicators.iterator();
                while (itIndicators.hasNext()) {
                    Indicator indicator = itIndicators.next();
                    IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
                    if (indicatorDefinition.eResource() == null) {
                        URI indicatorDefURI = ((InternalEObject) indicatorDefinition).eProxyURI();
                        if (supModeResource != null && UDIHelper.isUDI(indicator) && indicatorDefURI.lastSegment().equals(supModeResource.getURI().lastSegment())) {
                            indicator.setIndicatorDefinition((UDIndicatorDefinition) supplierModelElement);
                            break;
                        }
                    }
                }
                ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().save(supplierItem, true);
            }
        }
        // only save analysis item at here.
        ProxyRepositoryFactory.getInstance().save(property.getItem(), true);
    }
}
Also used : UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) Resource(org.eclipse.emf.ecore.resource.Resource) Dependency(orgomg.cwm.objectmodel.core.Dependency) URI(org.eclipse.emf.common.util.URI) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) Indicator(org.talend.dataquality.indicators.Indicator) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 7 with Dependency

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

the class ColumnSetAnalysisHandler method addIndicator.

/**
 * The resources that are connected to this analysis and that are potentially modified.
 */
// private Collection<Resource> modifiedResources = new HashSet<Resource>();
/**
 * Method "addColumnToAnalyze".
 *
 * @param column
 * @return
 */
public boolean addIndicator(List<ModelElement> columns, Indicator indicator) {
    for (ModelElement tdColumn : columns) {
        if (!analysis.getContext().getAnalysedElements().contains(tdColumn)) {
            analysis.getContext().getAnalysedElements().add(tdColumn);
        }
    }
    // store first level of indicators in result.
    analysis.getResults().getIndicators().add(indicator);
    initializeIndicator(indicator);
    DataManager connection = analysis.getContext().getConnection();
    if (connection == null) {
        // try to get one
        for (ModelElement element : columns) {
            TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(element);
            // $NON-NLS-1$
            log.error(Messages.getString("ColumnCorrelationAnalysisHandler.CONNNOTBEENSETINANALYSIS"));
            connection = ConnectionHelper.getTdDataProvider(tdColumn);
            if (connection != null) {
                analysis.getContext().setConnection(connection);
                break;
            }
        }
    }
    TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(analysis, connection);
    return rc.isOk();
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 8 with Dependency

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

the class DependenciesHandler method clearDependencies.

/**
 * Method "clearDependencies" is to be used before a file is deleted. The root element is given as argument and the
 * dependencies on this element are removed in all resources that depend on this element.
 *
 * @param elementToDelete a root element which file will be deleted.
 * @return the list of modified dependencies
 */
public List<Resource> clearDependencies(ModelElement elementToDelete) {
    EList<Dependency> clientDependencies;
    // get the client dependencies (
    clientDependencies = elementToDelete.getClientDependency();
    // locate resource of each Dependency object
    List<Resource> modifiedResources = new ArrayList<Resource>();
    Iterator<Dependency> it = clientDependencies.iterator();
    while (it.hasNext()) {
        Dependency dependency = it.next();
        // MOD qiongli bug 15587.if dependcy is Proxy,reload it and remove the client element
        if (dependency.eIsProxy()) {
            dependency = (Dependency) EObjectHelper.resolveObject(dependency);
        }
        // ~
        Resource dependencyResource = dependency.eResource();
        if (dependencyResource != null) {
            modifiedResources.add(dependencyResource);
        }
    }
    // this clears also the reverse dependencies: remove the elementToDelete
    // from
    // Dependency.getClient()
    clientDependencies.clear();
    // now get the objects that depend on the elementToDelete
    EList<Dependency> supplierDependencies = elementToDelete.getSupplierDependency();
    for (Dependency dependency : supplierDependencies) {
        EList<ModelElement> client = dependency.getClient();
        // get the resource of each client
        for (ModelElement modelElement : client) {
            Resource clientResource = modelElement.eResource();
            if (clientResource != null) {
                modifiedResources.add(clientResource);
            }
        }
        // clear the dependencies of all clients
        // this clear the corresponding getClientDependency() of each client
        // (objects that requires the
        // elementToDelete)
        client.clear();
    }
    // }
    return modifiedResources;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 9 with Dependency

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

the class DependenciesHandler method removeSupplierDependenciesBetweenModels.

/**
 * This method removes supplier dependencies. See
 * {@link DependenciesHandler#removeDependenciesBetweenModels(ModelElement, List)}
 *
 * @param rule
 * @param analyses
 * @return
 */
public boolean removeSupplierDependenciesBetweenModels(ModelElement rule, List<? extends ModelElement> analyses) {
    List<Resource> toRemoveResources = new ArrayList<Resource>();
    for (ModelElement modelElement : analyses) {
        toRemoveResources.add(modelElement.eResource());
    }
    // get the client dependencies (
    EList<Dependency> supplierDependencies = rule.getSupplierDependency();
    for (Dependency dependency : supplierDependencies) {
        EList<ModelElement> client = dependency.getClient();
        // get the resource of each client
        Iterator<ModelElement> dependencyIterator = client.iterator();
        while (dependencyIterator.hasNext()) {
            Resource clientResource = dependencyIterator.next().eResource();
            if (clientResource != null) {
                if (toRemoveResources.contains(clientResource)) {
                    dependencyIterator.remove();
                }
            }
        }
    }
    return true;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 10 with Dependency

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

the class DependenciesHandler method setUsageDependencyOn.

/**
 * Method "setUsageDependencyOn".
 *
 * @param client the element which depends on the supplier
 * @param supplier the element needed by the client element
 * @return the dependency object between the two given elements
 */
public TypedReturnCode<Dependency> setUsageDependencyOn(ModelElement client, ModelElement supplier) {
    // get the supplier's usage dependencies
    EList<Dependency> supplierDependencies = supplier.getSupplierDependency();
    // search for clients into them
    for (Dependency dependency : supplierDependencies) {
        if (dependency.getKind() != null && USAGE.compareTo(dependency.getKind()) == 0) {
            // if exist return true with the dependency
            EObject resolvedObject = ResourceHelper.resolveObject(dependency.getClient(), client);
            // check whether the client contains relation dependency, if yes remove the dependency firstly
            if (resolvedObject == null) {
                if (checkClientDependencyExist(client, supplier)) {
                    // normal case the code should not come here, except import same project with the second time
                    removeClientDependency(client, supplier);
                }
                // if not add analysis to the dependency
                dependency.getClient().add(client);
            }
            TypedReturnCode<Dependency> rc = new TypedReturnCode<Dependency>();
            rc.setObject(dependency);
            return rc;
        }
    }
    // if not exist create a usage dependency
    return createUsageDependencyOn(client, supplier);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) 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