Search in sources :

Example 11 with MatchRuleDefinition

use of org.talend.dataquality.rules.MatchRuleDefinition in project tdq-studio-se by Talend.

the class AElementPersistance method createItem.

/**
 * DOC bZhou Comment method "createItem".
 *
 * @param element
 * @return
 */
public Item createItem(ModelElement element) {
    Item item = null;
    // MOD mzhao feature 13114, 2010-05-19 distinguish tdq items.
    if (ModelElementIdentifier.isAnalysis(element)) {
        item = PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
        ((TDQAnalysisItem) item).setAnalysis((Analysis) element);
    } else if (ModelElementIdentifier.isDQRule(element)) {
        item = PropertiesFactory.eINSTANCE.createTDQBusinessRuleItem();
        ((TDQBusinessRuleItem) item).setDqrule((DQRule) element);
    } else if (ModelElementIdentifier.isDataProvider(element)) {
        if (element instanceof DatabaseConnection) {
            item = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
            ((ConnectionItem) item).setConnection((DatabaseConnection) element);
        }
        ((ConnectionItem) item).setConnection((Connection) element);
    } else if (ModelElementIdentifier.isMatchRule(element)) {
        // this Condition must before the IndicatorDefinition one because MatchRule instance of it.
        item = PropertiesFactory.eINSTANCE.createTDQMatchRuleItem();
        ((TDQMatchRuleItem) item).setMatchRule((MatchRuleDefinition) element);
    } else if (ModelElementIdentifier.isID(element)) {
        item = PropertiesFactory.eINSTANCE.createTDQIndicatorDefinitionItem();
        ((TDQIndicatorDefinitionItem) item).setIndicatorDefinition((IndicatorDefinition) element);
    } else if (ModelElementIdentifier.isPattern(element)) {
        item = PropertiesFactory.eINSTANCE.createTDQPatternItem();
        ((TDQPatternItem) item).setPattern((Pattern) element);
    } else if (ModelElementIdentifier.isReport(element)) {
        item = PropertiesFactory.eINSTANCE.createTDQReportItem();
        ((TDQReportItem) item).setReport((Report) element);
    } else {
        item = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createTDQItem();
    }
    ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(false);
    item.setState(itemState);
    if (item instanceof TDQItem) {
        setTDQItemFileName(element, item);
    }
    Resource eResource = element.eResource();
    if (eResource != null) {
        URI uri = eResource.getURI();
        if (uri.isPlatform()) {
            IPath elementPath = new Path(uri.toPlatformString(true)).removeLastSegments(1);
            IPath typedPath = ResourceManager.getRootProject().getFullPath().append(PropertyHelper.getItemTypedPath(item));
            IPath statePath = elementPath.makeRelativeTo(typedPath);
            itemState.setPath(statePath.toString());
        }
    }
    return item;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Pattern(org.talend.dataquality.domain.pattern.Pattern) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) IPath(org.eclipse.core.runtime.IPath) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Resource(org.eclipse.emf.ecore.resource.Resource) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) URI(org.eclipse.emf.common.util.URI) DQRule(org.talend.dataquality.rules.DQRule) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TDQItem(org.talend.core.model.properties.TDQItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) ItemState(org.talend.core.model.properties.ItemState) TDQItem(org.talend.core.model.properties.TDQItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 12 with MatchRuleDefinition

use of org.talend.dataquality.rules.MatchRuleDefinition in project tdq-studio-se by Talend.

the class MatchRuleDefinitionWriter method save.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.writer.AElementPersistance#save(org.talend.core.model.properties.Item, boolean)
     */
@Override
public ReturnCode save(final Item item, final boolean careDependency) {
    ReturnCode rc = new ReturnCode();
    RepositoryWorkUnit<Object> repositoryWorkUnit = new // $NON-NLS-1$
    RepositoryWorkUnit<Object>(// $NON-NLS-1$
    "save MatchRule Definition item") {

        @Override
        protected void run() throws LoginException, PersistenceException {
            TDQMatchRuleItem matchRuleItem = (TDQMatchRuleItem) item;
            MatchRuleDefinition matchRuleDefinition = matchRuleItem.getMatchRule();
            if (careDependency) {
                saveWithDependencies(matchRuleItem, matchRuleDefinition);
            } else {
                saveWithoutDependencies(matchRuleItem, matchRuleDefinition);
            }
        }
    };
    repositoryWorkUnit.setAvoidUnloadResources(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
    try {
        repositoryWorkUnit.throwPersistenceExceptionIfAny();
    } catch (PersistenceException e) {
        log.error(e, e);
        rc.setOk(Boolean.FALSE);
        rc.setMessage(e.getMessage());
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition)

Example 13 with MatchRuleDefinition

use of org.talend.dataquality.rules.MatchRuleDefinition in project tdq-studio-se by Talend.

the class AnaMatchSurvivorSection method checkAndRemoveEmptyMatchRule.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.dataquality.record.linkage.ui.section.MatchingKeySection#checkAndRemoveEmptyMatchRule(org.eclipse.
     * swt.custom.CTabItem)
     */
@Override
protected void checkAndRemoveEmptyMatchRule(CTabItem theTab) {
    MatchRule matchRule = getMatchRule(theTab);
    List<MatchKeyAndSurvivorDefinition> matchAndSurvDefList = matchRuleWithSurvMap.get(matchRule);
    if (matchAndSurvDefList.size() <= 0) {
        MatchRuleDefinition matchRuleDefinition = getMatchRuleDefinition();
        matchRuleDefinition.getMatchRules().remove(matchRule);
        for (MatchKeyAndSurvivorDefinition matchAndSurvDef : matchAndSurvDefList) {
            matchRuleDefinition.getSurvivorshipKeys().remove(matchAndSurvDef.getSurvivorShipKey());
        }
    }
}
Also used : MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) MatchRule(org.talend.dataquality.rules.MatchRule) MatchKeyAndSurvivorDefinition(org.talend.dataquality.record.linkage.ui.composite.tableviewer.definition.MatchKeyAndSurvivorDefinition)

Example 14 with MatchRuleDefinition

use of org.talend.dataquality.rules.MatchRuleDefinition in project tdq-studio-se by Talend.

the class MatchRuleElementTreeSelectionDialog method getParticularRulesFromNodes.

/**
 * Get particular rules from nodes
 *
 * @param nodes
 * @param retrieveDisplayValue get the display value when this parameter is set to true, otherwise, get the
 * component value.
 * @return
 */
public List<Map<String, String>> getParticularRulesFromNodes(Object[] nodes, boolean retrieveDisplayValue) {
    List<Map<String, String>> ruleValues = new ArrayList<Map<String, String>>();
    for (Object rule : nodes) {
        if (rule instanceof RuleRepNode) {
            RuleRepNode node = (RuleRepNode) rule;
            MatchRuleDefinition matchRuleDefinition = (MatchRuleDefinition) node.getRule();
            ruleValues.addAll(getParticularSurvivorshipRulesFromRules(matchRuleDefinition, retrieveDisplayValue));
        }
    }
    return ruleValues;
}
Also used : ArrayList(java.util.ArrayList) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) RuleRepNode(org.talend.dq.nodes.RuleRepNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with MatchRuleDefinition

use of org.talend.dataquality.rules.MatchRuleDefinition in project tdq-studio-se by Talend.

the class MatchRuleElementTreeSelectionDialog method createDialogArea.

@Override
protected Control createDialogArea(final Composite parent) {
    final SashForm form = new SashForm(parent, SWT.SMOOTH | SWT.VERTICAL | SWT.FILL);
    form.setSize(Math.min(Display.getCurrent().getActiveShell().getSize().x, 800), 580);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 0, 0);
    form.setLayoutData(data);
    Composite composite = (Composite) super.createDialogArea(form);
    getTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (dialogType != SUGGEST_TYPE) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                Object[] array = selection.toArray();
                if (array.length == 1) {
                    if (array[0] != null) {
                        MatchRuleDefinition matchRuleDefinition = null;
                        if (array[0] instanceof RuleRepNode) {
                            RuleRepNode node = (RuleRepNode) array[0];
                            matchRuleDefinition = (MatchRuleDefinition) node.getRule();
                        }
                        if (matchRuleDefinition != null) {
                            // MatchAnalysis tmatchGroup tRecordMatching tGenKey will come here
                            algorithmValue.setText(RecordMatcherType.valueOf(matchRuleDefinition.getRecordLinkageAlgorithm()).getLabel());
                            if (blockingKeysTable != null) {
                                blockingKeysTable.setInput(getBlockingKeysFromNodes(array, true));
                            }
                            if (matchingRulesTable != null) {
                                matchRulesTableComposite.dispose();
                                if (StringUtils.equals(RecordMatcherType.T_SwooshAlgorithm.name(), matchRuleDefinition.getRecordLinkageAlgorithm())) {
                                    if (particularSurvivRulesTableComposite != null) {
                                        particularSurvivRulesTableComposite.dispose();
                                        particularSurvivRulesTableComposite = null;
                                    }
                                    createSelectMatchRulesTableTswoosh(form);
                                    if (dialogType == MATCHGROUP_TYPE) {
                                        createParticularSurvivorshipRulesTableTswoosh(form);
                                        form.setWeights(new int[] { 5, 3, 2 });
                                    } else if (dialogType == MATCH_ANALYSIS_TYPE) {
                                        createParticularSurvivorshipRulesTableTswoosh(form);
                                        form.setWeights(new int[] { 4, 2, 2, 2 });
                                    }
                                    // MatchAnalysis tmatchGroup tRecordMatching will come here
                                    if (particularSurvivRulesTable != null) {
                                        // MatchAnalysis tmatchGroup will come here
                                        particularSurvivRulesTable.setInput(getParticularRulesFromNodes(array, true));
                                    }
                                } else {
                                    createSelectMatchRulesTableVsr(form);
                                    if (particularSurvivRulesTableComposite != null && dialogType == MATCHGROUP_TYPE) {
                                        particularSurvivRulesTableComposite.dispose();
                                        particularSurvivRulesTableComposite = null;
                                        form.setWeights(new int[] { 3, 2 });
                                    } else if (particularSurvivRulesTableComposite != null && dialogType == MATCH_ANALYSIS_TYPE) {
                                        particularSurvivRulesTableComposite.dispose();
                                        particularSurvivRulesTableComposite = null;
                                        form.setWeights(new int[] { 5, 3, 2 });
                                    }
                                }
                                matchingRulesTable.setInput(getMatchRulesFromNodes(array, true));
                                // refresh the dialog
                                matchRulesTableComposite.getParent().layout();
                                matchRulesTableComposite.getParent().redraw();
                            }
                        }
                    }
                }
            }
        }
    });
    if (dialogType == GENKEY_TYPE) {
        createSelectBlockingKeysTable(form);
        form.setWeights(new int[] { 3, 2 });
    } else if (dialogType == MATCHGROUP_TYPE) {
        createSelectMatchRulesTableVsr(form);
        createParticularSurvivorshipRulesTableTswoosh(form);
        form.setWeights(new int[] { 5, 3, 2 });
    } else if (dialogType == RECORD_MATCHING_TYPE) {
        createSelectMatchRulesTableVsr(form);
        form.setWeights(new int[] { 3, 2 });
    } else if (dialogType == MATCH_ANALYSIS_TYPE) {
        createSelectBlockingKeysTable(form);
        createSelectMatchRulesTableVsr(form);
        createParticularSurvivorshipRulesTableTswoosh(form);
        form.setWeights(new int[] { 4, 2, 2, 2 });
    } else if (dialogType == SUGGEST_TYPE) {
        createSelectBlockingKeysTable(form);
        createSelectMatchRulesTableVsr(form);
        form.setWeights(new int[] { 5, 2, 3 });
        if (blockingKeysTable != null) {
            blockingKeysTable.setInput(getBlockingKeysFromRules(matchRuleDefinitionInput, true));
        }
        if (matchingRulesTable != null) {
            matchingRulesTable.setInput(getMatchRulesFromRules(matchRuleDefinitionInput, true));
        }
    }
    createCheckerArea(composite);
    return composite;
}
Also used : SashForm(org.eclipse.swt.custom.SashForm) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) GridData(org.eclipse.swt.layout.GridData) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RuleRepNode(org.talend.dq.nodes.RuleRepNode)

