Search in sources :

Example 6 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class AdminSearchlistAction method validateUpdateFields.

public static void validateUpdateFields(final EditForm form, final Consumer<VaMessenger<FessMessages>> throwError) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (!fessConfig.validateIndexRequiredFields(form.doc)) {
        final List<String> invalidRequiredFields = fessConfig.invalidIndexRequiredFields(form.doc);
        throwError.accept(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable("doc." + invalidRequiredFields.get(0), form.docId);
        });
    }
    if (!fessConfig.validateIndexArrayFields(form.doc)) {
        final List<String> invalidArrayFields = fessConfig.invalidIndexArrayFields(form.doc);
        throwError.accept(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable("doc." + invalidArrayFields.get(0), form.docId);
        });
    }
    if (!fessConfig.validateIndexDateFields(form.doc)) {
        final List<String> invalidDateFields = fessConfig.invalidIndexDateFields(form.doc);
        throwError.accept(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable("doc." + invalidDateFields.get(0), form.docId);
        });
    }
    if (!fessConfig.validateIndexIntegerFields(form.doc)) {
        final List<String> invalidIntegerFields = fessConfig.invalidIndexIntegerFields(form.doc);
        throwError.accept(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable("doc." + invalidIntegerFields.get(0), form.docId);
        });
    }
    if (!fessConfig.validateIndexLongFields(form.doc)) {
        final List<String> invalidLongFields = fessConfig.invalidIndexLongFields(form.doc);
        throwError.accept(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable("doc." + invalidLongFields.get(0), form.docId);
        });
    }
    if (!fessConfig.validateIndexFloatFields(form.doc)) {
        final List<String> invalidFloatFields = fessConfig.invalidIndexFloatFields(form.doc);
        throwError.accept(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable("doc." + invalidFloatFields.get(0), form.docId);
        });
    }
    if (!fessConfig.validateIndexDoubleFields(form.doc)) {
        final List<String> invalidDoubleFields = fessConfig.invalidIndexDoubleFields(form.doc);
        throwError.accept(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable("doc." + invalidDoubleFields.get(0), form.docId);
        });
    }
}
Also used : FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 7 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class AdminGeneralAction method sendmail.

@Execute
public HtmlResponse sendmail(final MailForm form) {
    validate(form, messages -> {
    }, () -> {
        return asHtml(path_AdminGeneral_AdminGeneralJsp);
    });
    final String[] toAddresses = form.notificationTo.split(",");
    final Map<String, Object> dataMap = new HashMap<>();
    dataMap.put("hostname", systemHelper.getHostname());
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
    try {
        TestmailPostcard.droppedInto(postbox, postcard -> {
            postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
            postcard.addReplyTo(fessConfig.getMailReturnPath());
            stream(toAddresses).of(stream -> stream.forEach(address -> {
                postcard.addTo(address);
            }));
            BeanUtil.copyMapToBean(dataMap, postcard);
        });
        saveInfo(messages -> messages.addSuccessSendTestmail(GLOBAL));
        updateProperty(Constants.NOTIFICATION_TO_PROPERTY, form.notificationTo);
        systemProperties.store();
    } catch (final Exception e) {
        logger.warn("Failed to send a test mail.", e);
        saveError(messages -> messages.addErrorsFailedToSendTestmail(GLOBAL));
    }
    return redirectByParam(AdminGeneralAction.class, "notificationTo", form.notificationTo);
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) DynamicProperties(org.codelibs.core.misc.DynamicProperties) Logger(org.slf4j.Logger) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) ArrayList(java.util.ArrayList) Postbox(org.lastaflute.core.mail.Postbox) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) TestmailPostcard(org.codelibs.fess.mylasta.mail.TestmailPostcard) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) HashMap(java.util.HashMap) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Execute(org.lastaflute.web.Execute)

Example 8 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class FessXpathTransformer method putAdditionalData.

