Search in sources :

Example 1 with CsvWriter

use of com.orangesignal.csv.CsvWriter in project fess by codelibs.

the class ElevateWordService method exportCsv.

public void exportCsv(final Writer writer) {
    final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
    final CsvConfig cfg = new CsvConfig(',', '"', '"');
    cfg.setEscapeDisabled(false);
    cfg.setQuoteDisabled(false);
    @SuppressWarnings("resource") final CsvWriter csvWriter = new CsvWriter(writer, cfg);
    try {
        final List<String> list = new ArrayList<>();
        list.add("SuggestWord");
        list.add("Reading");
        list.add("Permissions");
        list.add("Label");
        list.add("Boost");
        csvWriter.writeValues(list);
        elevateWordBhv.selectCursor(cb -> cb.query().matchAll(), new EntityRowHandler<ElevateWord>() {

            @Override
            public void handle(final ElevateWord entity) {
                final List<String> list = new ArrayList<>();
                final String permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining(",")));
                addToList(list, entity.getSuggestWord());
                addToList(list, entity.getReading());
                addToList(list, permissions);
                addToList(list, entity.getTargetLabel());
                addToList(list, entity.getBoost());
                try {
                    csvWriter.writeValues(list);
                } catch (final IOException e) {
                    logger.warn("Failed to write a sugget elevate word: " + entity, e);
                }
            }

            private void addToList(final List<String> list, final Object value) {
                if (value == null) {
                    list.add(StringUtil.EMPTY);
                } else {
                    list.add(value.toString());
                }
            }
        });
        csvWriter.flush();
    } catch (final IOException e) {
        logger.warn("Failed to write a sugget elevate word.", e);
    }
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) EntityRowHandler(org.dbflute.bhv.readable.EntityRowHandler) Constants(org.codelibs.fess.Constants) ElevateWordPager(org.codelibs.fess.app.pager.ElevateWordPager) LoggerFactory(org.slf4j.LoggerFactory) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) PagingResultBean(org.dbflute.cbean.result.PagingResultBean) ElevateWordBhv(org.codelibs.fess.es.config.exbhv.ElevateWordBhv) ElevateWordCB(org.codelibs.fess.es.config.cbean.ElevateWordCB) ElevateWordToLabel(org.codelibs.fess.es.config.exentity.ElevateWordToLabel) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) FessEsClient(org.codelibs.fess.es.client.FessEsClient) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) CsvWriter(com.orangesignal.csv.CsvWriter) IOException(java.io.IOException) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) CsvConfig(com.orangesignal.csv.CsvConfig) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) ElevateWordToLabelBhv(org.codelibs.fess.es.config.exbhv.ElevateWordToLabelBhv) Writer(java.io.Writer) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) CsvReader(com.orangesignal.csv.CsvReader) CsvWriter(com.orangesignal.csv.CsvWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) ArrayList(java.util.ArrayList) List(java.util.List) CsvConfig(com.orangesignal.csv.CsvConfig) StringUtil(org.codelibs.core.lang.StringUtil)

Example 2 with CsvWriter

use of com.orangesignal.csv.CsvWriter in project fess by codelibs.

the class AdminBackupAction method writeCsvResponse.

private StreamResponse writeCsvResponse(final String id, final Consumer<CsvWriter> writeCall) {
    return asStream(id).contentTypeOctetStream().header("Pragma", "no-cache").header("Cache-Control", "no-cache").header("Expires", "Thu, 01 Dec 1994 16:00:00 GMT").stream(out -> {
        final CsvConfig cfg = new CsvConfig(',', '"', '"');
        cfg.setEscapeDisabled(false);
        cfg.setQuoteDisabled(false);
        try (final CsvWriter writer = new CsvWriter(new BufferedWriter(new OutputStreamWriter(out.stream(), fessConfig.getCsvFileEncoding())), cfg)) {
            writeCall.accept(writer);
            writer.flush();
        } catch (final Exception e) {
            logger.warn("Failed to write " + id + " to response.", e);
        }
    });
}
Also used : CsvWriter(com.orangesignal.csv.CsvWriter) OutputStreamWriter(java.io.OutputStreamWriter) CsvConfig(com.orangesignal.csv.CsvConfig) IORuntimeException(org.codelibs.core.exception.IORuntimeException) IOException(java.io.IOException) RuntimeIOException(com.healthmarketscience.jackcess.RuntimeIOException) BufferedWriter(java.io.BufferedWriter)

