Search in sources :

Example 1 with TdReport

use of org.talend.dataquality.reports.TdReport in project tdq-studio-se by Talend.

the class AElementPersistanceRealTest method testSaveWithoutDependenciesReport.

/**
 * Test method for
 * {@link org.talend.dq.writer.AElementPersistance#saveWithoutDependencies(org.talend.core.model.properties.Item, orgomg.cwm.objectmodel.core.ModelElement)}
 * .
 *
 * @throws PersistenceException
 */
@Test
public void testSaveWithoutDependenciesReport() throws PersistenceException {
    ReportWriter createReportWriter = ElementWriterFactory.getInstance().createReportWriter();
    // create analysis
    Analysis createAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    createAnalysis.setResults(createAnalysisResult);
    // $NON-NLS-1$
    createAnalysis.setName("AElementPersistanceRealTestanalysis6");
    // create analysis item
    TDQAnalysisItem createTDQAnalysisItem = PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
    createTDQAnalysisItem.setAnalysis(createAnalysis);
    Property createAnalysisProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    // $NON-NLS-1$
    createAnalysisProperty.setLabel("AElementPersistanceRealTestanalysis6");
    createAnalysisProperty.setId(EcoreUtil.generateUUID());
    createTDQAnalysisItem.setProperty(createAnalysisProperty);
    ProxyRepositoryFactory.getInstance().create(createTDQAnalysisItem, Path.EMPTY, false);
    // create report
    TdReport createTdReport = ReportsFactory.eINSTANCE.createTdReport();
    TDQReportItem createTDQReportItem = PropertiesFactory.eINSTANCE.createTDQReportItem();
    createTDQReportItem.setReport(createTdReport);
    Property createReportProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    // $NON-NLS-1$
    createReportProperty.setLabel("AElementPersistanceRealTestreport6");
    createTDQReportItem.setProperty(createReportProperty);
    createReportProperty.setId(EcoreUtil.generateUUID());
    ProxyRepositoryFactory.getInstance().create(createTDQReportItem, Path.EMPTY, false);
    createTdReport.addAnalysis(createAnalysis);
    // $NON-NLS-1$
    String repName = "rep61";
    // $NON-NLS-1$
    String exceptedFileName = repName + "_0.1.rep";
    createTdReport.setName(repName);
    ReturnCode create = createReportWriter.saveWithoutDependencies(createTDQReportItem, createTdReport);
    assertTrue(create.isOk());
    Assert.assertEquals(exceptedFileName, createTDQReportItem.getFilename());
    // $NON-NLS-1$
    String repName2 = "rep62";
    // $NON-NLS-1$
    String exceptedFileName2 = repName2 + "_0.1.rep";
    createTdReport.setName(repName2);
    create = createReportWriter.saveWithDependencies(createTDQReportItem, createTdReport);
    assertTrue(create.isOk());
    Assert.assertEquals(exceptedFileName2, createTDQReportItem.getFilename());
}
Also used : ReportWriter(org.talend.dq.writer.impl.ReportWriter) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) TdReport(org.talend.dataquality.reports.TdReport) Property(org.talend.core.model.properties.Property) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Test(org.junit.Test)

Example 2 with TdReport

use of org.talend.dataquality.reports.TdReport in project tdq-studio-se by Talend.

the class RepResourceFileHelper method getAnalysisFilesFromReport.

/**
 * DOC bZhou Comment method "getAnalysisFilesFromReport".
 *
 * Get all analysis files used by a Report.
 *
 * @param report
 * @return
 */
public List<IFile> getAnalysisFilesFromReport(Report report) {
    List<IFile> analysisFiles = new ArrayList<IFile>();
    // MOD yyin 20120530 TDQ-5050
    for (AnalysisMap anaMap : ((TdReport) report).getAnalysisMap()) {
        Analysis analysis = anaMap.getAnalysis();
        analysisFiles.add(ResourceFileMap.findCorrespondingFile(analysis));
    }
    return analysisFiles;
}
Also used : IFile(org.eclipse.core.resources.IFile) Analysis(org.talend.dataquality.analysis.Analysis) TdReport(org.talend.dataquality.reports.TdReport) ArrayList(java.util.ArrayList) AnalysisMap(org.talend.dataquality.reports.AnalysisMap)

Example 3 with TdReport

use of org.talend.dataquality.reports.TdReport in project tdq-studio-se by Talend.

