Search in sources :

Example 6 with LabelType

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

the class LabelTypeHelper method buildLabelTypePatternList.

protected void buildLabelTypePatternList(final List<LabelType> labelTypeList) {
    final List<LabelTypePattern> list = new ArrayList<>();
    for (final LabelType labelType : labelTypeList) {
        final String includedPaths = labelType.getIncludedPaths();
        final String excludedPaths = labelType.getExcludedPaths();
        if (StringUtil.isNotBlank(includedPaths) || StringUtil.isNotBlank(excludedPaths)) {
            try {
                list.add(new LabelTypePattern(labelType.getValue(), includedPaths, excludedPaths));
            } catch (final Exception e) {
                logger.warn("Failed to create a matching pattern of a label: {}, includedPaths:{}, excludedPaths:{}", labelType.getValue(), includedPaths, excludedPaths, e);
            }
        }
    }
    labelTypePatternList = list;
}
Also used : LabelType(org.codelibs.fess.es.config.exentity.LabelType) ArrayList(java.util.ArrayList)

Example 7 with LabelType

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

the class LabelTypeHelper method buildLabelTypeItems.

protected void buildLabelTypeItems(final List<LabelType> labelTypeList) {
    final List<LabelTypeItem> itemList = new ArrayList<>();
    for (final LabelType labelType : labelTypeList) {
        final LabelTypeItem item = new LabelTypeItem();
        item.setLabel(labelType.getName());
        item.setValue(labelType.getValue());
        item.setPermissions(labelType.getPermissions());
        item.setVirtualHost(labelType.getVirtualHost());
        item.setLocale(labelType.getLocale());
        itemList.add(item);
    }
    labelTypeItemList = itemList;
}
Also used : LabelType(org.codelibs.fess.es.config.exentity.LabelType) ArrayList(java.util.ArrayList)

Example 8 with LabelType

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

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

the class GsaConfigParser method startElement.

@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException {
    if (logger.isDebugEnabled()) {
        logger.debug("Start Element: {}", qName);
    }
    if (tagQueue.isEmpty() && !"eef".equalsIgnoreCase(qName)) {
        throw new GsaConfigException("Invalid format.");
    }
    if (COLLECTION.equalsIgnoreCase(qName) && COLLECTIONS.equalsIgnoreCase(tagQueue.peekLast())) {
        final long now = System.currentTimeMillis();
        final String name = attributes.getValue("Name");
        labelType = new LabelType();
        labelType.setName(name);
        labelType.setValue(name);
        labelType.setPermissions(new String[] { "Rguest" });
        labelType.setCreatedBy(Constants.SYSTEM_USER);
        labelType.setCreatedTime(now);
        labelType.setUpdatedBy(Constants.SYSTEM_USER);
        labelType.setUpdatedTime(now);
    }
    tagQueue.offer(qName);
}
Also used : LabelType(org.codelibs.fess.es.config.exentity.LabelType) GsaConfigException(org.codelibs.fess.exception.GsaConfigException)

Example 10 with LabelType

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

the class ApiAdminLabeltypeAction method settings.

// ===================================================================================
// Search Execute
// ==============
// GET /api/admin/labeltype/settings
// POST /api/admin/labeltype/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final LabelTypePager pager = copyBeanToNewBean(body, LabelTypePager.class);
    final List<LabelType> list = labelTypeService.getLabelTypeList(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 : ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminLabeltypeAction.getLabelType(org.codelibs.fess.app.web.admin.labeltype.AdminLabeltypeAction.getLabelType) LabelType(org.codelibs.fess.es.config.exentity.LabelType) LabelTypePager(org.codelibs.fess.app.pager.LabelTypePager) Execute(org.lastaflute.web.Execute)

Aggregations

LabelType (org.codelibs.fess.es.config.exentity.LabelType)12 Collectors (java.util.stream.Collectors)6 StringUtil (org.codelibs.core.lang.StringUtil)6 Constants (org.codelibs.fess.Constants)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Resource (javax.annotation.Resource)5 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)5 LabelTypePager (org.codelibs.fess.app.pager.LabelTypePager)5 LabelTypeService (org.codelibs.fess.app.service.LabelTypeService)5 PermissionHelper (org.codelibs.fess.helper.PermissionHelper)5 ComponentUtil (org.codelibs.fess.util.ComponentUtil)5 Execute (org.lastaflute.web.Execute)5 CrudMode (org.codelibs.fess.app.web.CrudMode)4 AdminLabeltypeAction.getLabelType (org.codelibs.fess.app.web.admin.labeltype.AdminLabeltypeAction.getLabelType)4 ApiResult (org.codelibs.fess.app.web.api.ApiResult)4 StreamUtil.split (org.codelibs.core.stream.StreamUtil.split)3 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)3 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)3 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)3