protected void putAdditionalData(final Map<String, Object> dataMap, final ResponseData responseData, final Document document) {
    // canonical
    if (StringUtil.isNotBlank(fessConfig.getCrawlerDocumentHtmlCanonicalXpath())) {
        final String canonicalUrl = getCanonicalUrl(responseData, document);
        if (canonicalUrl != null && !canonicalUrl.equals(responseData.getUrl())) {
            final Set<RequestData> childUrlSet = new HashSet<>();
            childUrlSet.add(RequestDataBuilder.newRequestData().get().url(canonicalUrl).build());
            throw new ChildUrlsException(childUrlSet, this.getClass().getName() + "#putAdditionalData(Map<String, Object>, ResponseData, Document)");
        }
    }
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final CrawlingInfoHelper crawlingInfoHelper = ComponentUtil.getCrawlingInfoHelper();
    final String sessionId = crawlingInfoHelper.getCanonicalSessionId(responseData.getSessionId());
    final PathMappingHelper pathMappingHelper = ComponentUtil.getPathMappingHelper();
    final CrawlingConfigHelper crawlingConfigHelper = ComponentUtil.getCrawlingConfigHelper();
    final CrawlingConfig crawlingConfig = crawlingConfigHelper.get(responseData.getSessionId());
    final Date documentExpires = crawlingInfoHelper.getDocumentExpires(crawlingConfig);
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final FileTypeHelper fileTypeHelper = ComponentUtil.getFileTypeHelper();
    final DocumentHelper documentHelper = ComponentUtil.getDocumentHelper();
    final LabelTypeHelper labelTypeHelper = ComponentUtil.getLabelTypeHelper();
    String url = responseData.getUrl();
    final String indexingTarget = crawlingConfig.getIndexingTarget(url);
    url = pathMappingHelper.replaceUrl(sessionId, url);
    final String mimeType = responseData.getMimeType();
    final Map<String, String> fieldConfigMap = crawlingConfig.getConfigParameterMap(ConfigName.FIELD);
    final Map<String, String> xpathConfigMap = crawlingConfig.getConfigParameterMap(ConfigName.XPATH);
    String urlEncoding;
    final UrlQueue<?> urlQueue = CrawlingParameterUtil.getUrlQueue();
    if (urlQueue != null && urlQueue.getEncoding() != null) {
        urlEncoding = urlQueue.getEncoding();
    } else {
        urlEncoding = responseData.getCharSet();
    }
    // cid
    final String configId = crawlingConfig.getConfigId();
    if (configId != null) {
        putResultDataBody(dataMap, fessConfig.getIndexFieldConfigId(), configId);
    }
    //  expires
    if (documentExpires != null) {
        putResultDataBody(dataMap, fessConfig.getIndexFieldExpires(), documentExpires);
    }
    // lang
    final String lang = systemHelper.normalizeLang(getSingleNodeValue(document, getLangXpath(fessConfig, xpathConfigMap), true));
    if (lang != null) {
        putResultDataBody(dataMap, fessConfig.getIndexFieldLang(), lang);
    }
    // title
    // content
    final String body = getSingleNodeValue(document, getContentXpath(fessConfig, xpathConfigMap), prunedContent);
    putResultDataBody(dataMap, fessConfig.getIndexFieldContent(), documentHelper.getContent(responseData, body, dataMap));
    if ((Constants.TRUE.equalsIgnoreCase(fieldConfigMap.get(fessConfig.getIndexFieldCache())) || fessConfig.isCrawlerDocumentCacheEnabled()) && fessConfig.isSupportedDocumentCacheMimetypes(mimeType)) {
        if (responseData.getContentLength() > 0 && responseData.getContentLength() <= fessConfig.getCrawlerDocumentCacheMaxSizeAsInteger().longValue()) {
            String charSet = responseData.getCharSet();
            if (charSet == null) {
                charSet = Constants.UTF_8;
            }
            try (final BufferedInputStream is = new BufferedInputStream(responseData.getResponseBody())) {
                // cache
                putResultDataBody(dataMap, fessConfig.getIndexFieldCache(), new String(InputStreamUtil.getBytes(is), charSet));
                putResultDataBody(dataMap, fessConfig.getIndexFieldHasCache(), Constants.TRUE);
            } catch (final Exception e) {
                logger.warn("Failed to write a cache: " + sessionId + ":" + responseData, e);
            }
        } else {
            logger.debug("Content size is too large({} > {}): {}", responseData.getContentLength(), fessConfig.getCrawlerDocumentCacheMaxSizeAsInteger(), responseData.getUrl());
        }
    }
    // digest
    final String digest = getSingleNodeValue(document, getDigestXpath(fessConfig, xpathConfigMap), false);
    if (StringUtil.isNotBlank(digest)) {
        putResultDataBody(dataMap, fessConfig.getIndexFieldDigest(), digest);
    } else {
        putResultDataBody(dataMap, fessConfig.getIndexFieldDigest(), documentHelper.getDigest(responseData, body, dataMap, fessConfig.getCrawlerDocumentHtmlMaxDigestLengthAsInteger()));
    }
    // segment
    putResultDataBody(dataMap, fessConfig.getIndexFieldSegment(), sessionId);
    // host
    putResultDataBody(dataMap, fessConfig.getIndexFieldHost(), getHost(url));
    // site
    putResultDataBody(dataMap, fessConfig.getIndexFieldSite(), getSite(url, urlEncoding));
    // filename
    final String fileName = getFileName(url, urlEncoding);
    if (StringUtil.isNotBlank(fileName)) {
        putResultDataBody(dataMap, fessConfig.getIndexFieldFilename(), fileName);
    }
    // url
    putResultDataBody(dataMap, fessConfig.getIndexFieldUrl(), url);
    // created
    final Date now = systemHelper.getCurrentTime();
    putResultDataBody(dataMap, fessConfig.getIndexFieldCreated(), now);
    // anchor
    putResultDataBody(dataMap, fessConfig.getIndexFieldAnchor(), getAnchorList(document, responseData));
    // mimetype
    putResultDataBody(dataMap, fessConfig.getIndexFieldMimetype(), mimeType);
    if (fileTypeHelper != null) {
        // filetype
        putResultDataBody(dataMap, fessConfig.getIndexFieldFiletype(), fileTypeHelper.get(mimeType));
    }
    // content_length
    putResultDataBody(dataMap, fessConfig.getIndexFieldContentLength(), Long.toString(responseData.getContentLength()));
    // last_modified
    final Date lastModified = responseData.getLastModified();
    if (lastModified != null) {
        putResultDataBody(dataMap, fessConfig.getIndexFieldLastModified(), lastModified);
        // timestamp
        putResultDataBody(dataMap, fessConfig.getIndexFieldTimestamp(), lastModified);
    } else {
        // timestamp
        putResultDataBody(dataMap, fessConfig.getIndexFieldTimestamp(), now);
    }
    // indexingTarget
    putResultDataBody(dataMap, Constants.INDEXING_TARGET, indexingTarget);
    //  boost
    putResultDataBody(dataMap, fessConfig.getIndexFieldBoost(), crawlingConfig.getDocumentBoost());
    // label: labelType
    final Set<String> labelTypeSet = new HashSet<>();
    for (final String labelType : crawlingConfig.getLabelTypeValues()) {
        labelTypeSet.add(labelType);
    }
    labelTypeSet.addAll(labelTypeHelper.getMatchedLabelValueSet(url));
    putResultDataBody(dataMap, fessConfig.getIndexFieldLabel(), labelTypeSet);
    // role: roleType
    final List<String> roleTypeList = new ArrayList<>();
    stream(crawlingConfig.getPermissions()).of(stream -> stream.forEach(p -> roleTypeList.add(p)));
    putResultDataBody(dataMap, fessConfig.getIndexFieldRole(), roleTypeList);
    // id
    putResultDataBody(dataMap, fessConfig.getIndexFieldId(), crawlingInfoHelper.generateId(dataMap));
    // parentId
    String parentUrl = responseData.getParentUrl();
    if (StringUtil.isNotBlank(parentUrl)) {
        parentUrl = pathMappingHelper.replaceUrl(sessionId, parentUrl);
        putResultDataBody(dataMap, fessConfig.getIndexFieldUrl(), parentUrl);
        putResultDataBody(dataMap, fessConfig.getIndexFieldParentId(), crawlingInfoHelper.generateId(dataMap));
        // set again
        putResultDataBody(dataMap, fessConfig.getIndexFieldUrl(), url);
    }
    // thumbnail
    final String thumbnailUrl = getThumbnailUrl(responseData, document);
    if (StringUtil.isNotBlank(thumbnailUrl)) {
        putResultDataBody(dataMap, fessConfig.getIndexFieldThumbnail(), thumbnailUrl);
    }
    // from config
    final Map<String, String> scriptConfigMap = crawlingConfig.getConfigParameterMap(ConfigName.SCRIPT);
    xpathConfigMap.entrySet().stream().filter(e -> !e.getKey().startsWith("default.")).forEach(e -> {
        final String key = e.getKey();
        final String value = getSingleNodeValue(document, e.getValue(), true);
        putResultDataWithTemplate(dataMap, key, value, scriptConfigMap.get(key));
    });
    crawlingConfig.getConfigParameterMap(ConfigName.VALUE).entrySet().stream().forEach(e -> {
        final String key = e.getKey();
        final String value = e.getValue();
        putResultDataWithTemplate(dataMap, key, value, scriptConfigMap.get(key));
    });
}
Also used : ChildUrlsException(org.codelibs.fess.crawler.exception.ChildUrlsException) CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) Constants(org.codelibs.fess.Constants) BufferedInputStream(java.io.BufferedInputStream) URL(java.net.URL) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) CrawlerSystemException(org.codelibs.fess.crawler.exception.CrawlerSystemException) ConfigName(org.codelibs.fess.es.config.exentity.CrawlingConfig.ConfigName) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Locale(java.util.Locale) DOMParser(org.cyberneko.html.parsers.DOMParser) Document(org.w3c.dom.Document) Map(java.util.Map) AccessResultData(org.codelibs.fess.crawler.entity.AccessResultData) InputStreamUtil(org.codelibs.core.io.InputStreamUtil) ResultData(org.codelibs.fess.crawler.entity.ResultData) Set(java.util.Set) List(java.util.List) FileTypeHelper(org.codelibs.fess.helper.FileTypeHelper) RequestData(org.codelibs.fess.crawler.entity.RequestData) ComponentUtil(org.codelibs.fess.util.ComponentUtil) CrawlingInfoHelper(org.codelibs.fess.helper.CrawlingInfoHelper) LabelTypeHelper(org.codelibs.fess.helper.LabelTypeHelper) PostConstruct(javax.annotation.PostConstruct) DocumentHelper(org.codelibs.fess.helper.DocumentHelper) XObject(org.apache.xpath.objects.XObject) UrlQueue(org.codelibs.fess.crawler.entity.UrlQueue) ResponseData(org.codelibs.fess.crawler.entity.ResponseData) CrawlingConfigHelper(org.codelibs.fess.helper.CrawlingConfigHelper) TransformerException(javax.xml.transform.TransformerException) HashMap(java.util.HashMap) SerializeUtil(org.codelibs.core.io.SerializeUtil) CrawlingParameterUtil(org.codelibs.fess.crawler.util.CrawlingParameterUtil) CrawlingConfig(org.codelibs.fess.es.config.exentity.CrawlingConfig) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) XpathTransformer(org.codelibs.fess.crawler.transformer.impl.XpathTransformer) Node(org.w3c.dom.Node) PrunedTag(org.codelibs.fess.util.PrunedTag) NamedNodeMap(org.w3c.dom.NamedNodeMap) InputSource(org.xml.sax.InputSource) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) NodeList(org.w3c.dom.NodeList) MalformedURLException(java.net.MalformedURLException) StringUtil(org.codelibs.core.lang.StringUtil) DuplicateHostHelper(org.codelibs.fess.helper.DuplicateHostHelper) ValueHolder(org.codelibs.core.misc.ValueHolder) SystemHelper(org.codelibs.fess.helper.SystemHelper) PathMappingHelper(org.codelibs.fess.helper.PathMappingHelper) ChildUrlsException(org.codelibs.fess.crawler.exception.ChildUrlsException) Collections(java.util.Collections) RequestDataBuilder(org.codelibs.fess.crawler.builder.RequestDataBuilder) DocumentHelper(org.codelibs.fess.helper.DocumentHelper) CrawlingConfig(org.codelibs.fess.es.config.exentity.CrawlingConfig) ArrayList(java.util.ArrayList) PathMappingHelper(org.codelibs.fess.helper.PathMappingHelper) LabelTypeHelper(org.codelibs.fess.helper.LabelTypeHelper) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Date(java.util.Date) CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) CrawlerSystemException(org.codelibs.fess.crawler.exception.CrawlerSystemException) TransformerException(javax.xml.transform.TransformerException) MalformedURLException(java.net.MalformedURLException) ChildUrlsException(org.codelibs.fess.crawler.exception.ChildUrlsException) CrawlingConfigHelper(org.codelibs.fess.helper.CrawlingConfigHelper) SystemHelper(org.codelibs.fess.helper.SystemHelper) BufferedInputStream(java.io.BufferedInputStream) RequestData(org.codelibs.fess.crawler.entity.RequestData) CrawlingInfoHelper(org.codelibs.fess.helper.CrawlingInfoHelper) FileTypeHelper(org.codelibs.fess.helper.FileTypeHelper) HashSet(java.util.HashSet)

