Search in sources :

Example 41 with Dependency

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

the class ModelElementAnalysisHandler method addIndicator.

public boolean addIndicator(ModelElement modelElement, Indicator... indicators) {
    if (!analysis.getContext().getAnalysedElements().contains(modelElement)) {
        analysis.getContext().getAnalysedElements().add(modelElement);
    }
    for (Indicator indicator : indicators) {
        // ADD TDQ-7164 msjian 2013-5-14:set default indicator parameters.
        if (indicator.getParameters() == null) {
            indicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
        }
        // TDQ-7164~
        // store first level of indicators in result.
        analysis.getResults().getIndicators().add(indicator);
        initializeIndicator(indicator, modelElement);
    }
    DataManager connection = analysis.getContext().getConnection();
    if (connection == null) {
        // try to get one
        // $NON-NLS-1$
        log.error(Messages.getString("ColumnCorrelationAnalysisHandler.CONNNOTBEENSETINANALYSIS"));
        connection = ModelElementHelper.getTdDataProvider(modelElement);
        analysis.getContext().setConnection(connection);
    }
    TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(analysis, connection);
    return rc.isOk();
}
Also used : DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) Dependency(orgomg.cwm.objectmodel.core.Dependency) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 42 with Dependency

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

the class CheckAndUpdateAnalysisDependencyTask method checkAndRemoveWrongDependencies.

/**
 * check each analysis if it has only one client dependency, if more than one, remove the useless one.
 *
 * @param list
 * @throws CoreException
 */
private void checkAndRemoveWrongDependencies(List<Analysis> analyses) throws CoreException {
    for (Analysis analysis : analyses) {
        if (analysis != null) {
            boolean isAnalysisModified = false;
            if (analysis.getContext().getAnalysedElements() == null || analysis.getContext().getAnalysedElements().size() < 1) {
                continue;
            }
            TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(analysis.getContext().getAnalysedElements().get(0));
            if (tdColumn == null) {
                continue;
            }
            // find the correct db connection from analyzed element
            DataManager correctDB = ConnectionHelper.getConnection(tdColumn);
            // check if the connection is correct or not
            DataManager connection = analysis.getContext().getConnection();
            if (connection == null || !correctDB.getName().equals(connection.getName())) {
                analysis.getContext().setConnection(correctDB);
                isAnalysisModified = true;
            }
            List<DataProvider> clientDependencyDB = null;
            for (Dependency dependency : analysis.getClientDependency()) {
                ModelElement supplier = dependency.getSupplier().get(0);
                if (supplier instanceof DataProvider) {
                    if (supplier != null && correctDB.getName().equals(supplier.getName())) {
                        continue;
                    } else {
                        if (clientDependencyDB == null) {
                            clientDependencyDB = new ArrayList<DataProvider>();
                        }
                        clientDependencyDB.add((DataProvider) supplier);
                    }
                }
            }
            if (clientDependencyDB != null) {
                for (DataProvider uselessDB : clientDependencyDB) {
                    // if the db in client dependency do not equal to the correct db, remove it from both the
                    // analysis and db connection
                    removeDependenciesBetweenAnaCon(uselessDB, analysis);
                    isAnalysisModified = true;
                }
            }
            if (isAnalysisModified) {
                EMFSharedResources.getInstance().saveResource(analysis.eResource());
            }
        }
    }
}
Also used : DataProvider(orgomg.cwm.foundation.softwaredeployment.DataProvider) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) Analysis(org.talend.dataquality.analysis.Analysis) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 43 with Dependency

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

the class CheckAndUpdateAnalysisDependencyTask method removeSupplierDependenciesBetweenModels.

private List<Resource> removeSupplierDependenciesBetweenModels(ModelElement elementFromRemove, List<? extends ModelElement> elementToRemove) {
    EList<Dependency> supplierDependencies;
    List<String> toRemoveResources = new ArrayList<String>();
    for (ModelElement modelElement : elementToRemove) {
        toRemoveResources.add(modelElement.getName());
    }
    // get the client dependencies (
    supplierDependencies = elementFromRemove.getSupplierDependency();
    List<Resource> modifiedResources = new ArrayList<Resource>();
    for (Dependency dependency : supplierDependencies) {
        EList<ModelElement> client = dependency.getClient();
        // get the resource of each client
        Iterator<ModelElement> dependencyIterator = client.iterator();
        while (dependencyIterator.hasNext()) {
            ModelElement dependencyModel = dependencyIterator.next();
            Resource clientResource = dependencyModel.eResource();
            if (clientResource != null) {
                if (toRemoveResources.contains(dependencyModel.getName())) {
                    modifiedResources.add(clientResource);
                    dependencyIterator.remove();
                }
            }
        }
    }
    return modifiedResources;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) 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