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.WebAuthPager;
25 import org.codelibs.fess.es.config.cbean.WebAuthenticationCB;
26 import org.codelibs.fess.es.config.exbhv.WebAuthenticationBhv;
27 import org.codelibs.fess.es.config.exentity.WebAuthentication;
28 import org.codelibs.fess.mylasta.direction.FessConfig;
29 import org.codelibs.fess.util.ParameterUtil;
30 import org.dbflute.cbean.result.PagingResultBean;
31 import org.dbflute.optional.OptionalEntity;
32
33 public class WebAuthenticationService {
34
35 @Resource
36 protected WebAuthenticationBhv webAuthenticationBhv;
37
38 @Resource
39 protected FessConfig fessConfig;
40
41 public List<WebAuthentication> getWebAuthenticationList(final WebAuthPager webAuthenticationPager) {
42
43 final PagingResultBean<WebAuthentication> webAuthenticationList = webAuthenticationBhv.selectPage(cb -> {
44 cb.paging(webAuthenticationPager.getPageSize(), webAuthenticationPager.getCurrentPageNumber());
45 setupListCondition(cb, webAuthenticationPager);
46 });
47
48
49 BeanUtil.copyBeanToBean(webAuthenticationList, webAuthenticationPager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
50 webAuthenticationPager.setPageNumberList(webAuthenticationList.pageRange(op -> {
51 op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
52 }).createPageNumberList());
53
54 return webAuthenticationList;
55 }
56
57 public OptionalEntity<WebAuthentication> getWebAuthentication(final String id) {
58 return webAuthenticationBhv.selectByPK(id);
59 }
60
61 public void store(final WebAuthentication webAuthentication) {
62 webAuthentication.setParameters(ParameterUtil.encrypt(webAuthentication.getParameters()));
63 webAuthenticationBhv.insertOrUpdate(webAuthentication, op -> {
64 op.setRefreshPolicy(Constants.TRUE);
65 });
66
67 }
68
69 public void delete(final WebAuthentication webAuthentication) {
70
71 webAuthenticationBhv.delete(webAuthentication, op -> {
72 op.setRefreshPolicy(Constants.TRUE);
73 });
74
75 }
76
77 protected void setupListCondition(final WebAuthenticationCB cb, final WebAuthPager webAuthenticationPager) {
78 if (webAuthenticationPager.id != null) {
79 cb.query().docMeta().setId_Equal(webAuthenticationPager.id);
80 }
81
82
83 cb.query().addOrderBy_Hostname_Asc();
84 cb.query().addOrderBy_WebConfigId_Asc();
85
86
87
88 }
89
90 public List<WebAuthentication> getWebAuthenticationList(final String webConfigId) {
91 return webAuthenticationBhv.selectList(cb -> {
92 cb.query().setWebConfigId_Equal(webConfigId);
93 cb.fetchFirst(fessConfig.getPageWebAuthMaxFetchSizeAsInteger());
94 });
95 }
96
97 }