Search in sources :

Example 31 with ReturnCode

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

the class IndicatorDefinitionMaterPage method checkBeforeSave.

/**
 * DOC xqliu Comment method "checkBeforeSave". ADD xqliu 2010-02-25 feature 11201
 *
 * @return
 */
protected ReturnCode checkBeforeSave() {
    ReturnCode rc = null;
    // check the size of the tempExpressionMap, if size=0(means no expression), return false
    if (tempExpressionMap.size() == 0) {
        rc = new ReturnCode();
        rc.setOk(false);
        // $NON-NLS-1$
        rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.validateNoExpression"));
        return rc;
    }
    // ADD yyi 2011-05-31 16158:add whitespace check for text fields.
    if (!checkWhithspace()) {
        rc = new ReturnCode();
        rc.setOk(false);
        // $NON-NLS-1$
        rc.setMessage(DefaultMessagesImpl.getString("AbstractMetadataFormPage.whitespace"));
        return rc;
    }
    ReturnCode checkCorrectForExpression = checkCorrectForExpression();
    if (!checkCorrectForExpression.isOk()) {
        return checkCorrectForExpression;
    }
    return checkCorrectForCharacterMapping();
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode)

Example 32 with ReturnCode

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

the class ConnectionInfoPage method checkDBConnection.

private ReturnCode checkDBConnection() {
    Connection connection = getCurrentModelElement();
    if (connection == null) {
        // $NON-NLS-1$
        return new ReturnCode("connection is null!", false);
    }
    String userName = loginText.getText();
    String password = passwordText.getText();
    // MOD qiongli 2011-9-5 feature TDQ-3317,handle context model
    if (connection.isContextMode()) {
        userName = JavaSqlFactory.getUsername(connection);
        password = JavaSqlFactory.getPassword(connection);
    }
    Properties props = new Properties();
    props.put(TaggedValueHelper.USER, userName);
    props.put(TaggedValueHelper.PASSWORD, password);
    // org.talend.cwm.db.connection.ConnectionUtils.checkCOnnection method
    return MetadataConnectionUtils.checkConnection((DatabaseConnection) connection);
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Properties(java.util.Properties)

Example 33 with ReturnCode

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

the class UDIMasterPage method checkBeforeSave.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.editor.indicator.IndicatorDefinitionMaterPage#checkBeforeSave()
     */
@Override
protected ReturnCode checkBeforeSave() {
    ReturnCode rc = super.checkBeforeSave();
    if (tempParameters != null) {
        // detecting the IndicatorDefinitionParameter whether include duplicate keywords
        Map<String, Integer> paraMap = new HashMap<String, Integer>();
        for (IndicatorDefinitionParameter para : tempParameters) {
            String key = para.getKey();
            Integer keyCount = paraMap.get(key);
            if (keyCount == null) {
                paraMap.put(key, Integer.valueOf(1));
            } else {
                paraMap.put(key, Integer.valueOf(keyCount.intValue() + 1));
            }
        }
        if (paraMap.size() != tempParameters.size()) {
            StringBuffer duplicateKeywords = new StringBuffer();
            for (String key : paraMap.keySet()) {
                Integer value = paraMap.get(key);
                if (value.intValue() > 1) {
                    // $NON-NLS-1$
                    duplicateKeywords.append("\n" + key);
                }
            }
            rc.setOk(false);
            rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.includeDuplicateKeywords", // $NON-NLS-1$
            duplicateKeywords.toString()));
            return rc;
        }
        // detecting the IndicatorDefinitionParameter whether include special characters
        for (IndicatorDefinitionParameter para : tempParameters) {
            String key = para.getKey();
            String value = para.getValue();
            if (!StringUtils.isBlank(key) && (key.indexOf(UDIHelper.PARA_SEPARATE_1) > -1 || key.indexOf(UDIHelper.PARA_SEPARATE_2) > -1)) {
                rc.setOk(false);
                rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.includeSpecialCharacter", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "\n" + UDIHelper.PARA_SEPARATE_1 + "\n" + UDIHelper.PARA_SEPARATE_2));
                return rc;
            }
            if (!StringUtils.isBlank(value) && (value.indexOf(UDIHelper.PARA_SEPARATE_1) > -1 || value.indexOf(UDIHelper.PARA_SEPARATE_2) > -1)) {
                rc.setOk(false);
                rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.includeSpecialCharacter", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "\n" + UDIHelper.PARA_SEPARATE_1 + "\n" + UDIHelper.PARA_SEPARATE_2));
                return rc;
            }
        }
    }
    // ADD klliu 2010-06-01 bug 13451: Class name of Java User Define Indicator must be validated
    if (!checkJavaDefinitionBeforeSave()) {
        ((IndicatorEditor) this.getEditor()).setSaveActionButtonState(false);
        rc.setOk(false);
        // $NON-NLS-1$
        rc.setMessage(DefaultMessagesImpl.getString("IndicatorDefinitionMaterPage.classPathError"));
        return rc;
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) HashMap(java.util.HashMap) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter)

