Search in sources :

Example 46 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ProfileAction method changePassword.

@Execute
public HtmlResponse changePassword(final ProfileForm form) {
    final VaErrorHook toIndexPage = () -> {
        form.clearSecurityInfo();
        return asIndexHtml();
    };
    validatePasswordForm(form, toIndexPage);
    final String username = getUserBean().map(u -> u.getUserId()).get();
    try {
        userService.changePassword(username, form.newPassword);
        saveInfo(messages -> messages.addSuccessChangedPassword(GLOBAL));
    } catch (final Exception e) {
        logger.error("Failed to change password for " + username, e);
        throwValidationError(messages -> messages.addErrorsFailedToChangePassword(GLOBAL), toIndexPage);
    }
    return redirect(getClass());
}
Also used : FessSearchAction(org.codelibs.fess.app.web.base.FessSearchAction) Logger(org.slf4j.Logger) UserPasswordCredential(org.lastaflute.web.login.credential.UserPasswordCredential) Resource(javax.annotation.Resource) Execute(org.lastaflute.web.Execute) LoggerFactory(org.slf4j.LoggerFactory) VaErrorHook(org.lastaflute.web.validation.VaErrorHook) UserService(org.codelibs.fess.app.service.UserService) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LoginAction(org.codelibs.fess.app.web.login.LoginAction) VaErrorHook(org.lastaflute.web.validation.VaErrorHook) Execute(org.lastaflute.web.Execute)

Example 47 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminUserAction method delete$setting.

// DELETE /api/admin/user/setting/{id}
@Execute
public JsonResponse<ApiResult> delete$setting(final String id) {
    final User entity = userService.getUser(id).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
        return null;
    });
    getUserBean().ifPresent(u -> {
        if (u.getFessUser() instanceof User && entity.getName().equals(u.getUserId())) {
            throwValidationErrorApi(messages -> messages.addErrorsCouldNotDeleteLoggedInUser(GLOBAL));
        }
    });
    try {
        userService.delete(entity);
        saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
    }
    return asJson(new ApiResult.ApiUpdateResponse().id(id).created(false).status(ApiResult.Status.OK).result());
}
Also used : List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) UserPager(org.codelibs.fess.app.pager.UserPager) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) Execute(org.lastaflute.web.Execute) JsonResponse(org.lastaflute.web.response.JsonResponse) AdminUserAction.getUser(org.codelibs.fess.app.web.admin.user.AdminUserAction.getUser) UserService(org.codelibs.fess.app.service.UserService) User(org.codelibs.fess.es.user.exentity.User) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminUserAction.getUser(org.codelibs.fess.app.web.admin.user.AdminUserAction.getUser) User(org.codelibs.fess.es.user.exentity.User) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Execute(org.lastaflute.web.Execute)

Example 48 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminUserAction method settings.

// GET /api/admin/user
// POST /api/admin/user
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final UserPager pager = copyBeanToNewBean(body, UserPager.class);
    final List<User> list = userService.getUserList(pager);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Also used : AdminUserAction.getUser(org.codelibs.fess.app.web.admin.user.AdminUserAction.getUser) User(org.codelibs.fess.es.user.exentity.User) ApiResult(org.codelibs.fess.app.web.api.ApiResult) UserPager(org.codelibs.fess.app.pager.UserPager) Execute(org.lastaflute.web.Execute)

Example 49 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminUserAction method post$setting.

// POST /api/admin/user/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final User entity = getUser(body).orElseGet(() -> {
        throwValidationErrorApi(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
        });
        return null;
    });
    try {
        userService.store(entity);
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
    }
    return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(false).status(ApiResult.Status.OK).result());
}
Also used : List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) UserPager(org.codelibs.fess.app.pager.UserPager) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) Execute(org.lastaflute.web.Execute) JsonResponse(org.lastaflute.web.response.JsonResponse) AdminUserAction.getUser(org.codelibs.fess.app.web.admin.user.AdminUserAction.getUser) UserService(org.codelibs.fess.app.service.UserService) User(org.codelibs.fess.es.user.exentity.User) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminUserAction.getUser(org.codelibs.fess.app.web.admin.user.AdminUserAction.getUser) User(org.codelibs.fess.es.user.exentity.User) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Execute(org.lastaflute.web.Execute)

Example 50 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminUserAction method put$setting.

// PUT /api/admin/user/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final User entity = getUser(body).orElseGet(() -> {
        throwValidationErrorApi(messages -> {
            messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
        });
        return null;
    });
    try {
        userService.store(entity);
        saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
    }
    return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(true).status(ApiResult.Status.OK).result());
}
Also used : List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) UserPager(org.codelibs.fess.app.pager.UserPager) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) Execute(org.lastaflute.web.Execute) JsonResponse(org.lastaflute.web.response.JsonResponse) AdminUserAction.getUser(org.codelibs.fess.app.web.admin.user.AdminUserAction.getUser) UserService(org.codelibs.fess.app.service.UserService) User(org.codelibs.fess.es.user.exentity.User) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminUserAction.getUser(org.codelibs.fess.app.web.admin.user.AdminUserAction.getUser) User(org.codelibs.fess.es.user.exentity.User) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Execute(org.lastaflute.web.Execute)

Aggregations

Execute (org.lastaflute.web.Execute)125 ApiResult (org.codelibs.fess.app.web.api.ApiResult)94 Resource (javax.annotation.Resource)83 CrudMode (org.codelibs.fess.app.web.CrudMode)77 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)71 JsonResponse (org.lastaflute.web.response.JsonResponse)71 Collectors (java.util.stream.Collectors)70 List (java.util.List)51 InputStream (java.io.InputStream)39 File (java.io.File)35 StreamResponse (org.lastaflute.web.response.StreamResponse)34 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)32 Status (org.codelibs.fess.app.web.api.ApiResult.Status)31 Constants (org.codelibs.fess.Constants)26 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)26 StringUtil (org.codelibs.core.lang.StringUtil)24 ComponentUtil (org.codelibs.fess.util.ComponentUtil)23 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)22 HtmlResponse (org.lastaflute.web.response.HtmlResponse)20 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)14