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>().logs(list.stream().map(this::createEditBody).collect(Collectors.toList()))
60 .total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
61 }
62
63
64 @Execute
65 public JsonResponse<ApiResult> get$log(final String id) {
66 return asJson(new ApiLogResponse().log(crawlingInfoService.getCrawlingInfo(id).map(this::createEditBody).orElseGet(() -> {
67 throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
68 return null;
69 })).status(Status.OK).result());
70 }
71
72
73 @Execute
74 public JsonResponse<ApiResult> delete$log(final String id) {
75 crawlingInfoService.getCrawlingInfo(id).ifPresent(entity -> {
76 try {
77 crawlingInfoService.delete(entity);
78 saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
79 } catch (final Exception e) {
80 throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
81 }
82 }).orElse(() -> {
83 throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
84 });
85 return asJson(new ApiResponse().status(Status.OK).result());
86 }
87
88
89 @Execute
90 public JsonResponse<ApiResult> delete$all() {
91 try {
92 crawlingInfoService.deleteOldSessions(processHelper.getRunningSessionIdSet());
93 saveInfo(messages -> messages.addSuccessCrawlingInfoDeleteAll(GLOBAL));
94 } catch (final Exception e) {
95 throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
96 }
97 return asJson(new ApiResponse().status(Status.OK).result());
98 }
99
100 protected EditBody createEditBody(final CrawlingInfo entity) {
101 final EditBody body = new EditBody();
102 copyBeanToBean(entity, body, copyOp -> {
103 copyOp.excludeNull();
104 });
105 return body;
106 }
107 }