Search in sources :

Example 6 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class ImportFactory method createAndStoreUDI.

/**
 * DOC xqliu Comment method "createAndStoreUDI".
 *
 * @param parameters
 * @param selectionFolder
 */
private static TypedReturnCode<Object> createAndStoreUDI(UDIParameters parameters, IFolder selectionFolder) {
    UDIndicatorDefinition indDef = UDIHelper.createUDI(parameters.name, parameters.auther, parameters.description, parameters.purpose, parameters.status, parameters.category, parameters.javaClassName, parameters.javaJarPath);
    for (String key : parameters.regex.keySet()) {
        TdExpression expression = BooleanExpressionHelper.createTdExpression(key, parameters.regex.get(key));
        indDef.getSqlGenericExpression().add(expression);
    }
    boolean validStatus = UDIHelper.isUDIValid(indDef);
    TaggedValueHelper.setValidStatus(validStatus, indDef);
    Map<String, String> paraMap = parameters.getParaMap();
    if (!paraMap.isEmpty()) {
        for (String key : paraMap.keySet()) {
            String value = paraMap.get(key);
            IndicatorDefinitionParameter idPara = DefinitionFactory.eINSTANCE.createIndicatorDefinitionParameter();
            idPara.setKey(key);
            idPara.setValue(value);
            indDef.getIndicatorDefinitionParameter().add(idPara);
        }
    }
    try {
        // $NON-NLS-1$
        String[] folderNames = parameters.relativePath.split("/");
        for (String folderName : folderNames) {
            IFolder folder = selectionFolder.getFolder(folderName);
            if (!folder.exists()) {
                folder.create(false, true, null);
            }
            selectionFolder = folder;
        }
    } catch (CoreException e) {
        log.error(e, e);
    }
    indDef = UDIUtils.createDefaultDrillDownList(indDef);
    return ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().create(indDef, selectionFolder);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class UpdateModeIndicatorDefinitionForAS400Task method doExecute.

@Override
protected boolean doExecute() throws Exception {
    boolean result = true;
    try {
        IndicatorDefinition indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition(MODE_INDICATOR_LABEL);
        URI uriItem = indicatorDefinition.eResource().getURI();
        File fileItem = null;
        if (uriItem.isPlatform()) {
            fileItem = WorkspaceUtils.ifileToFile(getIFile(indicatorDefinition));
        } else {
            fileItem = new File(uriItem.toFileString());
        }
        File fileProp = WorkspaceUtils.ifileToFile(PropertyHelper.getPropertyFile(indicatorDefinition));
        Property property = PropertyHelper.getProperty(indicatorDefinition);
        Item item = property.getItem();
        if (indicatorDefinition != null) {
            EList<TdExpression> sqlGenericExpression = indicatorDefinition.getSqlGenericExpression();
            boolean addAS400Expression = true;
            for (TdExpression expression : sqlGenericExpression) {
                if (SupportDBUrlType.AS400DEFAULTURL.getLanguage().equals(expression.getLanguage())) {
                    addAS400Expression = false;
                    break;
                }
            }
            if (addAS400Expression) {
                TDQIndicatorDefinitionItem indDefItem = (TDQIndicatorDefinitionItem) item;
                Resource itemResource = getResource(fileItem);
                IndicatorDefinition indDef = null;
                for (EObject object : itemResource.getContents()) {
                    if (object instanceof IndicatorDefinition) {
                        indDef = (IndicatorDefinition) object;
                        IndicatorDefinitionFileHelper.addSqlExpression(indDef, SupportDBUrlType.AS400DEFAULTURL.getLanguage(), BODY_MODE_AS400);
                        String relationPropPath = ReponsitoryContextBridge.getRootProject().getFullPath().append(new Path(fileProp.getPath()).makeRelativeTo(this.getWorkspacePath())).toOSString();
                        MetadataHelper.setPropertyPath(relationPropPath, indDef);
                        indDefItem.setIndicatorDefinition(indDef);
                    }
                }
                EMFUtil.saveResource(itemResource);
                Resource propResource = getResource(fileProp);
                Property newProperty = (Property) EcoreUtil.getObjectByType(propResource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
                newProperty.setAuthor(property.getAuthor());
                newProperty.setLabel(indDefItem.getIndicatorDefinition().getName());
                newProperty.setItem(item);
                item.setProperty(newProperty);
                propResource.getContents().clear();
                propResource.getContents().add(newProperty);
                propResource.getContents().add(item);
                propResource.getContents().add(item.getState());
                EMFUtil.saveResource(propResource);
            }
        }
    } catch (Exception e) {
        result = false;
        e.printStackTrace();
    }
    return result;
}
Also used : Path(org.eclipse.core.runtime.Path) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TdExpression(org.talend.cwm.relational.TdExpression) Resource(org.eclipse.emf.ecore.resource.Resource) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) URI(org.eclipse.emf.common.util.URI) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) EObject(org.eclipse.emf.ecore.EObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Property(org.talend.core.model.properties.Property)

Example 8 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class UpdateOracleAverageLengthTask method setNewExpression.

private void setNewExpression(IndicatorDefinition indDefinition, String newExpOracle) {
    if (indDefinition == null) {
        return;
    }
    EList<TdExpression> sqlExpressions = indDefinition.getSqlGenericExpression();
    String languge = null;
    for (TdExpression tdExp : sqlExpressions) {
        languge = tdExp.getLanguage();
        if (DbmsLanguageFactory.isOracle(languge)) {
            tdExp.setBody(newExpOracle);
        }
    }
    IndicatorDefinitionFileHelper.save(indDefinition);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression)

Example 9 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class UpdateRegularExpressionMatchingMysqlExpressionTask method doExecute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.migration.AMigrationTask#doExecute()
     */
@Override
protected boolean doExecute() throws Exception {
    IndicatorDefinition indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition(REGULAR_EXPRESSION_MATCHING_LABEL);
    if (indicatorDefinition != null) {
        EList<TdExpression> sqlGenericExpression = indicatorDefinition.getSqlGenericExpression();
        if (sqlGenericExpression != null && sqlGenericExpression.size() > 0) {
            boolean notFoundMysqlExpression = true;
            for (TdExpression expression : sqlGenericExpression) {
                if (expression != null && SupportDBUrlType.MYSQLDEFAULTURL.getLanguage().equals(expression.getLanguage())) {
                    notFoundMysqlExpression = false;
                    expression.setBody(MYSQL_EXPRESSION);
                    break;
                }
            }
            if (notFoundMysqlExpression) {
                TdExpression newExpression = BooleanExpressionHelper.createTdExpression(SupportDBUrlType.MYSQLDEFAULTURL.getLanguage(), MYSQL_EXPRESSION);
                sqlGenericExpression.add(newExpression);
            } else {
            // mysql expression have exist, so needn't to create a new mysql expression
            }
        }
    }
    return true;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 10 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class UpdateLowerUpperQuartileForDB2Task method updateSqlForDB2.

private boolean updateSqlForDB2(String indicatorName, String sqlExpression) {
    IndicatorDefinition indiDefinition = IndicatorDefinitionFileHelper.getSystemIndicatorByName(indicatorName);
    if (indiDefinition != null && IndicatorDefinitionFileHelper.removeSqlExpression(indiDefinition, DB2)) {
        List<TdExpression> remainExpLs = new ArrayList<TdExpression>();
        remainExpLs.addAll(indiDefinition.getSqlGenericExpression());
        indiDefinition.getSqlGenericExpression().clear();
        IndicatorDefinitionFileHelper.addSqlExpression(indiDefinition, DB2, sqlExpression);
        indiDefinition.getSqlGenericExpression().addAll(remainExpLs);
        return IndicatorDefinitionFileHelper.save(indiDefinition);
    }
    return true;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Aggregations

TdExpression (org.talend.cwm.relational.TdExpression)121 Test (org.junit.Test)51 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)30 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)29 ArrayList (java.util.ArrayList)19 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)19 Pattern (org.talend.dataquality.domain.pattern.Pattern)16 TdColumn (org.talend.cwm.relational.TdColumn)12 Expression (orgomg.cwm.objectmodel.core.Expression)12 BasicEList (org.eclipse.emf.common.util.BasicEList)11 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)11 Domain (org.talend.dataquality.domain.Domain)10 TdTable (org.talend.cwm.relational.TdTable)9 ProductVersion (org.talend.utils.ProductVersion)9 Analysis (org.talend.dataquality.analysis.Analysis)8 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)8 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)6 IFolder (org.eclipse.core.resources.IFolder)6