Search in sources :

Example 1 with AnalysisMap

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

the class RepNodeUtilsTest method testUpdateJrxmlRelatedReportIPath_2.

/**
 * Test for rename case: not change the jrxml source in the report which NOT use it. Test method for
 * {@link org.talend.dataprofiler.core.ui.utils.RepNodeUtils#updateJrxmlRelatedReport(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath)}
 * .
 */
@Test
public void testUpdateJrxmlRelatedReportIPath_2() {
    // $NON-NLS-1$
    String jrxmlPath = "TDQ_Libraries/JRXML Template/column/column_0.1.jrxml";
    // before update, the jrxml in the report
    for (AnalysisMap anaMap : realReport.getAnalysisMap()) {
        Assert.assertTrue(anaMap.getJrxmlSource().equals(oldJrxmlPath));
    }
    RepNodeUtils.updateJrxmlRelatedReport(new Path(jrxmlPath), new Path(newJrxmlPath));
    // jrxml.
    for (AnalysisMap anaMap : realReport.getAnalysisMap()) {
        Assert.assertTrue(anaMap.getJrxmlSource().equals(oldJrxmlPath));
    }
}
Also used : Path(org.eclipse.core.runtime.Path) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with AnalysisMap

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

the class RepNodeUtilsTest method setUp.

/**
 * can not use the real project to test, because the method RepositoryNodeHelper.getDataProfilingFolderNode will use
 * the UI view to fetch the node. so , can only mock for this test. The report and its analysismap with jrxml is
 * real created, not mocked object.
 *
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // create a report with user defined jrxml
    // $NON-NLS-1$
    realReport = ReportHelper.createReport("report20130124");
    AnalysisMap analysisMap = ReportsFactory.eINSTANCE.createAnalysisMap();
    analysisMap.setReportType(ReportHelper.ReportType.USER_MADE.getLabel());
    // $NON-NLS-1$
    analysisMap.setAnalysis(AnalysisHelper.createAnalysis("analysis20130124"));
    analysisMap.setJrxmlSource(oldJrxmlPath);
    realReport.getAnalysisMap().add(analysisMap);
    List<ReportRepNode> repNodes = new ArrayList<ReportRepNode>();
    ReportRepNode repNode = mock(ReportRepNode.class);
    repNodes.add(repNode);
    IRepositoryViewObject view = mock(IRepositoryViewObject.class);
    Property prop = mock(Property.class);
    Item item = mock(Item.class);
    when(prop.getItem()).thenReturn(item);
    when(view.getProperty()).thenReturn(prop);
    when(repNode.getObject()).thenReturn(view);
    when(repNode.getReport()).thenReturn(realReport);
    ProjectManager manager = mock(ProjectManager.class);
    // $NON-NLS-1$
    stub(method(ProjectManager.class, "getInstance")).toReturn(manager);
    Project project = mock(Project.class);
    when(manager.getCurrentProject()).thenReturn(project);
    PowerMockito.mock(ResourceManager.class);
    IProject iproject = mock(IProject.class);
    // $NON-NLS-1$
    when(iproject.getLocation()).thenReturn(new Path("/opt/runtime/tdqee/a1/"));
    // $NON-NLS-1$
    stub(method(ResourceManager.class, "getRootProject")).toReturn(iproject);
    IFile ifile = mock(IFile.class);
    when(iproject.getFile(newJrxmlPath)).thenReturn(ifile);
    // $NON-NLS-1$
    when(ifile.getLocation()).thenReturn(new Path("/opt/runtime/tdqee/a1/" + newJrxmlPath));
    PowerMockito.mockStatic(ModelElementHelper.class);
    IFile ifile2 = mock(IFile.class);
    when(ModelElementHelper.getIFile(realReport)).thenReturn(ifile2);
    when(ifile2.getLocation()).thenReturn(// $NON-NLS-1$
    new Path("/opt/runtime/tdqee/a1/TDQ_Data Profiling/Reports/report20130124_0.1.rep"));
    IFile ifile3 = mock(IFile.class);
    when(iproject.getFile(moveJrxmlPath)).thenReturn(ifile3);
    // $NON-NLS-1$
    when(ifile3.getLocation()).thenReturn(new Path("/opt/runtime/tdqee/a1/" + moveJrxmlPath));
    PowerMockito.mock(RepositoryNodeHelper.class);
    IRepositoryNode ReportRootFolderNode = mock(IRepositoryNode.class);
    // $NON-NLS-1$
    stub(method(RepositoryNodeHelper.class, "getDataProfilingFolderNode", EResourceConstant.class)).toReturn(ReportRootFolderNode);
    // $NON-NLS-1$
    stub(method(RepositoryNodeHelper.class, "getReportRepNodes", IRepositoryNode.class, boolean.class, boolean.class)).toReturn(repNodes);
    ProxyRepositoryFactory repFactory = mock(ProxyRepositoryFactory.class);
    PowerMockito.mockStatic(ProxyRepositoryFactory.class);
    when(ProxyRepositoryFactory.getInstance()).thenReturn(repFactory);
    // $NON-NLS-1$
    stub(method(ProxyRepositoryFactory.class, "save", Project.class, Item.class, boolean.class));
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) ProjectManager(org.talend.repository.ProjectManager) Item(org.talend.core.model.properties.Item) IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ReportRepNode(org.talend.dq.nodes.ReportRepNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) Property(org.talend.core.model.properties.Property) Before(org.junit.Before)

Example 3 with AnalysisMap

use of org.talend.dataquality.reports.AnalysisMap 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 4 with AnalysisMap

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

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

the class RepNodeUtils method updateJrxmlRelatedReport.

/**
 * when the report's user defined template(Jrxml file) changed its name, or be moved, the path info in the report's
 * anaMap: jrxml source should also be updated. This method is used to update the related reports when the jrxml
 * name or path is changed.
 *
 * @param jrxmlFileNames : the whole path with whole name of the jrxml, e.g./TDQ_Libraries/JRXML
 * Template/columnset/column_set_basic_0.1.jrxml
 * @param jrxmlFileNamesAfterMove
 */
