Search in sources :

Example 6 with ParserRule

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);
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) Property(org.talend.core.model.properties.Property) DQRule(org.talend.dataquality.rules.DQRule) BeforeClass(org.junit.BeforeClass)

Example 7 with ParserRule

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());
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) Test(org.junit.Test)

Example 8 with ParserRule

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;
    }
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) ArrayList(java.util.ArrayList) RuleRepNode(org.talend.dq.nodes.RuleRepNode) File(java.io.File)

Example 9 with ParserRule

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;
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) TdExpression(org.talend.cwm.relational.TdExpression) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with ParserRule

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);
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) BusinessRuleItemEditorInput(org.talend.dataprofiler.core.ui.editor.dqrules.BusinessRuleItemEditorInput) DQRuleEditor(org.talend.dataprofiler.core.ui.editor.dqrules.DQRuleEditor) DqRuleBuilder(org.talend.dq.dqrule.DqRuleBuilder) RuleRepNode(org.talend.dq.nodes.RuleRepNode) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ParserRule (org.talend.dataquality.rules.ParserRule)16 ArrayList (java.util.ArrayList)7 IFile (org.eclipse.core.resources.IFile)7 TdExpression (org.talend.cwm.relational.TdExpression)7 File (java.io.File)6 IFolder (org.eclipse.core.resources.IFolder)6 Test (org.junit.Test)6 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 ImportObject (org.talend.dataprofiler.core.ui.action.actions.ImportObject)4 ReturnCode (org.talend.utils.sugars.ReturnCode)4 IndicatorCategory (org.talend.dataquality.indicators.definition.IndicatorCategory)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 MatchRuleDefinition (org.talend.dataquality.rules.MatchRuleDefinition)2 DqRuleBuilder (org.talend.dq.dqrule.DqRuleBuilder)2 RuleRepNode (org.talend.dq.nodes.RuleRepNode)2 CSVWriter (com.talend.csv.CSVWriter)1 FileNotFoundException (java.io.FileNotFoundException)1