Search in sources :

Example 26 with StringUtil

use of org.codelibs.core.lang.StringUtil in project fess by codelibs.

the class ElevateWordService method importCsv.

public void importCsv(final Reader reader) {
    final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
    final CsvConfig cfg = new CsvConfig(',', '"', '"');
    cfg.setEscapeDisabled(false);
    cfg.setQuoteDisabled(false);
    @SuppressWarnings("resource") final CsvReader csvReader = new CsvReader(reader, cfg);
    try {
        List<String> list;
        // ignore header
        csvReader.readValues();
        while ((list = csvReader.readValues()) != null) {
            final String suggestWord = getValue(list, 0);
            if (StringUtil.isBlank(suggestWord)) {
                // skip
                continue;
            }
            try {
                final String[] permissions = split(getValue(list, 2), ",").get(stream -> stream.map(permissionHelper::encode).filter(StringUtil::isNotBlank).distinct().toArray(n -> new String[n]));
                final String[] labels = split(getValue(list, 3), ",").get(stream -> stream.filter(StringUtil::isNotBlank).distinct().toArray(n -> new String[n]));
                ElevateWord elevateWord = elevateWordBhv.selectEntity(cb -> {
                    cb.query().setSuggestWord_Equal(suggestWord);
                    if (permissions.length > 0) {
                        cb.query().setPermissions_InScope(stream(permissions).get(stream -> stream.collect(Collectors.toList())));
                    }
                }).orElse(null);
                final String reading = getValue(list, 1);
                final String boost = getValue(list, 4);
                final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
                if (elevateWord == null) {
                    elevateWord = new ElevateWord();
                    elevateWord.setSuggestWord(suggestWord);
                    elevateWord.setReading(reading);
                    elevateWord.setPermissions(permissions);
                    elevateWord.setBoost(StringUtil.isBlank(boost) ? 1.0f : Float.parseFloat(boost));
                    elevateWord.setCreatedBy(Constants.SYSTEM_USER);
                    elevateWord.setCreatedTime(now);
                    elevateWordBhv.insert(elevateWord);
                    final String id = elevateWord.getId();
                    final List<ElevateWordToLabel> mappingList = stream(labels).get(stream -> stream.map(l -> labelTypeBhv.selectEntity(cb -> cb.query().setValue_Equal(l)).map(e -> {
                        final ElevateWordToLabel m = new ElevateWordToLabel();
                        m.setElevateWordId(id);
                        m.setLabelTypeId(e.getId());
                        return m;
                    }).orElse(null)).filter(e -> e != null).collect(Collectors.toList()));
                    if (!mappingList.isEmpty()) {
                        elevateWordToLabelBhv.batchInsert(mappingList);
                    }
                } else if (StringUtil.isBlank(reading) && StringUtil.isBlank(boost)) {
                    elevateWordBhv.delete(elevateWord);
                    final String id = elevateWord.getId();
                    elevateWordToLabelBhv.queryDelete(cb -> cb.query().setElevateWordId_Equal(id));
                } else {
                    elevateWord.setReading(reading);
                    elevateWord.setPermissions(permissions);
                    elevateWord.setBoost(StringUtil.isBlank(boost) ? 1.0f : Float.parseFloat(boost));
                    elevateWord.setUpdatedBy(Constants.SYSTEM_USER);
                    elevateWord.setUpdatedTime(now);
                    elevateWordBhv.update(elevateWord);
                    final String id = elevateWord.getId();
                    final List<ElevateWordToLabel> mappingList = stream(labels).get(stream -> stream.map(l -> labelTypeBhv.selectEntity(cb -> cb.query().setValue_Equal(l)).map(e -> {
                        final List<ElevateWordToLabel> mList = elevateWordToLabelBhv.selectList(cb -> {
                            cb.query().setElevateWordId_Equal(id);
                            cb.query().setLabelTypeId_Equal(e.getId());
                        });
                        if (!mList.isEmpty()) {
                            return null;
                        }
                        final ElevateWordToLabel m = new ElevateWordToLabel();
                        m.setElevateWordId(id);
                        m.setLabelTypeId(e.getId());
                        return m;
                    }).orElse(null)).filter(e -> e != null).collect(Collectors.toList()));
                    if (!mappingList.isEmpty()) {
                        elevateWordToLabelBhv.batchInsert(mappingList);
                    }
                }
            } catch (final Exception e) {
                logger.warn("Failed to read a sugget elevate word: {}", list, e);
            }
        }
        elevateWordBhv.refresh();
    } catch (final IOException e) {
        logger.warn("Failed to read 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) IOException(java.io.IOException) ElevateWordToLabel(org.codelibs.fess.es.config.exentity.ElevateWordToLabel) IOException(java.io.IOException) CsvReader(com.orangesignal.csv.CsvReader) 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)

Example 27 with StringUtil

use of org.codelibs.core.lang.StringUtil in project fess by codelibs.

the class AdminAccesstokenAction method getAccessToken.

public static OptionalEntity<AccessToken> getAccessToken(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(Constants.COMMON_CONVERSION_RULE).exclude(TOKEN, Constants.PERMISSIONS, EXPIRED_TIME).dateConverter(Constants.DEFAULT_DATETIME_FORMAT, EXPIRES));
        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 : BeanUtil(org.codelibs.core.beans.util.BeanUtil) AccessTokenPager(org.codelibs.fess.app.pager.AccessTokenPager) Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) AccessTokenService(org.codelibs.fess.app.service.AccessTokenService) 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) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) CrudMode(org.codelibs.fess.app.web.CrudMode) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) AccessToken(org.codelibs.fess.es.config.exentity.AccessToken) 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) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) StringUtil(org.codelibs.core.lang.StringUtil)

