Search in sources :

Example 16 with SystemHelper

use of org.codelibs.fess.helper.SystemHelper in project fess by codelibs.

the class PurgeLogJob method execute.

public String execute() {
    final CrawlingInfoService crawlingInfoService = ComponentUtil.getComponent(CrawlingInfoService.class);
    final SearchLogService searchLogService = ComponentUtil.getComponent(SearchLogService.class);
    final JobLogService jobLogService = ComponentUtil.getComponent(JobLogService.class);
    final UserInfoService userInfoService = ComponentUtil.getComponent(UserInfoService.class);
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final StringBuilder resultBuf = new StringBuilder();
    // purge crawling sessions
    try {
        crawlingInfoService.deleteBefore(systemHelper.getCurrentTimeAsLong());
    } catch (final Exception e) {
        logger.error("Failed to purge crawling sessions.", e);
        resultBuf.append(e.getMessage()).append("\n");
    }
    // purge search logs
    try {
        final int days = ComponentUtil.getFessConfig().getPurgeSearchLogDay();
        if (days >= 0) {
            searchLogService.deleteBefore(days);
        } else {
            resultBuf.append("Skipped to purge search logs.\n");
        }
    } catch (final Exception e) {
        logger.error("Failed to purge search logs.", e);
        resultBuf.append(e.getMessage()).append("\n");
    }
    // purge job logs
    try {
        final int days = ComponentUtil.getFessConfig().getPurgeJobLogDay();
        if (days >= 0) {
            jobLogService.deleteBefore(days);
        } else {
            resultBuf.append("Skipped to purge job logs.\n");
        }
    } catch (final Exception e) {
        logger.error("Failed to purge job logs.", e);
        resultBuf.append(e.getMessage()).append("\n");
    }
    // purge user info
    try {
        final int days = ComponentUtil.getFessConfig().getPurgeUserInfoDay();
        if (days >= 0) {
            userInfoService.deleteBefore(days);
        } else {
            resultBuf.append("Skipped to purge user info logs.\n");
        }
    } catch (final Exception e) {
        logger.error("Failed to purge user info.", e);
        resultBuf.append(e.getMessage()).append("\n");
    }
    // update job logs
    try {
        jobLogService.updateStatus();
    } catch (final Exception e) {
        logger.error("Failed to purge job logs.", e);
        resultBuf.append(e.getMessage()).append("\n");
    }
    return resultBuf.toString();
}
Also used : SearchLogService(org.codelibs.fess.app.service.SearchLogService) SystemHelper(org.codelibs.fess.helper.SystemHelper) JobLogService(org.codelibs.fess.app.service.JobLogService) CrawlingInfoService(org.codelibs.fess.app.service.CrawlingInfoService) UserInfoService(org.codelibs.fess.app.service.UserInfoService)

Example 17 with SystemHelper

use of org.codelibs.fess.helper.SystemHelper in project fess by codelibs.

the class LdapManager method getRoles.

