Search in sources :

Example 41 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class AnalysisExecutorHelper method checkMatchingIndicator.

/**
 * DOC zhao Comment method "checkMatchingIndicator".
 *
 * @param indicator
 * @return
 */
private static ReturnCode checkMatchingIndicator(Indicator indicator) {
    ReturnCode rc = new ReturnCode(Boolean.TRUE);
    Domain domain = indicator.getParameters().getDataValidDomain();
    if (!domain.getBuiltInPatterns().isEmpty()) {
        return rc;
    }
    List<Pattern> patterns = domain.getPatterns();
    // check pattern matching indicator files' existence.
    if (!patterns.isEmpty() && isDependentFileExist(patterns.toArray(new Pattern[patterns.size()]))) {
        // Hot copy the pattern from separate file into built in.
        hotCopyPatterns(indicator, patterns);
    } else {
        List<Pattern> builtInPatterns = indicator.getParameters().getDataValidDomain().getBuiltInPatterns();
        if (builtInPatterns.isEmpty()) {
            // $NON-NLS-1$
            rc.setMessage(Messages.getString("AnalysisExecutor.BuiltInNoPatterns"));
            rc.setOk(false);
            return rc;
        } else {
            // Use built-in pattern instead.
            patterns.clear();
        }
    }
    return rc;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) ReturnCode(org.talend.utils.sugars.ReturnCode) Domain(org.talend.dataquality.domain.Domain)

Example 42 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class UDIUtils method checkUDIDependency.

public static ReturnCode checkUDIDependency(IndicatorDefinition definition, File delFile) {
    ReturnCode result = new ReturnCode(true);
    IPath filePath = new Path(delFile.getPath());
    if (!ResourceManager.getUDIJarFolder().getLocation().isPrefixOf(filePath)) {
        // filePath.makeRelativeTo(ResourceManager.getRootFolderLocation()))) {
        return result;
    }
    for (IRepositoryNode indiDefNode : RepositoryNodeHelper.getUdisRepositoryNodes(true)) {
        IndicatorDefinition indiDef = null;
        Item item = indiDefNode.getObject().getProperty().getItem();
        if (item instanceof TDQIndicatorDefinitionItem) {
            indiDef = ((TDQIndicatorDefinitionItem) item).getIndicatorDefinition();
        } else {
            continue;
        }
        // when it is itself, don't use this check.
        if (indiDef == definition) {
            continue;
        }
        // ADD end
        TaggedValue tv = TaggedValueHelper.getTaggedValue(TaggedValueHelper.JAR_FILE_PATH, indiDef.getTaggedValue());
        if (tv == null) {
            continue;
        }
        // $NON-NLS-1$
        String[] strArray = tv.getValue().split("\\|\\|");
        int index = Arrays.binarySearch(strArray, filePath.lastSegment());
        if (index >= 0) {
            // $NON-NLS-1$ //$NON-NLS-2$
            result.setMessage("The jar file(" + strArray[index] + ") has in use by UDI for " + indiDef.getName());
            result.setOk(false);
            return result;
        }
    }
    return result;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) ReturnCode(org.talend.utils.sugars.ReturnCode) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) IPath(org.eclipse.core.runtime.IPath) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 43 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ZipFileExportWriter method check.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.imex.model.FileSystemExportWriter#check()
     */
@Override
public List<String> check() {
    List<String> errors = new ArrayList<String>();
    // $NON-NLS-1$
    ReturnCode rc = new ReturnCode("The root file extension is invalid!", false);
    if (fileExtension != null) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        String[] validExtensions = new String[] { "zip", "tar", "tar.gz" };
        for (String ext : validExtensions) {
            if (StringUtils.equalsIgnoreCase(fileExtension, ext)) {
                rc.setOk(true);
                break;
            }
        }
    }
    if (!rc.isOk()) {
        errors.add(rc.getMessage());
    }
    return errors;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) ArrayList(java.util.ArrayList)

Example 44 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ColumnAnalysisExecutor method evaluate.