Aggregations

MatchRuleDefinition (org.talend.dataquality.rules.MatchRuleDefinition)35 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 RecordMatchingIndicator (org.talend.dataquality.indicators.columnset.RecordMatchingIndicator)8 MatchRule (org.talend.dataquality.rules.MatchRule)8 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)6 AlgorithmDefinition (org.talend.dataquality.rules.AlgorithmDefinition)6 MatchKeyDefinition (org.talend.dataquality.rules.MatchKeyDefinition)6 RuleRepNode (org.talend.dq.nodes.RuleRepNode)6 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)6 Test (org.junit.Test)5 Analysis (org.talend.dataquality.analysis.Analysis)5 MatchGroupResultConsumer (org.talend.dataquality.record.linkage.grouping.MatchGroupResultConsumer)5 Map (java.util.Map)4 IFile (org.eclipse.core.resources.IFile)4 BlockKeyIndicator (org.talend.dataquality.indicators.columnset.BlockKeyIndicator)4 TDQMatchRuleItem (org.talend.dataquality.properties.TDQMatchRuleItem)4 ExecuteMatchRuleHandler (org.talend.dq.analysis.match.ExecuteMatchRuleHandler)4 IFolder (org.eclipse.core.resources.IFolder)3 BlockKeyDefinition (org.talend.dataquality.rules.BlockKeyDefinition)3