public String[] getRoles(final LdapUser ldapUser, final String bindDn, final String accountFilter) {
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final List<String> roleList = new ArrayList<>();
    if (fessConfig.isLdapRoleSearchUserEnabled()) {
        roleList.add(systemHelper.getSearchRoleByUser(ldapUser.getName()));
    }
    // LDAP: cn=%s
    // AD: (&(objectClass=user)(sAMAccountName=%s))
    final String filter = String.format(accountFilter, ldapUser.getName());
    search(bindDn, filter, new String[] { fessConfig.getLdapMemberofAttribute() }, () -> ldapUser.getEnvironment(), result -> {
        processSearchRoles(result, (entryDn, name) -> {
            final boolean isRole = entryDn.toLowerCase(Locale.ROOT).indexOf("ou=role") != -1;
            if (isRole) {
                if (fessConfig.isLdapRoleSearchRoleEnabled()) {
                    roleList.add(systemHelper.getSearchRoleByRole(name));
                }
            } else if (fessConfig.isLdapRoleSearchGroupEnabled()) {
                roleList.add(systemHelper.getSearchRoleByGroup(name));
            }
        });
    });
    return roleList.toArray(new String[roleList.size()]);
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 18 with SystemHelper

use of org.codelibs.fess.helper.SystemHelper in project fess by codelibs.

the class ThumbnailManager method storeQueue.

protected void storeQueue(final List<Tuple4<String, String, String, String>> taskList) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final String[] targets = fessConfig.getThumbnailGeneratorTargetsAsArray();
    final List<ThumbnailQueue> list = new ArrayList<>();
    taskList.stream().filter(entity -> entity != null).forEach(task -> {
        for (final String target : targets) {
            final ThumbnailQueue entity = new ThumbnailQueue();
            entity.setGenerator(task.getValue1());
            entity.setThumbnailId(task.getValue2());
            entity.setUrl(task.getValue3());
            entity.setPath(task.getValue4());
            entity.setTarget(target);
            entity.setCreatedBy(Constants.SYSTEM_USER);
            entity.setCreatedTime(systemHelper.getCurrentTimeAsLong());
            list.add(entity);
        }
    });
    taskList.clear();
    final ThumbnailQueueBhv thumbnailQueueBhv = ComponentUtil.getComponent(ThumbnailQueueBhv.class);
    thumbnailQueueBhv.batchInsert(list);
}
Also used : ThumbnailQueueBhv(org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) FessSystemException(org.codelibs.fess.exception.FessSystemException) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LruHashMap(org.codelibs.core.collection.LruHashMap) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) ArrayList(java.util.ArrayList) ThumbnailQueue(org.codelibs.fess.es.config.exentity.ThumbnailQueue) PreDestroy(javax.annotation.PreDestroy) ResourceUtil(org.codelibs.fess.util.ResourceUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Lists(com.google.common.collect.Lists) Map(java.util.Map) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) Path(java.nio.file.Path) HttpSession(javax.servlet.http.HttpSession) Tuple4(org.codelibs.core.misc.Tuple4) Logger(org.slf4j.Logger) FileVisitor(java.nio.file.FileVisitor) Files(java.nio.file.Files) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) PostConstruct(javax.annotation.PostConstruct) ThumbnailQueueBhv(org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv) SystemHelper(org.codelibs.fess.helper.SystemHelper) ArrayList(java.util.ArrayList) ThumbnailQueue(org.codelibs.fess.es.config.exentity.ThumbnailQueue) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 19 with SystemHelper

use of org.codelibs.fess.helper.SystemHelper in project fess by codelibs.

the class GitBucketDataStoreImpl method createRoleList.

private List<String> createRoleList(final String owner, final Map<String, Object> repository) {
    Boolean isPrivate = true;
    if (repository.containsKey(PRIVATE_REPOSITORY_PARAM)) {
        isPrivate = (Boolean) repository.get(PRIVATE_REPOSITORY_PARAM);
    }
    if (!isPrivate) {
        return Collections.singletonList("Rguest");
    }
    @SuppressWarnings("unchecked") final List<String> collaboratorList = (List<String>) repository.get(COLLABORATORS_PARAM);
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    collaboratorList.add(owner);
    return collaboratorList.stream().map(user -> systemHelper.getSearchRoleByUser(user)).collect(Collectors.toList());
}
Also used : HcHttpClient(org.codelibs.fess.crawler.client.http.HcHttpClient) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) IndexUpdateCallback(org.codelibs.fess.ds.IndexUpdateCallback) RequestHeader(org.codelibs.fess.crawler.client.http.RequestHeader) JsonXContent(org.elasticsearch.common.xcontent.json.JsonXContent) CrawlingConfig(org.codelibs.fess.es.config.exentity.CrawlingConfig) Curl(org.codelibs.elasticsearch.runner.net.Curl) ArrayList(java.util.ArrayList) Map(java.util.Map) CrawlingConfigWrapper(org.codelibs.fess.es.config.exentity.CrawlingConfigWrapper) CurlResponse(org.codelibs.elasticsearch.runner.net.CurlResponse) URI(java.net.URI) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) DataConfig(org.codelibs.fess.es.config.exentity.DataConfig) Logger(org.slf4j.Logger) StringUtil(org.codelibs.core.lang.StringUtil) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) Collections(java.util.Collections) CrawlerClientFactory(org.codelibs.fess.crawler.client.CrawlerClientFactory) InputStream(java.io.InputStream) SystemHelper(org.codelibs.fess.helper.SystemHelper) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with SystemHelper