Example 9 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class FessTransformer method decodeUrlAsName.

public default default String decodeUrlAsName(final String url, final boolean escapePlus) {
    if (url == null) {
        return null;
    }
    final FessConfig fessConfig = getFessConfig();
    String enc = Constants.UTF_8;
    if (StringUtil.isBlank(fessConfig.getCrawlerDocumentFileNameEncoding())) {
        final UrlQueue<?> urlQueue = CrawlingParameterUtil.getUrlQueue();
        if (urlQueue != null) {
            final String parentUrl = urlQueue.getParentUrl();
            if (StringUtil.isNotEmpty(parentUrl)) {
                final String sessionId = urlQueue.getSessionId();
                final String pageEnc = getParentEncoding(parentUrl, sessionId);
                if (pageEnc != null) {
                    enc = pageEnc;
                } else if (urlQueue.getEncoding() != null) {
                    enc = urlQueue.getEncoding();
                }
            }
        }
    } else {
        enc = fessConfig.getCrawlerDocumentFileNameEncoding();
    }
    final String escapedUrl = escapePlus ? url.replace("+", "%2B") : url;
    try {
        return URLDecoder.decode(escapedUrl, enc);
    } catch (final Exception e) {
        return url;
    }
}
Also used : FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 10 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class FessCrawlerThread method getChildUrlSet.

