1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.app.web.api.admin.joblog;
17
18 import java.util.List;
19 import java.util.stream.Collectors;
20
21 import javax.annotation.Resource;
22
23 import org.codelibs.fess.app.pager.JobLogPager;
24 import org.codelibs.fess.app.service.JobLogService;
25 import org.codelibs.fess.app.web.api.ApiResult;
26 import org.codelibs.fess.app.web.api.ApiResult.ApiLogResponse;
27 import org.codelibs.fess.app.web.api.ApiResult.ApiResponse;
28 import org.codelibs.fess.app.web.api.ApiResult.Status;
29 import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
30 import org.codelibs.fess.es.config.exentity.JobLog;
31 import org.lastaflute.web.Execute;
32 import org.lastaflute.web.response.JsonResponse;
33
34
35
36
37 public class ApiAdminJoblogAction extends FessApiAdminAction {
38
39
40
41
42 @Resource
43 private JobLogService jobLogService;
44
45
46
47
48
49
50 @Execute
51 public JsonResponse<ApiResult> logs(final SearchBody body) {
52 validateApi(body, messages -> {});
53 final JobLogPager pager = copyBeanToNewBean(body, JobLogPager.class);
54 final List<JobLog> list = jobLogService.getJobLogList(pager);
55 return asJson(new ApiResult.ApiLogsResponse<EditBody>().logs(list.stream().map(this::createEditBody).collect(Collectors.toList()))
56 .total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
57 }
58
59
60 @Execute
61 public JsonResponse<ApiResult> get$log(final String id) {
62 return asJson(new ApiLogResponse().log(jobLogService.getJobLog(id).map(this::createEditBody).orElseGet(() -> {
63 throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
64 return null;
65 })).status(Status.OK).result());
66 }
67
68
69 @Execute
70 public JsonResponse<ApiResult> delete$log(final String id) {
71 jobLogService.getJobLog(id).ifPresent(entity -> {
72 try {
73 jobLogService.delete(entity);
74 saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
75 } catch (final Exception e) {
76 throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
77 }
78 }).orElse(() -> {
79 throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
80 });
81 return asJson(new ApiResponse().status(Status.OK).result());
82 }
83
84 protected EditBody createEditBody(final JobLog entity) {
85 final EditBody body = new EditBody();
86 copyBeanToBean(entity, body, copyOp -> {
87 copyOp.excludeNull();
88 });
89 return body;
90 }
91 }