1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.app.service;
17
18 import java.util.List;
19
20 import javax.annotation.Resource;
21
22 import org.codelibs.core.beans.util.BeanUtil;
23 import org.codelibs.fess.Constants;
24 import org.codelibs.fess.app.pager.FileAuthPager;
25 import org.codelibs.fess.es.config.cbean.FileAuthenticationCB;
26 import org.codelibs.fess.es.config.exbhv.FileAuthenticationBhv;
27 import org.codelibs.fess.es.config.exentity.FileAuthentication;
28 import org.codelibs.fess.mylasta.direction.FessConfig;
29 import org.dbflute.cbean.result.PagingResultBean;
30 import org.dbflute.optional.OptionalEntity;
31
32 public class FileAuthenticationService {
33
34 @Resource
35 protected FileAuthenticationBhv fileAuthenticationBhv;
36
37 @Resource
38 protected FessConfig fessConfig;
39
40 public List<FileAuthentication> getFileAuthenticationList(final FileAuthPager fileAuthenticationPager) {
41
42 final PagingResultBean<FileAuthentication> fileAuthenticationList = fileAuthenticationBhv.selectPage(cb -> {
43 cb.paging(fileAuthenticationPager.getPageSize(), fileAuthenticationPager.getCurrentPageNumber());
44 setupListCondition(cb, fileAuthenticationPager);
45 });
46
47
48 BeanUtil.copyBeanToBean(fileAuthenticationList, fileAuthenticationPager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
49 fileAuthenticationPager.setPageNumberList(fileAuthenticationList.pageRange(op -> {
50 op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
51 }).createPageNumberList());
52
53 return fileAuthenticationList;
54 }
55
56 public OptionalEntity<FileAuthentication> getFileAuthentication(final String id) {
57 return fileAuthenticationBhv.selectByPK(id);
58 }
59
60 public void store(final FileAuthentication fileAuthentication) {
61
62 fileAuthenticationBhv.insertOrUpdate(fileAuthentication, op -> {
63 op.setRefreshPolicy(Constants.TRUE);
64 });
65
66 }
67
68 public void delete(final FileAuthentication fileAuthentication) {
69
70 fileAuthenticationBhv.delete(fileAuthentication, op -> {
71 op.setRefreshPolicy(Constants.TRUE);
72 });
73
74 }
75
76 protected void setupListCondition(final FileAuthenticationCB cb, final FileAuthPager fileAuthenticationPager) {
77 if (fileAuthenticationPager.id != null) {
78 cb.query().docMeta().setId_Equal(fileAuthenticationPager.id);
79 }
80
81
82
83 cb.query().addOrderBy_Hostname_Asc();
84
85
86
87 }
88
89 public List<FileAuthentication> getFileAuthenticationList(final String fileConfigId) {
90 return fileAuthenticationBhv.selectList(cb -> {
91 cb.query().setFileConfigId_Equal(fileConfigId);
92 cb.fetchFirst(fessConfig.getPageFileAuthMaxFetchSizeAsInteger());
93 });
94 }
95 }