Search in sources :

Example 36 with Analysis

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

the class ResourceDropAdapterAssistant method handleDrop.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop (org.eclipse.ui.navigator.CommonDropAdapter,
     * org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object)
     */
@Override
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object target) {
    // alwaysOverwrite = false;
    if (aDropAdapter.getCurrentTarget() == null || aDropTargetEvent.data == null) {
        return Status.CANCEL_STATUS;
    }
    // IStatus status = null;
    IResource[] resources = null;
    TransferData currentTransfer = aDropAdapter.getCurrentTransfer();
    if (LocalSelectionTransfer.getTransfer().isSupportedType(currentTransfer)) {
        resources = getSelectedResources();
    } else if (ResourceTransfer.getInstance().isSupportedType(currentTransfer)) {
        resources = (IResource[]) aDropTargetEvent.data;
    }
    if ((target instanceof IFile)) {
        // && dropRep
        TdReport findReport = RepResourceFileHelper.getInstance().findReport(((IFile) target));
        List<Analysis> analyses = ReportHelper.getAnalyses(findReport);
        Map<String, Analysis> resourcesMap = new HashMap<String, Analysis>();
        for (Analysis ana : analyses) {
            String uriString = ana.eResource().getURI().toString();
            resourcesMap.put(uriString, ana);
        }
        if (resources != null && resources.length > 0) {
            List<Analysis> anaList = new ArrayList<Analysis>();
            for (IResource res : resources) {
                Analysis findAnalysis = AnaResourceFileHelper.getInstance().findAnalysis((IFile) res);
                if (findAnalysis != null) {
                    String uriKey = findAnalysis.eResource().getURI().toString();
                    if (resourcesMap.containsKey(uriKey)) {
                        findReport.removeAnalysis(resourcesMap.get(uriKey));
                    }
                    anaList.add(findAnalysis);
                }
            }
            // ReportHelper.addAnalyses(anaList, findReport);
            RepResourceFileHelper.getInstance().save(findReport);
        }
    } else if (resources != null && (target instanceof IFolder)) {
        // && dropSql
        IFolder folder = (IFolder) target;
        // IPath location = folder.getFullPath();
        for (IResource res : resources) {
            if (res.getType() != IResource.FILE) {
                return null;
            }
            if (folder.equals(res.getParent())) {
                continue;
            }
            String name = res.getName();
            IFile fileRes = (IFile) res;
            IFile movedIFile = folder.getFile(name);
            if (!FactoriesUtil.isEmfFile(fileRes.getFileExtension())) {
                try {
                    fileRes.move(movedIFile.getFullPath(), false, null);
                    fileRes.getParent().refreshLocal(IResource.DEPTH_INFINITE, null);
                    folder.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (CoreException e) {
                    ExceptionHandler.process(e);
                }
                return Status.OK_STATUS;
            }
            IContainer srcParent = fileRes.getParent();
            URI srcUri = URI.createPlatformResourceURI((fileRes).getFullPath().toString(), false);
            Resource resource = EMFSharedResources.getInstance().getResource(srcUri, true);
            if (resource != null) {
                URI desUri = URI.createPlatformResourceURI(folder.getFullPath().toString(), false);
                EMFSharedResources.getInstance().saveToUri(resource, desUri);
                // ADD xqliu 2010-09-21 bug 15685
                IFile propertyFile = PropertyHelper.getPropertyFile(fileRes);
                if (propertyFile != null) {
                    IFile movedPropertyFile = folder.getFile(propertyFile.getName());
                    try {
                        propertyFile.move(movedPropertyFile.getFullPath(), true, null);
                    } catch (CoreException e) {
                        ExceptionHandler.process(e);
                    }
                }
            // ~ 15685
            }
            try {
                closeEditorIfOpened(fileRes);
                fileRes.delete(true, null);
                srcParent.refreshLocal(IResource.DEPTH_INFINITE, null);
                folder.refreshLocal(IResource.DEPTH_INFINITE, null);
                // ADD xqliu 2010-09-25 bug 15685 update the path of ItemState
                Property property = PropertyHelper.getProperty(PropertyHelper.getPropertyFile(movedIFile));
                property.getItem().getState().setPath(PropertyHelper.computePath(property));
            // ~ 15685
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
            movedIFile = folder.getFile(name);
        }
    }
    ProxyRepositoryManager.getInstance().save();
    CorePlugin.getDefault().refreshDQView();
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) TdReport(org.talend.dataquality.reports.TdReport) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) CoreException(org.eclipse.core.runtime.CoreException) TransferData(org.eclipse.swt.dnd.TransferData) Analysis(org.talend.dataquality.analysis.Analysis) IContainer(org.eclipse.core.resources.IContainer) Property(org.talend.core.model.properties.Property) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 37 with Analysis

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

the class ItemRecord method computeDependencies.

/**
 * DOC bZhou Comment method "computeDependencies".
 */
private void computeDependencies(ModelElement mElement) {
    if (isJRXml()) {
        Collection<TdReport> allReports = (Collection<TdReport>) RepResourceFileHelper.getInstance().getAllElement();
        for (TdReport report : allReports) {
            // MOD yyi 2012-02-20 TDQ-4545 TDQ-4701: Change to relative path comparing.
            IPath pathRepFile = RepResourceFileHelper.findCorrespondingFile(report).getLocation();
            IPath pathJrxmlFile = new Path(file.getPath());
            String path = pathJrxmlFile.makeRelativeTo(pathRepFile).toString();
            for (AnalysisMap anaMap : report.getAnalysisMap()) {
                if (StringUtils.equals(path, anaMap.getJrxmlSource())) {
                    // TODO the File is jrxml, but the ModelElement is report ???
                    this.dependencySet.add(file);
                }
            }
        }
    } else if (mElement != null) {
        if (mElement instanceof Connection) {
            includeContextDependency((Connection) mElement);
            return;
        }
        List<File> dependencyFile = getClintDependencyForExport(mElement);
        for (File df : dependencyFile) {
            ModelElement modelElement = getElement(df);
            if (modelElement != null) {
                File depFile = EObjectHelper.modelElement2File(modelElement);
                if (depFile != null) {
                    this.dependencySet.add(depFile);
                }
                // MOD sizhaoliu 2013-04-13 TDQ-7082
                if (modelElement instanceof IndicatorDefinition) {
                    if (modelElement instanceof UDIndicatorDefinition) {
                        includeJUDIDependencies((IndicatorDefinition) modelElement);
                    } else {
                        for (IndicatorDefinition definition : ((IndicatorDefinition) modelElement).getAggregatedDefinitions()) {
                            includeAggregatedDependencies(definition);
                        }
                    }
                }
            }
        }
        // MOD yyi 2012-02-20 TDQ-4545 TDQ-4701: Map user define jrxm templates with report.
        if (mElement instanceof TdReport) {
            TdReport rep = (TdReport) mElement;
            for (AnalysisMap anaMap : rep.getAnalysisMap()) {
                ReportType reportType = ReportHelper.ReportType.getReportType(anaMap.getAnalysis(), anaMap.getReportType());
                boolean isUserMade = ReportHelper.ReportType.USER_MADE.equals(reportType);
                if (isUserMade) {
                    traverseFolderAndAddJrxmlDependencies(getJrxmlFolderFromReport(rep, ResourceManager.getJRXMLFolder()));
                }
            }
        } else if (mElement instanceof IndicatorDefinition) {
            // MOD sizhaoliu 2013-04-13 TDQ-7082
            IndicatorDefinition definition = (IndicatorDefinition) mElement;
            if (definition instanceof UDIndicatorDefinition) {
                includeJUDIDependencies(definition);
            } else {
                for (IndicatorDefinition defInd : definition.getAggregatedDefinitions()) {
                    includeAggregatedDependencies(defInd);
                }
            }
            // folder
            if (mElement instanceof MatchRuleDefinition) {
                includeCustomMatcherJarDependencies((MatchRuleDefinition) mElement);
            }
        } else if (mElement instanceof Analysis && AnalysisType.MATCH_ANALYSIS == AnalysisHelper.getAnalysisType((Analysis) mElement)) {
            includeCustomMatcherJarDependencies((Analysis) mElement);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdReport(org.talend.dataquality.reports.TdReport) Connection(org.talend.core.model.metadata.builder.connection.Connection) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) Collection(java.util.Collection) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) File(java.io.File) ReportType(org.talend.dataquality.helpers.ReportHelper.ReportType)

Example 38 with Analysis

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

the class ItemRecord method getClintDependencyForExport.

/**
 * @param mElement
 * @return SupplierDependency
 *
 * getClintDependency here will contain system indicators so only will be used by export case
 */
public List<File> getClintDependencyForExport(ModelElement mElement) {
    List<File> result = new ArrayList<File>();
    if (mElement != null) {
        result = iterateClientDependencies(mElement);
        // current object is analysis case
        if (mElement instanceof Analysis) {
            result.addAll(getSystemIndicaotrOfAnalysis(mElement));
        } else {
            // if object is report, then the analyses inside reports should be considered. The system indicators of
            // analyses should be added into the result list too.
            List<File> tempList = new ArrayList<File>();
            tempList.addAll(result);
            for (File tempFile : tempList) {
                ModelElement me = getElement(tempFile);
                if (me != null && me instanceof Analysis) {
                    result.addAll(getSystemIndicaotrOfAnalysis(me));
                }
            }
        }
    }
    return result;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) ArrayList(java.util.ArrayList) File(java.io.File)

Example 39 with Analysis

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

the class ItemRecord method getSystemIndicaotrOfAnalysis.

/**
 * get Analysis Dependency (for indicator only).
 *
 * @return get the list of indicator which in use by the analysis
 */
private List<File> getSystemIndicaotrOfAnalysis(ModelElement mElement) {
    List<File> listFile = new ArrayList<File>();
    if (mElement instanceof Analysis) {
        Analysis anaElement = (Analysis) mElement;
        List<Indicator> indicators = IndicatorHelper.getIndicators(anaElement.getResults());
        for (Indicator indicator : indicators) {
            if (indicator instanceof UserDefIndicator) {
                // whereRuleIndicator or UDIIndicator
                continue;
            }
            boolean isContain = false;
            IndicatorDefinition newIndicatorDefinition = indicator.getIndicatorDefinition();
            // MOD qiongli 2012-5-11 TDQ-5256
            if (newIndicatorDefinition == null) {
                continue;
            }
            for (File lf : listFile) {
                ModelElement me = getElement(lf);
                if (me != null && me instanceof IndicatorDefinition) {
                    IndicatorDefinition oldIndicatorDefinition = (IndicatorDefinition) me;
                    if (ModelElementHelper.compareUUID(oldIndicatorDefinition, newIndicatorDefinition)) {
                        isContain = true;
                        break;
                    }
                }
            }
            if (!isContain) {
                File depFile = EObjectHelper.modelElement2File(newIndicatorDefinition);
                if (depFile != null) {
                    FILE_ELEMENT_MAP.put(depFile, newIndicatorDefinition);
                    listFile.add(depFile);
                }
            }
        }
    }
    return listFile;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) ArrayList(java.util.ArrayList) File(java.io.File) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator)

Example 40 with Analysis

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

the class RespositoryDetailView method createFileDetail.

private boolean createFileDetail(boolean is, IFile fe2) {
    if (fe2.getFileExtension().equals(FactoriesUtil.PATTERN)) {
        Pattern pattern = PatternResourceFileHelper.getInstance().findPattern(fe2);
        createPatternDetail(pattern);
        is = false;
    } else if (fe2.getFileExtension().equals(FactoriesUtil.ANA)) {
        Analysis ana = AnaResourceFileHelper.getInstance().findAnalysis(fe2);
        createAnaysisDetail(ana);
        is = false;
    } else if (fe2.getFileExtension().equals(FactoriesUtil.REP)) {
        TdReport rep = RepResourceFileHelper.getInstance().findReport(fe2);
        createReportDetail(rep);
        is = false;
    } else if (fe2.getFileExtension().equals(FactoriesUtil.SQL)) {
        createSqlFileDetail(fe2);
        is = false;
    }
    return is;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) Analysis(org.talend.dataquality.analysis.Analysis) TdReport(org.talend.dataquality.reports.TdReport)

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