use of org.codelibs.fess.helper.SystemHelper in project fess by codelibs.

the class IndexUpdateCallbackImpl method store.

/* (non-Javadoc)
     * @see org.codelibs.fess.ds.impl.IndexUpdateCallback#store(java.util.Map)
     */
@Override
public void store(final Map<String, String> paramMap, final Map<String, Object> dataMap) {
    final long startTime = System.currentTimeMillis();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
    if (logger.isDebugEnabled()) {
        logger.debug("Adding " + dataMap);
    }
    //   required check
    final Object urlObj = dataMap.get(fessConfig.getIndexFieldUrl());
    if (urlObj == null) {
        throw new DataStoreException("url is null. dataMap=" + dataMap);
    }
    final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
    final CrawlingInfoHelper crawlingInfoHelper = ComponentUtil.getCrawlingInfoHelper();
    dataMap.put(fessConfig.getIndexFieldId(), crawlingInfoHelper.generateId(dataMap));
    final String url = dataMap.get(fessConfig.getIndexFieldUrl()).toString();
    if (fessConfig.getIndexerClickCountEnabledAsBoolean()) {
        addClickCountField(dataMap, url, fessConfig.getIndexFieldClickCount());
    }
    if (fessConfig.getIndexerFavoriteCountEnabledAsBoolean()) {
        addFavoriteCountField(dataMap, url, fessConfig.getIndexFieldFavoriteCount());
    }
    if (!dataMap.containsKey(fessConfig.getIndexFieldDocId())) {
        final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
        dataMap.put(fessConfig.getIndexFieldDocId(), systemHelper.generateDocId(dataMap));
    }
    synchronized (docList) {
        docList.add(dataMap);
        if (logger.isDebugEnabled()) {
            logger.debug("Added the document. " + "The number of a document cache is " + docList.size() + ".");
        }
        final Long contentLength = DocumentUtil.getValue(dataMap, fessConfig.getIndexFieldContentLength(), Long.class);
        if (contentLength != null) {
            docList.addContentSize(contentLength.longValue());
            if (docList.getContentSize() >= maxDocumentRequestSize) {
                indexingHelper.sendDocuments(fessEsClient, docList);
            }
        } else if (docList.size() >= fessConfig.getIndexerDataMaxDocumentCacheSizeAsInteger().intValue()) {
            indexingHelper.sendDocuments(fessEsClient, docList);
        }
        executeTime += System.currentTimeMillis() - startTime;
    }
    documentSize.getAndIncrement();
    if (logger.isDebugEnabled()) {
        logger.debug("The number of an added document is " + documentSize.get() + ".");
    }
}
Also used : DataStoreException(org.codelibs.fess.exception.DataStoreException) SystemHelper(org.codelibs.fess.helper.SystemHelper) IndexingHelper(org.codelibs.fess.helper.IndexingHelper) CrawlingInfoHelper(org.codelibs.fess.helper.CrawlingInfoHelper) FessEsClient(org.codelibs.fess.es.client.FessEsClient) AtomicLong(java.util.concurrent.atomic.AtomicLong) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Aggregations

SystemHelper (org.codelibs.fess.helper.SystemHelper)42 StringUtil (org.codelibs.core.lang.StringUtil)17 ComponentUtil (org.codelibs.fess.util.ComponentUtil)17 Constants (org.codelibs.fess.Constants)15 ArrayList (java.util.ArrayList)14 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)14 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)13 HashMap (java.util.HashMap)11 List (java.util.List)10 Map (java.util.Map)10 Collectors (java.util.stream.Collectors)10 OptionalThing (org.dbflute.optional.OptionalThing)8 Stream (java.util.stream.Stream)7 Resource (javax.annotation.Resource)7 StreamUtil.split (org.codelibs.core.stream.StreamUtil.split)7 Secured (org.codelibs.fess.annotation.Secured)7 CrudMode (org.codelibs.fess.app.web.CrudMode)7 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)7 RenderDataUtil (org.codelibs.fess.util.RenderDataUtil)7 OptionalEntity (org.dbflute.optional.OptionalEntity)7