Search in sources :

Example 61 with Analysis

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

the class TreeMessageInfoDialog method getLabelProvider.

protected ILabelProvider getLabelProvider() {
    if (labelProvider == null) {
        labelProvider = new LabelProvider() {

            @Override
            public String getText(Object obj) {
                if (obj == null) {
                    // $NON-NLS-1$
                    return "";
                }
                if (obj instanceof ImpactNode) {
                    return ((ImpactNode) obj).toString();
                } else if (obj instanceof IFile) {
                    IFile file = (IFile) obj;
                    ModelElement modelElement = ModelElementFileFactory.getModelElement(file);
                    // MOD msjian TDQ-5909: modify to displayName
                    return modelElement != null ? PropertyHelper.getProperty(modelElement).getDisplayName() : file.getName();
                } else if (obj instanceof RepositoryViewObject) {
                    // Added 20130226 TDQ-6899 show the name for Jrxml object (which has no related ModelElement)
                    return ((IRepositoryViewObject) obj).getLabel();
                } else if (obj instanceof MetadataTable) {
                    // ADD TDQ-7146: for all type's connection table/view node
                    return ((ModelElement) obj).getName();
                }
                Property property = PropertyHelper.getProperty((ModelElement) obj);
                return property == null ? ((ModelElement) obj).getName() : property.getDisplayName();
            }

            @Override
            public Image getImage(Object obj) {
                ModelElement modelElement = null;
                if (obj instanceof ModelElement) {
                    modelElement = (ModelElement) obj;
                } else if (obj instanceof ImpactNode) {
                    modelElement = ((ImpactNode) obj).getNodeElement();
                } else if (obj instanceof IFile) {
                    modelElement = ModelElementFileFactory.getModelElement((IFile) obj);
                } else if (obj instanceof RepositoryViewObject) {
                    // Added 20130226 TDQ-6899 show the name for Jrxml object (which has no related ModelElement)
                    return ImageLib.getImage(ImageLib.JRXML_ICON);
                }
                // ~
                if (modelElement == null) {
                    if (((ImpactNode) obj).getNode() != null) {
                        return ImageLib.getImage(ImageLib.JRXML_ICON);
                    }
                    return super.getImage(obj);
                }
                Image modelElementImage = null;
                String imgName = null;
                if (modelElement instanceof Analysis) {
                    imgName = ImageLib.ANALYSIS_OBJECT;
                } else if (modelElement instanceof TdReport) {
                    imgName = ImageLib.REPORT_OBJECT;
                } else if (modelElement instanceof DatabaseConnection) {
                    imgName = ImageLib.CONNECTION;
                } else if (modelElement instanceof DelimitedFileConnection) {
                    imgName = ImageLib.FILE_DELIMITED;
                } else if (modelElement instanceof Pattern) {
                    imgName = ImageLib.PATTERN_REG;
                } else if (modelElement instanceof IndicatorDefinition) {
                    // IndicatorDefinition
                    if (modelElement instanceof DQRule) {
                        imgName = ImageLib.DQ_RULE;
                    } else if (modelElement instanceof MatchRuleDefinition) {
                        imgName = ImageLib.MATCH_RULE_ICON;
                    } else {
                        imgName = ImageLib.IND_DEFINITION;
                    }
                // TDQ-8550~
                } else if (modelElement instanceof MetadataTable) {
                    imgName = ImageLib.TABLE;
                }
                if (imgName != null) {
                    modelElementImage = ImageLib.getImage(imgName);
                }
                // add lock icon on the image
                if (modelElementImage != null) {
                    if (modelElement != null) {
                        Property property = PropertyHelper.getProperty(modelElement);
                        if (property != null) {
                            Item item = property.getItem();
                            if (item != null) {
                                if (ProxyRepositoryManager.getInstance().isLockByUserOwn(item)) {
                                    modelElementImage = ImageLib.createLockedByOwnIcon(imgName);
                                } else if (ProxyRepositoryManager.getInstance().isLockByOthers(item)) {
                                    modelElementImage = ImageLib.createLockedByOtherIcon(imgName);
                                }
                            }
                        }
                    }
                    return modelElementImage;
                }
                return super.getImage(obj);
            }
        };
    }
    return labelProvider;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IFile(org.eclipse.core.resources.IFile) ImpactNode(org.talend.dataprofiler.core.ui.dialog.message.DeleteModelElementConfirmDialog.ImpactNode) TdReport(org.talend.dataquality.reports.TdReport) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) Image(org.eclipse.swt.graphics.Image) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DQRule(org.talend.dataquality.rules.DQRule) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Item(org.talend.core.model.properties.Item) Analysis(org.talend.dataquality.analysis.Analysis) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Property(org.talend.core.model.properties.Property) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject)

Example 62 with Analysis

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

