Search in sources :

Example 1 with CrawlingInfoParam

use of org.codelibs.fess.es.config.exentity.CrawlingInfoParam 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);
    }
}
Also used : CsvReader(com.orangesignal.csv.CsvReader) CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) 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) 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) 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) Logger(org.apache.logging.log4j.Logger) 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) LogManager(org.apache.logging.log4j.LogManager) CsvReader(com.orangesignal.csv.CsvReader) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CsvConfig(com.orangesignal.csv.CsvConfig) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) CrawlingInfoParam(org.codelibs.fess.es.config.exentity.CrawlingInfoParam) FessSystemException(org.codelibs.fess.exception.FessSystemException) IOException(java.io.IOException)

Example 2 with CrawlingInfoParam

use of org.codelibs.fess.es.config.exentity.CrawlingInfoParam in project fess by codelibs.

the class CrawlingInfoHelper method store.

public synchronized void store(final String sessionId, final boolean create) {
    CrawlingInfo crawlingInfo = create ? null : getCrawlingInfoService().getLast(sessionId);
    if (crawlingInfo == null) {
        crawlingInfo = new CrawlingInfo(sessionId);
        try {
            getCrawlingInfoService().store(crawlingInfo);
        } catch (final Exception e) {
            throw new FessSystemException("No crawling session.", e);
        }
    }
    if (infoMap != null) {
        final List<CrawlingInfoParam> crawlingInfoParamList = new ArrayList<>();
        for (final Map.Entry<String, String> entry : infoMap.entrySet()) {
            final CrawlingInfoParam crawlingInfoParam = new CrawlingInfoParam();
            crawlingInfoParam.setCrawlingInfoId(crawlingInfo.getId());
            crawlingInfoParam.setKey(entry.getKey());
            crawlingInfoParam.setValue(entry.getValue());
            crawlingInfoParamList.add(crawlingInfoParam);
        }
        getCrawlingInfoService().storeInfo(crawlingInfoParamList);
    }
    infoMap = null;
}
Also used : CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) FessSystemException(org.codelibs.fess.exception.FessSystemException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CrawlingInfoParam(org.codelibs.fess.es.config.exentity.CrawlingInfoParam) FessSystemException(org.codelibs.fess.exception.FessSystemException)

Example 3 with CrawlingInfoParam

use of org.codelibs.fess.es.config.exentity.CrawlingInfoParam in project fess by codelibs.

the class CrawlingInfoHelper method getInfoMap.

public Map<String, String> getInfoMap(final String sessionId) {
    final List<CrawlingInfoParam> crawlingInfoParamList = getCrawlingInfoService().getLastCrawlingInfoParamList(sessionId);
    final Map<String, String> map = new HashMap<>();
    for (final CrawlingInfoParam crawlingInfoParam : crawlingInfoParamList) {
        map.put(crawlingInfoParam.getKey(), crawlingInfoParam.getValue());
    }
    return map;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CrawlingInfoParam(org.codelibs.fess.es.config.exentity.CrawlingInfoParam)

Example 4 with CrawlingInfoParam

use of org.codelibs.fess.es.config.exentity.CrawlingInfoParam in project fess by codelibs.

the class CrawlingInfoService method storeInfo.

public void storeInfo(final List<CrawlingInfoParam> crawlingInfoParamList) {
    if (crawlingInfoParamList == null) {
        throw new FessSystemException("Crawling Session Info is null.");
    }
    final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
    for (final CrawlingInfoParam crawlingInfoParam : crawlingInfoParamList) {
        if (crawlingInfoParam.getCreatedTime() == null) {
            crawlingInfoParam.setCreatedTime(now);
        }
    }
    crawlingInfoParamBhv.batchInsert(crawlingInfoParamList, op -> op.setRefreshPolicy(Constants.TRUE));
}
Also used : CrawlingInfoParam(org.codelibs.fess.es.config.exentity.CrawlingInfoParam) FessSystemException(org.codelibs.fess.exception.FessSystemException)

Example 5 with CrawlingInfoParam

use of org.codelibs.fess.es.config.exentity.CrawlingInfoParam 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) 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) 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) Logger(org.apache.logging.log4j.Logger) 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) LogManager(org.apache.logging.log4j.LogManager) 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

CrawlingInfoParam (org.codelibs.fess.es.config.exentity.CrawlingInfoParam)5 FessSystemException (org.codelibs.fess.exception.FessSystemException)4 ArrayList (java.util.ArrayList)3 CrawlingInfo (org.codelibs.fess.es.config.exentity.CrawlingInfo)3 CsvConfig (com.orangesignal.csv.CsvConfig)2 CsvReader (com.orangesignal.csv.CsvReader)2 CsvWriter (com.orangesignal.csv.CsvWriter)2 IOException (java.io.IOException)2 Reader (java.io.Reader)2 Writer (java.io.Writer)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 LocalDateTime (java.time.LocalDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2