public static void updateJrxmlRelatedReport(List<String> jrxmlFileNames, List<String> jrxmlFileNamesAfterMove) {
    if (jrxmlFileNames.size() == 0 || jrxmlFileNamesAfterMove.size() == 0 || jrxmlFileNamesAfterMove.size() < jrxmlFileNames.size()) {
        return;
    }
    Project project = ProjectManager.getInstance().getCurrentProject();
    // get all reports
    IRepositoryNode ReportRootFolderNode = RepositoryNodeHelper.getDataProfilingFolderNode(EResourceConstant.REPORTS);
    List<ReportRepNode> repNodes = RepositoryNodeHelper.getReportRepNodes(ReportRootFolderNode, true, true);
    // go through every report to :if any one used current jrxml-->modify its jrxml resource name
    for (ReportRepNode report : repNodes) {
        boolean isUpdated = false;
        EList<AnalysisMap> analysisMap = ((TdReport) report.getReport()).getAnalysisMap();
        for (AnalysisMap anaMap : analysisMap) {
            for (int i = 0; i < jrxmlFileNames.size(); i++) {
                String oldPath = jrxmlFileNames.get(i);
                if (isUsedByJrxml(new Path(oldPath), anaMap)) {
                    // like: ../../../TDQ_Libraries/JRXML Template/column1/b01_column_basic_0.1.jrxml
                    String newPath = getRelativeJrxmlPath(report.getReport(), jrxmlFileNamesAfterMove.get(i));
                    // Added 20130128, using event/listener to refresh the page if opening
                    EventManager.getInstance().publish(report, EventEnum.DQ_JRXML_RENAME, newPath);
                    // save the new jrxml path.
                    anaMap.setJrxmlSource(newPath);
                    isUpdated = true;
                }
            }
        }
        if (isUpdated) {
            try {
                ProxyRepositoryFactory.getInstance().save(project, report.getObject().getProperty().getItem());
            } catch (PersistenceException e) {
                // $NON-NLS-1$
                MessageUI.openError(DefaultMessagesImpl.getString("RepNodeUtils.updateReport.fail", report.getLabel()));
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Project(org.talend.core.model.general.Project) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ReportRepNode(org.talend.dq.nodes.ReportRepNode) TdReport(org.talend.dataquality.reports.TdReport) PersistenceException(org.talend.commons.exception.PersistenceException) AnalysisMap(org.talend.dataquality.reports.AnalysisMap)

Aggregations

AnalysisMap (org.talend.dataquality.reports.AnalysisMap)18 TdReport (org.talend.dataquality.reports.TdReport)8 IPath (org.eclipse.core.runtime.IPath)5 Analysis (org.talend.dataquality.analysis.Analysis)5 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)5 ArrayList (java.util.ArrayList)4 Path (org.eclipse.core.runtime.Path)4 EList (org.eclipse.emf.common.util.EList)3 ReportType (org.talend.dataquality.helpers.ReportHelper.ReportType)3 ReportRepNode (org.talend.dq.nodes.ReportRepNode)3 IRepositoryNode (org.talend.repository.model.IRepositoryNode)3 IFile (org.eclipse.core.resources.IFile)2 Project (org.talend.core.model.general.Project)2 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 Item (org.talend.core.model.properties.Item)2 Property (org.talend.core.model.properties.Property)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 TDQReportItem (org.talend.dataquality.properties.TDQReportItem)2 ReturnCode (org.talend.utils.sugars.ReturnCode)2 File (java.io.File)1