use of org.talend.dq.writer.impl.IndicatorDefinitionWriter in project tdq-studio-se by Talend.
the class FileSystemImportWriterTest method testMergeSystemIndicator.
/**
* Test method for
* {@link org.talend.dataprofiler.core.ui.imex.model.FileSystemImportWriter#mergeSystemIndicator(org.talend.dataprofiler.core.ui.imex.model.ItemRecord, org.talend.dataquality.indicators.definition.IndicatorDefinition)}
* .
*/
@Test
public void testMergeSystemIndicator() {
ItemRecord mockItem = mock(ItemRecord.class);
TDQIndicatorDefinitionItem siItem = PropertiesFactory.eINSTANCE.createTDQIndicatorDefinitionItem();
Property siProp = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
IndicatorDefinition SIdef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
siItem.setIndicatorDefinition(SIdef);
siItem.setProperty(siProp);
IndicatorDefinition importedDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
// make mockItem has: one new template, one modified newer template, one modified older template.
// $NON-NLS-1$ //$NON-NLS-2$
TdExpression e0 = BooleanExpressionHelper.createTdExpression("new", "new body");
// $NON-NLS-1$
e0.setModificationDate("20130101");
// $NON-NLS-1$ //$NON-NLS-2$
TdExpression e1 = BooleanExpressionHelper.createTdExpression("tem_1", "modified newer body");
// $NON-NLS-1$
e1.setModificationDate("20130101");
// $NON-NLS-1$ //$NON-NLS-2$
TdExpression e2 = BooleanExpressionHelper.createTdExpression("tem_2", "modified older body");
// $NON-NLS-1$
e2.setModificationDate("20110101");
importedDef.getSqlGenericExpression().add(e0);
importedDef.getSqlGenericExpression().add(e1);
importedDef.getSqlGenericExpression().add(e2);
when(mockItem.getElement()).thenReturn(importedDef);
// $NON-NLS-1$ //$NON-NLS-2$
TdExpression e3 = BooleanExpressionHelper.createTdExpression("tem_1", "should be replaced");
// $NON-NLS-1$
e3.setModificationDate("20120101");
// $NON-NLS-1$ //$NON-NLS-2$
TdExpression e4 = BooleanExpressionHelper.createTdExpression("tem_2", "should keep this");
// $NON-NLS-1$
e4.setModificationDate("20120101");
SIdef.getSqlGenericExpression().add(e3);
SIdef.getSqlGenericExpression().add(e4);
ReturnCode rc = mock(ReturnCode.class);
when(rc.isOk()).thenReturn(true);
ElementWriterFactory ewFactory = mock(ElementWriterFactory.class);
IndicatorDefinitionWriter indWriter = mock(IndicatorDefinitionWriter.class);
when(indWriter.save(siItem, false)).thenReturn(rc);
// $NON-NLS-1$
stub(method(ElementWriterFactory.class, "getInstance")).toReturn(ewFactory);
when(ewFactory.createIndicatorDefinitionWriter()).thenReturn(indWriter);
// before merge
Assert.assertEquals(SIdef.getSqlGenericExpression().size(), 2);
writer.mergeSystemIndicator(mockItem, siItem);
// after merge
Assert.assertEquals(SIdef.getSqlGenericExpression().size(), 3);
for (TdExpression ex : SIdef.getSqlGenericExpression()) {
if (ex.getLanguage().equals("new")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("new body", ex.getBody());
} else if (ex.getLanguage().equals("tem_1")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("modified newer body", ex.getBody());
} else if (ex.getLanguage().equals("tem_2")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("should keep this", ex.getBody());
}
}
// other type?not SI
}
use of org.talend.dq.writer.impl.IndicatorDefinitionWriter in project tdq-studio-se by Talend.
the class AElementPersistanceRealTest method testCreateItemIndicatorDefinition.
/**
* Test method for
* {@link org.talend.dq.writer.AElementPersistance#createItem(orgomg.cwm.objectmodel.core.ModelElement)}.
*/
@Test
public void testCreateItemIndicatorDefinition() {
IndicatorDefinitionWriter createIndicatorDefinitionWriter = ElementWriterFactory.getInstance().createIndicatorDefinitionWriter();
// test normal name
// $NON-NLS-1$
String indDefName = "indDef1";
// $NON-NLS-1$
String exceptedFileName = indDefName + "_0.1.definition";
IndicatorDefinition createIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
createIndicatorDefinition.setName(indDefName);
Item createItem = createIndicatorDefinitionWriter.createItem(createIndicatorDefinition);
assertTrue(createItem instanceof TDQIndicatorDefinitionItem);
TDQIndicatorDefinitionItem indDefItem = (TDQIndicatorDefinitionItem) createItem;
assertTrue(indDefItem.getFilename().equals(exceptedFileName));
// test special name
// $NON-NLS-1$
String indDefName2 = "indDef1'¥‘”、《,》<> ";
// $NON-NLS-1$
String exceptedFileName2 = "indDef1____________0.1.definition";
IndicatorDefinition createIndicatorDefinition2 = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
createIndicatorDefinition2.setName(indDefName2);
Item createItem2 = createIndicatorDefinitionWriter.createItem(createIndicatorDefinition2);
assertTrue(createItem2 instanceof TDQIndicatorDefinitionItem);
TDQIndicatorDefinitionItem indDefItem2 = (TDQIndicatorDefinitionItem) createItem2;
assertTrue(indDefItem2.getFilename().equals(exceptedFileName2));
}
use of org.talend.dq.writer.impl.IndicatorDefinitionWriter 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;
}
Aggregations