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>()
56 .logs(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount())
57 .status(ApiResult.Status.OK).result());
58 }
59
60
61 @Execute
62 public JsonResponse<ApiResult> get$log(final String id) {
63 return asJson(new ApiLogResponse().log(jobLogService.getJobLog(id).map(entity -> createEditBody(entity)).orElseGet(() -> {
64 throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
65 return null;
66 })).status(Status.OK).result());
67 }
68
69
70 @Execute
71 public JsonResponse<ApiResult> delete$log(final String id) {
72 jobLogService.getJobLog(id).ifPresent(entity -> {
73 try {
74 jobLogService.delete(entity);
75 saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
76 } catch (final Exception e) {
77 throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
78 }
79 }).orElse(() -> {
80 throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
81 });
82 return asJson(new ApiResponse().status(Status.OK).result());
83 }
84
85 protected EditBody createEditBody(final JobLog entity) {
86 final EditBody body = new EditBody();
87 copyBeanToBean(entity, body, copyOp -> {
88 copyOp.excludeNull();
89 });
90 return body;
91 }
92 }