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());
}
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());
}
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;
}
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());
}
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;
});
}
Aggregations