Search in sources :

Example 1 with DatePatternFreqIndicator

use of org.talend.dataquality.indicators.DatePatternFreqIndicator in project tdq-studio-se by Talend.

the class IndicatorSelectDialog method isMatchCurrentIndicator.

public boolean isMatchCurrentIndicator(ModelElementIndicator currentIndicator, IIndicatorNode indicatorNode) {
    boolean returnValueForCurrentIndicator = true;
    IIndicatorNode parentNode = indicatorNode.getParent();
    boolean isParentPhoneStatistics = parentNode != null && parentNode.getIndicatorInstance() != null && parentNode.getIndicatorInstance() instanceof PhoneNumbStatisticsIndicator;
    if (!ModelElementIndicatorRule.match(indicatorNode, currentIndicator, this.language)) {
        returnValueForCurrentIndicator = false;
    }
    Indicator indicatorInstance = indicatorNode.getIndicatorInstance();
    if (null != indicatorInstance && !(indicatorInstance instanceof DatePatternFreqIndicator) && null != indicatorInstance.getIndicatorDefinition() && indicatorInstance.getIndicatorDefinition().getSqlGenericExpression().size() < 1 && ExecutionLanguage.SQL.equals(language) && !UDIHelper.isJavaUDI(indicatorInstance) && !indicatorNode.hasChildren() && !(currentIndicator instanceof DelimitedFileIndicator) && !isParentPhoneStatistics) {
        returnValueForCurrentIndicator = false;
    }
    return returnValueForCurrentIndicator;
}
Also used : DatePatternFreqIndicator(org.talend.dataquality.indicators.DatePatternFreqIndicator) PhoneNumbStatisticsIndicator(org.talend.dataquality.indicators.PhoneNumbStatisticsIndicator) IIndicatorNode(org.talend.dq.nodes.indicator.IIndicatorNode) DatePatternFreqIndicator(org.talend.dataquality.indicators.DatePatternFreqIndicator) PhoneNumbStatisticsIndicator(org.talend.dataquality.indicators.PhoneNumbStatisticsIndicator) DelimitedFileIndicator(org.talend.dataprofiler.core.model.DelimitedFileIndicator) Indicator(org.talend.dataquality.indicators.Indicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) DelimitedFileIndicator(org.talend.dataprofiler.core.model.DelimitedFileIndicator)

Example 2 with DatePatternFreqIndicator

use of org.talend.dataquality.indicators.DatePatternFreqIndicator in project tdq-studio-se by Talend.

the class IndicatorCommonUtil method handleFrequency.

/**
 * DOC xqliu Comment method "handleFrequency".
 *
 * @param indicator
 * @return
 */
private static Object handleFrequency(Indicator indicator) {
    FrequencyExt[] frequencyExt = null;
    if (UDIHelper.isUDI(indicator)) {
        UserDefIndicator udi = (UserDefIndicator) indicator;
        Set<Object> valueSet = udi.getDistinctValues();
        if (valueSet == null) {
            return null;
        }
        frequencyExt = new FrequencyExt[valueSet.size()];
        int i = 0;
        for (Object o : valueSet) {
            frequencyExt[i] = new FrequencyExt();
            frequencyExt[i].setKey(o);
            frequencyExt[i].setValue(udi.getCount(o));
            frequencyExt[i].setFrequency(udi.getFrequency(o));
            i++;
        }
    } else if (IndicatorEnum.DatePatternFreqIndicatorEnum.getIndicatorType().isInstance(indicator)) {
        DatePatternFreqIndicator datePatternFrequency = (DatePatternFreqIndicator) indicator;
        Map<String, Long> results = datePatternFrequency.getResult();
        frequencyExt = new FrequencyExt[results.size()];
        int i = 0;
        for (String key : results.keySet()) {
            Long value = results.get(key);
            Double frequency = datePatternFrequency.getFrequency(key);
            frequencyExt[i] = new FrequencyExt();
            frequencyExt[i].setKey(key);
            frequencyExt[i].setValue(value);
            frequencyExt[i].setFrequency(frequency);
            i++;
        }
    } else {
        FrequencyIndicator frequency = (FrequencyIndicator) indicator;
        Set<Object> valueSet = frequency.getDistinctValues();
        if (valueSet == null) {
            return null;
        }
        frequencyExt = new FrequencyExt[valueSet.size()];
        int i = 0;
        for (Object o : valueSet) {
            frequencyExt[i] = new FrequencyExt();
            frequencyExt[i].setKey(o);
            if (IndicatorsPackage.eINSTANCE.getSoundexFreqIndicator().equals(frequency.eClass()) || IndicatorsPackage.eINSTANCE.getSoundexLowFreqIndicator().equals(frequency.eClass())) {
                // MOD scorreia 2009-03-23 display distinct count when working with Soundex
                frequencyExt[i].setValue(((SoundexFreqIndicator) frequency).getDistinctCount(o));
            } else {
                frequencyExt[i].setValue(frequency.getCount(o));
            }
            frequencyExt[i].setFrequency(frequency.getFrequency(o));
            i++;
        }
    }
    return frequencyExt;
}
Also used : Set(java.util.Set) SoundexFreqIndicator(org.talend.dataquality.indicators.SoundexFreqIndicator) FrequencyIndicator(org.talend.dataquality.indicators.FrequencyIndicator) DatePatternFreqIndicator(org.talend.dataquality.indicators.DatePatternFreqIndicator) FrequencyExt(org.talend.dq.indicators.ext.FrequencyExt) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with DatePatternFreqIndicator

