Search in sources :

Example 1 with JavaUDIIndicatorParameter

use of org.talend.dataquality.domain.JavaUDIIndicatorParameter in project tdq-studio-se by Talend.

the class MyAndRegexIndicator method prepare.

@Override
public boolean prepare() {
    this.reset();
    String paramValue;
    Pattern pattern;
    if (parameters != null) {
        final Domain dataValidDomain = parameters.getIndicatorValidDomain();
        if (dataValidDomain != null) {
            patternList.clear();
            for (JavaUDIIndicatorParameter param : dataValidDomain.getJavaUDIIndicatorParameter()) {
                if (param != null) {
                    if (param.getKey().startsWith("pattern")) {
                        paramValue = param.getValue();
                        pattern = Pattern.compile(paramValue);
                        patternList.add(pattern);
                    }
                }
            }
        }
    }
    return !patternList.isEmpty();
}
Also used : Pattern(java.util.regex.Pattern) JavaUDIIndicatorParameter(org.talend.dataquality.domain.JavaUDIIndicatorParameter) Domain(org.talend.dataquality.domain.Domain)

Example 2 with JavaUDIIndicatorParameter

use of org.talend.dataquality.domain.JavaUDIIndicatorParameter 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)

Example 3 with JavaUDIIndicatorParameter

use of org.talend.dataquality.domain.JavaUDIIndicatorParameter in project tdq-studio-se by Talend.

the class JavaUDIParametersForm method initialize.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.wizard.indicator.forms.AbstractForm#initialize()
     */
@Override
protected void initialize() {
    EList<JavaUDIIndicatorParameter> javaUDIIndicatorParameter = parameters.getIndicatorValidDomain().getJavaUDIIndicatorParameter();
    for (JavaUDIIndicatorParameter judip : javaUDIIndicatorParameter) {
        content.add(judip);
    }
    viewer.refresh(content);
}
Also used : JavaUDIIndicatorParameter(org.talend.dataquality.domain.JavaUDIIndicatorParameter)

Example 4 with JavaUDIIndicatorParameter

use of org.talend.dataquality.domain.JavaUDIIndicatorParameter in project tdq-studio-se by Talend.

the class EMailValidationIndicator method initParameters.

boolean initParameters() {
    // Check prerequisite
    IndicatorParameters param = this.getParameters();
    if (param == null) {
        // $NON-NLS-1$
        log.error("No parameter set in the user defined indicator " + this.getName());
        return false;
    }
    Domain indicatorValidDomain = param.getIndicatorValidDomain();
    if (indicatorValidDomain == null) {
        // $NON-NLS-1$
        log.error("No parameter set in the user defined indicator " + this.getName());
        return false;
    }
    // else retrieve email from parameter
    EList<JavaUDIIndicatorParameter> javaUDIIndicatorParameter = indicatorValidDomain.getJavaUDIIndicatorParameter();
    for (JavaUDIIndicatorParameter p : javaUDIIndicatorParameter) {
        if (EMAIL_PARAM.equalsIgnoreCase(p.getKey())) {
            this.emailAddress = p.getValue();
        } else if (INVALID_PARAM.equalsIgnoreCase(p.getKey())) {
            this.storeInvalidData = true;
            // TODO add more checks on the file
            try {
                this.tempInvalidData = new StringBuffer();
                this.os = new FileOutputStream(new File(p.getValue()));
            } catch (FileNotFoundException e) {
                // $NON-NLS-1$
                log.error("Invalid file path in the user defined indicator: " + this.getName(), e);
                return false;
            }
        } else if (BUFFER_SIZE_PARAM.equalsIgnoreCase(p.getKey())) {
            try {
                this.buffSize = Integer.valueOf(p.getValue());
            } catch (Exception e) {
                // $NON-NLS-1$
                log.error("Invalid buffer size: " + p.getValue(), e);
                return false;
            }
        } else {
            // log warn but keep running (don't return false)
            if (!NAMING_PARAM.equalsIgnoreCase(p.getKey())) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                log.warn("Unknown parameter given to UDI: " + this.getName() + ": " + p.getKey() + " = " + p.getValue());
            }
        }
    }
    if (!this.isAddressValid(emailAddress)) {
        log.error(// $NON-NLS-1$ //$NON-NLS-2$
        "Invalid sender email set in parameters of the user defined indicator \"" + this.getName() + "\": " + emailAddress);
        return false;
    }
    return true;
}
Also used : IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) FileOutputStream(java.io.FileOutputStream) JavaUDIIndicatorParameter(org.talend.dataquality.domain.JavaUDIIndicatorParameter) FileNotFoundException(java.io.FileNotFoundException) Domain(org.talend.dataquality.domain.Domain) File(java.io.File) NamingException(javax.naming.NamingException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with JavaUDIIndicatorParameter

use of org.talend.dataquality.domain.JavaUDIIndicatorParameter in project tdq-studio-se by Talend.

the class MyOrRegexIndicator method prepare.

@Override
public boolean prepare() {
    String paramValue;
    Pattern pattern;
    if (parameters != null) {
        final Domain dataValidDomain = parameters.getIndicatorValidDomain();
        if (dataValidDomain != null) {
            patternList.clear();
            for (JavaUDIIndicatorParameter param : dataValidDomain.getJavaUDIIndicatorParameter()) {
                if (param != null) {
                    if (param.getKey().startsWith("pattern")) {
                        paramValue = param.getValue();
                        pattern = Pattern.compile(paramValue);
                        patternList.add(pattern);
                    }
                }
            }
        }
    }
    return super.prepare();
}
Also used : Pattern(java.util.regex.Pattern) JavaUDIIndicatorParameter(org.talend.dataquality.domain.JavaUDIIndicatorParameter) Domain(org.talend.dataquality.domain.Domain)

Aggregations

JavaUDIIndicatorParameter (org.talend.dataquality.domain.JavaUDIIndicatorParameter)8 Domain (org.talend.dataquality.domain.Domain)4 Pattern (java.util.regex.Pattern)2 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NamingException (javax.naming.NamingException)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1