Search in sources :

Example 6 with IndicatorDefinitionParameter

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

the class UDIMasterPage method createDefinitionParametersButton.

/**
 * create Buttons for Definition Parameters.
 *
 * @param comp
 */
private void createDefinitionParametersButton(Composite comp) {
    Composite composite = toolkit.createComposite(comp);
    GridData gd = new GridData();
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = SWT.CENTER;
    composite.setLayout(new GridLayout(2, false));
    composite.setLayoutData(gd);
    final Button addButton = new Button(composite, SWT.NONE);
    addButton.setImage(ImageLib.getImage(ImageLib.ADD_ACTION));
    // $NON-NLS-1$
    addButton.setToolTipText(DefaultMessagesImpl.getString("PatternMasterDetailsPage.add"));
    GridData labelGd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
    labelGd.horizontalAlignment = SWT.RIGHT;
    labelGd.widthHint = 65;
    addButton.setLayoutData(labelGd);
    addButton.addListener(SWT.MouseDown, new Listener() {

        public void handleEvent(Event event) {
            IndicatorDefinitionParameter ip = DefinitionFactory.eINSTANCE.createIndicatorDefinitionParameter();
            // $NON-NLS-1$
            ip.setKey("paraKey");
            // $NON-NLS-1$
            ip.setValue("paraValue");
            tempParameters.add(ip);
            if (parameterTableViewer != null) {
                parameterTableViewer.refresh(tempParameters);
                setDirty(true);
            }
        }
    });
    final Button romoveButton = new Button(composite, SWT.NONE);
    romoveButton.setImage(ImageLib.getImage(ImageLib.DELETE_ACTION));
    romoveButton.setToolTipText(REMOVE_BUTTON_TEXT);
    GridData reGd = new GridData();
    reGd.horizontalAlignment = SWT.LEFT;
    reGd.widthHint = 65;
    romoveButton.setLayoutData(reGd);
    romoveButton.addListener(SWT.MouseDown, new Listener() {

        public void handleEvent(Event event) {
            IStructuredSelection selection = (IStructuredSelection) parameterTableViewer.getSelection();
            Object o = selection.getFirstElement();
            if (o instanceof IndicatorDefinitionParameter) {
                element = (IndicatorDefinitionParameter) o;
                tempParameters.remove(element);
                parameterTableViewer.refresh(tempParameters);
                setDirty(true);
            }
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 7 with IndicatorDefinitionParameter

use of org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter 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 8 with IndicatorDefinitionParameter

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

the class FileSystemImportWriter method mergeSystemIndicator.

/**
 * Added: (20120808 yyin, TDQ-4189) The system indicators are not read-only because the user may want to write his
 * own SQL template. so this task deals with the modified SI from imported one, and merge them with the current
 * studio. 1)only when the user select the"Overwrite existing items" on the import wizard(and the modifydate is
 * newer than the current studio's SI), the conflict modification in imported SI will overwrite the ones in current
 * studio, otherwise, the SI in current studio will keep. 2)If a language does not exist in the system indicator but
 * exists in the user modified indicator, then we add it 3)if a language exists in the system indicator but has been
 * removed in the user modified indicator, then we keep the system indicator definition. [for Indicator
 * matadata(Purpose, Description, Author, Status): 1) will replace old value with new value if new value is not
 * blank; 2) will keep old value if new value is blank][for IndicatorDefinitionParameter: 1) will replace the same
 * name old parameter with new parameter; 2) will keep the old parameter if new one don't include the same name
 * parameter ]
 *
 * @param record imported modified system indicator
 * @param siDef the system indicator in the current studio
 */
protected void mergeSystemIndicator(ItemRecord record, TDQIndicatorDefinitionItem siDefItem) {
    // only when the Si is modified, do the save
    boolean isModified = false;
    // old object
    IndicatorDefinition siDef = siDefItem.getIndicatorDefinition();
    Property siProp = siDefItem.getProperty();
    // new object
    IndicatorDefinition indDef = (IndicatorDefinition) record.getElement();
    Property indDefProp = record.getProperty();
    // get expression list from record
    EList<TdExpression> importedExs = indDef.getSqlGenericExpression();
    // for each expression:
    for (TdExpression importedEx : importedExs) {
        // if the modify date ==null, means it is not modified, do nothing
        if (importedEx.getModificationDate() == null) {
            continue;
        }
        // find the related template in system indicator(with same language)
        TdExpression systemExpression = null;
        for (TdExpression ex : siDef.getSqlGenericExpression()) {
            if (ex.getLanguage().equals(importedEx.getLanguage())) {
                systemExpression = ex;
                break;
            }
        }
        // if new, add to SI
        if (systemExpression == null) {
            IndicatorDefinitionFileHelper.addSqlExpression(siDef, importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
            isModified = true;
        } else {
            // if the expression are different: compare the modify date, make the SI keep the new one
            if (replaceExpression(systemExpression, importedEx)) {
                IndicatorDefinitionFileHelper.removeSqlExpression(siDef, importedEx.getLanguage());
                IndicatorDefinitionFileHelper.addSqlExpression(siDef, importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
                isModified = true;
            }
        }
    }
    // handle the category
    IndicatorCategory siDefCategory = IndicatorCategoryHelper.getCategory(siDef);
    IndicatorCategory indDefCategory = IndicatorCategoryHelper.getCategory(indDef);
    siDefCategory = (IndicatorCategory) EObjectHelper.resolveObject(siDefCategory);
    indDefCategory = (IndicatorCategory) EObjectHelper.resolveObject(indDefCategory);
    if (!ModelElementHelper.compareUUID(siDefCategory, indDefCategory)) {
        // use the imported one
        IndicatorCategoryHelper.setCategory(siDef, indDefCategory);
        isModified = true;
    } else {
        // if the uuid is the same, but the label is different
        if (siDefCategory != null && indDefCategory != null && !siDefCategory.eIsProxy()) {
            if (!indDefCategory.equals(siDefCategory)) {
                // especially: "Pattern Finder" is changed by us
                if (!indDefCategory.getLabel().equals(RenamePatternFinderFolderTask.PATTERN_FINDER)) {
                    IndicatorCategoryHelper.setCategory(siDef, indDefCategory);
                    isModified = true;
                }
            }
        }
    }
    // for Indicator Metadata
    if (siProp != null && indDefProp != null) {
        if (!StringUtils.isBlank(indDefProp.getPurpose())) {
            siProp.setPurpose(indDefProp.getPurpose());
        }
        if (!StringUtils.isBlank(indDefProp.getDescription())) {
            siProp.setDescription(indDefProp.getDescription());
        }
        siProp.setAuthor(indDefProp.getAuthor());
        siProp.setStatusCode(indDefProp.getStatusCode());
        isModified = true;
    }
    // for judi's jar file information
    String jarFilePath = TaggedValueHelper.getJarFilePath(indDef);
    if (!StringUtils.isBlank(jarFilePath)) {
        TaggedValueHelper.setJarFilePath(jarFilePath, siDef);
        isModified = true;
    }
    String classNameText = TaggedValueHelper.getClassNameText(indDef);
    if (!StringUtils.isBlank(classNameText)) {
        TaggedValueHelper.setClassNameText(classNameText, siDef);
        isModified = true;
    }
    // for IndicatorDefinintionParameter
    EList<IndicatorDefinitionParameter> siParameter = siDef.getIndicatorDefinitionParameter();
    EList<IndicatorDefinitionParameter> indDefParameter = indDef.getIndicatorDefinitionParameter();
    List<IndicatorDefinitionParameter> tempParameter = new ArrayList<IndicatorDefinitionParameter>();
    for (IndicatorDefinitionParameter indDefPara : indDefParameter) {
        boolean include = false;
        String key = indDefPara.getKey();
        for (IndicatorDefinitionParameter siPara : siParameter) {
            if (key.equals(siPara.getKey())) {
                include = true;
                siPara.setValue(indDefPara.getValue());
                isModified = true;
            }
        }
        if (!include) {
            tempParameter.add(indDefPara);
            isModified = true;
        }
    }
    if (isModified && !tempParameter.isEmpty()) {
        siParameter.addAll(tempParameter);
    }
    if (isModified) {
        try {
            ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().save(siDefItem, false);
        } catch (Exception e) {
            log.error(e);
        }
    }
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) ArrayList(java.util.ArrayList) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) Property(org.talend.core.model.properties.Property) CoreException(org.eclipse.core.runtime.CoreException) LoginException(org.talend.commons.exception.LoginException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 9 with IndicatorDefinitionParameter

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

the class ExportFactory method getRelatedValueFromIndicatorDefinition.

private static Map<PatternToExcelEnum, String> getRelatedValueFromIndicatorDefinition(IndicatorDefinition indicatorDefinition, IFolder folder) {
    Map<PatternToExcelEnum, String> idMap = new HashMap<PatternToExcelEnum, String>();
    if (folder != null) {
        IFile file = ResourceFileMap.findCorrespondingFile(indicatorDefinition);
        URI relativeURI = folder.getLocationURI().relativize(file.getParent().getLocationURI());
        // get the basic information
        idMap.put(PatternToExcelEnum.Label, relpaceTempHasEscapeCharactor(indicatorDefinition.getName()));
        idMap.put(PatternToExcelEnum.Purpose, relpaceTempHasEscapeCharactor(MetadataHelper.getPurpose(indicatorDefinition)));
        idMap.put(PatternToExcelEnum.Description, relpaceTempHasEscapeCharactor(MetadataHelper.getDescription(indicatorDefinition)));
        idMap.put(PatternToExcelEnum.Author, relpaceTempHasEscapeCharactor(MetadataHelper.getAuthor(indicatorDefinition)));
        idMap.put(PatternToExcelEnum.RelativePath, relativeURI.toString());
        idMap.put(PatternToExcelEnum.Category, UDIHelper.getUDICategory(indicatorDefinition).getLabel());
        TaggedValue tagValue = TaggedValueHelper.getTaggedValue(TaggedValueHelper.CLASS_NAME_TEXT, indicatorDefinition.getTaggedValue());
        idMap.put(PatternToExcelEnum.JavaClassName, tagValue == null ? null : tagValue.getValue());
        tagValue = TaggedValueHelper.getTaggedValue(TaggedValueHelper.JAR_FILE_PATH, indicatorDefinition.getTaggedValue());
        idMap.put(PatternToExcelEnum.JavaJarPath, tagValue == null ? null : tagValue.getValue());
        for (PatternLanguageType languagetype : PatternLanguageType.values()) {
            for (Expression expression : indicatorDefinition.getSqlGenericExpression()) {
                if (expression != null && expression.getLanguage().equalsIgnoreCase(languagetype.getLiteral())) {
                    idMap.put(languagetype.getExcelEnum(), expression.getBody());
                }
            }
            if (!idMap.containsKey(languagetype.getExcelEnum())) {
                // $NON-NLS-1$
                idMap.put(languagetype.getExcelEnum(), "");
            }
        }
        // put the IndicatorDefinitionParameter into Map
        StringBuffer strBuf = new StringBuffer();
        EList<IndicatorDefinitionParameter> indDefParas = indicatorDefinition.getIndicatorDefinitionParameter();
        for (IndicatorDefinitionParameter indDefPara : indDefParas) {
            strBuf.append(indDefPara.getKey() + UDIHelper.PARA_SEPARATE_1 + indDefPara.getValue() + UDIHelper.PARA_SEPARATE_2);
        }
        idMap.put(PatternToExcelEnum.IndicatorDefinitionParameter, strBuf.toString());
    }
    return idMap;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) URI(java.net.URI)

Example 10 with IndicatorDefinitionParameter

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

the class IndicatorDefinitionParameterImpl method clone.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
@Override
public IndicatorDefinitionParameter clone() {
    IndicatorDefinitionParameter result = DefinitionFactory.eINSTANCE.createIndicatorDefinitionParameter();
    result.setKey(this.getKey());
    result.setValue(this.getValue());
    return result;
}
Also used : IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter)

Aggregations

IndicatorDefinitionParameter (org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter)12 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)5 IFolder (org.eclipse.core.resources.IFolder)4 TdExpression (org.talend.cwm.relational.TdExpression)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 CSVReader (com.talend.csv.CSVReader)2 HashMap (java.util.HashMap)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)2 ReturnCode (org.talend.utils.sugars.ReturnCode)2 Expression (orgomg.cwm.objectmodel.core.Expression)2 IOException (java.io.IOException)1 URI (java.net.URI)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1