Search in sources :

Example 1 with CrawlingInfo

use of org.codelibs.fess.es.config.exentity.CrawlingInfo 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 CrawlingInfo

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

the class CrawlingInfoService method getLastCrawlingInfoParamList.

public List<CrawlingInfoParam> getLastCrawlingInfoParamList(final String sessionId) {
    final CrawlingInfo crawlingInfo = getLast(sessionId);
    if (crawlingInfo == null) {
        return Collections.emptyList();
    }
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    return crawlingInfoParamBhv.selectList(cb -> {
        cb.query().setCrawlingInfoId_Equal(crawlingInfo.getId());
        cb.query().addOrderBy_CreatedTime_Asc();
        cb.paging(fessConfig.getPageCrawlingInfoParamMaxFetchSizeAsInteger(), 1);
    });
}
Also used : CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 3 with CrawlingInfo

use of org.codelibs.fess.es.config.exentity.CrawlingInfo 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 4 with CrawlingInfo

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

the class CrawlingInfoHelper method updateParams.

public void updateParams(final String sessionId, final String name, final int dayForCleanup) {
    final CrawlingInfo crawlingInfo = getCrawlingInfoService().getLast(sessionId);
    if (crawlingInfo == null) {
        logger.warn("No crawling session: {}", sessionId);
        return;
    }
    if (StringUtil.isNotBlank(name)) {
        crawlingInfo.setName(name);
    } else {
        crawlingInfo.setName(Constants.CRAWLING_INFO_SYSTEM_NAME);
    }
    if (dayForCleanup >= 0) {
        final long expires = getExpiredTime(dayForCleanup);
        crawlingInfo.setExpiredTime(expires);
        documentExpires = expires;
    }
    try {
        getCrawlingInfoService().store(crawlingInfo);
    } catch (final Exception e) {
        throw new FessSystemException("No crawling session.", e);
    }
}
Also used : CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) FessSystemException(org.codelibs.fess.exception.FessSystemException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FessSystemException(org.codelibs.fess.exception.FessSystemException)

Example 5 with CrawlingInfo

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

the class CrawlingInfoService method deleteSessionIdsBefore.

public void deleteSessionIdsBefore(final String activeSessionId, final String name, final long date) {
    final List<CrawlingInfo> crawlingInfoList = crawlingInfoBhv.selectList(cb -> {
        cb.query().filtered((cq, cf) -> {
            cq.setExpiredTime_LessEqual(date);
            if (StringUtil.isNotBlank(name)) {
                cf.setName_Equal(name);
            }
            if (activeSessionId != null) {
                cf.setSessionId_NotEqual(activeSessionId);
            }
        });
        cb.fetchFirst(fessConfig.getPageCrawlingInfoMaxFetchSizeAsInteger());
        cb.specify().columnId();
    });
    if (!crawlingInfoList.isEmpty()) {
        final List<String> crawlingInfoIdList = new ArrayList<>();
        for (final CrawlingInfo cs : crawlingInfoList) {
            crawlingInfoIdList.add(cs.getId());
        }
        crawlingInfoParamBhv.queryDelete(cb2 -> cb2.query().setCrawlingInfoId_InScope(crawlingInfoIdList));
        crawlingInfoBhv.batchDelete(crawlingInfoList, op -> op.setRefreshPolicy(Constants.TRUE));
    }
}
Also used : CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) ArrayList(java.util.ArrayList)

Aggregations

CrawlingInfo (org.codelibs.fess.es.config.exentity.CrawlingInfo)8 ArrayList (java.util.ArrayList)4 CrawlingInfoPager (org.codelibs.fess.app.pager.CrawlingInfoPager)4 FessSystemException (org.codelibs.fess.exception.FessSystemException)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Resource (javax.annotation.Resource)3 CrawlingInfoParam (org.codelibs.fess.es.config.exentity.CrawlingInfoParam)3 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)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 UnsupportedEncodingException (java.io.UnsupportedEncodingException)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