Search in sources :

Example 1 with UserDefIndicator

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

the class SplitSysIndicatorTask method updateIndDefinition.

private void updateIndDefinition(Indicator ind) {
    if (ind == null) {
        return;
    }
    IndicatorDefinition indicatorDefinition = ind.getIndicatorDefinition();
    if (indicatorDefinition == null) {
        return;
    }
    // ADD xqliu 2010-07-28 13676 don't update UserDefIndicator
    if (ind instanceof UserDefIndicator) {
        return;
    }
    // ~ 13676
    CwmResource indDefResource = (CwmResource) indicatorDefinition.eResource();
    if (indDefResource == null) {
        // MOD scorreia 2010-10-05 16030 set the link between indicators and their definition
        if (DefinitionHandler.getInstance().setDefaultIndicatorDefinition(ind)) {
            if (log.isDebugEnabled()) {
                log.debug(// $NON-NLS-1$//$NON-NLS-2$
                "MIGRATING: indicator definition " + indicatorDefinition.getName() + " in indicator " + ind.getName() + " in analysis " + // $NON-NLS-1$
                ind.eResource());
            }
        } else {
            log.error(DefaultMessagesImpl.getString("SplitSysIndicatorTask_LogErr", indicatorDefinition.getName(), ind.getName(), // $NON-NLS-1$
            ind.eResource()));
        }
    // ~ 16030
    } else {
        // Find updated indicator definition
        IndicatorDefinition updatedDefinition = DefinitionHandler.getInstance().getDefinitionById(indDefResource.getID(ind.getIndicatorDefinition()));
        ind.setIndicatorDefinition(updatedDefinition);
    }
}
Also used : CwmResource(org.talend.model.emf.CwmResource) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 2 with UserDefIndicator

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

the class PatternStatisticeStateUtilTest method testGetUnitValueCase2.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.editor.preview.model.states.pattern.PatternStatisticeStateUtil#getUnitValue(org.talend.dataquality.indicators.Indicator, java.lang.Object)}
 * .
 * case2:normal UDI case
 */
@Test
public void testGetUnitValueCase2() {
    PatternMatchingExt pMatchExt = null;
    UserDefIndicator userDefIndicator = IndicatorSqlFactoryImpl.eINSTANCE.createUserDefIndicator();
    userDefIndicator.setComputed(true);
    userDefIndicator.setMatchingValueCount(40l);
    userDefIndicator.setNotMatchingValueCount(50l);
    PatternMatchingExt unitValue = PatternStatisticeStateUtil.getUnitValue(userDefIndicator, pMatchExt);
    // $NON-NLS-1$
    Assert.assertEquals("Matching count value shoud be 40l", 40l, unitValue.getMatchingValueCount());
    // $NON-NLS-1$
    Assert.assertEquals("Not matching count value shoud be 50l", 50l, unitValue.getNotMatchingValueCount());
    // $NON-NLS-1$
    Assert.assertNotEquals("unitValue should not same with pMatchExt but it is not now", pMatchExt, unitValue);
}
Also used : PatternMatchingExt(org.talend.dq.indicators.ext.PatternMatchingExt) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Test(org.junit.Test)

Example 3 with UserDefIndicator

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

the class UDIUtilsTest method testCheckExistInList.

/**
 * Test method for {@link
 * org.talend.dataprofiler.core.ui.utils.UDIUtils#checkExistInList(EList<org.talend.cwm.relational.TdExpression>,
 * java.lang.String, java.lang.String)} .
 */
@Test
public void testCheckExistInList() {
    // create user define indicator
    UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
    UDIndicatorDefinition indicatorDefinition = UserdefineFactory.eINSTANCE.createUDIndicatorDefinition();
    // $NON-NLS-1$
    indicatorDefinition.setName("user define");
    userDefIndicator.setName(indicatorDefinition.getName());
    userDefIndicator.setIndicatorDefinition(indicatorDefinition);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    TdExpression tdExpression = UDIUtils.createNewTdExpression("MySQL", "5.0.2", "select * from test");
    indicatorDefinition.getViewRowsExpression().add(tdExpression);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    TdExpression tdExpression_2 = UDIUtils.createNewTdExpression("Oracle", "5.0.2", "select * from test");
    indicatorDefinition.getViewRowsExpression().add(tdExpression_2);
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(UDIUtils.checkExistInList(indicatorDefinition.getViewRowsExpression(), "Oracle", "5.0.2"));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertFalse(UDIUtils.checkExistInList(indicatorDefinition.getViewRowsExpression(), "MySQL", "5.1.2"));
    // $NON-NLS-1$
    assertFalse(UDIUtils.checkExistInList(indicatorDefinition.getViewRowsExpression(), "Oracle", null));
}
Also used : UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Test(org.junit.Test)

Example 4 with UserDefIndicator

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

the class DbmsLanguage method getRegexPatternString.

/**
 * Method "getRegexPatternString".
 *
 * @param indicator
 * @return the regular expression or null if none was found
 */
