use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.
the class UpdateDemoDqruleTask method doExecute.
@Override
protected boolean doExecute() throws Exception {
boolean result = true;
try {
WhereRule whereRule = WhereRuleHandler.getInstance().getWhereRule(DEMO_DQRULE_NAME);
URI uriItem = whereRule.eResource().getURI();
File fileItem = null;
if (uriItem.isPlatform()) {
fileItem = WorkspaceUtils.ifileToFile(getIFile(whereRule));
} else {
fileItem = new File(uriItem.toFileString());
}
File fileProp = WorkspaceUtils.ifileToFile(PropertyHelper.getPropertyFile(whereRule));
Property property = PropertyHelper.getProperty(whereRule);
Item item = property.getItem();
if (whereRule != null) {
TDQBusinessRuleItem dqruleItem = (TDQBusinessRuleItem) item;
Resource itemResource = getResource(fileItem);
for (EObject object : itemResource.getContents()) {
if (object instanceof WhereRule) {
whereRule = (WhereRule) object;
whereRule.getSqlGenericExpression().clear();
IndicatorDefinitionFileHelper.addSqlExpression(whereRule, SQL, BODY_DEMO_DQRULE);
String relationPropPath = ReponsitoryContextBridge.getRootProject().getFullPath().append(new Path(fileProp.getPath()).makeRelativeTo(this.getWorkspacePath())).toOSString();
MetadataHelper.setPropertyPath(relationPropPath, whereRule);
dqruleItem.setDqrule(whereRule);
}
EMFUtil.saveResource(itemResource);
Resource propResource = getResource(fileProp);
Property newProperty = (Property) EcoreUtil.getObjectByType(propResource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
newProperty.setAuthor(property.getAuthor());
newProperty.setLabel(dqruleItem.getDqrule().getName());
newProperty.setItem(item);
item.setProperty(newProperty);
propResource.getContents().clear();
propResource.getContents().add(newProperty);
propResource.getContents().add(item);
propResource.getContents().add(item.getState());
EMFUtil.saveResource(propResource);
}
}
} catch (Exception e) {
result = false;
e.printStackTrace();
}
return result;
}
use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.
the class AnalysisTableTreeViewer method removeUncheckedWhereRuleIndicator.
/**
* DOC xqliu Comment method "removeUncheckedWhereRuleIndicator". ADD xqliu 2009-04-30 bug 6808
*
* @param ownedWhereRuleNodes
* @param results
* @param tableIndicator
*/
private void removeUncheckedWhereRuleIndicator(Object[] ownedWhereRuleNodes, Object[] results, TableIndicator tableIndicator) {
ArrayList<Object> removeList = new ArrayList<Object>();
for (Object node : ownedWhereRuleNodes) {
boolean remove = true;
for (Object result : results) {
if (node.equals(result)) {
remove = false;
break;
}
}
if (remove) {
removeList.add(node);
}
}
TableIndicatorUnit[] indicatorUnits = tableIndicator.getIndicatorUnits();
for (TableIndicatorUnit unit : indicatorUnits) {
IndicatorDefinition indicatorDefinition = unit.getIndicator().getIndicatorDefinition();
if (indicatorDefinition instanceof WhereRule) {
WhereRule wr = (WhereRule) indicatorDefinition;
RuleRepNode recursiveFindNode = RepositoryNodeHelper.recursiveFindRuleSql(wr);
for (Object obj : removeList) {
RuleRepNode node = (RuleRepNode) obj;
if (recursiveFindNode.equals(node)) {
// the order can not be changed
removeItemBranch(this.indicatorTreeItemMap.get(unit));
deleteIndicatorItems(tableIndicator, unit);
// ~the order can not be changed
break;
}
}
}
}
}
use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutor method getValidStatement.
/**
* DOC xqliu Comment method "getValidStatement". 2009-10-29 bug 9702
*
* @param dataFilterAsString
* @param indicator
* @param valid
* @return
*/
public String getValidStatement(String dataFilterAsString, Indicator indicator, boolean valid) {
if (!isAnalyzedElementValid(indicator)) {
return PluginConstant.EMPTY_STRING;
}
IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
return PluginConstant.EMPTY_STRING;
}
Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
if (!isExpressionValid(sqlGenericExpression, indicator)) {
return PluginConstant.EMPTY_STRING;
}
// --- get indicator parameters and convert them into sql expression
List<String> whereExpressionAnalysis = new ArrayList<String>();
if (StringUtils.isNotBlank(dataFilterAsString)) {
whereExpressionAnalysis.add(dataFilterAsString);
}
List<String> whereExpressionDQRule = new ArrayList<String>();
String setAliasA = PluginConstant.EMPTY_STRING;
final EList<JoinElement> joinConditions = indicator.getJoinConditions();
if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
WhereRule wr = (WhereRule) indicatorDefinition;
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);
setAliasA = PluginConstant.EMPTY_STRING.equals(setAliasA) ? joinCopy.getTableAliasA() : setAliasA;
}
}
}
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;
}
String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
// ### evaluate SQL Statement depending on indicators ###
String completedSqlString = null;
// --- default case
// allow join
String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
String genericSql = sqlGenericExpression.getBody();
// $NON-NLS-1$//$NON-NLS-2$
setAliasA = PluginConstant.EMPTY_STRING.equals(setAliasA) ? "*" : setAliasA + ".*";
// $NON-NLS-1$
genericSql = genericSql.replace("COUNT(*)", setAliasA);
completedSqlString = dbms().fillGenericQueryWithJoin(genericSql, setName, joinclause);
// ~
completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, valid);
return completedSqlString;
}
use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.
the class NewDQRulesWizard method createAndSaveCWMFile.
public TypedReturnCode<Object> createAndSaveCWMFile(ModelElement cwmElement) {
WhereRule whereRule = (WhereRule) cwmElement;
TaggedValueHelper.setValidStatus(true, whereRule);
whereRule.setWhereExpression(parameter.getWhereClause());
whereRule.setCriticalityLevel(CRITICALITY_LEVEL_DEFAULT);
whereRule.getSqlGenericExpression().add(getExpression());
// MOD scorreia 2009-04-29 bug 7151: add the category
IndicatorCategory ruleIndicatorCategory = DefinitionHandler.getInstance().getDQRuleIndicatorCategory();
if (ruleIndicatorCategory != null && !whereRule.getCategories().contains(ruleIndicatorCategory)) {
whereRule.getCategories().add(ruleIndicatorCategory);
}
IFolder folder = parameter.getFolderProvider().getFolderResource();
return ElementWriterFactory.getInstance().createdRuleWriter().create(whereRule, folder);
}
use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.
the class RuleFolderFliter method select.
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
// MOD klliu bug TDQ-3202 filter Parser Rule folder and item.
if (element instanceof IFile) {
IFile file = (IFile) element;
if (FactoriesUtil.DQRULE.equals(file.getFileExtension())) {
// add support for match rule
ModelElement modelElement = DQRuleResourceFileHelper.getInstance().getModelElement(file);
if (modelElement == null) {
return false;
}
ModelElement rule = DQRuleResourceFileHelper.getInstance().doSwitch(modelElement);
if (rule != null && rule instanceof MatchRuleDefinition) {
return true;
}
// ~
WhereRule findWhereRule = DQRuleResourceFileHelper.getInstance().findWhereRule(file);
if (findWhereRule == null) {
return false;
}
return true;
}
} else if (element instanceof IFolder) {
IFolder folder = (IFolder) element;
boolean subFolder = ResourceService.isSubFolder(ResourceManager.getRulesFolder(), folder);
if (subFolder) {
return !folder.getFullPath().equals(ResourceManager.getRulesParserFolder().getFullPath());
}
return subFolder;
}
// ~
return isShowFile;
}
Aggregations