Example 28 with StringUtil

use of org.codelibs.core.lang.StringUtil in project fess by codelibs.

the class AdminWebconfigAction method createnew.

// ===================================================================================
// Edit Execute
// ============
// -----------------------------------------------------
// Entry Page
// ----------
@Execute
@Secured({ ROLE })
public HtmlResponse createnew() {
    saveToken();
    return asEditHtml().useForm(CreateForm.class, op -> {
        op.setup(form -> {
            form.initialize();
            ComponentUtil.getCrawlingConfigHelper().getDefaultConfig(ConfigType.WEB).ifPresent(entity -> {
                copyBeanToBean(entity, form, copyOp -> {
                    copyOp.excludeNull();
                    copyOp.exclude(Stream.concat(Stream.of(Constants.COMMON_CONVERSION_RULE), Stream.of(Constants.PERMISSIONS, Constants.VIRTUAL_HOSTS)).toArray(n -> new String[n]));
                });
                final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
                form.permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
                form.virtualHosts = stream(entity.getVirtualHosts()).get(stream -> stream.filter(StringUtil::isNotBlank).map(String::trim).collect(Collectors.joining("\n")));
                form.name = null;
            });
            form.crudMode = CrudMode.CREATE;
        });
    });
}
Also used : Constants(org.codelibs.fess.Constants) WebConfigService(org.codelibs.fess.app.service.WebConfigService) 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) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) RenderData(org.lastaflute.web.response.render.RenderData) RoleTypeService(org.codelibs.fess.app.service.RoleTypeService) WebConfig(org.codelibs.fess.es.config.exentity.WebConfig) HtmlResponse(org.lastaflute.web.response.HtmlResponse) ConfigType(org.codelibs.fess.es.config.exentity.CrawlingConfig.ConfigType) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Collectors(java.util.stream.Collectors) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) Stream(java.util.stream.Stream) ComponentUtil(org.codelibs.fess.util.ComponentUtil) ScheduledJobService(org.codelibs.fess.app.service.ScheduledJobService) SystemHelper(org.codelibs.fess.helper.SystemHelper) WebConfigPager(org.codelibs.fess.app.pager.WebConfigPager) Execute(org.lastaflute.web.Execute) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) StringUtil(org.codelibs.core.lang.StringUtil) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 29 with StringUtil

