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