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