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);
}
}
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);
}
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));
}
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;
}
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()]);
}
Aggregations