Search in sources :

Example 36 with SystemHelper

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

the class AdminElevatewordAction method getElevateWord.

public static OptionalEntity<ElevateWord> getElevateWord(final CreateForm form) {
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final String username = systemHelper.getUsername();
    final long currentTime = systemHelper.getCurrentTimeAsLong();
    return getEntity(form, username, currentTime).map(entity -> {
        entity.setUpdatedBy(username);
        entity.setUpdatedTime(currentTime);
        BeanUtil.copyBeanToBean(form, entity, op -> op.exclude(Stream.concat(Stream.of(Constants.COMMON_CONVERSION_RULE), Stream.of(Constants.PERMISSIONS)).toArray(n -> new String[n])));
        final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
        entity.setPermissions(split(form.permissions, "\n").get(stream -> stream.map(permissionHelper::encode).filter(StringUtil::isNotBlank).distinct().toArray(n -> new String[n])));
        return entity;
    });
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) FessSystemException(org.codelibs.fess.exception.FessSystemException) ElevateWordPager(org.codelibs.fess.app.pager.ElevateWordPager) OptionalThing(org.dbflute.optional.OptionalThing) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) CrudMode(org.codelibs.fess.app.web.CrudMode) CommonPoolUtil(org.codelibs.core.concurrent.CommonPoolUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) RenderData(org.lastaflute.web.response.render.RenderData) OutputStreamWriter(java.io.OutputStreamWriter) HtmlResponse(org.lastaflute.web.response.HtmlResponse) Path(java.nio.file.Path) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) ElevateWordService(org.codelibs.fess.app.service.ElevateWordService) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) ActionResponse(org.lastaflute.web.response.ActionResponse) Stream(java.util.stream.Stream) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) Writer(java.io.Writer) Execute(org.lastaflute.web.Execute) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) BufferedReader(java.io.BufferedReader) SuggestHelper(org.codelibs.fess.helper.SuggestHelper) InputStream(java.io.InputStream) SystemHelper(org.codelibs.fess.helper.SystemHelper) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) StringUtil(org.codelibs.core.lang.StringUtil)

Example 37 with SystemHelper

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

the class AdminLogAction method getLogFileItems.

public static List<Map<String, Object>> getLogFileItems() {
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final List<Map<String, Object>> logFileItems = new ArrayList<>();
    final String logFilePath = systemHelper.getLogFilePath();
    if (StringUtil.isNotBlank(logFilePath)) {
        final Path logDirPath = Paths.get(logFilePath);
        try (Stream<Path> stream = Files.list(logDirPath)) {
            stream.filter(entry -> isLogFilename(entry.getFileName().toString())).sorted().forEach(filePath -> {
                final Map<String, Object> map = new HashMap<>();
                final String name = filePath.getFileName().toString();
                map.put("id", Base64.getUrlEncoder().encodeToString(name.getBytes(StandardCharsets.UTF_8)));
                map.put("name", name);
                try {
                    map.put("lastModified", new Date(Files.getLastModifiedTime(filePath).toMillis()));
                } catch (final IOException e) {
                    throw new IORuntimeException(e);
                }
                logFileItems.add(map);
            });
        } catch (final Exception e) {
            throw new FessSystemException("Failed to access log files.", e);
        }
    }
    return logFileItems;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) FessSystemException(org.codelibs.fess.exception.FessSystemException) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) IOException(java.io.IOException) FessSystemException(org.codelibs.fess.exception.FessSystemException) SystemHelper(org.codelibs.fess.helper.SystemHelper) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 38 with SystemHelper

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

the class AdminGeneralAction method updateConfig.

