use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.
the class FileTreeLabelProviderTest method setUpBeforeClass.
/**
* DOC zshen Comment method "setUpBeforeClass".
*
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
DQRule createSqlRule = RulesFactory.eINSTANCE.createWhereRule();
ParserRule createParserRule = RulesFactory.eINSTANCE.createParserRule();
MatchRuleDefinition createMatchRuleDefinition = RulesFactory.eINSTANCE.createMatchRuleDefinition();
// $NON-NLS-1$
createSqlRule.setName("sqlRule1");
// $NON-NLS-1$
createParserRule.setName("parserRule1");
// $NON-NLS-1$
createMatchRuleDefinition.setName("matchRule");
createTDQSQLRuleItem = PropertiesFactory.eINSTANCE.createTDQBusinessRuleItem();
createTDQSQLRuleItem.setDqrule(createSqlRule);
createTDQParserRuleItem = PropertiesFactory.eINSTANCE.createTDQBusinessRuleItem();
createTDQParserRuleItem.setDqrule(createParserRule);
createTDQMatchRuleItem = PropertiesFactory.eINSTANCE.createTDQMatchRuleItem();
createTDQMatchRuleItem.setMatchRule(createMatchRuleDefinition);
Property createSQLRuleProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
createSQLRuleProperty.setItem(createTDQSQLRuleItem);
createSQLRuleProperty.setLabel(createSqlRule.getName());
Property createParserRuleProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
createParserRuleProperty.setItem(createTDQParserRuleItem);
createParserRuleProperty.setLabel(createParserRule.getName());
Property createMatchRuleProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
createMatchRuleProperty.setItem(createTDQMatchRuleItem);
createMatchRuleProperty.setLabel(createMatchRuleDefinition.getName());
ProxyRepositoryFactory.getInstance().create(createTDQSQLRuleItem, Path.EMPTY);
ProxyRepositoryFactory.getInstance().create(createTDQParserRuleItem, Path.EMPTY);
ProxyRepositoryFactory.getInstance().create(createTDQMatchRuleItem, Path.EMPTY);
}
use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.
the class EResourceConstantTest method testGetTypedConstantItem_1.
/**
* Test method for
* {@link org.talend.resource.EResourceConstant#getTypedConstant(org.talend.core.model.properties.Item)}. test for
* parser rule
*/
@Test
public void testGetTypedConstantItem_1() {
ParserRule parseRule = mock(ParserRule.class);
ruleItem.setDqrule(parseRule);
EResourceConstant rc = EResourceConstant.getTypedConstant(ruleItem);
Assert.assertEquals(rc.getPath(), EResourceConstant.RULES_PARSER.getPath());
}
use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.
the class ExportParserRuleWizard method performFinish.
@Override
public boolean performFinish() {
String targetFile = page.getTargetFile();
Object[] elements = page.getSelectedTree().getCheckedElements();
List<ParserRule> parserRules = new ArrayList<ParserRule>();
for (Object element : elements) {
if (element instanceof RuleRepNode) {
RuleRepNode ruleNode = (RuleRepNode) element;
ParserRule parserRule = (ParserRule) ruleNode.getRule();
parserRules.add(parserRule);
}
}
if ("".equals(targetFile)) {
// $NON-NLS-1$
MessageDialog.openError(getShell(), DefaultMessagesImpl.getString("ExportParserRuleWizard.Error"), // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("ExportParserRuleWizard.SpecifyValidResource"));
return false;
} else {
File resource = new File(targetFile);
if (isForExchange) {
// export for exchange
for (Iterator<ParserRule> iterator = parserRules.iterator(); iterator.hasNext(); ) {
ParserRule parserRule = iterator.next();
ExportFactory.export(resource, folder, parserRule);
// $NON-NLS-1$
File parserRuleFile = new File(resource, ExportFactory.toLocalFileName(parserRule.getName() + ".csv"));
if (parserRuleFile.isFile() && parserRuleFile.exists()) {
try {
// $NON-NLS-1$
FilesUtils.zip(parserRuleFile, parserRuleFile.getPath() + ".zip");
parserRuleFile.delete();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
} else {
// Export to local
ExportFactory.export(resource, folder, parserRules.toArray(new ParserRule[parserRules.size()]));
}
CorePlugin.getDefault().refreshDQView(RepositoryNodeHelper.getLibrariesFolderNode(EResourceConstant.RULES_PARSER));
CorePlugin.getDefault().refreshWorkSpace();
return true;
}
}
use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.
the class TOPRepositoryService method getPaserRulesFromRules.
public List<Map<String, String>> getPaserRulesFromRules(Object parser) {
if (parser != null && parser instanceof ParserRule) {
List<Map<String, String>> ruleValues = new ArrayList<Map<String, String>>();
for (TdExpression exp : ((ParserRule) parser).getExpression()) {
Map<String, String> pr = new HashMap<String, String>();
// MOD yyi 2011-08-12 TDQ-1698:avoid importing null value
pr.put(RULE_NAME, null == exp.getName() ? StringUtils.EMPTY : exp.getName());
pr.put(RULE_VALUE, null == exp.getBody() ? StringUtils.EMPTY : exp.getBody());
pr.put(RULE_TYPE, null == exp.getLanguage() ? StringUtils.EMPTY : exp.getLanguage().toUpperCase());
ruleValues.add(pr);
}
return ruleValues;
}
return null;
}
use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.
the class TOPRepositoryService method createParserRuleItem.
public void createParserRuleItem(ArrayList<HashMap<String, Object>> values, String parserRuleName) {
ParserRule parserRule = null;
DqRuleBuilder ruleBuilder = new DqRuleBuilder();
boolean ruleInitialized = ruleBuilder.initializeParserRuleBuilder(parserRuleName);
if (ruleInitialized) {
parserRule = ruleBuilder.getParserRule();
}
TaggedValueHelper.setValidStatus(true, parserRule);
for (HashMap<String, Object> expression : values) {
parserRule.addExpression(expression.get(RULE_NAME).toString(), expression.get(RULE_TYPE) instanceof Integer ? Integer.toString((Integer) expression.get(RULE_TYPE)) : expression.get(RULE_TYPE).toString(), expression.get(RULE_VALUE).toString());
}
IndicatorCategory ruleIndicatorCategory = DefinitionHandler.getInstance().getDQRuleIndicatorCategory();
if (ruleIndicatorCategory != null && !parserRule.getCategories().contains(ruleIndicatorCategory)) {
parserRule.getCategories().add(ruleIndicatorCategory);
}
IFolder folder = ResourceManager.getRulesParserFolder();
TypedReturnCode<Object> returnObject = ElementWriterFactory.getInstance().createdRuleWriter().create(parserRule, folder);
Object object = returnObject.getObject();
RuleRepNode parserRuleNode = RepositoryNodeHelper.recursiveFindRuleParser(parserRule);
BusinessRuleItemEditorInput parserRuleEditorInput = new BusinessRuleItemEditorInput(parserRuleNode);
CorePlugin.getDefault().openEditor(parserRuleEditorInput, DQRuleEditor.class.getName());
refresh(object);
}
Aggregations