Search in sources :

Example 6 with FileConfig

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

the class GsaConfigParser method endElement.

@Override
public void endElement(final String uri, final String localName, final String qName) throws SAXException {
    if (logger.isDebugEnabled()) {
        logger.debug("End Element: {}", qName);
    }
    if (GOOD_URLS.equalsIgnoreCase(qName)) {
        if (labelType != null) {
            labelType.setIncludedPaths(parseFilterPaths(textBuf.toString(), true, true));
        } else if (GLOBALPARAMS.equalsIgnoreCase(tagQueue.get(tagQueue.size() - 2))) {
            globalParams.put(GOOD_URLS, textBuf.toString());
        }
    } else if (BAD_URLS.equalsIgnoreCase(qName)) {
        if (labelType != null) {
            labelType.setExcludedPaths(parseFilterPaths(textBuf.toString(), true, true));
        } else if (GLOBALPARAMS.equalsIgnoreCase(tagQueue.get(tagQueue.size() - 2))) {
            globalParams.put(BAD_URLS, textBuf.toString());
        }
    } else if (START_URLS.equalsIgnoreCase(qName) && GLOBALPARAMS.equalsIgnoreCase(tagQueue.get(tagQueue.size() - 2))) {
        globalParams.put(START_URLS, textBuf.toString());
    } else if (labelType != null && COLLECTION.equalsIgnoreCase(qName)) {
        labelList.add(labelType);
        labelType = null;
    } else if (GLOBALPARAMS.equalsIgnoreCase(qName)) {
        final Object startUrls = globalParams.get(START_URLS);
        if (startUrls != null) {
            final long now = System.currentTimeMillis();
            final List<String> urlList = split(startUrls.toString(), "\n").get(stream -> stream.map(String::trim).filter(StringUtil::isNotBlank).collect(Collectors.toList()));
            final String webUrls = urlList.stream().filter(s -> Arrays.stream(webProtocols).anyMatch(p -> s.startsWith(p))).collect(Collectors.joining("\n"));
            if (StringUtil.isNotBlank(webUrls)) {
                webConfig = new WebConfig();
                webConfig.setName("Default");
                webConfig.setAvailable(true);
                webConfig.setBoost(1.0f);
                webConfig.setConfigParameter(StringUtil.EMPTY);
                webConfig.setIntervalTime(1000);
                webConfig.setNumOfThread(3);
                webConfig.setSortOrder(1);
                webConfig.setUrls(webUrls);
                webConfig.setIncludedUrls(parseFilterPaths(globalParams.get(GOOD_URLS), true, false));
                webConfig.setIncludedDocUrls(StringUtil.EMPTY);
                webConfig.setExcludedUrls(parseFilterPaths(globalParams.get(BAD_URLS), true, false));
                webConfig.setExcludedDocUrls(StringUtil.EMPTY);
                webConfig.setUserAgent(userAgent);
                webConfig.setPermissions(new String[] { "Rguest" });
                webConfig.setCreatedBy(Constants.SYSTEM_USER);
                webConfig.setCreatedTime(now);
                webConfig.setUpdatedBy(Constants.SYSTEM_USER);
                webConfig.setUpdatedTime(now);
            }
            final String fileUrls = urlList.stream().filter(s -> Arrays.stream(fileProtocols).anyMatch(p -> s.startsWith(p))).collect(Collectors.joining("\n"));
            if (StringUtil.isNotBlank(fileUrls)) {
                fileConfig = new FileConfig();
                fileConfig.setName("Default");
                fileConfig.setAvailable(true);
                fileConfig.setBoost(1.0f);
                fileConfig.setConfigParameter(StringUtil.EMPTY);
                fileConfig.setIntervalTime(0);
                fileConfig.setNumOfThread(5);
                fileConfig.setSortOrder(2);
                fileConfig.setPaths(fileUrls);
                fileConfig.setIncludedPaths(parseFilterPaths(globalParams.get(GOOD_URLS), false, true));
                fileConfig.setIncludedDocPaths(StringUtil.EMPTY);
                fileConfig.setExcludedPaths(parseFilterPaths(globalParams.get(BAD_URLS), false, true));
                fileConfig.setExcludedDocPaths(StringUtil.EMPTY);
                fileConfig.setPermissions(new String[] { "Rguest" });
                fileConfig.setCreatedBy(Constants.SYSTEM_USER);
                fileConfig.setCreatedTime(now);
                fileConfig.setUpdatedBy(Constants.SYSTEM_USER);
                fileConfig.setUpdatedTime(now);
            }
        }
    } else if ("user_agent".equalsIgnoreCase(qName) && GLOBALPARAMS.equalsIgnoreCase(tagQueue.get(tagQueue.size() - 2))) {
        userAgent = textBuf.toString().trim();
    }
    tagQueue.pollLast();
    textBuf.setLength(0);
}
Also used : Arrays(java.util.Arrays) Constants(org.codelibs.fess.Constants) SAXParserFactory(javax.xml.parsers.SAXParserFactory) HashMap(java.util.HashMap) LabelType(org.codelibs.fess.es.config.exentity.LabelType) ArrayList(java.util.ArrayList) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) GsaConfigException(org.codelibs.fess.exception.GsaConfigException) Map(java.util.Map) SAXParser(javax.xml.parsers.SAXParser) Attributes(org.xml.sax.Attributes) LinkedList(java.util.LinkedList) XMLConstants(javax.xml.XMLConstants) FileConfig(org.codelibs.fess.es.config.exentity.FileConfig) WebConfig(org.codelibs.fess.es.config.exentity.WebConfig) InputSource(org.xml.sax.InputSource) OptionalEntity(org.dbflute.optional.OptionalEntity) StringUtil(org.codelibs.core.lang.StringUtil) Collectors(java.util.stream.Collectors) DefaultHandler(org.xml.sax.helpers.DefaultHandler) List(java.util.List) Logger(org.apache.logging.log4j.Logger) SAXException(org.xml.sax.SAXException) Pattern(java.util.regex.Pattern) LogManager(org.apache.logging.log4j.LogManager) FileConfig(org.codelibs.fess.es.config.exentity.FileConfig) WebConfig(org.codelibs.fess.es.config.exentity.WebConfig) StringUtil(org.codelibs.core.lang.StringUtil)

