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();
}
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);
}
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;
}
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;
}
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;
}
Aggregations