Search in sources :

Example 96 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class AnalysisWriter method addDependencies.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.writer.AElementPersistance#addDependencies(orgomg.cwm.objectmodel.core.ModelElement)
     */
@Override
public void addDependencies(ModelElement element) {
    Analysis analysis = (Analysis) element;
    List<IndicatorDefinition> udis = AnalysisHelper.getUserDefinedIndicators(analysis);
    try {
        for (IndicatorDefinition udi : udis) {
            if (udi == null) {
                continue;
            }
            InternalEObject iudi = (InternalEObject) udi;
            if (!iudi.eIsProxy()) {
                DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(udi);
                // only do save when the dependency is not reference project node
                if (recursiveFind != null && recursiveFind.getProject().isMainProject()) {
                    TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(analysis, udi);
                    if (dependencyReturn.isOk()) {
                        Property property = PropertyHelper.getProperty(udi);
                        if (property != null) {
                            TDQItem udiItem = (TDQItem) property.getItem();
                            if (udiItem instanceof TDQIndicatorDefinitionItem) {
                                ((TDQIndicatorDefinitionItem) udiItem).setIndicatorDefinition(udi);
                            } else if (udiItem instanceof TDQBusinessRuleItem) {
                                ((TDQBusinessRuleItem) udiItem).setDqrule((DQRule) udi);
                            }
                        }
                        ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(udi.eResource());
                    }
                }
            }
        }
        List<Pattern> patterns = AnalysisHelper.getPatterns(analysis);
        for (Pattern pattern : patterns) {
            InternalEObject iptn = (InternalEObject) pattern;
            if (!iptn.eIsProxy()) {
                DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(pattern);
                // only do save when the dependency is not reference project node
                if (recursiveFind != null && recursiveFind.getProject().isMainProject()) {
                    TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(analysis, pattern);
                    if (dependencyReturn.isOk()) {
                        Property property = PropertyHelper.getProperty(pattern);
                        if (property != null && property.getItem() instanceof TDQPatternItem) {
                            TDQPatternItem patternItem = (TDQPatternItem) property.getItem();
                            patternItem.setPattern(pattern);
                        }
                        ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(pattern.eResource());
                    // EMFUtil.saveSingleResource(pattern.eResource());
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        log.error(e, e);
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Dependency(orgomg.cwm.objectmodel.core.Dependency) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DQRule(org.talend.dataquality.rules.DQRule) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) Analysis(org.talend.dataquality.analysis.Analysis) PersistenceException(org.talend.commons.exception.PersistenceException) TDQItem(org.talend.core.model.properties.TDQItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) Property(org.talend.core.model.properties.Property) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 97 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class ReportWriter method addDependencies.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.writer.AElementPersistance#addDependencies(orgomg.cwm.objectmodel.core.ModelElement)
     */
@Override
public void addDependencies(ModelElement element) {
    TdReport report = (TdReport) element;
    List<Analysis> analyses = ReportHelper.getAnalyses(report);
    for (Analysis ana : analyses) {
        // TDQ-7999,filter the proxy.
        if (!ana.eIsProxy()) {
            AnalysisRepNode recursiveFindAnalysis = RepositoryNodeHelper.recursiveFindAnalysis(ana);
            // only do save when the dependency is not reference project node
            if (recursiveFindAnalysis != null && recursiveFindAnalysis.getProject().isMainProject()) {
                TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(report, ana);
                if (dependencyReturn.isOk()) {
                    try {
                        Property property = PropertyHelper.getProperty(ana);
                        if (property != null) {
                            Item item = property.getItem();
                            if (item instanceof TDQAnalysisItem) {
                                TDQAnalysisItem anaItem = (TDQAnalysisItem) item;
                                anaItem.setAnalysis(ana);
                            }
                        }
                        ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(ana.eResource());
                    } catch (PersistenceException e) {
                        log.error(e, e);
                    }
                }
            }
        }
    }
}
Also used : TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Item(org.talend.core.model.properties.Item) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) Analysis(org.talend.dataquality.analysis.Analysis) TdReport(org.talend.dataquality.reports.TdReport) PersistenceException(org.talend.commons.exception.PersistenceException) Dependency(orgomg.cwm.objectmodel.core.Dependency) Property(org.talend.core.model.properties.Property) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 98 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class WorkbenchUtils method impactExistingAnalyses.

/**
 * DOC qiongli TDQ-3317:move this method from ReloadDatabaseAction. to this class .
 *
 * @param oldDataProvider
 * @throws PartInitException
 */
public static void impactExistingAnalyses(DataProvider oldDataProvider) throws PartInitException {
    EList<Dependency> clientDependencies = oldDataProvider.getSupplierDependency();
    List<Analysis> unsynedAnalyses = new ArrayList<Analysis>();
    for (Dependency dep : clientDependencies) {
        for (ModelElement mod : dep.getClient()) {
            // MOD mzhao 2009-08-24 The dependencies include "Property" and "Analysis"
            if (!(mod instanceof Analysis)) {
                continue;
            }
            Analysis ana = (Analysis) mod;
            unsynedAnalyses.add(ana);
        }
        for (Analysis analysis : unsynedAnalyses) {
            // Reload.
            IFile file = getTempAnalysisFile(analysis);
            Analysis tempAnalysis = (Analysis) AnaResourceFileHelper.getInstance().getModelElement(file);
            // MOD qiongli 2010-8-17,bug 14977
            if (tempAnalysis != null) {
                Resource eResource = tempAnalysis.eResource();
                Map<EObject, Collection<Setting>> referenceMaps = EcoreUtil.UnresolvedProxyCrossReferencer.find(eResource);
                Iterator<EObject> it = referenceMaps.keySet().iterator();
                ModelElement eobj = null;
                boolean isModified = false;
                while (it.hasNext()) {
                    eobj = (ModelElement) it.next();
                    Collection<Setting> settings = referenceMaps.get(eobj);
                    for (Setting setting : settings) {
                        if (setting.getEObject() instanceof AnalysisContext) {
                            tempAnalysis.getContext().getAnalysedElements().remove(eobj);
                            isModified = true;
                        } else if (setting.getEObject() instanceof Indicator) {
                            // the only indicator in the column set analysis. (Added TDQ-8842 20140512 yyin)
                            if (AnalysisType.COLUMN_SET.equals(tempAnalysis.getParameters().getAnalysisType())) {
                                // ~
                                ((SimpleStatIndicator) setting.getEObject()).getAnalyzedColumns().remove(eobj);
                            } else {
                                tempAnalysis.getResults().getIndicators().remove(setting.getEObject());
                            }
                            isModified = true;
                        }
                    }
                }
                if (isModified) {
                    saveTempAnalysis(file, tempAnalysis);
                }
                // Should reopen this analyis's editor if it is opened now. what ever it is modified or not.
                EventManager.getInstance().publish(tempAnalysis.getName(), EventEnum.DQ_ANALYSIS_REOPEN_EDITOR, null);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) Dependency(orgomg.cwm.objectmodel.core.Dependency) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Indicator(org.talend.dataquality.indicators.Indicator) SimpleStatIndicator(org.talend.dataquality.indicators.columnset.SimpleStatIndicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Collection(java.util.Collection) SimpleStatIndicator(org.talend.dataquality.indicators.columnset.SimpleStatIndicator)

Example 99 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class DQRepositoryViewLabelProvider method addWarnIconIfNeeded.

/**
 * if it is needed,add a over warning icon..eg., it is empty analysis or report; imported a MDM analysis or report.
 *
 * @param image
 * @param node
 * @param originalImageName
 * @return
 */
private Image addWarnIconIfNeeded(IRepositoryNode node, String originalImageName) {
    ModelElement modEle = RepositoryNodeHelper.getResourceModelElement(node);
    ERepositoryObjectType objectType = node.getObjectType();
    if (modEle != null) {
        if (ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT == objectType) {
            Analysis analysis = (Analysis) modEle;
            AnalysisContext context = analysis.getContext();
            if (context == null) {
                return ImageLib.createInvalidIcon(originalImageName);
            }
            EList<ModelElement> analysedElements = context.getAnalysedElements();
            DataManager connection = context.getConnection();
            if (analysedElements.isEmpty() || connection instanceof MDMConnection) {
                return ImageLib.createInvalidIcon(originalImageName);
            }
        } else if (ERepositoryObjectType.TDQ_REPORT_ELEMENT == objectType) {
            TdReport report = (TdReport) modEle;
            EList<AnalysisMap> analysisMap = report.getAnalysisMap();
            if (analysisMap.isEmpty()) {
                return ImageLib.createInvalidIcon(originalImageName);
            }
            for (AnalysisMap anaMap : report.getAnalysisMap()) {
                Analysis analysis = anaMap.getAnalysis();
                if (analysis == null || analysis.getContext() == null) {
                    continue;
                }
                DataManager connection = analysis.getContext().getConnection();
                if (connection instanceof MDMConnection) {
                    return ImageLib.createInvalidIcon(originalImageName);
                }
            }
        }
    }
    return ImageLib.getImage(originalImageName);
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EList(org.eclipse.emf.common.util.EList) Analysis(org.talend.dataquality.analysis.Analysis) TdReport(org.talend.dataquality.reports.TdReport) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection)

Example 100 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class WorkbenchUtils method nodifyDependedAnalysis.

public static void nodifyDependedAnalysis(ConnectionItem connectionItem) {
    // Added TDQ-8360 20140410 yyin: notify each depended analysis
    EList<Dependency> clientDependencies = connectionItem.getConnection().getSupplierDependency();
    for (Dependency dep : clientDependencies) {
        for (ModelElement mod : dep.getClient()) {
            if (!(mod instanceof Analysis)) {
                continue;
            }
            EventManager.getInstance().publish(mod, EventEnum.DQ_ANALYSIS_REFRESH_DATAPROVIDER_LIST, null);
            EventManager.getInstance().publish(mod, EventEnum.DQ_MATCH_ANALYSIS_REFRESH_DATAPROVIDER_LABEL, null);
        }
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Aggregations

Analysis (org.talend.dataquality.analysis.Analysis)137 Test (org.junit.Test)36 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)36 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)30 ArrayList (java.util.ArrayList)28 Property (org.talend.core.model.properties.Property)28 Indicator (org.talend.dataquality.indicators.Indicator)27 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)27 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)26 PersistenceException (org.talend.commons.exception.PersistenceException)19 Connection (org.talend.core.model.metadata.builder.connection.Connection)18 ReturnCode (org.talend.utils.sugars.ReturnCode)18 Dependency (orgomg.cwm.objectmodel.core.Dependency)18 TdColumn (org.talend.cwm.relational.TdColumn)16 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)16 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)15 Pattern (org.talend.dataquality.domain.pattern.Pattern)15 IFile (org.eclipse.core.resources.IFile)14 File (java.io.File)12 IPath (org.eclipse.core.runtime.IPath)12