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));
}
}
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));
}
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;
}
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());
}
}
}
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()));
}
}
}
}
Aggregations