Example 34 with ReturnCode

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

the class CatalogEvaluator method executeSqlQuery.

@Override
protected ReturnCode executeSqlQuery(String sqlStatement) throws SQLException {
    ReturnCode ok = new ReturnCode(true);
    // --- preconditions
    DataProvider dataProvider = this.getDataManager();
    if (this.elementToIndicators.values().isEmpty()) {
        // $NON-NLS-1$
        String msg = Messages.getString("Evaluator.NoInidcator1");
        log.error(msg);
        ok.setReturnCode(msg, false);
        return ok;
    }
    Indicator[] indics = this.getAllIndicators();
    if (indics.length == 0) {
        // $NON-NLS-1$
        String msg = Messages.getString("Evaluator.NoInidcator2", dataProvider);
        log.error(msg);
        ok.setReturnCode(msg, false);
        return ok;
    }
    for (Indicator indicator : indics) {
        CatalogIndicator catalogIndicator = DataqualitySwitchHelper.CATALOG_SWITCH.doSwitch(indicator);
        if (catalogIndicator == null) {
            continue;
        }
        Catalog catalog = (Catalog) catalogIndicator.getAnalyzedElement();
        String catName = catalog.getName();
        // MOD yyi 2009-11-30 10187
        if (!checkCatalog(catName)) {
            // $NON-NLS-1$
            ok.setReturnCode(Messages.getString("Evaluator.catalogNotExist", catName), false);
            return ok;
        }
        // MOD qiongli 2012-8-9,Method 'Method not supported' not supported for HiveConnection
        if (dbms().supportCatalogSelection()) {
            connection.setCatalog(catName);
        }
        List<Schema> schemas = CatalogHelper.getSchemas(catalog);
        if (schemas.isEmpty()) {
            // no schema
            evalCatalogIndic(catalogIndicator, catalog, ok);
        } else {
            catalogIndicator.setAnalyzedElement(catalog);
            catalogIndicator.setSchemaCount(schemas.size());
            // --- create SchemaIndicator for each pair of catalog schema
            for (Schema tdSchema : schemas) {
                // --- create SchemaIndicator for each catalog
                SchemaIndicator schemaIndic = SchemaFactory.eINSTANCE.createSchemaIndicator();
                // MOD xqliu 2009-1-21 feature 4715
                DefinitionHandler.getInstance().setDefaultIndicatorDefinition(schemaIndic);
                evalSchemaIndicLow(catalogIndicator, schemaIndic, catalog, tdSchema, ok);
            }
        }
    }
    return ok;
}
Also used : DataProvider(orgomg.cwm.foundation.softwaredeployment.DataProvider) SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator) ReturnCode(org.talend.utils.sugars.ReturnCode) Schema(orgomg.cwm.resource.relational.Schema) CatalogIndicator(org.talend.dataquality.indicators.schema.CatalogIndicator) CatalogIndicator(org.talend.dataquality.indicators.schema.CatalogIndicator) SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator) Indicator(org.talend.dataquality.indicators.Indicator) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 35 with ReturnCode

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

the class DelimitedFileIndicatorEvaluator method useDelimitedReader.

/**
 * DOC talend Comment method "useDelimitedReader".
 *
 * @param file
 * @param delimitedFileconnection2
 * @param analysisElementList
 * @param columnElementList
 * @param indicToRowMap
 * @return
 */
private ReturnCode useDelimitedReader(List<ModelElement> analysisElementList, List<MetadataColumn> columnElementList, EMap<Indicator, AnalyzedDataSet> indicToRowMap) {
    // use TOSDelimitedReader in FileInputDelimited to parse.
    ReturnCode returnCode = new ReturnCode(true);
    try {
        FileInputDelimited fileInputDelimited = createFileInputDelimited();
        long currentRow = JavaSqlFactory.getHeadValue(delimitedFileconnection);
        while (fileInputDelimited.nextRecord()) {
            if (!continueRun()) {
                break;
            }
            currentRow++;
            int columsCount = fileInputDelimited.getColumnsCountOfCurrentRow();
            String[] rowValues = new String[columsCount];
            for (int i = 0; i < columsCount; i++) {
                rowValues[i] = fileInputDelimited.get(i);
            }
            returnCode.setOk(returnCode.isOk() && handleByARow(rowValues, currentRow, analysisElementList, columnElementList, indicToRowMap).isOk());
        }
        fileInputDelimited.close();
    } catch (IOException e) {
        log.error(e, e);
    }
    return returnCode;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) FileInputDelimited(org.talend.fileprocess.FileInputDelimited) IOException(java.io.IOException)

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