Search in sources :

Example 1 with ParserRuleToExcelEnum

use of org.talend.dataprofiler.core.ui.wizard.parserrule.ParserRuleToExcelEnum in project tdq-studio-se by Talend.

the class ExportFactory method getParserRuleEnumValues.

/**
 * DOC klliu Comment method "getParserRuleEnumValues".
 *
 * @return
 */
private static ParserRuleToExcelEnum[] getParserRuleEnumValues() {
    List<ParserRuleToExcelEnum> realValues = new ArrayList<ParserRuleToExcelEnum>();
    ParserRuleToExcelEnum[] values = ParserRuleToExcelEnum.values();
    for (ParserRuleToExcelEnum parserEnum : values) {
        if (!(parserEnum.equals(ParserRuleToExcelEnum.Body) || parserEnum.equals(ParserRuleToExcelEnum.Language))) {
            realValues.add(parserEnum);
        }
    }
    return realValues.toArray(new ParserRuleToExcelEnum[realValues.size()]);
}
Also used : ArrayList(java.util.ArrayList) ParserRuleToExcelEnum(org.talend.dataprofiler.core.ui.wizard.parserrule.ParserRuleToExcelEnum)

Example 2 with ParserRuleToExcelEnum

use of org.talend.dataprofiler.core.ui.wizard.parserrule.ParserRuleToExcelEnum 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 3 with ParserRuleToExcelEnum

use of org.talend.dataprofiler.core.ui.wizard.parserrule.ParserRuleToExcelEnum in project tdq-studio-se by Talend.

the class ExportFactory method getRelatedValueFromParserRule.

private static Map<ParserRuleToExcelEnum, String> getRelatedValueFromParserRule(ParserRule parserRule, IFolder folder, TdExpression tde) {
    Map<ParserRuleToExcelEnum, String> idMap = new HashMap<ParserRuleToExcelEnum, String>();
    if (folder != null) {
        IFile file = ResourceFileMap.findCorrespondingFile(parserRule);
        URI relativeURI = folder.getLocationURI().relativize(file.getParent().getLocationURI());
        // get the basic information
        idMap.put(ParserRuleToExcelEnum.Label, relpaceTempHasEscapeCharactor(parserRule.getName()));
        idMap.put(ParserRuleToExcelEnum.Purpose, relpaceTempHasEscapeCharactor(MetadataHelper.getPurpose(parserRule)));
        idMap.put(ParserRuleToExcelEnum.Description, relpaceTempHasEscapeCharactor(MetadataHelper.getDescription(parserRule)));
        idMap.put(ParserRuleToExcelEnum.Author, relpaceTempHasEscapeCharactor(MetadataHelper.getAuthor(parserRule)));
        idMap.put(ParserRuleToExcelEnum.RelativePath, relativeURI.toString());
        idMap.put(ParserRuleToExcelEnum.Name, replaceQual(tde.getName()));
        idMap.put(ParserRuleToExcelEnum.Type, replaceQual(tde.getLanguage()));
        idMap.put(ParserRuleToExcelEnum.Value, replaceQual(tde.getBody()));
    }
    return idMap;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) ParserRuleToExcelEnum(org.talend.dataprofiler.core.ui.wizard.parserrule.ParserRuleToExcelEnum) URI(java.net.URI)

Aggregations

ParserRuleToExcelEnum (org.talend.dataprofiler.core.ui.wizard.parserrule.ParserRuleToExcelEnum)3 IFile (org.eclipse.core.resources.IFile)2 CSVWriter (com.talend.csv.CSVWriter)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TdExpression (org.talend.cwm.relational.TdExpression)1 ParserRule (org.talend.dataquality.rules.ParserRule)1