Search in sources :

Example 11 with ParserRule

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;
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with ParserRule

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());
        }
    }
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) TdExpression(org.talend.cwm.relational.TdExpression) FileNotFoundException(java.io.FileNotFoundException) CSVWriter(com.talend.csv.CSVWriter) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserRuleToExcelEnum(org.talend.dataprofiler.core.ui.wizard.parserrule.ParserRuleToExcelEnum) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 13 with ParserRule

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);
    }
// ~
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ParserRule(org.talend.dataquality.rules.ParserRule) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) PartInitException(org.eclipse.ui.PartInitException) MatchRuleMasterDetailsPage(org.talend.dataprofiler.core.ui.editor.matchrule.MatchRuleMasterDetailsPage) DefaultSaveAction(org.talend.dataprofiler.core.ui.action.actions.DefaultSaveAction) TdEditorToolBar(org.talend.dataprofiler.core.ui.editor.TdEditorToolBar)

Example 14 with ParserRule

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;
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 15 with ParserRule

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);
    }
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) DqRuleBuilder(org.talend.dq.dqrule.DqRuleBuilder)

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