use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class AbstractMatchKeyWithChartTableSection method computeMatchResult.
protected TypedReturnCode<RecordMatchingIndicator> computeMatchResult() {
TypedReturnCode<RecordMatchingIndicator> rc = new TypedReturnCode<RecordMatchingIndicator>(false);
final Object[] IndicatorList = MatchRuleAnlaysisUtils.getNeedIndicatorFromAna(analysis);
final RecordMatchingIndicator recordMatchingIndicator = EcoreUtil.copy((RecordMatchingIndicator) IndicatorList[0]);
BlockKeyIndicator blockKeyIndicator = EcoreUtil.copy((BlockKeyIndicator) IndicatorList[1]);
ExecuteMatchRuleHandler execHandler = new ExecuteMatchRuleHandler();
MatchGroupResultConsumer matchResultConsumer = createMatchGroupResultConsumer(recordMatchingIndicator);
// Set match key schema to the record matching indicator.
MetadataColumn[] completeColumnSchema = AnalysisRecordGroupingUtils.getCompleteColumnSchema(columnMap);
String[] colSchemaString = new String[completeColumnSchema.length];
int idx = 0;
for (MetadataColumn metadataCol : completeColumnSchema) {
colSchemaString[idx++] = metadataCol.getName();
}
recordMatchingIndicator.setMatchRowSchema(colSchemaString);
recordMatchingIndicator.reset();
TypedReturnCode<MatchGroupResultConsumer> execute = execHandler.execute(columnMap, recordMatchingIndicator, matchRows, blockKeyIndicator, matchResultConsumer);
if (!execute.isOk()) {
rc.setMessage(DefaultMessagesImpl.getString("RunAnalysisAction.failRunAnalysis", analysis.getName(), // $NON-NLS-1$
execute.getMessage()));
return rc;
} else {
if (execute.getObject().getFullMatchResult() == null) {
return rc;
}
// TDQ-9741, the "chart" result must be stored for hiding group(not compute again)
tableResult = execute.getObject().getFullMatchResult();
groupSize2groupFrequency = recordMatchingIndicator.getGroupSize2groupFrequency();
}
rc.setOk(true);
rc.setObject(recordMatchingIndicator);
return rc;
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class ImportFactory method importToStucture.
/**
* DOC xqliu Comment method "importToStucture".
*
* @param importObject
* @param selectionFolder
* @param type
* @param skip
* @param rename
* @param importItemName
* @return
*/
public static List<ReturnCode> importToStucture(ImportObject importObject, IFolder selectionFolder, ExpressionType type, boolean skip, boolean rename, String importItemName) {
List<ReturnCode> importEvent = new ArrayList<ReturnCode>();
// MOD qiongli 2012-12-20 TDQ-5899(issue 2),should get all patterns from Pattern folder.
Set<String> names = PatternUtilities.getNestFolderPatternNames(new HashSet<String>(), ResourceManager.getPatternFolder());
File importFile = importObject.getObjFile();
String fileExtName = getFileExtName(importFile);
if (FileUtils.isCSV(fileExtName)) {
try {
CSVReader reader = FileUtils.createCSVReader(importFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
reader.setSkipEmptyRecords(true);
reader.readHeaders();
while (reader.readNext()) {
String name = reader.get(PatternToExcelEnum.Label.getLiteral());
if (names.contains(name)) {
if (skip) {
importEvent.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.patternInported", name), // $NON-NLS-1$
false));
continue;
}
if (rename) {
// $NON-NLS-1$ //$NON-NLS-2$
name = name + "(" + new Date() + ")";
}
}
PatternParameters patternParameters = new ImportFactory().new PatternParameters();
patternParameters.name = name;
patternParameters.auther = reader.get(PatternToExcelEnum.Author.getLiteral());
patternParameters.description = reader.get(PatternToExcelEnum.Description.getLiteral());
patternParameters.purpose = reader.get(PatternToExcelEnum.Purpose.getLiteral());
patternParameters.relativePath = reader.get(PatternToExcelEnum.RelativePath.getLiteral());
for (PatternLanguageType languagetype : PatternLanguageType.values()) {
String cellStr = reader.get(languagetype.getExcelEnum().getLiteral());
if (cellStr != null && !cellStr.equals("")) {
// $NON-NLS-1$
patternParameters.regex.put(languagetype.getLiteral(), cellStr);
}
}
try {
TypedReturnCode<Object> create = createAndStorePattern(patternParameters, selectionFolder, type);
if (create.isOk()) {
names.add(name);
importEvent.add(new ReturnCode(// $NON-NLS-1$
DefaultMessagesImpl.getString(// $NON-NLS-1$
"ImportFactory.importPattern", // $NON-NLS-1$
name, selectionFolder.getProjectRelativePath().toString()), true));
} else {
throw new TalendInternalPersistenceException(create.getMessage());
}
} catch (Exception e) {
// $NON-NLS-1$
importEvent.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.SaveFailed", name), false));
}
}
reader.close();
} catch (Exception e) {
log.error(e, e);
// $NON-NLS-1$
importEvent.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.importFailed"), false));
}
}
importObject.copyJarFiles();
// ADD xqliu 2012-04-27 TDQ-5149
checkImportEvent(importItemName, importEvent);
// ~ TDQ-5149
return importEvent;
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class ImportFactory method importIndicatorToStucture.
/**
* DOC xqliu Comment method "importIndicatorToStucture".
*
* @param importObject
* @param selectionFolder
* @param skip
* @param rename
* @param importItemName
* @return
*/
public static List<ReturnCode> importIndicatorToStucture(ImportObject importObject, IFolder selectionFolder, boolean skip, boolean rename, String importItemName) {
List<ReturnCode> information = new ArrayList<ReturnCode>();
Set<String> names = UDIHelper.getAllIndicatorNames(selectionFolder);
File importFile = importObject.getObjFile();
String fileExtName = getFileExtName(importFile);
if (FileUtils.isCSV(fileExtName)) {
String name = PluginConstant.EMPTY_STRING;
try {
CSVReader reader = FileUtils.createCSVReader(importFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
reader.setSkipEmptyRecords(true);
reader.readHeaders();
// $NON-NLS-1$
java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat("yyyyMMddHHmmssSSS");
while (reader.readNext()) {
name = reader.get(PatternToExcelEnum.Label.getLiteral());
if (names.contains(name)) {
if (skip) {
// $NON-NLS-1$
information.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.Imported", name), false));
continue;
}
if (rename) {
// $NON-NLS-1$ //$NON-NLS-2$
name = name + "(" + simpleDateFormat.format(new Date()) + Math.random() + ")";
}
}
UDIParameters udiParameters = new ImportFactory().new UDIParameters();
udiParameters.name = name;
udiParameters.auther = reader.get(PatternToExcelEnum.Author.getLiteral());
udiParameters.description = reader.get(PatternToExcelEnum.Description.getLiteral());
udiParameters.purpose = reader.get(PatternToExcelEnum.Purpose.getLiteral());
udiParameters.relativePath = reader.get(PatternToExcelEnum.RelativePath.getLiteral());
udiParameters.category = reader.get(PatternToExcelEnum.Category.getLiteral());
udiParameters.javaClassName = reader.get(PatternToExcelEnum.JavaClassName.getLiteral());
udiParameters.javaJarPath = reader.get(PatternToExcelEnum.JavaJarPath.getLiteral());
String[] headers = reader.getHeaders();
String[] columnsValue = reader.getValues();
HashMap<String, String> record = new HashMap<String, String>();
for (int i = 0; i < headers.length; i++) {
// TDQ-6714: fix when there is no regexp for the imported udi (csv) file.
if (i >= columnsValue.length) {
// $NON-NLS-1$
record.put(headers[i], "");
} else {
if (columnsValue[i] != null && columnsValue[i].length() > 0) {
record.put(headers[i], columnsValue[i]);
}
}
}
for (PatternLanguageType languagetype : PatternLanguageType.values()) {
String cellStr = record.get(languagetype.getExcelEnum().getLiteral());
if (cellStr != null && !cellStr.equals("\"\"")) {
// $NON-NLS-1$
udiParameters.regex.put(languagetype.getLiteral(), trimQuote(cellStr));
}
}
udiParameters.setParaMap(buildIndDefPara(record));
TypedReturnCode<Object> create = createAndStoreUDI(udiParameters, selectionFolder);
if (create.isOk()) {
names.add(name);
// add the suscess message to display.
information.add(new ReturnCode(// $NON-NLS-1$
DefaultMessagesImpl.getString(// $NON-NLS-1$
"ImportFactory.importedSucess", ((TDQItem) create.getObject()).getProperty().getDisplayName(), selectionFolder.getProjectRelativePath().toString()), true));
} else {
throw new TalendInternalPersistenceException(create.getMessage());
}
}
reader.close();
} catch (Exception e) {
log.error(e, e);
// $NON-NLS-1$
information.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.importedFailed", name), false));
}
}
// MOD qiongli 2011-11-28 TDQ-4038.consider to import the definition file.
if (FactoriesUtil.DEFINITION.equalsIgnoreCase(fileExtName)) {
String propFilePath = importFile.getPath().replaceFirst(PluginConstant.DOT_STRING + fileExtName, PluginConstant.DOT_STRING + FactoriesUtil.PROPERTIES_EXTENSION);
File propFile = new File(propFilePath);
// just import the definition file which have the realted Property file.
if (!propFile.exists()) {
return information;
}
String name = importFile.getName();
try {
if (names.contains(name)) {
if (skip) {
// $NON-NLS-1$
information.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.Imported", name), false));
return information;
}
if (rename) {
// $NON-NLS-1$ //$NON-NLS-2$
name = name + "(" + new Date() + Math.random() + ")";
}
}
IFile elementFile = selectionFolder.getFile(name);
if (!elementFile.exists()) {
elementFile.create(new FileInputStream(importFile), false, null);
ModelElement modelElement = ModelElementFileFactory.getModelElement(elementFile);
if (modelElement != null) {
ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().create(modelElement, selectionFolder);
DefinitionHandler.getInstance().reloadIndicatorsDefinitions();
names.add(name);
information.add(new ReturnCode(// $NON-NLS-1$
DefaultMessagesImpl.getString(// $NON-NLS-1$
"ImportFactory.importedSucess", name), true));
}
}
} catch (Exception e) {
log.error(e);
// $NON-NLS-1$
information.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.importedFailed", name), false));
}
}
importObject.copyJarFiles();
// ADD xqliu 2012-04-27 TDQ-5149
checkImportEvent(importItemName, information);
// ~ TDQ-5149
return information;
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class PatternLabelProvider method createIndicatorUnit.
/**
* DOC xqliu Comment method "createIndicatorUnit".
*
* @param pfile
* @param modelElementIndicator
* @param analysis
* @param indicatorDefinition
* @return
*/
public static TypedReturnCode<IndicatorUnit> createIndicatorUnit(Pattern pattern, ModelElementIndicator modelElementIndicator, Analysis analysis, IndicatorDefinition indicatorDefinition) {
TypedReturnCode<IndicatorUnit> result = new TypedReturnCode<IndicatorUnit>();
for (Indicator indicator : modelElementIndicator.getIndicators()) {
// MOD xwang 2011-08-01 bug TDQ-2730
if (UDIHelper.getMatchingIndicatorName(indicatorDefinition, pattern).equals(indicator.getName()) && indicator instanceof PatternMatchingIndicator) {
result.setOk(false);
// $NON-NLS-1$
result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.Selected"));
return result;
}
// ~
}
// MOD scorreia 2009-01-06: when expression type is not set (version
// TOP-1.1.x), then it's supposed to be a
// regexp pattern. This could be false because expression type was not
// set into SQL pattern neither in TOP-1.1.
// This means that there could exist the need for a migration task to
// set the expression type depending on the
// folder where the pattern is stored. The method
// DomainHelper.getExpressionType(pattern) tries to find the type
// of pattern.
Indicator patternMatchingIndicator = null;
String expressionType = DomainHelper.getExpressionType(pattern);
boolean isSQLPattern = (ExpressionType.SQL_LIKE.getLiteral().equals(expressionType));
if (indicatorDefinition != null) {
patternMatchingIndicator = UDIFactory.createUserDefIndicator(indicatorDefinition, pattern);
} else {
patternMatchingIndicator = isSQLPattern ? PatternIndicatorFactory.createSqlPatternMatchingIndicator(pattern) : PatternIndicatorFactory.createRegexpMatchingIndicator(pattern);
}
IEditorPart theEdit = CorePlugin.getDefault().getCurrentActiveEditor();
if (theEdit != null && theEdit instanceof AnalysisEditor && analysis.getContext().getConnection() == null) {
theEdit.doSave(null);
}
ExecutionLanguage executionLanguage = analysis.getParameters().getExecutionLanguage();
DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(analysis);
if (dbmsLanguage.isSql()) {
// $NON-NLS-1$
MessageUI.openWarning(DefaultMessagesImpl.getString("PatternUtilities.ConnectionError"));
result.setOk(false);
return result;
}
boolean isJavaEngin = ExecutionLanguage.JAVA.equals(executionLanguage);
Expression returnExpression = dbmsLanguage.getRegexp(pattern);
// MOD gdbu 2011-8-26 bug : TDQ-2169
if ((ExpressionType.REGEXP.getLiteral().equals(expressionType) || ExpressionType.SQL_LIKE.getLiteral().equals(expressionType)) && returnExpression == null) {
// ~TDQ-2169
String executeType = isJavaEngin ? executionLanguage.getName() : dbmsLanguage.getDbmsName();
boolean openPattern = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("PatternUtilities.Warning"), // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("PatternUtilities.NoExpression", executeType, pattern.getName()));
if (openPattern) {
RepositoryNode node = RepositoryNodeHelper.recursiveFind(pattern);
if (RepositoryNodeHelper.canOpenEditor(node)) {
new OpenItemEditorAction(new IRepositoryNode[] { node }).run();
}
}
result.setOk(false);
return result;
}
// a regular expression for the analyzed
// database, but we probably test also whether the analyzed database
// support the regular expressions (=> check
// DB type, DB number version, existence of UDF)
DataManager dm = analysis.getContext().getConnection();
if (dm != null) {
TypedReturnCode<java.sql.Connection> trc = JavaSqlFactory.createConnection((Connection) dm);
// MOD qiongli 2011-1-10 feature 16796
boolean isDelimitedFileConnection = ConnectionUtils.isDelimitedFileConnection((DataProvider) dm);
if (trc != null) {
// SoftwareSystem softwareSystem = DatabaseContentRetriever.getSoftwareSystem(conn);
// MOD sizhaoliu TDQ-6316
dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(dm);
}
// MOD xqliu 2010-08-12 bug 14601
if (!(isSQLPattern || DefinitionHandler.getInstance().canRunRegularExpressionMatchingIndicator(dbmsLanguage, isJavaEngin, pattern) || isDelimitedFileConnection)) {
// MessageDialogWithToggle.openInformation(null,
// DefaultMessagesImpl.getString("PatternUtilities.Pattern"), DefaultMessagesImpl //$NON-NLS-1$
// .getString("PatternUtilities.couldnotSetIndicator")); //$NON-NLS-1$
result.setOk(false);
// $NON-NLS-1$
result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.couldnotSetIndicator"));
return result;
}
// ~ 14601
}
// when the indicator is created.
if (indicatorDefinition == null) {
if (!DefinitionHandler.getInstance().setDefaultIndicatorDefinition(patternMatchingIndicator)) {
// $NON-NLS-1$
log.error(DefaultMessagesImpl.getString("PatternUtilities.SetFailed", patternMatchingIndicator.getName()));
}
} else {
patternMatchingIndicator.setIndicatorDefinition(indicatorDefinition);
}
IndicatorEnum type = IndicatorEnum.findIndicatorEnum(patternMatchingIndicator.eClass());
IndicatorUnit addIndicatorUnit = modelElementIndicator.addSpecialIndicator(type, patternMatchingIndicator);
DependenciesHandler.getInstance().setUsageDependencyOn(analysis, pattern);
result.setOk(true);
// $NON-NLS-1$
result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.OK"));
result.setObject(addIndicatorUnit);
return result;
}
Aggregations