use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminDictSynonymAction method post$upload.
// POST /api/admin/dict/synonym/upload/{dictId}
@Execute
public JsonResponse<ApiResult> post$upload(final String dictId, final UploadForm form) {
form.dictId = dictId;
validateApi(form, messages -> {
});
final SynonymFile file = synonymService.getSynonymFile(form.dictId).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL));
return null;
});
try (InputStream inputStream = form.synonymFile.getInputStream()) {
file.update(inputStream);
} catch (final Throwable e) {
e.printStackTrace();
throwValidationErrorApi(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL));
}
return asJson(new ApiResult.ApiResponse().status(ApiResult.Status.OK).result());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminDictSynonymAction method get$settings.
// GET /api/admin/dict/synonym/settings/{dictId}
@Execute
public JsonResponse<ApiResult> get$settings(final String dictId, final SearchBody body) {
body.dictId = dictId;
validateApi(body, messages -> {
});
final SynonymPager pager = copyBeanToNewBean(body, SynonymPager.class);
return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(synonymService.getSynonymList(body.dictId, pager).stream().map(protwordsItem -> createEditBody(protwordsItem, dictId)).collect(Collectors.toList())).status(ApiResult.Status.OK).result());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminDictSynonymAction method put$setting.
// PUT /api/admin/dict/synonym/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 SynonymItem entity = new AdminDictSynonymAction().createSynonymItem(body, () -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
return null;
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
return null;
});
synonymService.store(body.dictId, entity);
return asJson(new ApiResult.ApiUpdateResponse().id(String.valueOf(entity.getId())).created(true).status(ApiResult.Status.OK).result());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminBoostdocAction method post$setting.
// POST /api/admin/boostdoc/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.EDIT;
final BoostDocumentRule boostDoc = getBoostDocumentRule(body).map(entity -> {
try {
boostDocumentRuleService.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(boostDoc.getId()).created(false).status(Status.OK).result());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminCrawlinginfoAction method delete$all.
// DELETE /api/admin/crawlinginfo/all
@Execute
public JsonResponse<ApiResult> delete$all() {
try {
crawlingInfoService.deleteOldSessions(processHelper.getRunningSessionIdSet());
saveInfo(messages -> messages.addSuccessCrawlingInfoDeleteAll(GLOBAL));
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return asJson(new ApiResponse().status(Status.OK).result());
}
Aggregations