use of org.talend.dataquality.indicators.DatePatternFreqIndicator in project tdq-studio-se by Talend.

the class IndicatorParametersImplTest method testEBasicSetContainerInternalEObjectInt.

/**
 * Test method for
 * {@link org.talend.dataquality.indicators.impl.IndicatorParametersImpl#eBasicSetContainer(org.eclipse.emf.ecore.InternalEObject, int)}
 * .
 */
@Test
public void testEBasicSetContainerInternalEObjectInt() {
    IndicatorDefaultValueServiceUtil.getIstance().getIndicatorDVService().setFrequencyLimitResult(FREQUENCYRESULTLIMIT);
    IndicatorDefaultValueServiceUtil.getIstance().getIndicatorDVService().setLowFrequencyLimitResult(LOWFREQUENCYRESULTLIMIT);
    // freqyency value indicator
    FrequencyIndicator createFrequencyIndicator = IndicatorsFactory.eINSTANCE.createFrequencyIndicator();
    createFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createFrequencyIndicator.getParameters().getTopN());
    // low freqyency value indicator
    LowFrequencyIndicator createLowFrequencyIndicator = IndicatorsFactory.eINSTANCE.createLowFrequencyIndicator();
    createLowFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(LOWFREQUENCYRESULTLIMIT, createLowFrequencyIndicator.getParameters().getTopN());
    // date freqyency value indicator
    DateFrequencyIndicator createDateFrequencyIndicator = IndicatorsFactory.eINSTANCE.createDateFrequencyIndicator();
    createDateFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createDateFrequencyIndicator.getParameters().getTopN());
    // date low freqyency value indicator
    DateLowFrequencyIndicator createDateLowFrequencyIndicator = IndicatorsFactory.eINSTANCE.createDateLowFrequencyIndicator();
    createDateLowFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(LOWFREQUENCYRESULTLIMIT, createDateLowFrequencyIndicator.getParameters().getTopN());
    // week freqyency value indicator
    WeekFrequencyIndicator createWeekFrequencyIndicator = IndicatorsFactory.eINSTANCE.createWeekFrequencyIndicator();
    createWeekFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createWeekFrequencyIndicator.getParameters().getTopN());
    // week low freqyency value indicator
    WeekLowFrequencyIndicator createWeekLowFrequencyIndicator = IndicatorsFactory.eINSTANCE.createWeekLowFrequencyIndicator();
    createWeekLowFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(LOWFREQUENCYRESULTLIMIT, createWeekLowFrequencyIndicator.getParameters().getTopN());
    // Month freqyency value indicator
    MonthFrequencyIndicator createMonthFrequencyIndicator = IndicatorsFactory.eINSTANCE.createMonthFrequencyIndicator();
    createMonthFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createMonthFrequencyIndicator.getParameters().getTopN());
    // Month low freqyency value indicator
    MonthLowFrequencyIndicator createMonthLowFrequencyIndicator = IndicatorsFactory.eINSTANCE.createMonthLowFrequencyIndicator();
    createMonthLowFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(LOWFREQUENCYRESULTLIMIT, createMonthLowFrequencyIndicator.getParameters().getTopN());
    // quarter freqyency value indicator
    QuarterFrequencyIndicator createQuarterFrequencyIndicator = IndicatorsFactory.eINSTANCE.createQuarterFrequencyIndicator();
    createQuarterFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createQuarterFrequencyIndicator.getParameters().getTopN());
    // quarter low freqyency value indicator
    QuarterLowFrequencyIndicator createQuarterLowFrequencyIndicator = IndicatorsFactory.eINSTANCE.createQuarterLowFrequencyIndicator();
    createQuarterLowFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(LOWFREQUENCYRESULTLIMIT, createQuarterLowFrequencyIndicator.getParameters().getTopN());
    // year freqyency value indicator
    YearFrequencyIndicator createYearFrequencyIndicator = IndicatorsFactory.eINSTANCE.createYearFrequencyIndicator();
    createYearFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createYearFrequencyIndicator.getParameters().getTopN());
    // year low freqyency value indicator
    YearLowFrequencyIndicator createYearLowFrequencyIndicator = IndicatorsFactory.eINSTANCE.createYearLowFrequencyIndicator();
    createYearLowFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(LOWFREQUENCYRESULTLIMIT, createYearLowFrequencyIndicator.getParameters().getTopN());
    // bin freqyency value indicator
    BinFrequencyIndicator createBinFrequencyIndicator = IndicatorsFactory.eINSTANCE.createBinFrequencyIndicator();
    createBinFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createBinFrequencyIndicator.getParameters().getTopN());
    // bin low freqyency value indicator
    BinLowFrequencyIndicator createBinLowFrequencyIndicator = IndicatorsFactory.eINSTANCE.createBinLowFrequencyIndicator();
    createBinLowFrequencyIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(LOWFREQUENCYRESULTLIMIT, createBinLowFrequencyIndicator.getParameters().getTopN());
    // pattern freqyency value indicator
    PatternFreqIndicator createPatternFreqIndicator = IndicatorsFactory.eINSTANCE.createPatternFreqIndicator();
    createPatternFreqIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createPatternFreqIndicator.getParameters().getTopN());
    // pattern low freqyency value indicator
    PatternLowFreqIndicator createPatternLowFreqIndicator = IndicatorsFactory.eINSTANCE.createPatternLowFreqIndicator();
    createPatternLowFreqIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(LOWFREQUENCYRESULTLIMIT, createPatternLowFreqIndicator.getParameters().getTopN());
    // east asia freqyency value indicator
    EastAsiaPatternFreqIndicator createEastAsiaPatternFreqIndicator = IndicatorsFactory.eINSTANCE.createEastAsiaPatternFreqIndicator();
    createEastAsiaPatternFreqIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createEastAsiaPatternFreqIndicator.getParameters().getTopN());
    // east asia low freqyency value indicator
    EastAsiaPatternLowFreqIndicator createEastAsiaPatternLowFreqIndicator = IndicatorsFactory.eINSTANCE.createEastAsiaPatternLowFreqIndicator();
    createEastAsiaPatternLowFreqIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(LOWFREQUENCYRESULTLIMIT, createEastAsiaPatternLowFreqIndicator.getParameters().getTopN());
    // soundex freqyency value indicator
    SoundexFreqIndicator createSoundexFreqIndicator = IndicatorsFactory.eINSTANCE.createSoundexFreqIndicator();
    createSoundexFreqIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createSoundexFreqIndicator.getParameters().getTopN());
    // soundex low freqyency value indicator
    SoundexLowFreqIndicator createSoundexLowFreqIndicator = IndicatorsFactory.eINSTANCE.createSoundexLowFreqIndicator();
    createSoundexLowFreqIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(LOWFREQUENCYRESULTLIMIT, createSoundexLowFreqIndicator.getParameters().getTopN());
    // Date pattern freqyency value indicator
    DatePatternFreqIndicator createDatePatternFreqIndicator = IndicatorsFactory.eINSTANCE.createDatePatternFreqIndicator();
    createDatePatternFreqIndicator.setParameters(IndicatorsFactory.eINSTANCE.createIndicatorParameters());
    Assert.assertEquals(FREQUENCYRESULTLIMIT, createDatePatternFreqIndicator.getParameters().getTopN());
}
Also used : QuarterLowFrequencyIndicator(org.talend.dataquality.indicators.QuarterLowFrequencyIndicator) BinLowFrequencyIndicator(org.talend.dataquality.indicators.BinLowFrequencyIndicator) WeekLowFrequencyIndicator(org.talend.dataquality.indicators.WeekLowFrequencyIndicator) DateLowFrequencyIndicator(org.talend.dataquality.indicators.DateLowFrequencyIndicator) LowFrequencyIndicator(org.talend.dataquality.indicators.LowFrequencyIndicator) MonthLowFrequencyIndicator(org.talend.dataquality.indicators.MonthLowFrequencyIndicator) YearLowFrequencyIndicator(org.talend.dataquality.indicators.YearLowFrequencyIndicator) QuarterFrequencyIndicator(org.talend.dataquality.indicators.QuarterFrequencyIndicator) DateFrequencyIndicator(org.talend.dataquality.indicators.DateFrequencyIndicator) EastAsiaPatternFreqIndicator(org.talend.dataquality.indicators.EastAsiaPatternFreqIndicator) MonthLowFrequencyIndicator(org.talend.dataquality.indicators.MonthLowFrequencyIndicator) YearLowFrequencyIndicator(org.talend.dataquality.indicators.YearLowFrequencyIndicator) EastAsiaPatternLowFreqIndicator(org.talend.dataquality.indicators.EastAsiaPatternLowFreqIndicator) PatternLowFreqIndicator(org.talend.dataquality.indicators.PatternLowFreqIndicator) SoundexFreqIndicator(org.talend.dataquality.indicators.SoundexFreqIndicator) QuarterLowFrequencyIndicator(org.talend.dataquality.indicators.QuarterLowFrequencyIndicator) QuarterFrequencyIndicator(org.talend.dataquality.indicators.QuarterFrequencyIndicator) FrequencyIndicator(org.talend.dataquality.indicators.FrequencyIndicator) BinLowFrequencyIndicator(org.talend.dataquality.indicators.BinLowFrequencyIndicator) WeekLowFrequencyIndicator(org.talend.dataquality.indicators.WeekLowFrequencyIndicator) DateLowFrequencyIndicator(org.talend.dataquality.indicators.DateLowFrequencyIndicator) LowFrequencyIndicator(org.talend.dataquality.indicators.LowFrequencyIndicator) WeekFrequencyIndicator(org.talend.dataquality.indicators.WeekFrequencyIndicator) YearFrequencyIndicator(org.talend.dataquality.indicators.YearFrequencyIndicator) BinFrequencyIndicator(org.talend.dataquality.indicators.BinFrequencyIndicator) DateFrequencyIndicator(org.talend.dataquality.indicators.DateFrequencyIndicator) MonthLowFrequencyIndicator(org.talend.dataquality.indicators.MonthLowFrequencyIndicator) MonthFrequencyIndicator(org.talend.dataquality.indicators.MonthFrequencyIndicator) YearLowFrequencyIndicator(org.talend.dataquality.indicators.YearLowFrequencyIndicator) WeekLowFrequencyIndicator(org.talend.dataquality.indicators.WeekLowFrequencyIndicator) EastAsiaPatternLowFreqIndicator(org.talend.dataquality.indicators.EastAsiaPatternLowFreqIndicator) YearFrequencyIndicator(org.talend.dataquality.indicators.YearFrequencyIndicator) DateLowFrequencyIndicator(org.talend.dataquality.indicators.DateLowFrequencyIndicator) DatePatternFreqIndicator(org.talend.dataquality.indicators.DatePatternFreqIndicator) BinFrequencyIndicator(org.talend.dataquality.indicators.BinFrequencyIndicator) QuarterLowFrequencyIndicator(org.talend.dataquality.indicators.QuarterLowFrequencyIndicator) BinLowFrequencyIndicator(org.talend.dataquality.indicators.BinLowFrequencyIndicator) MonthFrequencyIndicator(org.talend.dataquality.indicators.MonthFrequencyIndicator) SoundexLowFreqIndicator(org.talend.dataquality.indicators.SoundexLowFreqIndicator) DatePatternFreqIndicator(org.talend.dataquality.indicators.DatePatternFreqIndicator) EastAsiaPatternFreqIndicator(org.talend.dataquality.indicators.EastAsiaPatternFreqIndicator) PatternFreqIndicator(org.talend.dataquality.indicators.PatternFreqIndicator) WeekFrequencyIndicator(org.talend.dataquality.indicators.WeekFrequencyIndicator) Test(org.junit.Test)

