use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.
the class AnalysisExecutorHelper method checkIndicatorWithChild.
/**
* DOC zhao Comment method "checkIndicatorWithChild".
*
* @param indicator
* @return
*/
private static ReturnCode checkIndicatorWithChild(Indicator indicator) {
ReturnCode rc = new ReturnCode(Boolean.TRUE);
if (indicator.getBuiltInIndicatorDefinition() != null) {
return rc;
}
// Get indicator definition from dependent file
IndicatorDefinition dependentDefinition = indicator.getIndicatorDefinition();
if (isDependentFileExist(dependentDefinition)) {
IndicatorDefinition deepCopiedDefinition;
if (dependentDefinition instanceof WhereRule) {
deepCopiedDefinition = copyWhereRule((WhereRule) dependentDefinition);
} else {
deepCopiedDefinition = EObjectHelper.deepCopy(dependentDefinition);
}
// Hot copy to built-in definition.
deepCopiedDefinition.getSupplierDependency().clear();
// TDQ-10737 Because 'BuiltInIndicatorDefinition' is a containment reference, need to Clear these 3 non-containment
// reference list
deepCopiedDefinition.getCategories().clear();
deepCopiedDefinition.getAggregatedDefinitions().clear();
deepCopiedDefinition.getSubCategories().clear();
indicator.setBuiltInIndicatorDefinition(deepCopiedDefinition);
EMFUtil.saveResource(indicator.eResource());
} else {
IndicatorDefinition builtInDefinition = indicator.getBuiltInIndicatorDefinition();
if (builtInDefinition == null) {
// $NON-NLS-1$
rc.setMessage(Messages.getString("AnalysisExecutor.BuiltInNoIndicators"));
rc.setOk(false);
return rc;
} else {
indicator.setIndicatorDefinition(null);
}
}
return rc;
}
use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.
the class WhereRuleHandler method getWhereRule.
/**
* DOC xqliu Comment method "getWhereRule".
*
* @param name
* @return
*/
public WhereRule getWhereRule(String name) {
WhereRule result = null;
List<? extends ModelElement> rules = DQRuleResourceFileHelper.getInstance().getAllElement();
for (ModelElement rule : rules) {
if (rule instanceof WhereRule && name.equals(rule.getName())) {
result = (WhereRule) rule;
break;
}
}
return result;
}
use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.
the class EResourceConstantTest method testGetTypedConstantItem_2.
/**
* Test method for
* {@link org.talend.resource.EResourceConstant#getTypedConstant(org.talend.core.model.properties.Item)}. test for
* where rule
*/
@Test
public void testGetTypedConstantItem_2() {
WhereRule whereRule = mock(WhereRule.class);
ruleItem.setDqrule(whereRule);
EResourceConstant rc = EResourceConstant.getTypedConstant(ruleItem);
Assert.assertEquals(rc.getPath(), EResourceConstant.RULES_SQL.getPath());
}
use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.
the class AElementPersistanceRealTest method testCreateItemWhereRule.
/**
* Test method for
* {@link org.talend.dq.writer.AElementPersistance#createItem(orgomg.cwm.objectmodel.core.ModelElement)}.
*/
@Test
public void testCreateItemWhereRule() {
DQRuleWriter createdRuleWriter = ElementWriterFactory.getInstance().createdRuleWriter();
// test normal name
// $NON-NLS-1$
String whereRuleName = "whereRule1";
// $NON-NLS-1$
String exceptedFileName = whereRuleName + "_0.1.rules";
WhereRule createWhereRule = RulesFactory.eINSTANCE.createWhereRule();
createWhereRule.setName(whereRuleName);
Item createItem = createdRuleWriter.createItem(createWhereRule);
assertTrue(createItem instanceof TDQBusinessRuleItem);
TDQBusinessRuleItem ruleItem = (TDQBusinessRuleItem) createItem;
assertTrue(ruleItem.getFilename().equals(exceptedFileName));
// test special name
// $NON-NLS-1$
String whereRuleName2 = "whereRule1*\\/?";
// $NON-NLS-1$
String exceptedFileName2 = "whereRule1_____0.1.rules";
WhereRule createWhereRule2 = RulesFactory.eINSTANCE.createWhereRule();
createWhereRule2.setName(whereRuleName2);
Item createItem2 = createdRuleWriter.createItem(createWhereRule2);
assertTrue(createItem2 instanceof TDQBusinessRuleItem);
TDQBusinessRuleItem ruleItem2 = (TDQBusinessRuleItem) createItem2;
assertTrue(ruleItem2.getFilename().equals(exceptedFileName2));
}
use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutor method createSqlQuery.
private boolean createSqlQuery(String dataFilterAsString, Indicator indicator, boolean withWhereOfRule) throws AnalysisExecutionException {
if (!isAnalyzedElementValid(indicator)) {
return Boolean.FALSE;
}
IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
return Boolean.FALSE;
}
Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
if (!isExpressionValid(sqlGenericExpression, indicator)) {
return Boolean.FALSE;
}
// --- get indicator parameters and convert them into sql expression
List<String> whereExpressionDQRule = new ArrayList<String>();
final EList<JoinElement> joinConditions = indicator.getJoinConditions();
if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
WhereRule wr = (WhereRule) indicatorDefinition;
if (withWhereOfRule) {
whereExpressionDQRule.add(wr.getWhereExpression());
}
// MOD scorreia 2009-03-13 copy joins conditions into the indicator
joinConditions.clear();
if (!isJoinConditionEmpty(indicator)) {
for (JoinElement joinelt : wr.getJoins()) {
JoinElement joinCopy = EcoreUtil.copy(joinelt);
joinConditions.add(joinCopy);
}
}
}
NamedColumnSet set = SwitchHelpers.NAMED_COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement());
String schemaName = getQuotedSchemaName(set);
// --- normalize table name
String catalogName = getQuotedCatalogName(set);
if (catalogName == null && schemaName != null) {
// try to get catalog above schema
final Schema parentSchema = SchemaHelper.getParentSchema(set);
final Catalog parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
catalogName = parentCatalog != null ? parentCatalog.getName() : null;
}
// --- default case
// allow join
String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
String completedSqlString = dbms().fillGenericQueryWithJoin(sqlGenericExpression.getBody(), setName, joinclause);
// ~
List<String> whereExpressionAnalysis = new ArrayList<String>();
if (StringUtils.isNotBlank(dataFilterAsString)) {
whereExpressionAnalysis.add(dataFilterAsString);
}
completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, true);
// completedSqlString is the final query
String finalQuery = completedSqlString;
TdExpression instantiateSqlExpression = BooleanExpressionHelper.createTdExpression(dbms().getDbmsName(), finalQuery);
indicator.setInstantiatedExpression(instantiateSqlExpression);
return true;
}
Aggregations