use of org.lastaflute.web.Execute 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.lastaflute.web.Execute in project fess by codelibs.
the class ApiAdminDictProtwordsAction method post$upload.
// POST /api/admin/dict/protwords/upload/{dictId}
@Execute
public JsonResponse<ApiResult> post$upload(final String dictId, final UploadForm form) {
form.dictId = dictId;
validateApi(form, messages -> {
});
final ProtwordsFile file = protwordsService.getProtwordsFile(form.dictId).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL));
return null;
});
try (InputStream inputStream = form.protwordsFile.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.Execute in project fess by codelibs.
the class ApiAdminDictProtwordsAction method post$setting.
// POST /api/admin/dict/protwords/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 ProtwordsItem entity = createProtwordsItem(body, () -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, String.valueOf(body.id)));
return null;
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, String.valueOf(body.id)));
return null;
});
protwordsService.store(body.dictId, entity);
return asJson(new ApiResult.ApiUpdateResponse().id(String.valueOf(entity.getId())).created(false).status(ApiResult.Status.OK).result());
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class ApiAdminDictSeunjeonAction method post$upload.
// POST /api/admin/dict/seunjeon/upload/{dictId}
@Execute
public JsonResponse<ApiResult> post$upload(final String dictId, final UploadForm form) {
form.dictId = dictId;
validateApi(form, messages -> {
});
final SeunjeonFile file = seunjeonService.getSeunjeonFile(form.dictId).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL));
return null;
});
try (InputStream inputStream = form.seunjeonFile.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.Execute in project fess by codelibs.
the class ApiAdminDictSeunjeonAction method get$download.
// GET /api/admin/dict/seunjeon/download/{dictId}
@Execute
public StreamResponse get$download(final String dictId, final DownloadBody body) {
body.dictId = dictId;
validateApi(body, messages -> {
});
return seunjeonService.getSeunjeonFile(body.dictId).map(file -> {
return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
try (InputStream inputStream = file.getInputStream()) {
out.write(inputStream);
}
});
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL));
return null;
});
}
Aggregations