Example 3 with CsvWriter

use of com.orangesignal.csv.CsvWriter in project fess by codelibs.

the class ApiAdminBackupAction method writeCsvResponse.

private StreamResponse writeCsvResponse(final String id, final Consumer<CsvWriter> writeCall) {
    return asStream(id).contentTypeOctetStream().header("Pragma", "no-cache").header("Cache-Control", "no-cache").header("Expires", "Thu, 01 Dec 1994 16:00:00 GMT").stream(out -> {
        final CsvConfig cfg = new CsvConfig(',', '"', '"');
        cfg.setEscapeDisabled(false);
        cfg.setQuoteDisabled(false);
        try (final CsvWriter writer = new CsvWriter(new BufferedWriter(new OutputStreamWriter(out.stream(), fessConfig.getCsvFileEncoding())), cfg)) {
            writeCall.accept(writer);
            writer.flush();
        }
    });
}
Also used : CsvWriter(com.orangesignal.csv.CsvWriter) OutputStreamWriter(java.io.OutputStreamWriter) CsvConfig(com.orangesignal.csv.CsvConfig) BufferedWriter(java.io.BufferedWriter)

Example 4 with CsvWriter

use of com.orangesignal.csv.CsvWriter in project fess by codelibs.

the class BadWordService method exportCsv.

public void exportCsv(final Writer writer) {
    final CsvConfig cfg = new CsvConfig(',', '"', '"');
    cfg.setEscapeDisabled(false);
    cfg.setQuoteDisabled(false);
    @SuppressWarnings("resource") final CsvWriter csvWriter = new CsvWriter(writer, cfg);
    try {
        final List<String> list = new ArrayList<>();
        list.add("BadWord");
        csvWriter.writeValues(list);
        badWordBhv.selectCursor(cb -> cb.query().matchAll(), new EntityRowHandler<BadWord>() {

            @Override
            public void handle(final BadWord entity) {
                final List<String> list = new ArrayList<>();
                addToList(list, entity.getSuggestWord());
                try {
                    csvWriter.writeValues(list);
                } catch (final IOException e) {
                    logger.warn("Failed to write a sugget bad word: " + entity, e);
                }
            }

            private void addToList(final List<String> list, final Object value) {
                if (value == null) {
                    list.add(StringUtil.EMPTY);
                } else {
                    list.add(value.toString());
                }
            }
        });
        csvWriter.flush();
    } catch (final IOException e) {
        logger.warn("Failed to write a sugget bad word.", e);
    }
}
Also used : CsvWriter(com.orangesignal.csv.CsvWriter) BadWord(org.codelibs.fess.es.config.exentity.BadWord) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ArrayList(java.util.ArrayList) List(java.util.List) CsvConfig(com.orangesignal.csv.CsvConfig)

Example 5 with CsvWriter

use of com.orangesignal.csv.CsvWriter in project fess by codelibs.

the class CrawlingInfoService method exportCsv.

