Search in sources :

Example 6 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminDictProtwordsAction method put$setting.

// PUT /api/admin/dict/protwords/setting/{dictId}
@Execute
public JsonResponse<ApiResult> put$setting(final String dictId, final CreateBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final ProtwordsItem entity = createProtwordsItem(body, () -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    });
    protwordsService.store(body.dictId, entity);
    return asJson(new ApiResult.ApiUpdateResponse().id(String.valueOf(entity.getId())).created(true).status(ApiResult.Status.OK).result());
}
Also used : AdminDictProtwordsAction.createProtwordsItem(org.codelibs.fess.app.web.admin.dict.protwords.AdminDictProtwordsAction.createProtwordsItem) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) ProtwordsPager(org.codelibs.fess.app.pager.ProtwordsPager) Resource(javax.annotation.Resource) UploadForm(org.codelibs.fess.app.web.admin.dict.protwords.UploadForm) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) File(java.io.File) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) ProtwordsItem(org.codelibs.fess.dict.protwords.ProtwordsItem) ProtwordsService(org.codelibs.fess.app.service.ProtwordsService) Execute(org.lastaflute.web.Execute) ProtwordsFile(org.codelibs.fess.dict.protwords.ProtwordsFile) InputStream(java.io.InputStream) ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminDictProtwordsAction.createProtwordsItem(org.codelibs.fess.app.web.admin.dict.protwords.AdminDictProtwordsAction.createProtwordsItem) ProtwordsItem(org.codelibs.fess.dict.protwords.ProtwordsItem) Execute(org.lastaflute.web.Execute)

Example 7 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminDictProtwordsAction method get$settings.

// GET /api/admin/dict/protwords/settings/{dictId}
@Execute
public JsonResponse<ApiResult> get$settings(final String dictId, final SearchBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    final ProtwordsPager pager = copyBeanToNewBean(body, ProtwordsPager.class);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(protwordsService.getProtwordsList(body.dictId, pager).stream().map(protwordsItem -> createEditBody(protwordsItem, dictId)).collect(Collectors.toList())).status(ApiResult.Status.OK).result());
}
Also used : AdminDictProtwordsAction.createProtwordsItem(org.codelibs.fess.app.web.admin.dict.protwords.AdminDictProtwordsAction.createProtwordsItem) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) ProtwordsPager(org.codelibs.fess.app.pager.ProtwordsPager) Resource(javax.annotation.Resource) UploadForm(org.codelibs.fess.app.web.admin.dict.protwords.UploadForm) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) File(java.io.File) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) ProtwordsItem(org.codelibs.fess.dict.protwords.ProtwordsItem) ProtwordsService(org.codelibs.fess.app.service.ProtwordsService) Execute(org.lastaflute.web.Execute) ProtwordsFile(org.codelibs.fess.dict.protwords.ProtwordsFile) InputStream(java.io.InputStream) ProtwordsPager(org.codelibs.fess.app.pager.ProtwordsPager) Execute(org.lastaflute.web.Execute)

Example 8 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminDictSeunjeonAction method post$setting.

// POST /api/admin/dict/seunjeon/setting/{dictId}
@Execute
public JsonResponse<ApiResult> post$setting(final String dictId, final EditBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final SeunjeonItem entity = new AdminDictSeunjeonAction().createSeunjeonItem(body, () -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, String.valueOf(body.id)));
        return null;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, String.valueOf(body.id)));
        return null;
    });
    seunjeonService.store(body.dictId, entity);
    return asJson(new ApiResult.ApiUpdateResponse().id(String.valueOf(entity.getId())).created(false).status(ApiResult.Status.OK).result());
}
Also used : SeunjeonItem(org.codelibs.fess.dict.seunjeon.SeunjeonItem) SeunjeonItem(org.codelibs.fess.dict.seunjeon.SeunjeonItem) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) SeunjeonService(org.codelibs.fess.app.service.SeunjeonService) Resource(javax.annotation.Resource) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) File(java.io.File) UploadForm(org.codelibs.fess.app.web.admin.dict.seunjeon.UploadForm) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) SeunjeonFile(org.codelibs.fess.dict.seunjeon.SeunjeonFile) AdminDictSeunjeonAction(org.codelibs.fess.app.web.admin.dict.seunjeon.AdminDictSeunjeonAction) Execute(org.lastaflute.web.Execute) InputStream(java.io.InputStream) SeunjeonPager(org.codelibs.fess.app.pager.SeunjeonPager) ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminDictSeunjeonAction(org.codelibs.fess.app.web.admin.dict.seunjeon.AdminDictSeunjeonAction) Execute(org.lastaflute.web.Execute)

Example 9 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminGroupAction method post$setting.

// POST /api/admin/group/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final Group entity = getGroup(body).orElseGet(() -> {
        throwValidationErrorApi(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
        });
        return null;
    });
    try {
        groupService.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 : GroupService(org.codelibs.fess.app.service.GroupService) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) JsonResponse(org.lastaflute.web.response.JsonResponse) User(org.codelibs.fess.es.user.exentity.User) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) GroupPager(org.codelibs.fess.app.pager.GroupPager) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) AdminGroupAction.getGroup(org.codelibs.fess.app.web.admin.group.AdminGroupAction.getGroup) Execute(org.lastaflute.web.Execute) Group(org.codelibs.fess.es.user.exentity.Group) AdminGroupAction.getGroup(org.codelibs.fess.app.web.admin.group.AdminGroupAction.getGroup) Group(org.codelibs.fess.es.user.exentity.Group) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Execute(org.lastaflute.web.Execute)

Example 10 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminGroupAction method delete$setting.

// DELETE /api/admin/group/setting/{id}
@Execute
public JsonResponse<ApiResult> delete$setting(final String id) {
    final Group entity = groupService.getGroup(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 {
        groupService.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 : GroupService(org.codelibs.fess.app.service.GroupService) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) JsonResponse(org.lastaflute.web.response.JsonResponse) User(org.codelibs.fess.es.user.exentity.User) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) GroupPager(org.codelibs.fess.app.pager.GroupPager) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) AdminGroupAction.getGroup(org.codelibs.fess.app.web.admin.group.AdminGroupAction.getGroup) Execute(org.lastaflute.web.Execute) Group(org.codelibs.fess.es.user.exentity.Group) AdminGroupAction.getGroup(org.codelibs.fess.app.web.admin.group.AdminGroupAction.getGroup) Group(org.codelibs.fess.es.user.exentity.Group) User(org.codelibs.fess.es.user.exentity.User) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Execute(org.lastaflute.web.Execute)

Aggregations

Resource (javax.annotation.Resource)65 ApiResult (org.codelibs.fess.app.web.api.ApiResult)65 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)65 Execute (org.lastaflute.web.Execute)65 JsonResponse (org.lastaflute.web.response.JsonResponse)65 CrudMode (org.codelibs.fess.app.web.CrudMode)63 Collectors (java.util.stream.Collectors)61 List (java.util.List)43 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)31 Status (org.codelibs.fess.app.web.api.ApiResult.Status)31 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)26 InputStream (java.io.InputStream)23 StreamResponse (org.lastaflute.web.response.StreamResponse)23 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)22 File (java.io.File)18 Constants (org.codelibs.fess.Constants)12 StringUtil (org.codelibs.core.lang.StringUtil)9 ComponentUtil (org.codelibs.fess.util.ComponentUtil)9 WebConfigService (org.codelibs.fess.app.service.WebConfigService)6 ApiErrorResponse (org.codelibs.fess.app.web.api.ApiResult.ApiErrorResponse)6