use of org.codelibs.core.lang.StringUtil in project fess by codelibs.

the class AdminWebconfigAction method getWebConfig.

public static OptionalEntity<WebConfig> getWebConfig(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, Constants.VIRTUAL_HOSTS)).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])));
        entity.setVirtualHosts(split(form.virtualHosts, "\n").get(stream -> stream.filter(StringUtil::isNotBlank).distinct().map(String::trim).toArray(n -> new String[n])));
        return entity;
    });
}
Also used : Constants(org.codelibs.fess.Constants) WebConfigService(org.codelibs.fess.app.service.WebConfigService) 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) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) RenderData(org.lastaflute.web.response.render.RenderData) RoleTypeService(org.codelibs.fess.app.service.RoleTypeService) WebConfig(org.codelibs.fess.es.config.exentity.WebConfig) HtmlResponse(org.lastaflute.web.response.HtmlResponse) ConfigType(org.codelibs.fess.es.config.exentity.CrawlingConfig.ConfigType) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Collectors(java.util.stream.Collectors) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) Stream(java.util.stream.Stream) ComponentUtil(org.codelibs.fess.util.ComponentUtil) ScheduledJobService(org.codelibs.fess.app.service.ScheduledJobService) SystemHelper(org.codelibs.fess.helper.SystemHelper) WebConfigPager(org.codelibs.fess.app.pager.WebConfigPager) Execute(org.lastaflute.web.Execute) SystemHelper(org.codelibs.fess.helper.SystemHelper) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) StringUtil(org.codelibs.core.lang.StringUtil)

Example 30 with StringUtil

use of org.codelibs.core.lang.StringUtil in project fess by codelibs.

the class ApiAdminAccesstokenAction method createEditBody.

protected EditBody createEditBody(final AccessToken entity) {
    final EditBody body = new EditBody();
    copyBeanToBean(entity, body, copyOp -> copyOp.exclude(Constants.PERMISSIONS, AdminAccesstokenAction.EXPIRED_TIME).excludeNull().dateConverter(Constants.DEFAULT_DATETIME_FORMAT, AdminAccesstokenAction.EXPIRES));
    final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
    body.permissions = stream(entity.getPermissions()).get(stream -> stream.map(permissionHelper::decode).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
    body.crudMode = null;
    return body;
}
Also used : AccessTokenPager(org.codelibs.fess.app.pager.AccessTokenPager) AdminAccesstokenAction.getAccessToken(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction.getAccessToken) Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) 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) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) AdminAccesstokenAction(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction) ComponentUtil(org.codelibs.fess.util.ComponentUtil) AccessToken(org.codelibs.fess.es.config.exentity.AccessToken) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) ApiConfigsResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigsResponse) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) StringUtil(org.codelibs.core.lang.StringUtil)

Aggregations

StringUtil (org.codelibs.core.lang.StringUtil)46 ComponentUtil (org.codelibs.fess.util.ComponentUtil)41 Constants (org.codelibs.fess.Constants)40 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)38 Collectors (java.util.stream.Collectors)35 List (java.util.List)30 StreamUtil.split (org.codelibs.core.stream.StreamUtil.split)27 PermissionHelper (org.codelibs.fess.helper.PermissionHelper)26 ArrayList (java.util.ArrayList)25 Resource (javax.annotation.Resource)20 CrudMode (org.codelibs.fess.app.web.CrudMode)19 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)19 OptionalThing (org.dbflute.optional.OptionalThing)19 Execute (org.lastaflute.web.Execute)19 Map (java.util.Map)17 Stream (java.util.stream.Stream)17 SystemHelper (org.codelibs.fess.helper.SystemHelper)17 OptionalEntity (org.dbflute.optional.OptionalEntity)17 LogManager (org.apache.logging.log4j.LogManager)16 Logger (org.apache.logging.log4j.Logger)16