Search in sources :

Example 1 with LabelType

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

the class LabelTypeHelper method getMatchedLabelValueSet.

public Set<String> getMatchedLabelValueSet(final String path) {
    if (labelTypePatternList == null) {
        synchronized (this) {
            if (labelTypePatternList == null) {
                final List<LabelType> labelTypeList = ComponentUtil.getComponent(LabelTypeService.class).getLabelTypeList();
                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: " + labelType.getValue() + ", includedPaths:" + includedPaths + ", excludedPaths:" + excludedPaths, e);
                        }
                    }
                }
                labelTypePatternList = list;
            }
        }
    }
    if (labelTypePatternList.isEmpty()) {
        return Collections.emptySet();
    }
    final Set<String> valueSet = new HashSet<>();
    for (final LabelTypePattern pattern : labelTypePatternList) {
        if (pattern.match(path)) {
            valueSet.add(pattern.getValue());
        }
    }
    return valueSet;
}
Also used : LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) LabelType(org.codelibs.fess.es.config.exentity.LabelType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 2 with LabelType

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

the class ApiAdminLabeltypeAction method post$setting.

// POST /api/admin/labeltype/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final LabelType labelType = getLabelType(body).map(entity -> {
        try {
            labelTypeService.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(labelType.getId()).created(false).status(Status.OK).result());
}
Also used : AdminLabeltypeAction.getLabelType(org.codelibs.fess.app.web.admin.labeltype.AdminLabeltypeAction.getLabelType) Constants(org.codelibs.fess.Constants) LabelTypePager(org.codelibs.fess.app.pager.LabelTypePager) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) 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) LabelType(org.codelibs.fess.es.config.exentity.LabelType) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) 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) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminLabeltypeAction.getLabelType(org.codelibs.fess.app.web.admin.labeltype.AdminLabeltypeAction.getLabelType) LabelType(org.codelibs.fess.es.config.exentity.LabelType) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 3 with LabelType

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

the class GsaConfigParserTest method test_parse.

public void test_parse() throws IOException {
    GsaConfigParser parser = new GsaConfigParser();
    try (InputStream is = ResourceUtil.getResourceAsStream("data/gsaconfig.xml")) {
        parser.parse(new InputSource(is));
    }
    parser.getWebConfig().ifPresent(c -> {
        System.out.println(c.toString());
    }).orElse(() -> fail());
    parser.getFileConfig().ifPresent(c -> {
        System.out.println(c.toString());
    }).orElse(() -> fail());
    LabelType[] labelTypes = parser.getLabelTypes();
    assertEquals(3, labelTypes.length);
}
Also used : InputSource(org.xml.sax.InputSource) UnitFessTestCase(org.codelibs.fess.unit.UnitFessTestCase) ResourceUtil(org.codelibs.core.io.ResourceUtil) IOException(java.io.IOException) LabelType(org.codelibs.fess.es.config.exentity.LabelType) InputStream(java.io.InputStream) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) LabelType(org.codelibs.fess.es.config.exentity.LabelType)

Example 4 with LabelType

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

the class AdminLabeltypeAction method getLabelType.

public static OptionalEntity<LabelType> getLabelType(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);
        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(s -> permissionHelper.encode(s)).filter(StringUtil::isNotBlank).distinct().toArray(n -> new String[n])));
        return entity;
    });
}
Also used : Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) LabelTypePager(org.codelibs.fess.app.pager.LabelTypePager) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) OptionalEntity(org.dbflute.optional.OptionalEntity) OptionalThing(org.dbflute.optional.OptionalThing) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) Collectors(java.util.stream.Collectors) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) LabelType(org.codelibs.fess.es.config.exentity.LabelType) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) 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) RoleTypeService(org.codelibs.fess.app.service.RoleTypeService) HtmlResponse(org.lastaflute.web.response.HtmlResponse) SystemHelper(org.codelibs.fess.helper.SystemHelper) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) StringUtil(org.codelibs.core.lang.StringUtil)

Example 5 with LabelType

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

the class ElevateWordService method exportCsv.

public void exportCsv(final Writer writer) {
    final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
    final CsvConfig cfg = new CsvConfig(',', '"', '"');
    cfg.setEscapeDisabled(false);
    cfg.setQuoteDisabled(false);
    @SuppressWarnings("resource") final CsvWriter csvWriter = new CsvWriter(writer, cfg);
    try {
        final List<String> list = new ArrayList<>();
        list.add("SuggestWord");
        list.add("Reading");
        list.add("Permissions");
        list.add("Labels");
        list.add("Boost");
        csvWriter.writeValues(list);
        elevateWordBhv.selectCursor(cb -> cb.query().matchAll(), new EntityRowHandler<ElevateWord>() {

            @Override
            public void handle(final ElevateWord entity) {
                final List<String> list = new ArrayList<>();
                final String permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining(",")));
                final String labels = elevateWordToLabelBhv.selectList(cb -> cb.query().setElevateWordId_Equal(entity.getId())).stream().map(e -> labelTypeBhv.selectByPK(e.getLabelTypeId()).map(LabelType::getValue).filter(StringUtil::isNotBlank).orElse(null)).distinct().sorted().collect(Collectors.joining(","));
                addToList(list, entity.getSuggestWord());
                addToList(list, entity.getReading());
                addToList(list, permissions);
                addToList(list, labels);
                addToList(list, entity.getBoost());
                try {
                    csvWriter.writeValues(list);
                } catch (final IOException e) {
                    logger.warn("Failed to write a sugget elevate word: {}", entity, e);
                }
            }

            private void addToList(final List<String> list, final Object value) {
                if (value == null) {
                    list.add(StringUtil.EMPTY);
                } else {
                    list.add(value.toString());
                }
            }
        });
        csvWriter.flush();
    } catch (final IOException e) {
        logger.warn("Failed to write a sugget elevate word.", e);
    }
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) EntityRowHandler(org.dbflute.bhv.readable.EntityRowHandler) Constants(org.codelibs.fess.Constants) ElevateWordPager(org.codelibs.fess.app.pager.ElevateWordPager) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) LabelType(org.codelibs.fess.es.config.exentity.LabelType) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) PagingResultBean(org.dbflute.cbean.result.PagingResultBean) LabelTypeBhv(org.codelibs.fess.es.config.exbhv.LabelTypeBhv) ElevateWordBhv(org.codelibs.fess.es.config.exbhv.ElevateWordBhv) ElevateWordCB(org.codelibs.fess.es.config.cbean.ElevateWordCB) ElevateWordToLabel(org.codelibs.fess.es.config.exentity.ElevateWordToLabel) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) CsvWriter(com.orangesignal.csv.CsvWriter) IOException(java.io.IOException) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) CsvConfig(com.orangesignal.csv.CsvConfig) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) ElevateWordToLabelBhv(org.codelibs.fess.es.config.exbhv.ElevateWordToLabelBhv) Writer(java.io.Writer) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) LogManager(org.apache.logging.log4j.LogManager) CsvReader(com.orangesignal.csv.CsvReader) CsvWriter(com.orangesignal.csv.CsvWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) ArrayList(java.util.ArrayList) List(java.util.List) CsvConfig(com.orangesignal.csv.CsvConfig) StringUtil(org.codelibs.core.lang.StringUtil)

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