public static void updateConfig(final FessConfig fessConfig, final EditForm form) {
    fessConfig.setLoginRequired(isCheckboxEnabled(form.loginRequired));
    fessConfig.setResultCollapsed(isCheckboxEnabled(form.resultCollapsed));
    fessConfig.setLoginLinkEnabled(isCheckboxEnabled(form.loginLink));
    fessConfig.setThumbnailEnabled(isCheckboxEnabled(form.thumbnail));
    fessConfig.setIncrementalCrawling(isCheckboxEnabled(form.incrementalCrawling));
    fessConfig.setDayForCleanup(form.dayForCleanup);
    fessConfig.setCrawlingThreadCount(form.crawlingThreadCount);
    fessConfig.setSearchLog(isCheckboxEnabled(form.searchLog));
    fessConfig.setUserInfo(isCheckboxEnabled(form.userInfo));
    fessConfig.setUserFavorite(isCheckboxEnabled(form.userFavorite));
    fessConfig.setWebApiJson(isCheckboxEnabled(form.webApiJson));
    fessConfig.setAppValue(form.appValue);
    fessConfig.setDefaultLabelValue(form.defaultLabelValue);
    fessConfig.setDefaultSortValue(form.defaultSortValue);
    fessConfig.setVirtualHostValue(form.virtualHostValue);
    fessConfig.setAppendQueryParameter(isCheckboxEnabled(form.appendQueryParameter));
    fessConfig.setIgnoreFailureType(form.ignoreFailureType);
    fessConfig.setFailureCountThreshold(form.failureCountThreshold);
    fessConfig.setWebApiPopularWord(isCheckboxEnabled(form.popularWord));
    fessConfig.setCsvFileEncoding(form.csvFileEncoding);
    fessConfig.setPurgeSearchLogDay(form.purgeSearchLogDay);
    fessConfig.setPurgeJobLogDay(form.purgeJobLogDay);
    fessConfig.setPurgeUserInfoDay(form.purgeUserInfoDay);
    fessConfig.setPurgeByBots(form.purgeByBots);
    fessConfig.setNotificationTo(form.notificationTo);
    fessConfig.setSuggestSearchLog(isCheckboxEnabled(form.suggestSearchLog));
    fessConfig.setSuggestDocuments(isCheckboxEnabled(form.suggestDocuments));
    fessConfig.setPurgeSuggestSearchLogDay(form.purgeSuggestSearchLogDay);
    fessConfig.setLdapProviderUrl(form.ldapProviderUrl);
    fessConfig.setLdapSecurityPrincipal(form.ldapSecurityPrincipal);
    fessConfig.setLdapAdminSecurityPrincipal(form.ldapAdminSecurityPrincipal);
    if (form.ldapAdminSecurityCredentials != null && StringUtil.isNotBlank(form.ldapAdminSecurityCredentials.replace("*", " "))) {
        fessConfig.setLdapAdminSecurityCredentials(form.ldapAdminSecurityCredentials);
    }
    fessConfig.setLdapBaseDn(form.ldapBaseDn);
    fessConfig.setLdapAccountFilter(form.ldapAccountFilter);
    fessConfig.setLdapGroupFilter(form.ldapGroupFilter);
    fessConfig.setLdapMemberofAttribute(form.ldapMemberofAttribute);
    fessConfig.setNotificationLogin(form.notificationLogin);
    fessConfig.setNotificationSearchTop(form.notificationSearchTop);
    fessConfig.setStorageEndpoint(form.storageEndpoint);
    if (form.storageAccessKey != null && StringUtil.isNotBlank(form.storageAccessKey.replace("*", " "))) {
        fessConfig.setStorageAccessKey(form.storageAccessKey);
    }
    if (form.storageSecretKey != null && StringUtil.isNotBlank(form.storageSecretKey.replace("*", " "))) {
        fessConfig.setStorageSecretKey(form.storageSecretKey);
    }
    fessConfig.setStorageBucket(form.storageBucket);
    fessConfig.storeSystemProperties();
    ComponentUtil.getLdapManager().updateConfig();
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    systemHelper.refreshDesignJspFiles();
    systemHelper.updateSystemProperties();
    if (StringUtil.isNotBlank(form.logLevel)) {
        systemHelper.setLogLevel(form.logLevel);
    }
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper)

Example 39 with SystemHelper

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

the class AdminRelatedqueryAction method getRelatedQuery.

public static OptionalEntity<RelatedQuery> getRelatedQuery(final CreateForm form) {
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final String username = systemHelper.getUsername();
    final long currentTime = systemHelper.getCurrentTimeAsLong();
    return getEntity(form, username, currentTime).map(entity -> {
        entity.setUpdatedBy(username);
        entity.setUpdatedTime(currentTime);
        BeanUtil.copyBeanToBean(form, entity, op -> op.exclude(Stream.concat(Stream.of(Constants.COMMON_CONVERSION_RULE), Stream.of(Constants.QUERIES)).toArray(n -> new String[n])));
        entity.setQueries(split(form.queries, "\n").get(stream -> stream.filter(StringUtil::isNotBlank).toArray(n -> new String[n])));
        return entity;
    });
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) RelatedQueryPager(org.codelibs.fess.app.pager.RelatedQueryPager) OptionalEntity(org.dbflute.optional.OptionalEntity) OptionalThing(org.dbflute.optional.OptionalThing) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) RelatedQuery(org.codelibs.fess.es.config.exentity.RelatedQuery) Collectors(java.util.stream.Collectors) RelatedQueryService(org.codelibs.fess.app.service.RelatedQueryService) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Stream(java.util.stream.Stream) CrudMode(org.codelibs.fess.app.web.CrudMode) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) SystemHelper(org.codelibs.fess.helper.SystemHelper) Execute(org.lastaflute.web.Execute) RenderData(org.lastaflute.web.response.render.RenderData) HtmlResponse(org.lastaflute.web.response.HtmlResponse) SystemHelper(org.codelibs.fess.helper.SystemHelper)

Example 40 with SystemHelper

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

the class AdminSearchlistAction method getDoc.

public static OptionalEntity<Map<String, Object>> getDoc(final CreateForm form) {
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    switch(form.crudMode) {
        case CrudMode.CREATE:
            final Map<String, Object> entity = new HashMap<>();
            entity.put(fessConfig.getIndexFieldDocId(), systemHelper.generateDocId(entity));
            return OptionalEntity.of(entity);
        case CrudMode.EDIT:
            final String docId;
            if (form.doc != null) {
                docId = (String) form.doc.get(fessConfig.getIndexFieldDocId());
            } else {
                docId = null;
            }
            if (StringUtil.isNotBlank(docId)) {
                return searchEngineClient.getDocument(fessConfig.getIndexDocumentUpdateIndex(), builder -> {
                    builder.setQuery(QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId));
                    return true;
                });
            }
            break;
        default:
            break;
    }
    return OptionalEntity.empty();
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper) HashMap(java.util.HashMap) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) 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