the class RemoveAnalysisAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    DQRespositoryView findView = CorePlugin.getDefault().getRepositoryView();
    if (findView == null) {
        return;
    }
    TreeSelection treeSelection = (TreeSelection) findView.getCommonViewer().getSelection();
    TreePath[] paths = treeSelection.getPaths();
    List<Analysis> analysisList;
    Analysis analysisObj = null;
    Map<TDQReportItem, List<Analysis>> removeMap = new HashMap<TDQReportItem, List<Analysis>>();
    for (TreePath path : paths) {
        Object lastSegment = path.getLastSegment();
        if (!(lastSegment instanceof ReportAnalysisRepNode)) {
            return;
        }
        // MOD sizhaoliu 2012-06-12 TDQ-5051 "Remove Anaysis" menu item is not in the right place
        ReportAnalysisRepNode repNode = (ReportAnalysisRepNode) lastSegment;
        analysisObj = repNode.getAnalysis();
        TDQReportItem reportItem = repNode.getReportItem();
        analysisList = removeMap.get(reportItem);
        if (analysisList == null) {
            analysisList = new ArrayList<Analysis>();
            analysisList.add(analysisObj);
            removeMap.put(reportItem, analysisList);
        } else {
            analysisList.add(analysisObj);
        }
    }
    if (analysisObj == null) {
        return;
    }
    String message = paths.length > 1 ? DefaultMessagesImpl.getString("RemoveAnalysisAction.areYouDeleteElement0", // $NON-NLS-1$
    paths.length) : // $NON-NLS-1$
    DefaultMessagesImpl.getString("RemoveAnalysisAction.areYouDeleteElement2", analysisObj.getName());
    boolean openConfirm = MessageDialog.openConfirm(null, DefaultMessagesImpl.getString("RemoveAnalysisAction.confirmResourceDelete"), // $NON-NLS-1$
    message);
    if (openConfirm) {
        Iterator<TDQReportItem> iterator = removeMap.keySet().iterator();
        while (iterator.hasNext()) {
            TDQReportItem reportItem = iterator.next();
            ReportHelper.removeAnalyses((TdReport) reportItem.getReport(), removeMap.get(reportItem));
            // save now modified resources (that contain the Dependency
            // objects)
            ElementWriterFactory.getInstance().createReportWriter().save(reportItem, true);
        }
        IFolder reportsFolder = ResourceManager.getReportsFolder();
        try {
            reportsFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
        } catch (CoreException e) {
            log.error(e, e);
        }
        findView.getCommonViewer().refresh();
    }
}
Also used : HashMap(java.util.HashMap) TreePath(org.eclipse.jface.viewers.TreePath) CoreException(org.eclipse.core.runtime.CoreException) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Analysis(org.talend.dataquality.analysis.Analysis) ArrayList(java.util.ArrayList) List(java.util.List) DQRespositoryView(org.talend.dataprofiler.core.ui.views.DQRespositoryView) ReportAnalysisRepNode(org.talend.dq.nodes.ReportAnalysisRepNode) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) IFolder(org.eclipse.core.resources.IFolder)

Example 63 with Analysis

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

the class AnalysisHelper method getAnalysisUUID.

/**
 * Get Analysis uuid by indicator
 *
 * @param indicator
 * @return
 */
public static String getAnalysisUUID(Indicator indicator) {
    Analysis analysis = getAnalysis(indicator);
    String analysisUUID = null;
    if (analysis != null) {
        analysisUUID = ResourceHelper.getUUID(analysis);
    }
    return analysisUUID;
}
Also used : Analysis(org.talend.dataquality.analysis.Analysis)

Example 64 with Analysis

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

the class AnalysisHelper method createAnalysis.

/**
 * Method "createAnalysis".
 *
 * @param name the name of the analysis
 * @return the new analysis with the given name
 */
public static Analysis createAnalysis(String name) {
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    analysis.setName(name);
    return analysis;
}
Also used : Analysis(org.talend.dataquality.analysis.Analysis)

Example 65 with Analysis

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

the class EObjectHelper method getFirstDependency.

/**
 * get the first Dependency of node(only used for METADATA_CON_TABLE and METADATA_CON_VIEW).
 *
 * @param node
 * @return
 */
public static List<ModelElement> getFirstDependency(IRepositoryNode node) {
    List<ModelElement> result = new ArrayList<ModelElement>();
    if (node == null) {
        return result;
    }
    // use the connection supplier to get analyses, and then check them when they use the droped table
    // get the connection
    ModelElement deleteModel = RepositoryNodeHelper.getMetadataElement(node);
    Connection connection = ModelElementHelper.getConnection(deleteModel);
    if (connection == null) {
        return result;
    }
    // get the supplier Dependency of the connection
    EList<Dependency> supplierDependency = connection.getSupplierDependency();
    if (supplierDependency != null && supplierDependency.size() > 0) {
        EList<ModelElement> clients = supplierDependency.get(0).getClient();
        for (ModelElement client : clients) {
            if (!(client instanceof Analysis)) {
                continue;
            }
            Analysis analysis = (Analysis) client;
            if (analysis.eIsProxy()) {
                analysis = (Analysis) EObjectHelper.resolveObject(analysis);
            }
            AnalysisContext context = analysis.getContext();
            EList<ModelElement> analysedElements = context.getAnalysedElements();
            if (analysedElements != null && analysedElements.size() > 0) {
                ModelElement analysisModel = null;
                ModelElement firstAnalysisElement = analysedElements.get(0);
                if (firstAnalysisElement instanceof MetadataColumn) {
                    analysisModel = ModelElementHelper.getContainer(firstAnalysisElement);
                } else if (firstAnalysisElement instanceof MetadataTable) {
                    analysisModel = firstAnalysisElement;
                }
                if (compareModelElement(deleteModel, analysisModel)) {
                    result.add(analysis);
                    break;
                }
            }
        }
    }
    return result;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Analysis(org.talend.dataquality.analysis.Analysis) ArrayList(java.util.ArrayList) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Dependency(orgomg.cwm.objectmodel.core.Dependency) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext)

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