Search in sources :

Example 56 with IndicatorDefinition

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

the class DefinitionHandler method updateAggregates.

/**
 * Update aggregates for some indicators(Simple Statistic Indicator/Text Statistic Indicator...).make the path/name
 * of indicator definition in agregate right and is not a proxy).
 */
public void updateAggregates() {
    List<IndicatorDefinition> indicatorsDefinitions = getIndicatorsDefinitions();
    String defFileExt = PluginConstant.DOT_STRING + FactoriesUtil.DEFINITION;
    for (IndicatorDefinition indiDef : indicatorsDefinitions) {
        EList<IndicatorDefinition> aggregatedDefinitions = indiDef.getAggregatedDefinitions();
        List<IndicatorDefinition> updatedAggrDefinitions = new ArrayList<IndicatorDefinition>();
        if (indiDef.eIsProxy() || aggregatedDefinitions == null || aggregatedDefinitions.isEmpty()) {
            continue;
        }
        for (IndicatorDefinition aggrDef : aggregatedDefinitions) {
            URI oldUri = EObjectHelper.getURI(aggrDef);
            if (oldUri == null) {
                continue;
            }
            String oldLabel = (oldUri.lastSegment());
            oldLabel = oldLabel.replace(defFileExt, PluginConstant.EMPTY_STRING);
            if (oldLabel.equalsIgnoreCase("Inter Quartile Range")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                oldLabel = "IQR";
            }
            IndicatorDefinition find = getIndicatorDefinition(oldLabel);
            if (find != null) {
                updatedAggrDefinitions.add(find);
            }
        }
        indiDef.getAggregatedDefinitions().clear();
        indiDef.getAggregatedDefinitions().addAll(updatedAggrDefinitions);
        EMFSharedResources.getInstance().saveResource(indiDef.eResource());
    }
}
Also used : ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) URI(org.eclipse.emf.common.util.URI)

Example 57 with IndicatorDefinition

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

the class DefinitionHandler method getIndicatorModelElement.

private final ModelElement getIndicatorModelElement(File file) {
    DefinitionSwitch<IndicatorDefinition> definitionSwitch = new DefinitionSwitch<IndicatorDefinition>() {

        @Override
        public IndicatorDefinition caseIndicatorDefinition(IndicatorDefinition object) {
            return object;
        }
    };
    if (file != null) {
        Resource resource = EmfFileResourceUtil.getInstance().getFileResource(file.getAbsolutePath());
        EList<EObject> contents = resource.getContents();
        if (contents.isEmpty()) {
            // $NON-NLS-1$
            log.error("no content in: " + resource);
        }
        for (EObject object : contents) {
            ModelElement switchObject = definitionSwitch.doSwitch(object);
            if (switchObject != null) {
                return switchObject;
            }
        }
    }
    return null;
}
Also used : DefinitionSwitch(org.talend.dataquality.indicators.definition.util.DefinitionSwitch) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EObject(org.eclipse.emf.ecore.EObject) CwmResource(org.talend.model.emf.CwmResource) Resource(org.eclipse.emf.ecore.resource.Resource) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)

Example 58 with IndicatorDefinition

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

the class DefinitionHandler method reloadAllUDIs.

/**
 * reload all user defined indicators, when some udi's name is changed, this method will be needed
 */
public void reloadAllUDIs() {
    List<IndicatorDefinition> udis = new ArrayList<IndicatorDefinition>();
    for (IndicatorDefinition indicatorDefinition : this.getIndicatorsDefinitions()) {
        if (indicatorDefinition instanceof UDIndicatorDefinition) {
            udis.add(indicatorDefinition);
        }
    }
    // remove all udis
    this.getIndicatorsDefinitions().removeAll(udis);
    // reload all udis
    this.getIndicatorsDefinitions().addAll(IndicatorResourceFileHelper.getInstance().getAllUDIs());
}
Also used : UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)

Example 59 with IndicatorDefinition

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

the class DefinitionHandler method updateRegex.

public boolean updateRegex(String dbmsName, String regexpFunction) {
    boolean ok = true;
    boolean replaced = false;
    IndicatorDefinition regexIndDef = this.getIndicatorDefinition(REGULAR_EXPRESSION_MATCHING);
    EList<TdExpression> sqlGenericExpression = regexIndDef.getSqlGenericExpression();
    for (Expression expression : sqlGenericExpression) {
        // MOD qiongli 2011-4-18,bug 16723.data cleansing.
        if (DbmsLanguageFactory.compareDbmsLanguage(dbmsName, expression.getLanguage())) {
            replaced = replaceBodyWith(expression, regexpFunction);
        }
    }
    if (!replaced) {
        // add new expression
        String genericSQL = getGenericSQL(dbmsName, regexpFunction);
        TdExpression createdExpression = BooleanExpressionHelper.createTdExpression(dbmsName, genericSQL);
        sqlGenericExpression.add(createdExpression);
    }
    return ok;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)

Example 60 with IndicatorDefinition

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

the class DefinitionHandler method getDefinitionById.

/**
 * DOC mzhao Get indicator definition by definition id (xmi id).
 *
 * @param definitionId
 * @return
 */
public IndicatorDefinition getDefinitionById(String definitionId) {
    for (IndicatorDefinition indDef : this.getIndicatorsDefinitions()) {
        CwmResource resource = (CwmResource) indDef.eResource();
        if (resource == null) {
            return null;
        }
        EObject object = resource.getEObject(definitionId);
        if (object != null && DefinitionPackage.eINSTANCE.getIndicatorDefinition().equals(object.eClass())) {
            return (IndicatorDefinition) object;
        }
    }
    return null;
}
Also used : CwmResource(org.talend.model.emf.CwmResource) EObject(org.eclipse.emf.ecore.EObject) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)

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