Search in sources :

Example 1 with WhereRule

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;
}
Also used : Path(org.eclipse.core.runtime.Path) Item(org.talend.core.model.properties.Item) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) WhereRule(org.talend.dataquality.rules.WhereRule) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) URI(org.eclipse.emf.common.util.URI) File(java.io.File) IFile(org.eclipse.core.resources.IFile) Property(org.talend.core.model.properties.Property)

Example 2 with WhereRule

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;
                }
            }
        }
    }
}
Also used : WhereRule(org.talend.dataquality.rules.WhereRule) ArrayList(java.util.ArrayList) TableIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.TableIndicatorUnit) RuleRepNode(org.talend.dq.nodes.RuleRepNode) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 3 with WhereRule

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;
}
Also used : JoinElement(org.talend.dataquality.rules.JoinElement) WhereRule(org.talend.dataquality.rules.WhereRule) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Schema(orgomg.cwm.resource.relational.Schema) ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 4 with WhereRule

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);
}
Also used : WhereRule(org.talend.dataquality.rules.WhereRule) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with WhereRule

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;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IFile(org.eclipse.core.resources.IFile) WhereRule(org.talend.dataquality.rules.WhereRule) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

WhereRule (org.talend.dataquality.rules.WhereRule)15 ArrayList (java.util.ArrayList)5 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)5 IFile (org.eclipse.core.resources.IFile)4 IFolder (org.eclipse.core.resources.IFolder)3 TDQBusinessRuleItem (org.talend.dataquality.properties.TDQBusinessRuleItem)3 MatchRuleDefinition (org.talend.dataquality.rules.MatchRuleDefinition)3 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)3 NamedColumnSet (orgomg.cwm.resource.relational.NamedColumnSet)3 Resource (org.eclipse.emf.ecore.resource.Resource)2 Test (org.junit.Test)2 Item (org.talend.core.model.properties.Item)2 TdExpression (org.talend.cwm.relational.TdExpression)2 Analysis (org.talend.dataquality.analysis.Analysis)2 Indicator (org.talend.dataquality.indicators.Indicator)2 RowCountIndicator (org.talend.dataquality.indicators.RowCountIndicator)2 WhereRuleIndicator (org.talend.dataquality.indicators.sql.WhereRuleIndicator)2 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)2 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)2 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)2