Search in sources :

Example 1 with AccessToken

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

the class ApiAdminAccesstokenAction method post$setting.

// POST /api/admin/accesstoken/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final AccessToken accessToken = getAccessToken(body).map(entity -> {
        try {
            accessTokenService.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(accessToken.getId()).created(false).status(Status.OK).result());
}
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) AccessTokenService(org.codelibs.fess.app.service.AccessTokenService) 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) 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) AdminAccesstokenAction.getAccessToken(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction.getAccessToken) AccessToken(org.codelibs.fess.es.config.exentity.AccessToken) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 2 with AccessToken

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

the class ApiAdminAccesstokenAction method settings.

// ===================================================================================
//                                                                      Search Execute
//                                                                      ==============
// GET /api/admin/accesstoken
// POST /api/admin/accesstoken
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final AccessTokenPager pager = copyBeanToNewBean(body, AccessTokenPager.class);
    final List<AccessToken> list = accessTokenService.getAccessTokenList(pager);
    return asJson(new ApiConfigsResponse<EditBody>().settings(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(Status.OK).result());
}
Also used : AdminAccesstokenAction.getAccessToken(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction.getAccessToken) AccessToken(org.codelibs.fess.es.config.exentity.AccessToken) AccessTokenPager(org.codelibs.fess.app.pager.AccessTokenPager) Execute(org.lastaflute.web.Execute)

Example 3 with AccessToken

use of org.codelibs.fess.es.config.exentity.AccessToken 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) AccessTokenService(org.codelibs.fess.app.service.AccessTokenService) 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) 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)

Example 4 with AccessToken

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

the class ApiAdminAccesstokenAction method put$setting.

// PUT /api/admin/accesstoken/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final AccessToken accessToken = getAccessToken(body).map(entity -> {
        entity.setToken(systemHelper.generateAccessToken());
        try {
            accessTokenService.store(entity);
        } catch (final Exception e) {
            throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
        }
        return entity;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    });
    return asJson(new ApiUpdateResponse().id(accessToken.getId()).created(true).status(Status.OK).result());
}
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) AccessTokenService(org.codelibs.fess.app.service.AccessTokenService) 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) 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) AdminAccesstokenAction.getAccessToken(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction.getAccessToken) AccessToken(org.codelibs.fess.es.config.exentity.AccessToken) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 5 with AccessToken

use of org.codelibs.fess.es.config.exentity.AccessToken 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) 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)

Aggregations

AccessTokenPager (org.codelibs.fess.app.pager.AccessTokenPager)5 AccessToken (org.codelibs.fess.es.config.exentity.AccessToken)5 Execute (org.lastaflute.web.Execute)5 Collectors (java.util.stream.Collectors)4 Resource (javax.annotation.Resource)4 StringUtil (org.codelibs.core.lang.StringUtil)4 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)4 Constants (org.codelibs.fess.Constants)4 AccessTokenService (org.codelibs.fess.app.service.AccessTokenService)4 CrudMode (org.codelibs.fess.app.web.CrudMode)4 AdminAccesstokenAction.getAccessToken (org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction.getAccessToken)4 PermissionHelper (org.codelibs.fess.helper.PermissionHelper)4 ComponentUtil (org.codelibs.fess.util.ComponentUtil)4 List (java.util.List)3 AdminAccesstokenAction (org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction)3 ApiResult (org.codelibs.fess.app.web.api.ApiResult)3 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)3 ApiConfigsResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigsResponse)3 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)3 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)3