protected Set<RequestData> getChildUrlSet(final FessEsClient fessEsClient, final String id) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
    final List<Map<String, Object>> docList = indexingHelper.getChildDocumentList(fessEsClient, id, new String[] { fessConfig.getIndexFieldUrl() });
    if (docList.isEmpty()) {
        return null;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Found documents: " + docList);
    }
    final Set<RequestData> urlSet = new HashSet<>(docList.size());
    for (final Map<String, Object> doc : docList) {
        final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
        if (StringUtil.isNotBlank(url)) {
            urlSet.add(RequestDataBuilder.newRequestData().get().url(url).build());
        }
    }
    return urlSet;
}
Also used : IndexingHelper(org.codelibs.fess.helper.IndexingHelper) RequestData(org.codelibs.fess.crawler.entity.RequestData) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)108 ArrayList (java.util.ArrayList)41 Map (java.util.Map)33 HashMap (java.util.HashMap)32 List (java.util.List)27 ComponentUtil (org.codelibs.fess.util.ComponentUtil)27 Logger (org.slf4j.Logger)26 LoggerFactory (org.slf4j.LoggerFactory)26 StringUtil (org.codelibs.core.lang.StringUtil)24 Constants (org.codelibs.fess.Constants)22 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)21 IOException (java.io.IOException)15 SystemHelper (org.codelibs.fess.helper.SystemHelper)15 PostConstruct (javax.annotation.PostConstruct)14 FessSystemException (org.codelibs.fess.exception.FessSystemException)14 File (java.io.File)11 Date (java.util.Date)11 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)11 Hashtable (java.util.Hashtable)10 FessEsClient (org.codelibs.fess.es.client.FessEsClient)9