public String getRegexPatternString(Indicator indicator) {
    if (indicator instanceof PatternMatchingIndicator || (indicator instanceof UserDefIndicator && IndicatorCategoryHelper.isUserDefMatching(IndicatorCategoryHelper.getCategory(indicator.getIndicatorDefinition())))) {
        IndicatorParameters parameters = indicator.getParameters();
        if (parameters == null) {
            return null;
        }
        Domain dataValidDomain = parameters.getDataValidDomain();
        if (dataValidDomain == null) {
            return null;
        }
        EList<Pattern> patterns = dataValidDomain.getPatterns();
        for (Pattern pattern : patterns) {
            Expression expression = this.getRegexp(pattern);
            return expression == null ? null : expression.getBody();
        }
    }
    return null;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) Domain(org.talend.dataquality.domain.Domain) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 5 with UserDefIndicator

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

the class UDIUtils method createIndicatorUnit.

public static IndicatorUnit[] createIndicatorUnit(IndicatorDefinition udid, ModelElementIndicator meIndicator, Analysis analysis) throws Throwable {
    List<IndicatorUnit> addIndicatorUnits = new ArrayList<IndicatorUnit>();
    // can't add the same user defined indicator
    for (Indicator indicator : meIndicator.getIndicators()) {
        // MOD xwang 2011-08-01 bug TDQ-2730
        if (udid.getName().equals(indicator.getName()) && indicator instanceof UserDefIndicator) {
            // $NON-NLS-1$
            MessageUI.openWarning(DefaultMessagesImpl.getString("UDIUtils.UDISelected", udid.getName()));
            return null;
        }
    }
    Indicator udi = UDIFactory.createUserDefIndicator(udid);
    udi.setIndicatorDefinition(udid);
    // MOD mzhao feature 11128, Handle Java User Defined Indicator.
    Indicator judi = UDIHelper.adaptToJavaUDI(udi);
    if (judi != null) {
        udi = judi;
    }
    IEditorPart activeEditor = CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor == null || !(activeEditor instanceof AnalysisEditor)) {
        return null;
    }
    ExecutionLanguage executionLanguage = ((AnalysisEditor) activeEditor).getUIExecuteEngin();
    boolean isJavaEngin = ExecutionLanguage.JAVA.equals(executionLanguage);
    DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(analysis, executionLanguage);
    Expression returnExpression = dbmsLanguage.getExpression(udi);
    String executeType = isJavaEngin ? executionLanguage.getName() : dbmsLanguage.getDbmsName();
    // MOD qiongli 2013.5.22 TDQ-7282.if don't find a valid java expression for JUDI,should also pop this dialog.
    boolean finddExpression = true;
    if (isJavaEngin && judi == null || !isJavaEngin && returnExpression == null) {
        finddExpression = false;
    }
    if (!finddExpression) {
        // open the editor
        boolean openUDI = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("PatternUtilities.Warning"), // $NON-NLS-1$ //$NON-NLS-2$
        DefaultMessagesImpl.getString("UDIUtils.NoExpression", executeType));
        if (openUDI) {
            RepositoryNode node = RepositoryNodeHelper.recursiveFind(udid);
            if (RepositoryNodeHelper.canOpenEditor(node)) {
                new OpenItemEditorAction(new IRepositoryNode[] { node }).run();
            }
        }
        return null;
    }
    // dbmsLanguage
    IndicatorParameters parameters = udi.getParameters();
    if (parameters == null) {
        parameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
        udi.setParameters(parameters);
    }
    Domain indicatorValidDomain = parameters.getIndicatorValidDomain();
    if (indicatorValidDomain == null) {
        // $NON-NLS-1$
        indicatorValidDomain = DomainHelper.createDomain("JAVA_UDI_PARAMETERS");
        parameters.setIndicatorValidDomain(indicatorValidDomain);
    }
    List<IndicatorDefinitionParameter> indicatorDefs = udid.getIndicatorDefinitionParameter();
    for (IndicatorDefinitionParameter idp : indicatorDefs) {
        JavaUDIIndicatorParameter judip = DomainHelper.createJavaUDIIndicatorParameter(idp.getKey(), idp.getValue());
        indicatorValidDomain.getJavaUDIIndicatorParameter().add(judip);
    }
    IndicatorEnum indicatorType = IndicatorEnum.findIndicatorEnum(udi.eClass());
    addIndicatorUnits.add(meIndicator.addSpecialIndicator(indicatorType, udi));
    DependenciesHandler.getInstance().setUsageDependencyOn(analysis, udid);
    return addIndicatorUnits.toArray(new IndicatorUnit[addIndicatorUnits.size()]);
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) IndicatorEnum(org.talend.dq.nodes.indicator.type.IndicatorEnum) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) ArrayList(java.util.ArrayList) JavaUDIIndicatorParameter(org.talend.dataquality.domain.JavaUDIIndicatorParameter) ExecutionLanguage(org.talend.dataquality.analysis.ExecutionLanguage) IEditorPart(org.eclipse.ui.IEditorPart) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Indicator(org.talend.dataquality.indicators.Indicator) DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor) Domain(org.talend.dataquality.domain.Domain) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Aggregations

UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)23 Test (org.junit.Test)9 TdExpression (org.talend.cwm.relational.TdExpression)7 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)7 ArrayList (java.util.ArrayList)6 Indicator (org.talend.dataquality.indicators.Indicator)6 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)6 Analysis (org.talend.dataquality.analysis.Analysis)5 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)5 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)5 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)4 Expression (orgomg.cwm.objectmodel.core.Expression)4 Path (org.eclipse.core.runtime.Path)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 ItemState (org.talend.core.model.properties.ItemState)3 Property (org.talend.core.model.properties.Property)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 IndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)3 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)3 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)3