Search in sources :

Example 1 with ReportWriter

use of org.talend.dq.writer.impl.ReportWriter 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 ReportWriter

use of org.talend.dq.writer.impl.ReportWriter in project tdq-studio-se by Talend.

the class AElementPersistanceRealTest method testCreateItemReport.

/**
 * Test method for
 * {@link org.talend.dq.writer.AElementPersistance#createItem(orgomg.cwm.objectmodel.core.ModelElement)}.
 */
@Test
public void testCreateItemReport() {
    ReportWriter createReportWriter = ElementWriterFactory.getInstance().createReportWriter();
    // test normal name
    // $NON-NLS-1$
    String repName = "rep1";
    // $NON-NLS-1$
    String exceptedFileName = repName + "_0.1.rep";
    Report createReport = InformationreportingFactory.eINSTANCE.createReport();
    createReport.setName(repName);
    Item createItem = createReportWriter.createItem(createReport);
    assertTrue(createItem instanceof TDQReportItem);
    TDQReportItem reportItem = (TDQReportItem) createItem;
    assertTrue(reportItem.getFilename().equals(exceptedFileName));
    // test special name
    // $NON-NLS-1$
    String repName2 = "rep1#^&";
    // $NON-NLS-1$
    String exceptedFileName2 = "rep1____0.1.rep";
    Report createReport2 = InformationreportingFactory.eINSTANCE.createReport();
    createReport2.setName(repName2);
    Item createItem2 = createReportWriter.createItem(createReport2);
    assertTrue(createItem2 instanceof TDQReportItem);
    TDQReportItem reportItem2 = (TDQReportItem) createItem2;
    assertTrue(reportItem2.getFilename().equals(exceptedFileName2));
}
Also used : TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) ReportWriter(org.talend.dq.writer.impl.ReportWriter) TdReport(org.talend.dataquality.reports.TdReport) Report(orgomg.cwmx.analysis.informationreporting.Report) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) Test(org.junit.Test)

Example 3 with ReportWriter

use of org.talend.dq.writer.impl.ReportWriter in project tdq-studio-se by Talend.

the class TDQResourceChangeHandler method create.

@Override
public Resource create(IProject project, Item item, int classID, IPath path) {
    String fileExtension = FileConstants.ITEM_EXTENSION;
    Resource itemResource = null;
    try {
        switch(classID) {
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_ANALYSIS_ITEM:
                fileExtension = FileConstants.ANA_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT, false, fileExtension);
                AnalysisWriter createAnalysisWrite = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createAnalysisWrite();
                Analysis analysis = ((TDQAnalysisItem) item).getAnalysis();
                createAnalysisWrite.addResourceContent(itemResource, analysis);
                createAnalysisWrite.addDependencies(analysis);
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_REPORT_ITEM:
                fileExtension = FileConstants.REP_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_REPORT_ELEMENT, false, fileExtension);
                ReportWriter createReportWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createReportWriter();
                Report report = ((TDQReportItem) item).getReport();
                createReportWriter.addResourceContent(itemResource, report);
                createReportWriter.addDependencies(report);
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_INDICATOR_DEFINITION_ITEM:
                fileExtension = FileConstants.DEF_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_INDICATOR_ELEMENT, false, fileExtension);
                IndicatorDefinition indicatorDefinition = ((TDQIndicatorDefinitionItem) item).getIndicatorDefinition();
                IndicatorDefinitionWriter createIndicatorDefinitionWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createIndicatorDefinitionWriter();
                createIndicatorDefinitionWriter.addResourceContent(itemResource, indicatorDefinition);
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_PATTERN_ITEM:
                fileExtension = FileConstants.PAT_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_PATTERN_ELEMENT, false, fileExtension);
                Pattern pattern = ((TDQPatternItem) item).getPattern();
                PatternWriter createPatternWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createPatternWriter();
                createPatternWriter.addResourceContent(itemResource, pattern);
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_BUSINESS_RULE_ITEM:
                fileExtension = FileConstants.RULE_EXTENSION;
                // MOD gdbu 2011-6-10 bug : 21823 2011-06-27 revert the error type code by klliu
                DQRule dqrule = ((TDQBusinessRuleItem) item).getDqrule();
                if (dqrule instanceof WhereRule) {
                    itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_RULES_SQL, false, fileExtension);
                } else {
                    itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_RULES_PARSER, false, fileExtension);
                }
                // ~21823
                DQRuleWriter createdRuleWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createdRuleWriter();
                createdRuleWriter.addResourceContent(itemResource, dqrule);
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_JRXML_ITEM:
                fileExtension = FileConstants.JRXML_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_JRAXML_ELEMENT, true, fileExtension);
                itemResource.getContents().add(((TDQFileItem) item).getContent());
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_SOURCE_FILE_ITEM:
                fileExtension = FileConstants.SQL_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT, true, fileExtension);
                itemResource.getContents().add(((TDQFileItem) item).getContent());
                break;
            case org.talend.dataquality.properties.PropertiesPackage.TDQ_MATCH_RULE_ITEM:
                fileExtension = FileConstants.RULE_EXTENSION;
                itemResource = xmiResourceManager.createItemResourceWithExtension(project, item, path, ERepositoryObjectType.TDQ_RULES_MATCHER, false, fileExtension);
                MatchRuleDefinition matchRuleDefinition = ((TDQMatchRuleItem) item).getMatchRule();
                MatchRuleDefinitionWriter matchRuleDefinitionWriter = org.talend.dq.writer.impl.ElementWriterFactory.getInstance().createdMatchRuleWriter();
                matchRuleDefinitionWriter.addResourceContent(itemResource, matchRuleDefinition);
                break;
            default:
        }
    } catch (PersistenceException e) {
        log.error(e, e);
    }
    return itemResource;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Report(orgomg.cwmx.analysis.informationreporting.Report) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) DQRuleWriter(org.talend.dq.writer.impl.DQRuleWriter) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) PatternWriter(org.talend.dq.writer.impl.PatternWriter) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DQRule(org.talend.dataquality.rules.DQRule) ReportWriter(org.talend.dq.writer.impl.ReportWriter) WhereRule(org.talend.dataquality.rules.WhereRule) Analysis(org.talend.dataquality.analysis.Analysis) IndicatorDefinitionWriter(org.talend.dq.writer.impl.IndicatorDefinitionWriter) PersistenceException(org.talend.commons.exception.PersistenceException) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) MatchRuleDefinitionWriter(org.talend.dq.writer.impl.MatchRuleDefinitionWriter) AnalysisWriter(org.talend.dq.writer.impl.AnalysisWriter) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Aggregations

TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)3 TDQReportItem (org.talend.dataquality.properties.TDQReportItem)3 ReportWriter (org.talend.dq.writer.impl.ReportWriter)3 Test (org.junit.Test)2 Analysis (org.talend.dataquality.analysis.Analysis)2 TDQBusinessRuleItem (org.talend.dataquality.properties.TDQBusinessRuleItem)2 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)2 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)2 TdReport (org.talend.dataquality.reports.TdReport)2 Report (orgomg.cwmx.analysis.informationreporting.Report)2 IResource (org.eclipse.core.resources.IResource)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 Item (org.talend.core.model.properties.Item)1 Property (org.talend.core.model.properties.Property)1 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)1 Pattern (org.talend.dataquality.domain.pattern.Pattern)1 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)1 TDQMatchRuleItem (org.talend.dataquality.properties.TDQMatchRuleItem)1 DQRule (org.talend.dataquality.rules.DQRule)1