use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.
the class TOPRepositoryService method getPaserRulesFromResources.
/*
* Added yyi 2011-08-04 TDQ-3186
*
* @see org.talend.core.ITDQRepositoryService#getPaserRulesFromResources(java.lang.Object[])
*/
public List<Map<String, String>> getPaserRulesFromResources(Object[] rules) {
List<Map<String, String>> ruleValues = new ArrayList<Map<String, String>>();
for (Object rule : rules) {
if (rule instanceof IFile) {
ParserRule parserRule = (ParserRule) DQRuleResourceFileHelper.getInstance().findDQRule((IFile) rule);
ruleValues.addAll(getPaserRulesFromRules(parserRule));
}
}
return ruleValues;
}
use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.
the class ExportFactory method export.
public static void export(File exportFile, IFolder folder, ParserRule... parserRules) {
if (exportFile.isDirectory()) {
for (ParserRule pr : parserRules) {
// $NON-NLS-1$
File file = new File(exportFile, pr.getName() + ".csv");
export(file, folder, pr);
}
}
String fileExtName = getFileExtName(exportFile);
if (FileUtils.isCSV(fileExtName)) {
try {
CSVWriter out = FileUtils.createCSVWriter(exportFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
List<TdExpression> expressions = parserRules[0].getExpression();
ParserRuleToExcelEnum[] values = getParserRuleEnumValues();
String[] temp = new String[values.length];
for (int i = 0; i < expressions.toArray().length + 1; i++) {
for (int j = 0; j < values.length; j++) {
if (i == 0) {
temp[j] = values[j].getLiteral();
} else {
Map<ParserRuleToExcelEnum, String> relatedValueFromParserRule = getRelatedValueFromParserRule(parserRules[0], folder, expressions.get(i - 1));
temp[j] = relatedValueFromParserRule.get(values[j]);
}
}
out.writeNext(temp);
}
out.flush();
out.close();
} catch (FileNotFoundException fe) {
MessageDialogWithToggle.openError(null, DefaultMessagesImpl.getString("ExportFactory.errorOne"), // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("ExportFactory.notFoundFile"));
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.
the class DQRuleEditor method addPages.
@Override
protected void addPages() {
ModelElement currentRuleModelElement = getCurrentModelElement();
try {
if (currentRuleModelElement != null) {
if (currentRuleModelElement instanceof ParserRule) {
parserPage = new ParserRuleMasterDetailsPage(this, ID, // $NON-NLS-1$
DefaultMessagesImpl.getString("DQRuleEditor.parserRuleSettings"));
addPage(parserPage);
setPartName(parserPage.getIntactElemenetName());
} else if (currentRuleModelElement instanceof MatchRuleDefinition) {
matchPage = new MatchRuleMasterDetailsPage(this);
addPage(matchPage);
setPartName(matchPage.getIntactElemenetName());
setTitleImage(ImageLib.getImage(ImageLib.MATCH_RULE_WHITE_ICON));
} else {
masterPage = new DQRuleMasterDetailsPage(this, ID, // $NON-NLS-1$
DefaultMessagesImpl.getString("DQRuleEditor.dqRuleSettings"));
addPage(masterPage);
setPartName(masterPage.getIntactElemenetName());
}
}
} catch (PartInitException e) {
ExceptionHandler.process(e, Level.ERROR);
}
// ADD xqliu 2009-07-02 bug 7687
TdEditorToolBar toolbar = getToolBar();
// MOD msjian 2011-9-22 TDQ-3372: Add a "save" button in the parser rule editor
if (toolbar != null && (masterPage != null || parserPage != null || matchPage != null)) {
// TDQ-3372 ~
saveAction = new DefaultSaveAction(this);
saveAction.setEnabled(false);
toolbar.addActions(saveAction);
}
// ~
}
use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.
the class ParserRuleMasterDetailsPage method getParseRuleRepNodeFromInput.
/**
* get PatternRepNode From editorInput
*
* @param editorInput
* @return
*/
private RuleRepNode getParseRuleRepNodeFromInput(IEditorInput editorInput) {
if (editorInput instanceof FileEditorInput) {
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
IFile file = fileEditorInput.getFile();
if (file != null) {
ParserRule parserRule = (ParserRule) DQRuleResourceFileHelper.getInstance().findDQRule(file);
parserRule = (ParserRule) EObjectHelper.resolveObject(parserRule);
return RepositoryNodeHelper.recursiveFindRuleParser(parserRule);
}
} else if (editorInput instanceof BusinessRuleItemEditorInput) {
return ((BusinessRuleItemEditorInput) editorInput).getRepNode();
}
return null;
}
use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.
the class ImportFactory method createAndStoreParserRule.
/**
* DOC klliu Comment method "createAndStoreParserRule".
*
* @param prParameters
* @param selectionFolder
*/
public static void createAndStoreParserRule(ParserRuleParameters prParameters, IFolder selectionFolder, String name) {
DqRuleBuilder ruleBuilder = new DqRuleBuilder();
boolean ruleInitialized = ruleBuilder.initializeParserRuleBuilder(prParameters.label);
if (ruleInitialized) {
ParserRule parserRule = ruleBuilder.getParserRule();
parserRule.setName(name);
TaggedValueHelper.setValidStatus(true, parserRule);
List<ParserRuleTdExpresstion> prExpresstions = prParameters.getPrExpresstions();
for (ParserRuleTdExpresstion prtde : prExpresstions) {
parserRule.addExpression(prtde.name, prtde.type, prtde.value);
}
IndicatorCategory ruleIndicatorCategory = DefinitionHandler.getInstance().getDQRuleIndicatorCategory();
if (ruleIndicatorCategory != null && !parserRule.getCategories().contains(ruleIndicatorCategory)) {
parserRule.getCategories().add(ruleIndicatorCategory);
}
ElementWriterFactory.getInstance().createdRuleWriter().create(parserRule, selectionFolder);
}
}
Aggregations