1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.app.web.api.admin.crawlinginfo;
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.CrawlingInfoPager;
24 import org.codelibs.fess.app.service.CrawlingInfoService;
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.CrawlingInfo;
31 import org.codelibs.fess.helper.ProcessHelper;
32 import org.lastaflute.web.Execute;
33 import org.lastaflute.web.response.JsonResponse;
34
35
36
37
38 public class ApiAdminCrawlinginfoAction extends FessApiAdminAction {
39
40
41
42
43 @Resource
44 private CrawlingInfoService crawlingInfoService;
45 @Resource
46 protected ProcessHelper processHelper;
47
48
49
50
51
52
53
54 @Execute
55 public JsonResponse<ApiResult> logs(final SearchBody body) {
56 validateApi(body, messages -> {});
57 final CrawlingInfoPager pager = copyBeanToNewBean(body, CrawlingInfoPager.class);
58 final List<CrawlingInfo> list = crawlingInfoService.getCrawlingInfoList(pager);
59 return asJson(new ApiResult.ApiLogsResponse<EditBody>()
60 .logs(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount())
61 .status(ApiResult.Status.OK).result());
62 }
63
64
65 @Execute
66 public JsonResponse<ApiResult> get$log(final String id) {
67 return asJson(new ApiLogResponse()
68 .log(crawlingInfoService.getCrawlingInfo(id).map(entity -> createEditBody(entity)).orElseGet(() -> {
69 throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
70 return null;
71 })).status(Status.OK).result());
72 }
73
74
75 @Execute
76 public JsonResponse<ApiResult> delete$log(final String id) {
77 crawlingInfoService.getCrawlingInfo(id).ifPresent(entity -> {
78 try {
79 crawlingInfoService.delete(entity);
80 saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
81 } catch (final Exception e) {
82 throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
83 }
84 }).orElse(() -> {
85 throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
86 });
87 return asJson(new ApiResponse().status(Status.OK).result());
88 }
89
90
91 @Execute
92 public JsonResponse<ApiResult> delete$all() {
93 try {
94 crawlingInfoService.deleteOldSessions(processHelper.getRunningSessionIdSet());
95 saveInfo(messages -> messages.addSuccessCrawlingInfoDeleteAll(GLOBAL));
96 } catch (final Exception e) {
97 throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
98 }
99 return asJson(new ApiResponse().status(Status.OK).result());
100 }
101
102 protected EditBody createEditBody(final CrawlingInfo entity) {
103 final EditBody body = new EditBody();
104 copyBeanToBean(entity, body, copyOp -> {
105 copyOp.excludeNull();
106 });
107 return body;
108 }
109 }