the class ContextHelper method getOutputFolderFromReports.

/**
 * if all the reports have the same output folder return it, else return null.
 *
 * @param reports
 * @return the context var or real string or null
 */
public static String getOutputFolderFromReports(List<TdReport> reports) {
    String result = null;
    if (reports != null && !reports.isEmpty()) {
        if (reports.size() == 1) {
            TdReport report = reports.get(0);
            String ofName = ReportHelper.getOutputFolderNameAssinged(report);
            if (StringUtils.isNotBlank(ofName) && StringUtils.isNotBlank(ContextHelper.getReportContextValue(report, ofName))) {
                result = ofName;
            }
        } else {
            boolean isContextMode = true;
            String contextVar = null;
            Set<String> temp = new HashSet<String>();
            for (TdReport report : reports) {
                String ofNameAssinged = ReportHelper.getOutputFolderNameAssinged(report);
                // so just return null
                if (StringUtils.isBlank(ofNameAssinged) || StringUtils.isBlank(ContextHelper.getReportContextValue(report, ofNameAssinged))) {
                    return null;
                }
                contextVar = ofNameAssinged;
                if (isContextMode) {
                    isContextMode = ContextHelper.isContextVar(ofNameAssinged);
                }
                String ofName = ContextHelper.getReportContextValue(report, ofNameAssinged);
                if (StringUtils.isNotBlank(ofName)) {
                    temp.add(ofName);
                }
            }
            if (temp.size() == 1) {
                if (isContextMode) {
                    result = contextVar;
                } else {
                    result = temp.iterator().next();
                }
            }
        }
    }
    return result;
}
Also used : TdReport(org.talend.dataquality.reports.TdReport) HashSet(java.util.HashSet)

Example 4 with TdReport

use of org.talend.dataquality.reports.TdReport in project tdq-studio-se by Talend.

the class LocalRepositoryObjectCRUD method relocateJrxmlTemplates.

/**
 * update user define jrxml template path.
 *
 * @param sourceNode
 * @param targetNode
 * @link {@link #moveReportRepNode(IRepositoryNode, IRepositoryNode)}
 */
private void relocateJrxmlTemplates(IRepositoryNode sourceNode, IRepositoryNode targetNode) {
    IPath targetPath = RepositoryNodeHelper.getPath(targetNode);
    IFolder targetFolder = ResourceManager.getRootProject().getFolder(targetPath);
    TdReport rep = (TdReport) RepositoryNodeHelper.getModelElementFromRepositoryNode(sourceNode);
    IPath jrxmlPath = null;
    IPath relativePath = null;
    ReportType reportType = null;
    for (AnalysisMap anaMap : rep.getAnalysisMap()) {
        reportType = ReportHelper.ReportType.getReportType(anaMap.getAnalysis(), anaMap.getReportType());
        // Relocate the jrxml template path for user define type.
        if (ReportHelper.ReportType.USER_MADE.equals(reportType)) {
            jrxmlPath = RepResourceFileHelper.findCorrespondingFile(rep).getParent().getLocation().append(anaMap.getJrxmlSource());
            // $NON-NLS-1$
            relativePath = jrxmlPath.makeRelativeTo(targetFolder.getLocation().append("/"));
            anaMap.setJrxmlSource(relativePath.toString());
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) TdReport(org.talend.dataquality.reports.TdReport) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) ReportType(org.talend.dataquality.helpers.ReportHelper.ReportType) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with TdReport

use of org.talend.dataquality.reports.TdReport 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)

Aggregations

TdReport (org.talend.dataquality.reports.TdReport)18 Analysis (org.talend.dataquality.analysis.Analysis)9 AnalysisMap (org.talend.dataquality.reports.AnalysisMap)8 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)7 ArrayList (java.util.ArrayList)5 IPath (org.eclipse.core.runtime.IPath)5 Property (org.talend.core.model.properties.Property)5 TDQReportItem (org.talend.dataquality.properties.TDQReportItem)4 IFile (org.eclipse.core.resources.IFile)3 EList (org.eclipse.emf.common.util.EList)3 Item (org.talend.core.model.properties.Item)3 IFolder (org.eclipse.core.resources.IFolder)2 Path (org.eclipse.core.runtime.Path)2 Test (org.junit.Test)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 Pattern (org.talend.dataquality.domain.pattern.Pattern)2 ReportType (org.talend.dataquality.helpers.ReportHelper.ReportType)2 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)2