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);
}
}
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);
}
});
}
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();
}
});
}
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);
}
}
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);
}
}
Aggregations