Example 4 with DatePatternFreqIndicator

use of org.talend.dataquality.indicators.DatePatternFreqIndicator in project tdq-studio-se by Talend.

the class DrillDownEditorInput method filterAdaptDataList.

/**
 * @return get the data which will be displayed on the drill down editor.
 */
public List<Object[]> filterAdaptDataList() {
    // get columnValue
    List<Object[]> newColumnElementList = new ArrayList<Object[]>();
    AnalyzedDataSet analysisDataSet = this.getAnalysis().getResults().getIndicToRowMap().get(currIndicator);
    // TDQ-10545 : when restart studio and without run analysis, analysisDataSet is null
    if (analysisDataSet == null) {
        return newColumnElementList;
    }
    // TDQ-10545~
    if (analysisDataSet.getData() != null && analysisDataSet.getData().size() > 0) {
        List<Object[]> dataList = analysisDataSet.getData();
        newColumnElementList.addAll(getDesignatedData(dataList));
    } else if (analysisDataSet.getFrequencyData() != null && analysisDataSet.getFrequencyData().size() > 0) {
        String selectValue = this.getSelectValue();
        if (currIndicator instanceof LengthIndicator) {
            selectValue = ((LengthIndicator) currIndicator).getLength().toString();
        }
        // MOD yyi 2011-12-14 TDQ-4166:View rows for Date Pattern Frequency Indicator.
        if (currIndicator instanceof DatePatternFreqIndicator) {
            for (Object expression : analysisDataSet.getFrequencyData().keySet()) {
                if (Pattern.matches(((DatePatternFreqIndicator) currIndicator).getRegex(selectValue), expression.toString())) {
                    newColumnElementList.addAll(analysisDataSet.getFrequencyData().get(expression));
                }
            }
        } else {
            // MOD msjian TDQ-4617 2012-2-8: fixed a NPE
            List<Object[]> list = analysisDataSet.getFrequencyData().get(selectValue);
            if (list != null && list.size() > 0) {
                newColumnElementList.addAll(list);
            }
        // TDQ-4617 ~
        }
    } else if (analysisDataSet.getPatternData() != null && analysisDataSet.getPatternData().size() > 0) {
        if (DrillDownUtils.judgeMenuType(getMenuType(), DrillDownUtils.MENU_INVALID_TYPE)) {
            newColumnElementList.addAll(getDesignatedData((List<Object[]>) analysisDataSet.getPatternData().get(AnalyzedDataSetImpl.INVALID_VALUE)));
        } else if (DrillDownUtils.judgeMenuType(getMenuType(), DrillDownUtils.MENU_VALID_TYPE)) {
            newColumnElementList.addAll(getDesignatedData((List<Object[]>) analysisDataSet.getPatternData().get(AnalyzedDataSetImpl.VALID_VALUE)));
        }
    }
    return newColumnElementList;
}
Also used : AnalyzedDataSet(org.talend.dataquality.analysis.AnalyzedDataSet) DatePatternFreqIndicator(org.talend.dataquality.indicators.DatePatternFreqIndicator) ArrayList(java.util.ArrayList) EObject(org.eclipse.emf.ecore.EObject) LengthIndicator(org.talend.dataquality.indicators.LengthIndicator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with DatePatternFreqIndicator

use of org.talend.dataquality.indicators.DatePatternFreqIndicator in project tdq-studio-se by Talend.

the class ChartTableFactory method addMenuAndTip.

public static void addMenuAndTip(final TableViewer tbViewer, final IDataExplorer explorer, final Analysis analysis) {
    final Table table = tbViewer.getTable();
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            // MOD xqliu 2009-05-11 bug 6561
            if (table.getMenu() != null) {
                table.getMenu().setVisible(false);
            }
            if (e.button == 3) {
                StructuredSelection selection = (StructuredSelection) tbViewer.getSelection();
                final ChartDataEntity dataEntity = (ChartDataEntity) selection.getFirstElement();
                final Indicator indicator = dataEntity != null ? dataEntity.getIndicator() : null;
                if (indicator != null && dataEntity != null) {
                    Menu menu = new Menu(table.getShell(), SWT.POP_UP);
                    table.setMenu(menu);
                    MenuItemEntity[] itemEntities = ChartTableMenuGenerator.generate(explorer, analysis, dataEntity);
                    if (ExecutionLanguage.SQL == analysis.getParameters().getExecutionLanguage()) {
                        boolean showExtraMenu = false;
                        for (final MenuItemEntity itemEntity : itemEntities) {
                            MenuItem item = new MenuItem(menu, SWT.PUSH);
                            item.setText(itemEntity.geti18nLabel());
                            item.setImage(itemEntity.getIcon());
                            item.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e1) {
                                    // DBMSLanguage.
                                    if (isPatternMatchingIndicator(indicator) && !((PatternExplorer) explorer).isImplementRegexFunction(itemEntity.getLabel())) {
                                        MessageDialog.openInformation(null, itemEntity.getLabel(), // $NON-NLS-1$
                                        DefaultMessagesImpl.getString("ChartTableFactory.NoSupportPatternTeradata"));
                                        return;
                                    }
                                    String query = itemEntity.getQuery();
                                    String editorName = indicator.getName();
                                    Connection tdDataProvider = (Connection) analysis.getContext().getConnection();
                                    SqlExplorerUtils.getDefault().runInDQViewer(tdDataProvider, query, editorName);
                                }
                            });
                            // condition columns
                            if (IndicatorHelper.isWhereRuleIndicator(indicator)) {
                                // MOD yyin 20121126 TDQ-6477,show the menu only when Join condition exists
                                WhereRuleIndicator ind = (WhereRuleIndicator) indicator;
                                EList<JoinElement> joinConditions = ind.getJoinConditions();
                                if (joinConditions.size() > 0) {
                                    showExtraMenu = true;
                                }
                            }
                            if (isPatternFrequencyIndicator(indicator) && !isEastAsiaPatternFrequencyIndicator(indicator)) {
                                createMenuOfGenerateRegularPattern(analysis, menu, dataEntity);
                            }
                        }
                        // show extra menu to create simple analysis, help user to find the duplicated rows
                        if (showExtraMenu) {
                            MenuItem itemCreateWhereRule = new MenuItem(menu, SWT.PUSH);
                            itemCreateWhereRule.setText(DefaultMessagesImpl.getString(// $NON-NLS-1$
                            "ChartTableFactory.JoinConditionColumnsAnalysis"));
                            itemCreateWhereRule.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e1) {
                                    final StructuredSelection selectionOne = (StructuredSelection) tbViewer.getSelection();
                                    // MOD xqliu 2012-05-11 TDQ-5314
                                    Object firstElement = selectionOne.getFirstElement();
                                    if (firstElement instanceof WhereRuleChartDataEntity) {
                                        // get the WhereRuleIndicator
                                        WhereRuleChartDataEntity wrChartDataEntity = (WhereRuleChartDataEntity) firstElement;
                                        WhereRuleIndicator wrInd = (WhereRuleIndicator) wrChartDataEntity.getIndicator();
                                        // run the CreateDuplicatesAnalysisAction
                                        CreateDuplicatesAnalysisAction action = new CreateDuplicatesAnalysisAction(buildColumnsMap(wrInd));
                                        action.run();
                                    }
                                // ~ TDQ-5314
                                }

                                /**
                                 * DOC xqliu Comment method "buildColumnsMap".
                                 *
                                 * @param wrInd
                                 * @return
                                 */
                                private Map<ColumnSet, List<TdColumn>> buildColumnsMap(WhereRuleIndicator wrInd) {
                                    Map<ColumnSet, List<TdColumn>> map = new HashMap<ColumnSet, List<TdColumn>>();
                                    // get all columns from the WhereRuleIndicator
                                    List<TdColumn> columns = new ArrayList<TdColumn>();
                                    EList<JoinElement> joinConditions = wrInd.getJoinConditions();
                                    for (JoinElement joinElement : joinConditions) {
                                        // add left column
                                        TdColumn tempColumn = (TdColumn) joinElement.getColA();
                                        if (!columns.contains(tempColumn)) {
                                            columns.add(tempColumn);
                                        }
                                        // add right column
                                        tempColumn = (TdColumn) joinElement.getColB();
                                        if (!columns.contains(tempColumn)) {
                                            columns.add(tempColumn);
                                        }
                                    }
                                    // build the map
                                    for (TdColumn column : columns) {
                                        ColumnSet columnSet = ColumnHelper.getColumnOwnerAsColumnSet(column);
                                        List<TdColumn> list = map.get(columnSet);
                                        if (list == null) {
                                            list = new ArrayList<TdColumn>();
                                            map.put(columnSet, list);
                                        }
                                        list.add(column);
                                    }
                                    // get the user selected map
                                    return getUserSelectedMap(map);
                                }

                                /**
                                 * DOC xqliu Comment method "getUserSelectedMap".
                                 *
                                 * @param map
                                 * @return
                                 */
                                private Map<ColumnSet, List<TdColumn>> getUserSelectedMap(Map<ColumnSet, List<TdColumn>> map) {
                                    Map<ColumnSet, List<TdColumn>> userMap = new HashMap<ColumnSet, List<TdColumn>>();
                                    // get the column nodes
                                    List<RepositoryNode> columnNodes = getColumnNodes(map);
                                    // get the connection node
                                    RepositoryNode rootNode = getConnectionNode(map);
                                    // show the dialog, let user select the columns
                                    if (!columnNodes.isEmpty() && rootNode != null) {
                                        ColumnsMapSelectionDialog dialog = new ColumnsMapSelectionDialog(null, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), // $NON-NLS-1$
                                        DefaultMessagesImpl.getString("ColumnsMapSelectionDialog.columnSelection"), // $NON-NLS-1$
                                        columnNodes, // $NON-NLS-1$
                                        rootNode, // $NON-NLS-1$
                                        DefaultMessagesImpl.getString("ColumnsMapSelectionDialog.columnSelections"));
                                        dialog.setAllMap(map);
                                        if (dialog.open() == Window.OK) {
                                            userMap = dialog.getUserMap();
                                        }
                                    }
                                    return userMap;
                                }

                                /**
                                 * DOC xqliu Comment method "getConnectionNode".
                                 *
                                 * @param map
                                 * @return
                                 */
                                private RepositoryNode getConnectionNode(Map<ColumnSet, List<TdColumn>> map) {
                                    RepositoryNode node = null;
                                    if (map != null && !map.isEmpty()) {
                                        Connection connection = ConnectionHelper.getConnection(map.keySet().iterator().next());
                                        if (connection != null) {
                                            node = RepositoryNodeHelper.recursiveFind(connection);
                                        }
                                    }
                                    return node;
                                }

                                /**
                                 * DOC xqliu Comment method "getColumnNodes".
                                 *
                                 * @param map
                                 * @return
                                 */
                                private List<RepositoryNode> getColumnNodes(Map<ColumnSet, List<TdColumn>> map) {
                                    List<RepositoryNode> nodes = new ArrayList<RepositoryNode>();
                                    if (map != null && !map.isEmpty()) {
                                        List<TdColumn> columns = new ArrayList<TdColumn>();
                                        Set<ColumnSet> keySet = map.keySet();
                                        for (ColumnSet cs : keySet) {
                                            columns.addAll(map.get(cs));
                                        }
                                        if (!columns.isEmpty()) {
                                            for (TdColumn column : columns) {
                                                nodes.add(RepositoryNodeHelper.recursiveFind(column));
                                            }
                                        }
                                    }
                                    return nodes;
                                }
                            });
                        }
                    } else {
                        if (analysis.getParameters().isStoreData()) {
                            // if allow drill down
                            if (indicator.isUsedMapDBMode()) {
                                DrillDownUtils.createDrillDownMenuForMapDB(dataEntity, menu, itemEntities, analysis);
                            } else {
                                DrillDownUtils.createDrillDownMenuForJava(dataEntity, menu, itemEntities, analysis);
                            }
                            if (isPatternFrequencyIndicator(indicator) && !isEastAsiaPatternFrequencyIndicator(indicator)) {
                                for (final MenuItemEntity itemEntity : itemEntities) {
                                    createMenuOfGenerateRegularPattern(analysis, menu, dataEntity);
                                }
                            }
                        }
                        // MOD by zshen feature 11574:add menu "Generate regular pattern" to date pattern
                        if (isDatePatternFrequencyIndicator(indicator)) {
                            final DatePatternFreqIndicator dateIndicator = (DatePatternFreqIndicator) indicator;
                            MenuItem itemCreatePatt = new MenuItem(menu, SWT.PUSH);
                            // $NON-NLS-1$
                            itemCreatePatt.setText(DefaultMessagesImpl.getString("ChartTableFactory.GenerateRegularPattern"));
                            itemCreatePatt.setImage(ImageLib.getImage(ImageLib.PATTERN_REG));
                            itemCreatePatt.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e1) {
                                    DbmsLanguage language = DbmsLanguageFactory.createDbmsLanguage(analysis);
                                    IFolder folder = ResourceManager.getPatternRegexFolder();
                                    String model = dataEntity.getLabel();
                                    String regex = dateIndicator.getRegex(model);
                                    new CreatePatternAction(folder, ExpressionType.REGEXP, "'" + regex + "'", model == null ? "" : "match \"" + model + "\"", language.getDbmsName()).run();
                                }
                            });
                        }
                    }
                    addJobGenerationMenu(menu, analysis, indicator);
                    // ~11574
                    menu.setVisible(true);
                }
            }
        }
    });
    // add tooltip
    TableUtils.addTooltipForTable(table);
    TableUtils.addActionTooltip(table);
}
Also used : HashMap(java.util.HashMap) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) Menu(org.eclipse.swt.widgets.Menu) CreatePatternAction(org.talend.dataprofiler.core.pattern.actions.CreatePatternAction) CreateDuplicatesAnalysisAction(org.talend.dataprofiler.core.ui.action.actions.CreateDuplicatesAnalysisAction) TdTable(org.talend.cwm.relational.TdTable) Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) MenuItem(org.eclipse.swt.widgets.MenuItem) WhereRuleChartDataEntity(org.talend.dq.indicators.preview.table.WhereRuleChartDataEntity) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) RepositoryNode(org.talend.repository.model.RepositoryNode) ColumnsMapSelectionDialog(org.talend.dataprofiler.core.ui.dialog.ColumnsMapSelectionDialog) UniqueCountIndicator(org.talend.dataquality.indicators.UniqueCountIndicator) EastAsiaPatternLowFreqIndicator(org.talend.dataquality.indicators.EastAsiaPatternLowFreqIndicator) FrequencyIndicator(org.talend.dataquality.indicators.FrequencyIndicator) DatePatternFreqIndicator(org.talend.dataquality.indicators.DatePatternFreqIndicator) EastAsiaPatternFreqIndicator(org.talend.dataquality.indicators.EastAsiaPatternFreqIndicator) WellFormE164PhoneCountIndicator(org.talend.dataquality.indicators.WellFormE164PhoneCountIndicator) PatternLowFreqIndicator(org.talend.dataquality.indicators.PatternLowFreqIndicator) PatternFreqIndicator(org.talend.dataquality.indicators.PatternFreqIndicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) ValidPhoneCountIndicator(org.talend.dataquality.indicators.ValidPhoneCountIndicator) WellFormIntePhoneCountIndicator(org.talend.dataquality.indicators.WellFormIntePhoneCountIndicator) PossiblePhoneCountIndicator(org.talend.dataquality.indicators.PossiblePhoneCountIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) SqlPatternMatchingIndicator(org.talend.dataquality.indicators.SqlPatternMatchingIndicator) DistinctCountIndicator(org.talend.dataquality.indicators.DistinctCountIndicator) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) WellFormNationalPhoneCountIndicator(org.talend.dataquality.indicators.WellFormNationalPhoneCountIndicator) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) JoinElement(org.talend.dataquality.rules.JoinElement) EList(org.eclipse.emf.common.util.EList) TdColumn(org.talend.cwm.relational.TdColumn) WhereRuleChartDataEntity(org.talend.dq.indicators.preview.table.WhereRuleChartDataEntity) DatePatternFreqIndicator(org.talend.dataquality.indicators.DatePatternFreqIndicator) Map(java.util.Map) HashMap(java.util.HashMap) PatternExplorer(org.talend.dq.analysis.explore.PatternExplorer) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

DatePatternFreqIndicator (org.talend.dataquality.indicators.DatePatternFreqIndicator)5 FrequencyIndicator (org.talend.dataquality.indicators.FrequencyIndicator)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 EastAsiaPatternFreqIndicator (org.talend.dataquality.indicators.EastAsiaPatternFreqIndicator)2 EastAsiaPatternLowFreqIndicator (org.talend.dataquality.indicators.EastAsiaPatternLowFreqIndicator)2 Indicator (org.talend.dataquality.indicators.Indicator)2 PatternFreqIndicator (org.talend.dataquality.indicators.PatternFreqIndicator)2 PatternLowFreqIndicator (org.talend.dataquality.indicators.PatternLowFreqIndicator)2 SoundexFreqIndicator (org.talend.dataquality.indicators.SoundexFreqIndicator)2 Set (java.util.Set)1 IFolder (org.eclipse.core.resources.IFolder)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1