Search in sources :

Example 41 with IndicatorDefinition

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

the class UdiLabelProvider method getText.

@Override
public String getText(Object element) {
    if (element instanceof IFile) {
        IFile file = (IFile) element;
        IndicatorDefinition udi = IndicatorResourceFileHelper.getInstance().findIndDefinition(file);
        if (udi != null) {
            return udi.getName();
        }
    }
    if (element instanceof IFolder) {
        return ((IFolder) element).getName();
    }
    if (element instanceof File) {
        File file = (File) element;
        return file.getName();
    }
    // $NON-NLS-1$
    return "";
}
Also used : IFile(org.eclipse.core.resources.IFile) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IFolder(org.eclipse.core.resources.IFolder)

Example 42 with IndicatorDefinition

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

the class UdiLabelProvider method getImage.

@Override
public Image getImage(Object element) {
    if (element instanceof IFolder) {
        return ImageLib.getImage(ImageLib.FOLDERNODE_IMAGE);
    }
    if (element instanceof IFile) {
        IndicatorDefinition findUdi = IndicatorResourceFileHelper.getInstance().findIndDefinition((IFile) element);
        boolean validStatus = TaggedValueHelper.getValidStatus(findUdi);
        ImageDescriptor imageDescriptor = ImageLib.getImageDescriptor(ImageLib.IND_DEFINITION);
        if (!validStatus) {
            ImageDescriptor warnImg = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_WARN_TSK);
            DecorationOverlayIcon icon = new DecorationOverlayIcon(imageDescriptor.createImage(), warnImg, IDecoration.BOTTOM_RIGHT);
            imageDescriptor = icon;
        }
        return imageDescriptor.createImage();
    }
    if (element instanceof File) {
        return ImageLib.getImage(ImageLib.JAR_FILE);
    }
    return null;
}
Also used : DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) IFile(org.eclipse.core.resources.IFile) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IFolder(org.eclipse.core.resources.IFolder)

Example 43 with IndicatorDefinition

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

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

the class ItemRecord method includeAggregatedDependencies.

private void includeAggregatedDependencies(IndicatorDefinition definition) {
    File depFile = EObjectHelper.modelElement2File(definition);
    if (depFile != null) {
        FILE_ELEMENT_MAP.put(depFile, definition);
        this.dependencySet.add(depFile);
    }
    for (IndicatorDefinition aggregatedDefinition : definition.getAggregatedDefinitions()) {
        includeAggregatedDependencies(aggregatedDefinition);
    }
}
Also used : File(java.io.File) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 45 with IndicatorDefinition

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

the class ItemRecord method computeDependencies.

/**
 * DOC bZhou Comment method "computeDependencies".
 */
private void computeDependencies(ModelElement mElement) {
    if (isJRXml()) {
        Collection<TdReport> allReports = (Collection<TdReport>) RepResourceFileHelper.getInstance().getAllElement();
        for (TdReport report : allReports) {
            // MOD yyi 2012-02-20 TDQ-4545 TDQ-4701: Change to relative path comparing.
            IPath pathRepFile = RepResourceFileHelper.findCorrespondingFile(report).getLocation();
            IPath pathJrxmlFile = new Path(file.getPath());
            String path = pathJrxmlFile.makeRelativeTo(pathRepFile).toString();
            for (AnalysisMap anaMap : report.getAnalysisMap()) {
                if (StringUtils.equals(path, anaMap.getJrxmlSource())) {
                    // TODO the File is jrxml, but the ModelElement is report ???
                    this.dependencySet.add(file);
                }
            }
        }
    } else if (mElement != null) {
        if (mElement instanceof Connection) {
            includeContextDependency((Connection) mElement);
            return;
        }
        List<File> dependencyFile = getClintDependencyForExport(mElement);
        for (File df : dependencyFile) {
            ModelElement modelElement = getElement(df);
            if (modelElement != null) {
                File depFile = EObjectHelper.modelElement2File(modelElement);
                if (depFile != null) {
                    this.dependencySet.add(depFile);
                }
                // MOD sizhaoliu 2013-04-13 TDQ-7082
                if (modelElement instanceof IndicatorDefinition) {
                    if (modelElement instanceof UDIndicatorDefinition) {
                        includeJUDIDependencies((IndicatorDefinition) modelElement);
                    } else {
                        for (IndicatorDefinition definition : ((IndicatorDefinition) modelElement).getAggregatedDefinitions()) {
                            includeAggregatedDependencies(definition);
                        }
                    }
                }
            }
        }
        // MOD yyi 2012-02-20 TDQ-4545 TDQ-4701: Map user define jrxm templates with report.
        if (mElement instanceof TdReport) {
            TdReport rep = (TdReport) mElement;
            for (AnalysisMap anaMap : rep.getAnalysisMap()) {
                ReportType reportType = ReportHelper.ReportType.getReportType(anaMap.getAnalysis(), anaMap.getReportType());
                boolean isUserMade = ReportHelper.ReportType.USER_MADE.equals(reportType);
                if (isUserMade) {
                    traverseFolderAndAddJrxmlDependencies(getJrxmlFolderFromReport(rep, ResourceManager.getJRXMLFolder()));
                }
            }
        } else if (mElement instanceof IndicatorDefinition) {
            // MOD sizhaoliu 2013-04-13 TDQ-7082
            IndicatorDefinition definition = (IndicatorDefinition) mElement;
            if (definition instanceof UDIndicatorDefinition) {
                includeJUDIDependencies(definition);
            } else {
                for (IndicatorDefinition defInd : definition.getAggregatedDefinitions()) {
                    includeAggregatedDependencies(defInd);
                }
            }
            // folder
            if (mElement instanceof MatchRuleDefinition) {
                includeCustomMatcherJarDependencies((MatchRuleDefinition) mElement);
            }
        } else if (mElement instanceof Analysis && AnalysisType.MATCH_ANALYSIS == AnalysisHelper.getAnalysisType((Analysis) mElement)) {
            includeCustomMatcherJarDependencies((Analysis) mElement);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdReport(org.talend.dataquality.reports.TdReport) Connection(org.talend.core.model.metadata.builder.connection.Connection) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) Collection(java.util.Collection) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) File(java.io.File) ReportType(org.talend.dataquality.helpers.ReportHelper.ReportType)

Aggregations

IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)141 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)37 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)34 TdExpression (org.talend.cwm.relational.TdExpression)31 File (java.io.File)22 Analysis (org.talend.dataquality.analysis.Analysis)16 IFile (org.eclipse.core.resources.IFile)15 Property (org.talend.core.model.properties.Property)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 Indicator (org.talend.dataquality.indicators.Indicator)12 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)12 Path (org.eclipse.core.runtime.Path)10 IFolder (org.eclipse.core.resources.IFolder)9 BasicEList (org.eclipse.emf.common.util.BasicEList)9 TdColumn (org.talend.cwm.relational.TdColumn)9 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)7 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)7