@Override
protected ReturnCode evaluate(Analysis analysis, java.sql.Connection connection, String sqlStatement) {
    IndicatorEvaluator eval = CreateIndicatorEvaluator(analysis);
    // MOD xqliu 2009-02-09 bug 6237
    eval.setMonitor(getMonitor());
    // set it into the evaluator
    eval.setConnection(connection);
    // use pooled connection
    eval.setPooledConnection(POOLED_CONNECTION);
    // --- add indicators
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    RowCountIndicatorsAdapter.getInstance().clear();
    for (Indicator indicator : indicators) {
        assert indicator != null;
        TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(indicator.getAnalyzedElement());
        if (tdColumn == null) {
            continue;
        }
        // --- get the schema owner
        if (!belongToSameSchemata(tdColumn)) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.GivenColumn", tdColumn.getName()));
            return new ReturnCode(getErrorMessage(), Boolean.FALSE);
        }
        String columnName = ColumnHelper.getFullName(tdColumn);
        eval.storeIndicator(columnName, indicator);
    }
    // when to close connection
    boolean closeAtTheEnd = true;
    Package catalog = schemata.values().iterator().next();
    if (!eval.selectCatalog(catalog.getName())) {
        // $NON-NLS-1$
        log.warn(Messages.getString("ColumnAnalysisExecutor.FAILEDTOSELECTCATALOG", catalog.getName()));
    }
    return eval.evaluateIndicators(sqlStatement, closeAtTheEnd);
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) ReturnCode(org.talend.utils.sugars.ReturnCode) IndicatorEvaluator(org.talend.dq.indicators.IndicatorEvaluator) Package(orgomg.cwm.objectmodel.core.Package) Indicator(org.talend.dataquality.indicators.Indicator)

Example 45 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ColumnSetAnalysisExecutor method runAnalysis.

/*
     * (non-Jsdoc)
     * 
     * @see org.talend.dq.analysis.AnalysisExecutor#runAnalysis(org.talend.dataquality.analysis.Analysis,
     * java.lang.String)
     */
@Override
protected boolean runAnalysis(Analysis analysis, String sqlStatement) {
    ColumnSetIndicatorEvaluator eval = createIndicatorEvaluator(analysis);
    eval.setMonitor(getMonitor());
    // --- add indicators
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    for (Indicator indicator : indicators) {
        if (ColumnsetPackage.eINSTANCE.getColumnSetMultiValueIndicator().isSuperTypeOf(indicator.eClass())) {
            ColumnSetMultiValueIndicator colSetMultValIndicator = (ColumnSetMultiValueIndicator) indicator;
            colSetMultValIndicator.prepare();
            eval.storeIndicator(indicator.getName(), colSetMultValIndicator);
        }
    }
    TypedReturnCode<java.sql.Connection> connection = null;
    // MOD yyi 2011-02-22 17871:delimitefile
    if (!isDelimitedFile) {
        connection = initConnection(analysis, eval);
        if (!connection.isOk()) {
            return false;
        }
    }
    // when to close connection
    boolean closeAtTheEnd = true;
    ReturnCode rc = eval.evaluateIndicators(sqlStatement, closeAtTheEnd);
    // close connection
    if (connection != null) {
        if (POOLED_CONNECTION) {
            // release the pooled connection
            resetConnectionPool(analysis);
        } else {
            ConnectionUtils.closeConnection(connection.getObject());
        }
    }
    if (!rc.isOk()) {
        traceError(rc.getMessage());
    }
    if (getMonitor() != null) {
        getMonitor().worked(compIndicatorsWorked);
    }
    return rc.isOk();
}
Also used : ColumnSetIndicatorEvaluator(org.talend.dq.indicators.ColumnSetIndicatorEvaluator) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) Connection(java.sql.Connection) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator)

Aggregations

ReturnCode (org.talend.utils.sugars.ReturnCode)175 ArrayList (java.util.ArrayList)42 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)42 Test (org.junit.Test)29 File (java.io.File)26 Connection (org.talend.core.model.metadata.builder.connection.Connection)26 Indicator (org.talend.dataquality.indicators.Indicator)25 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)17 IFile (org.eclipse.core.resources.IFile)16 IRepositoryNode (org.talend.repository.model.IRepositoryNode)16 IFolder (org.eclipse.core.resources.IFolder)15 SQLException (java.sql.SQLException)14 PersistenceException (org.talend.commons.exception.PersistenceException)11 TdColumn (org.talend.cwm.relational.TdColumn)11 IOException (java.io.IOException)10 EObject (org.eclipse.emf.ecore.EObject)10 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)10