use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class SimpleStatisticsExplorerTest method testGetQueryMap.
/**
* Test method for {@link org.talend.dq.analysis.explore.SimpleStatisticsExplorer#getQueryMap()}.
*/
@Test
public void testGetQueryMap() {
Analysis ana = UnitTestBuildHelper.createAndInitAnalysis();
TdTable table = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
table.setName("TDQ_CALENDAR");
TdColumn column = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdColumn();
// $NON-NLS-1$
column.setName("CAL_DATE");
TdSqlDataType tdsql = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdSqlDataType();
// $NON-NLS-1$
tdsql.setName("DATE");
tdsql.setJavaDataType(Types.DATE);
column.setSqlDataType(tdsql);
table.getOwnedElement().add(column);
column.setOwner(table);
// create user define indicator
UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
UDIndicatorDefinition indicatorDefinition = UserdefineFactory.eINSTANCE.createUDIndicatorDefinition();
// $NON-NLS-1$
indicatorDefinition.setName("user define");
userDefIndicator.setName(indicatorDefinition.getName());
userDefIndicator.setIndicatorDefinition(indicatorDefinition);
// $NON-NLS-1$
TdExpression newTdExp = BooleanExpressionHelper.createTdExpression("SQL", body, null);
newTdExp.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
indicatorDefinition.getViewRowsExpression().add(newTdExp);
// $NON-NLS-1$ //$NON-NLS-2$
ChartDataEntity chartDataEntity = new ChartDataEntity(userDefIndicator, "2012-06-05", "1");
chartDataEntity.setLabelNull(false);
// $NON-NLS-1$
chartDataEntity.setKey("2012-06-05");
userDefIndicator.setAnalyzedElement(column);
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
createAnalysisResult.setResultMetadata(createExecutionInformations);
createAnalysisResult.getIndicators().add(userDefIndicator);
userDefIndicator.setAnalyzedElement(column);
ana.setResults(createAnalysisResult);
SimpleStatisticsExplorer simpleStatisticsExplorer = new SimpleStatisticsExplorer();
Assert.assertTrue(simpleStatisticsExplorer.setAnalysis(ana));
simpleStatisticsExplorer.setEnitty(chartDataEntity);
Map<String, String> queryMap = simpleStatisticsExplorer.getQueryMap();
assertFalse(queryMap.isEmpty());
assertEquals(1, queryMap.size());
System.err.println(queryMap.get("View rows"));
assertEquals(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"-- Analysis: anaA ;\n" + "-- Type of Analysis: Column Analysis ;\n" + "-- Purpose: ;\n" + "-- Description: ;\n" + "-- AnalyzedElement: CAL_DATE ;\n" + "-- Indicator: user define ;\n" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"-- Showing: View rows ;\n" + "SELECT * FROM TDQ_CALENDAR ", // $NON-NLS-1$ //$NON-NLS-2$
queryMap.get("View rows"));
// test when is not sql engine
ana.getParameters().setExecutionLanguage(ExecutionLanguage.JAVA);
Map<String, String> queryMap_java = simpleStatisticsExplorer.getQueryMap();
assertFalse(queryMap_java.isEmpty());
assertEquals(1, queryMap_java.size());
// $NON-NLS-1$
assertEquals(null, queryMap_java.get("View rows"));
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class IndicatorDefinitionFileHelper method addSqlExpression.
/**
* keep the modify date
*
* @param definition
* @param language
* @param body
* @param modifyDate
* @return
*/
public static boolean addSqlExpression(IndicatorDefinition definition, String language, String body, String modifyDate) {
if (null == definition) {
return false;
}
TdExpression e = BooleanExpressionHelper.createTdExpression(language, body);
e.setModificationDate(modifyDate);
return definition.getSqlGenericExpression().add(e);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class UDIUtils method createNewTdExpression.
/**
* create New TdExpression.
*
* @param language
* @param version
* @param body
* @return
*/
public static TdExpression createNewTdExpression(String language, String version, String body) {
TdExpression newTdExp = BooleanExpressionHelper.createTdExpression(language, body, version);
newTdExp.setModificationDate(getCurrentDateTime());
return newTdExp;
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class FileSystemImportWriter method mergeParserRule.
/**
* for ParserRule: 1) replace the same name old rule with new rule; 2) will keep the old rule if new one don't
* include the same name rule
*
* @param record imported modified parser rule
* @param parserRuleItem the parser rule in the current studio
*/
protected void mergeParserRule(ItemRecord record, TDQBusinessRuleItem parserRuleItem) {
// only when the parser rule is modified, do the save
boolean isModified = false;
// old object
DQRule parserRule = parserRuleItem.getDqrule();
Property parserRuleProp = parserRuleItem.getProperty();
// new object
DQRule recordRule = (DQRule) record.getElement();
Property recordRuleProp = record.getProperty();
// get expression list from record
EList<TdExpression> importedExs = recordRule.getSqlGenericExpression();
// for each expression:
for (TdExpression importedEx : importedExs) {
TdExpression systemExpression = null;
for (TdExpression ex : parserRule.getSqlGenericExpression()) {
if (ex.getName().equals(importedEx.getName())) {
systemExpression = ex;
break;
}
}
if (systemExpression != null) {
IndicatorDefinitionFileHelper.removeSqlExpressionByName(parserRule, importedEx.getName());
IndicatorDefinitionFileHelper.addSqlExpression(parserRule, importedEx.getName(), importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
} else {
IndicatorDefinitionFileHelper.addSqlExpression(parserRule, importedEx.getName(), importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
}
isModified = true;
}
// for ParserRule Metadata
if (parserRuleProp != null && recordRuleProp != null) {
if (!StringUtils.isBlank(recordRuleProp.getPurpose())) {
parserRuleProp.setPurpose(recordRuleProp.getPurpose());
}
if (!StringUtils.isBlank(recordRuleProp.getDescription())) {
parserRuleProp.setDescription(recordRuleProp.getDescription());
}
parserRuleProp.setAuthor(recordRuleProp.getAuthor());
parserRuleProp.setStatusCode(recordRuleProp.getStatusCode());
isModified = true;
}
if (isModified) {
ElementWriterFactory.getInstance().createdRuleWriter().save(parserRuleItem, false);
}
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class FileSystemImportWriter method mergePattern.
/**
* when imported pattern is from lower version, even if it is modified, the "modify date" is still null, so, even if
* the modify date is null ,still do the comparation. [for Pattern matadata(Purpose, Description, Author, Status):
* 1) will replace old value with new value if new value is not blank; 2) will keep old value if new value is blank]
*
* @param record
* @param patternItem
*/
protected void mergePattern(ItemRecord record, TDQPatternItem patternItem) {
// only when the Si is modified, do the save
boolean isModified = false;
// old objects
Pattern pattern = patternItem.getPattern();
Property patternProp = patternItem.getProperty();
// new objects
Pattern recordPattern = (Pattern) record.getElement();
Property recordProp = record.getProperty();
// get expression list from record
EList<PatternComponent> importComponents = recordPattern.getComponents();
// for each expression:
for (PatternComponent component : importComponents) {
// if the modify date ==null, maybe it is from lower version, still do the compare
TdExpression importEx = ((RegularExpression) component).getExpression();
PatternComponent replaced = null;
for (PatternComponent pComp : pattern.getComponents()) {
TdExpression pex = ((RegularExpression) pComp).getExpression();
if (importEx.getLanguage().equals(pex.getLanguage())) {
replaced = pComp;
break;
}
}
// if new, add to SI
if (replaced == null) {
pattern.getComponents().add(createPatternComponent(component));
isModified = true;
} else {
// if the expression are different: compare the modify date, make the SI keep the new one
if (replaceExpression(((RegularExpression) replaced).getExpression(), importEx)) {
pattern.getComponents().remove(replaced);
pattern.getComponents().add(createPatternComponent(component));
isModified = true;
}
}
}
// for Pattern Metadata
if (patternProp != null && recordProp != null) {
if (!StringUtils.isBlank(recordProp.getPurpose())) {
patternProp.setPurpose(recordProp.getPurpose());
}
if (!StringUtils.isBlank(recordProp.getDescription())) {
patternProp.setDescription(recordProp.getDescription());
}
patternProp.setAuthor(recordProp.getAuthor());
patternProp.setStatusCode(recordProp.getStatusCode());
isModified = true;
}
if (isModified) {
ElementWriterFactory.getInstance().createPatternWriter().save(patternItem, false);
}
}
Aggregations