use of com.orangesignal.csv.CsvConfig 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.CsvConfig 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.CsvConfig 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("Labels");
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(",")));
final String labels = elevateWordToLabelBhv.selectList(cb -> cb.query().setElevateWordId_Equal(entity.getId())).stream().map(e -> labelTypeBhv.selectByPK(e.getLabelTypeId()).map(LabelType::getValue).filter(StringUtil::isNotBlank).orElse(null)).distinct().sorted().collect(Collectors.joining(","));
addToList(list, entity.getSuggestWord());
addToList(list, entity.getReading());
addToList(list, permissions);
addToList(list, labels);
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.CsvConfig in project fess by codelibs.
the class CrawlingInfoService method importCsv.
public void importCsv(final Reader reader) {
@SuppressWarnings("resource") final CsvReader csvReader = new CsvReader(reader, new CsvConfig());
final DateFormat formatter = new SimpleDateFormat(CoreLibConstants.DATE_FORMAT_ISO_8601_EXTEND);
try {
List<String> list;
// ignore header
csvReader.readValues();
while ((list = csvReader.readValues()) != null) {
try {
final String sessionId = list.get(0);
CrawlingInfo crawlingInfo = crawlingInfoBhv.selectEntity(cb -> {
cb.query().setSessionId_Equal(sessionId);
cb.specify().columnSessionId();
}).orElse(// TODO
null);
if (crawlingInfo == null) {
crawlingInfo = new CrawlingInfo();
crawlingInfo.setSessionId(list.get(0));
crawlingInfo.setCreatedTime(formatter.parse(list.get(1)).getTime());
crawlingInfoBhv.insert(crawlingInfo, op -> op.setRefreshPolicy(Constants.TRUE));
}
final CrawlingInfoParam entity = new CrawlingInfoParam();
entity.setCrawlingInfoId(crawlingInfo.getId());
entity.setKey(list.get(2));
entity.setValue(list.get(3));
entity.setCreatedTime(formatter.parse(list.get(4)).getTime());
crawlingInfoParamBhv.insert(entity, op -> op.setRefreshPolicy(Constants.TRUE));
} catch (final Exception e) {
logger.warn("Failed to read a click log: {}", list, e);
}
}
} catch (final IOException e) {
logger.warn("Failed to read a click log.", e);
}
}
use of com.orangesignal.csv.CsvConfig in project fess by codelibs.
the class CsvDataStoreImpl method storeData.
@Override
protected void storeData(final DataConfig dataConfig, final IndexUpdateCallback callback, final Map<String, String> paramMap, final Map<String, String> scriptMap, final Map<String, Object> defaultDataMap) {
final long readInterval = getReadInterval(paramMap);
final List<File> csvFileList = getCsvFileList(paramMap);
if (csvFileList.isEmpty()) {
logger.warn("No CSV file.");
return;
}
final String csvFileEncoding = getCsvFileEncoding(paramMap);
final boolean hasHeaderLine = hasHeaderLine(paramMap);
final CsvConfig csvConfig = buildCsvConfig(paramMap);
for (final File csvFile : csvFileList) {
processCsv(dataConfig, callback, paramMap, scriptMap, defaultDataMap, csvConfig, csvFile, readInterval, csvFileEncoding, hasHeaderLine);
}
}
Aggregations