use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class DelimitedFileIndicatorEvaluator method executeSqlQuery.
@Override
protected ReturnCode executeSqlQuery(String sqlStatement) {
ReturnCode returnCode = new ReturnCode(true);
if (delimitedFileconnection == null) {
delimitedFileconnection = (DelimitedFileConnection) analysis.getContext().getConnection();
}
if (delimitedFileconnection.isContextMode()) {
IRepositoryContextService service = CoreRuntimePlugin.getInstance().getRepositoryContextService();
delimitedFileconnection = (DelimitedFileConnection) service.cloneOriginalValueConnection(delimitedFileconnection);
}
String path = JavaSqlFactory.getURL(delimitedFileconnection);
IPath iPath = new Path(path);
File file = iPath.toFile();
if (!file.exists()) {
// $NON-NLS-1$
returnCode.setReturnCode(Messages.getString("DelimitedFileIndicatorEvaluator.CanNotFindFile"), false);
return returnCode;
}
List<ModelElement> analysisElementList = this.analysis.getContext().getAnalysedElements();
EMap<Indicator, AnalyzedDataSet> indicToRowMap = analysis.getResults().getIndicToRowMap();
indicToRowMap.clear();
List<MetadataColumn> columnElementList = new ArrayList<MetadataColumn>();
for (int i = 0; i < analysisElementList.size(); i++) {
MetadataColumn mColumn = (MetadataColumn) analysisElementList.get(i);
MetadataTable mTable = ColumnHelper.getColumnOwnerAsMetadataTable(mColumn);
columnElementList = mTable == null ? columnElementList : mTable.getColumns();
if (!columnElementList.isEmpty()) {
break;
}
}
ReturnCode readDataReturnCode = new ReturnCode(true);
// use CsvReader to parse.
if (Escape.CSV.equals(delimitedFileconnection.getEscapeType())) {
readDataReturnCode = useCsvReader(file, analysisElementList, columnElementList, indicToRowMap);
} else {
readDataReturnCode = useDelimitedReader(analysisElementList, columnElementList, indicToRowMap);
}
// handle error message
if (!readDataReturnCode.isOk()) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), // $NON-NLS-1$
Messages.getString("DelimitedFileIndicatorEvaluator.badlyForm.Title"), // $NON-NLS-1$
Messages.getString("DelimitedFileIndicatorEvaluator.badlyForm.Message"));
}
});
}
// Added yyin 20120608 TDQ-3589
for (MetadataColumn col : columnElementList) {
List<Indicator> indicators = getIndicators(col.getLabel());
for (Indicator indicator : indicators) {
if (indicator instanceof DuplicateCountIndicator) {
AnalyzedDataSet analyzedDataSet = indicToRowMap.get(indicator);
if (analyzedDataSet == null) {
analyzedDataSet = AnalysisFactory.eINSTANCE.createAnalyzedDataSet();
indicToRowMap.put(indicator, analyzedDataSet);
analyzedDataSet.setDataCount(analysis.getParameters().getMaxNumberRows());
analyzedDataSet.setRecordSize(0);
}
// indicator.finalizeComputation();
addResultToIndicatorToRowMap(indicator, indicToRowMap);
}
}
}
return returnCode;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class DelimitedFileIndicatorEvaluator method handleByARow.
private ReturnCode handleByARow(String[] rowValues, long currentRow, List<ModelElement> analysisElementList, List<MetadataColumn> columnElementList, EMap<Indicator, AnalyzedDataSet> indicToRowMap) {
ReturnCode returnCode = new ReturnCode(true);
Object object = null;
int maxNumberRows = analysis.getParameters().getMaxNumberRows();
int recordIncrement = 0;
element: for (int i = 0; i < analysisElementList.size(); i++) {
MetadataColumn mColumn = (MetadataColumn) analysisElementList.get(i);
Integer position = ColumnHelper.getColumnIndex(mColumn);
// warning with a file of badly form
if (position == null || position >= rowValues.length) {
log.warn(// $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DelimitedFileIndicatorEvaluator.incorrectData", mColumn.getLabel(), currentRow, delimitedFileconnection.getFilePath()));
returnCode.setOk(false);
continue;
}
object = TalendTypeConvert.convertToObject(mColumn.getTalendType(), rowValues[position], mColumn.getPattern());
List<Indicator> indicators = getIndicators(mColumn.getLabel());
for (Indicator indicator : indicators) {
if (!continueRun()) {
break element;
}
// bug 19036,to irregularly data,still compute for RowCountIndicator
if (object == null && !(indicator instanceof RowCountIndicator)) {
continue element;
}
// Added yyin 20120608 TDQ-3589
if (indicator instanceof DuplicateCountIndicator) {
((DuplicateCountIndicator) indicator).handle(object, rowValues);
} else {
// ~
indicator.handle(object);
}
AnalyzedDataSet analyzedDataSet = indicToRowMap.get(indicator);
if (analyzedDataSet == null) {
analyzedDataSet = AnalysisFactory.eINSTANCE.createAnalyzedDataSet();
indicToRowMap.put(indicator, analyzedDataSet);
analyzedDataSet.setDataCount(maxNumberRows);
analyzedDataSet.setRecordSize(0);
}
// see IndicatorEvaluator line 166, the logic is almost the same
if (analysis.getParameters().isStoreData()) {
if (indicator.mustStoreRow()) {
List<Object[]> valueObjectList = initDataSet(indicator, indicToRowMap, object);
recordIncrement = valueObjectList.size();
List<Object> inputRowList = new ArrayList<Object>();
for (int j = 0; j < rowValues.length; j++) {
Object newobject = rowValues[j];
if (indicator.isUsedMapDBMode()) {
inputRowList.add(newobject == null ? PluginConstant.NULL_STRING : newobject);
continue;
} else {
if (recordIncrement < maxNumberRows) {
if (recordIncrement < valueObjectList.size()) {
valueObjectList.get(recordIncrement)[j] = newobject;
} else {
Object[] valueObject = new Object[rowValues.length];
valueObject[j] = newobject;
valueObjectList.add(valueObject);
}
} else {
break;
}
}
}
if (indicator.isUsedMapDBMode()) {
MapDBUtils.handleDrillDownData(object, inputRowList, indicator);
}
} else if (indicator instanceof UniqueCountIndicator && analysis.getResults().getIndicToRowMap().get(indicator).getData() != null) {
List<Object[]> removeValueObjectList = analysis.getResults().getIndicToRowMap().get(indicator).getData();
if (columnElementList.size() == 0) {
continue;
}
int offsetting = columnElementList.indexOf(indicator.getAnalyzedElement());
for (Object[] dataObject : removeValueObjectList) {
// Added yyin 20120611 TDQ5279
if (object instanceof Integer) {
if (object.equals(Integer.parseInt((String) dataObject[offsetting]))) {
removeValueObjectList.remove(dataObject);
break;
}
}
// ~
if (dataObject[offsetting].equals(object)) {
removeValueObjectList.remove(dataObject);
break;
}
}
}
}
}
}
return returnCode;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ColumnSetIndicatorEvaluator method evaluateIndicators.
@Override
public ReturnCode evaluateIndicators(String sqlStatement, boolean closeConnection) {
ReturnCode returnCode = super.evaluateIndicators(sqlStatement, closeConnection);
storeDataSet();
return returnCode;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ConnectionEvaluator method executeSqlQuery.
/*
* (non-Javadoc)
*
* @see org.talend.dq.indicators.Evaluator#executeSqlQuery(java.lang.String)
*
* Note that the given statement is not used.
*/
@Override
protected ReturnCode executeSqlQuery(String sqlStatement) throws SQLException {
// assert this.getAnalyzedElements().size() == 1 : "Invalid number of analyzed elements: "
// + this.getAnalyzedElements().size();
ReturnCode ok = new ReturnCode(true);
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;
}
elementIndics = this.elementToIndicators.values().iterator().next();
if (elementIndics.isEmpty()) {
// $NON-NLS-1$
String msg = Messages.getString("Evaluator.NoInidcator2", dataProvider);
log.error(msg);
ok.setReturnCode(msg, false);
return ok;
}
ConnectionIndicator connectionIndicator = getConnectionIndicator();
this.resetCounts(connectionIndicator);
List<Catalog> catalogs = ConnectionHelper.getCatalogs(dataProvider);
if (isTos(dataProvider)) {
cleanUpCatalog(catalogs);
}
if (this.getMonitor() != null) {
this.getMonitor().beginTask("Analyze catalogs", 100);
}
int temp = 0;
if (catalogs.isEmpty()) {
// no catalog, only schemata
List<Schema> schemata = ConnectionHelper.getSchema(dataProvider);
// MOD yyi 2009-11-30 10187
for (Schema tdSchema : schemata) {
if (!checkSchema(tdSchema)) {
// $NON-NLS-1$
ok.setReturnCode(Messages.getString("Evaluator.schemaNotExist", tdSchema.getName()), false);
return ok;
}
}
// for (Schema tdSchema : schemata) {
for (int i = 0; i < schemata.size(); i++) {
Schema tdSchema = schemata.get(i);
if (this.getMonitor() != null) {
this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementSchema", tdSchema.getName())));
}
evalSchemaIndic(tdSchema, ok);
if (this.getMonitor() != null) {
int current = (i + 1) * 100 / schemata.size();
if (current > temp) {
this.getMonitor().worked(current - temp);
temp = current;
}
}
}
} else {
// MOD yyi 2009-11-30 10187
for (Catalog tdCatalog : catalogs) {
if (!checkCatalog(tdCatalog.getName())) {
// $NON-NLS-1$
ok.setReturnCode(Messages.getString("Evaluator.catalogNotExist", tdCatalog.getName()), false);
return ok;
}
}
// for (Catalog tdCatalog : catalogs) {
for (int i = 0; i < catalogs.size(); i++) {
if (this.continueRun()) {
Catalog tdCatalog = catalogs.get(i);
String catName = tdCatalog.getName();
if (this.getMonitor() != null) {
this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementCatalog", catName)));
}
if (dbms().supportCatalogSelection()) {
try {
connection.setCatalog(catName);
} catch (SQLException e) {
// $NON-NLS-1$
log.warn("Exception while executing SQL query " + sqlStatement, e);
}
}
CatalogIndicator catalogIndic = SchemaFactory.eINSTANCE.createCatalogIndicator();
// MOD xqliu 2009-1-21 feature 4715
DefinitionHandler.getInstance().setDefaultIndicatorDefinition(catalogIndic);
List<Schema> schemas = CatalogHelper.getSchemas(tdCatalog);
if (schemas.isEmpty()) {
// no schema
evalCatalogIndic(catalogIndic, tdCatalog, ok);
} else {
catalogIndic.setAnalyzedElement(tdCatalog);
// --- create SchemaIndicator for each pair of catalog schema
for (Schema tdSchema : schemas) {
if (this.continueRun()) {
if (this.getMonitor() != null) {
this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementCatalog", catName) + ", " + Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementSchema", tdSchema.getName())));
}
// --- create SchemaIndicator for each catalog
SchemaIndicator schemaIndic = SchemaFactory.eINSTANCE.createSchemaIndicator();
// MOD xqliu 2009-1-21 feature 4715
DefinitionHandler.getInstance().setDefaultIndicatorDefinition(schemaIndic);
evalSchemaIndicLow(catalogIndic, schemaIndic, tdCatalog, tdSchema, ok);
}
}
catalogIndic.setSchemaCount(schemas.size());
}
if (this.getMonitor() != null) {
int current = (i + 1) * 100 / catalogs.size();
if (current > temp) {
this.getMonitor().worked(current - temp);
temp = current;
}
}
}
}
if (this.getMonitor() != null) {
this.getMonitor().done();
}
}
if (log.isDebugEnabled()) {
printCounts(connectionIndicator);
}
return ok;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ReportFileHelper method deleteRepOutputFolder.
/**
* delete the related output folder of report.
*
* @param reportFile
* @throws PersistenceException
*/
public static ReturnCode deleteRepOutputFolder(final IFile reportFile) throws PersistenceException {
final ReturnCode rc = new ReturnCode(Boolean.TRUE);
RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit(ProjectManager.getInstance().getCurrentProject(), // $NON-NLS-1$
"deleteRepOutputFolder") {
@Override
protected void run() throws LoginException, PersistenceException {
IFolder reportOutputFolder = ReportFileHelper.getOutputFolder(reportFile);
if (reportOutputFolder != null && reportOutputFolder.exists()) {
try {
IContainer parent = reportOutputFolder.getParent();
// refresh the parent at begin
if (parent != null) {
parent.refreshLocal(IResource.DEPTH_INFINITE, null);
}
// delete folder
File file = WorkspaceUtils.ifolderToFile(reportOutputFolder);
if (file != null && file.exists()) {
deleteFolder(file);
}
// refresh the parent at end
if (parent != null) {
parent.refreshLocal(IResource.DEPTH_INFINITE, null);
}
} catch (CoreException e) {
log.warn(e);
}
} else {
rc.setOk(Boolean.FALSE);
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
repositoryWorkUnit.throwPersistenceExceptionIfAny();
return rc;
}
Aggregations