Example 7 with FileConfig

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

the class ApiAdminFileconfigAction method post$setting.

// POST /api/admin/fileconfig/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final FileConfig fileConfig = getFileConfig(body).map(entity -> {
        try {
            fileConfigService.store(entity);
        } catch (final Exception e) {
            throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
        }
        return entity;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
        return null;
    });
    return asJson(new ApiUpdateResponse().id(fileConfig.getId()).created(false).status(Status.OK).result());
}
Also used : Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) AdminFileconfigAction.getFileConfig(org.codelibs.fess.app.web.admin.fileconfig.AdminFileconfigAction.getFileConfig) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) FileConfigPager(org.codelibs.fess.app.pager.FileConfigPager) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FileConfigService(org.codelibs.fess.app.service.FileConfigService) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) FileConfig(org.codelibs.fess.es.config.exentity.FileConfig) AdminFileconfigAction.getFileConfig(org.codelibs.fess.app.web.admin.fileconfig.AdminFileconfigAction.getFileConfig) FileConfig(org.codelibs.fess.es.config.exentity.FileConfig) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 8 with FileConfig

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

the class ApiAdminFileconfigAction method settings.

// ===================================================================================
// Search Execute
// ==============
// GET /api/admin/fileconfig/settings
// POST /api/admin/fileconfig/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final FileConfigPager pager = copyBeanToNewBean(body, FileConfigPager.class);
    final List<FileConfig> list = fileConfigService.getFileConfigList(pager);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(list.stream().map(this::createEditBody).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Also used : AdminFileconfigAction.getFileConfig(org.codelibs.fess.app.web.admin.fileconfig.AdminFileconfigAction.getFileConfig) FileConfig(org.codelibs.fess.es.config.exentity.FileConfig) ApiResult(org.codelibs.fess.app.web.api.ApiResult) FileConfigPager(org.codelibs.fess.app.pager.FileConfigPager) Execute(org.lastaflute.web.Execute)

Example 9 with FileConfig

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

the class AdminFileauthAction method registerFileConfigItems.

protected void registerFileConfigItems(final RenderData data) {
    final List<Map<String, String>> itemList = new ArrayList<>();
    final List<FileConfig> fileConfigList = crawlingConfigHelper.getAllFileConfigList(false, false, false, null);
    for (final FileConfig fileConfig : fileConfigList) {
        itemList.add(createItem(fileConfig.getName(), fileConfig.getId().toString()));
    }
    RenderDataUtil.register(data, "fileConfigItems", itemList);
}
Also used : FileConfig(org.codelibs.fess.es.config.exentity.FileConfig) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FileConfig (org.codelibs.fess.es.config.exentity.FileConfig)9 StringUtil (org.codelibs.core.lang.StringUtil)7 Constants (org.codelibs.fess.Constants)7 List (java.util.List)6 ComponentUtil (org.codelibs.fess.util.ComponentUtil)6 Execute (org.lastaflute.web.Execute)6 Collectors (java.util.stream.Collectors)5 Resource (javax.annotation.Resource)5 FileConfigPager (org.codelibs.fess.app.pager.FileConfigPager)5 FileConfigService (org.codelibs.fess.app.service.FileConfigService)5 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)4 CrudMode (org.codelibs.fess.app.web.CrudMode)4 AdminFileconfigAction.getFileConfig (org.codelibs.fess.app.web.admin.fileconfig.AdminFileconfigAction.getFileConfig)4 ApiResult (org.codelibs.fess.app.web.api.ApiResult)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 StreamUtil.split (org.codelibs.core.stream.StreamUtil.split)3 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)3