public void exportCsv(final Writer writer) {
    final CsvConfig cfg = new CsvConfig(',', '"', '"');
    cfg.setEscapeDisabled(false);
    cfg.setQuoteDisabled(false);
    @SuppressWarnings("resource") final CsvWriter csvWriter = new CsvWriter(writer, cfg);
    try {
        final List<String> list = new ArrayList<>();
        list.add("SessionId");
        list.add("SessionCreatedTime");
        list.add("Key");
        list.add("Value");
        list.add("CreatedTime");
        csvWriter.writeValues(list);
        final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(CoreLibConstants.DATE_FORMAT_ISO_8601_EXTEND);
        crawlingInfoParamBhv.selectCursor(cb -> cb.query().matchAll(), new EntityRowHandler<CrawlingInfoParam>() {

            @Override
            public void handle(final CrawlingInfoParam entity) {
                final List<String> list = new ArrayList<>();
                entity.getCrawlingInfo().ifPresent(crawlingInfo -> {
                    addToList(list, crawlingInfo.getSessionId());
                    addToList(list, crawlingInfo.getCreatedTime());
                });
                // TODO
                if (!entity.getCrawlingInfo().isPresent()) {
                    addToList(list, "");
                    addToList(list, "");
                }
                addToList(list, entity.getKey());
                addToList(list, entity.getValue());
                addToList(list, entity.getCreatedTime());
                try {
                    csvWriter.writeValues(list);
                } catch (final IOException e) {
                    logger.warn("Failed to write a crawling session info: " + entity, e);
                }
            }

            private void addToList(final List<String> list, final Object value) {
                if (value == null) {
                    list.add(StringUtil.EMPTY);
                } else if (value instanceof LocalDateTime) {
                    list.add(((LocalDateTime) value).format(formatter));
                } else {
                    list.add(value.toString());
                }
            }
        });
        csvWriter.flush();
    } catch (final IOException e) {
        logger.warn("Failed to write a crawling session info.", e);
    }
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) EntityRowHandler(org.dbflute.bhv.readable.EntityRowHandler) Constants(org.codelibs.fess.Constants) FessSystemException(org.codelibs.fess.exception.FessSystemException) CrawlingInfoBhv(org.codelibs.fess.es.config.exbhv.CrawlingInfoBhv) ListResultBean(org.dbflute.cbean.result.ListResultBean) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) SimpleDateFormat(java.text.SimpleDateFormat) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) CrawlingInfoParam(org.codelibs.fess.es.config.exentity.CrawlingInfoParam) PagingResultBean(org.dbflute.cbean.result.PagingResultBean) DateFormat(java.text.DateFormat) CrawlingInfoPager(org.codelibs.fess.app.pager.CrawlingInfoPager) Logger(org.slf4j.Logger) OptionalEntity(org.dbflute.optional.OptionalEntity) CrawlingInfoParamBhv(org.codelibs.fess.es.config.exbhv.CrawlingInfoParamBhv) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) CsvWriter(com.orangesignal.csv.CsvWriter) Set(java.util.Set) IOException(java.io.IOException) Reader(java.io.Reader) CoreLibConstants(org.codelibs.core.CoreLibConstants) Collectors(java.util.stream.Collectors) CrawlingInfoCB(org.codelibs.fess.es.config.cbean.CrawlingInfoCB) CsvConfig(com.orangesignal.csv.CsvConfig) List(java.util.List) CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DateTimeFormatter(java.time.format.DateTimeFormatter) Writer(java.io.Writer) Collections(java.util.Collections) CsvReader(com.orangesignal.csv.CsvReader) LocalDateTime(java.time.LocalDateTime) CsvWriter(com.orangesignal.csv.CsvWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ArrayList(java.util.ArrayList) List(java.util.List) CsvConfig(com.orangesignal.csv.CsvConfig) DateTimeFormatter(java.time.format.DateTimeFormatter) CrawlingInfoParam(org.codelibs.fess.es.config.exentity.CrawlingInfoParam)

Aggregations

CsvConfig (com.orangesignal.csv.CsvConfig)5 CsvWriter (com.orangesignal.csv.CsvWriter)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CsvReader (com.orangesignal.csv.CsvReader)2 BufferedWriter (java.io.BufferedWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Reader (java.io.Reader)2 Writer (java.io.Writer)2 Collectors (java.util.stream.Collectors)2 Resource (javax.annotation.Resource)2 BeanUtil (org.codelibs.core.beans.util.BeanUtil)2 StringUtil (org.codelibs.core.lang.StringUtil)2 Constants (org.codelibs.fess.Constants)2 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)2 ComponentUtil (org.codelibs.fess.util.ComponentUtil)2 EntityRowHandler (org.dbflute.bhv.readable.EntityRowHandler)2 PagingResultBean (org.dbflute.cbean.result.PagingResultBean)2 OptionalEntity (org.dbflute.optional.OptionalEntity)2