This is a cache of https://fess.codelibs.org/xref/org/codelibs/fess/app/service/GroupService.html. It is a snapshot of the page at 2020-10-25T01:24:10.587+0000.
<strong>g</strong>roupService xref
View Javadoc
1   /*
2    * Copyright 2012-2020 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.app.service;
17  
18  import static org.codelibs.core.stream.StreamUtil.stream;
19  
20  import java.util.List;
21  
22  import javax.annotation.Resource;
23  
24  import org.codelibs.core.beans.util.BeanUtil;
25  import org.codelibs.fess.Constants;
26  import org.codelibs.fess.app.pager.groupPager;
27  import org.codelibs.fess.es.user.cbean.groupCB;
28  import org.codelibs.fess.es.user.exbhv.groupBhv;
29  import org.codelibs.fess.es.user.exbhv.UserBhv;
30  import org.codelibs.fess.es.user.exentity.group;
31  import org.codelibs.fess.mylasta.direction.FessConfig;
32  import org.codelibs.fess.util.ComponentUtil;
33  import org.dbflute.cbean.result.PagingResultBean;
34  import org.dbflute.optional.OptionalEntity;
35  
36  public class groupService {
37  
38      @Resource
39      protected groupBhv groupBhv;
40  
41      @Resource
42      protected FessConfig fessConfig;
43  
44      @Resource
45      protected UserBhv userBhv;
46  
47      public List<group&gt; getgroupList(final groupPager groupPager) {
48  
49          final PagingResultBean<group&gt; groupList = groupBhv.selectPage(cb -&gt; {
50              cb.paging(groupPager.getPageSize(), groupPager.getCurrentPageNumber());
51              setupListCondition(cb, groupPager);
52          });
53  
54          // update pager
55          BeanUtil.copyBeanToBean(groupList, groupPager, option -&gt; option.include(Constants.PAgER_CONVERSION_RULE));
56          groupPager.setPageNumberList(groupList.pageRange(op -&gt; {
57              op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
58          }).createPageNumberList());
59  
60          return groupList;
61      }
62  
63      public OptionalEntity<group&gt; getgroup(final String id) {
64          return groupBhv.selectByPK(id).map(g -&gt; {
65              ComponentUtil.getLdapManager().apply(g);
66              return g;
67          });
68      }
69  
70      public void store(final group group) {
71          ComponentUtil.getLdapManager().insert(group);
72  
73          groupBhv.insertOrUpdate(group, op -&gt; {
74              op.setRefreshPolicy(Constants.TRUE);
75          });
76  
77      }
78  
79      public void delete(final group group) {
80          ComponentUtil.getLdapManager().delete(group);
81  
82          groupBhv.delete(group, op -&gt; {
83              op.setRefreshPolicy(Constants.TRUE);
84          });
85  
86          userBhv.selectCursor(
87                  cb -&gt; cb.query().setgroups_Equal(group.getId()),
88                  entity -&gt; {
89                      entity.setgroups(stream(entity.getgroups()).get(
90                              stream -&gt; stream.filter(s -&gt; !s.equals(group.getId())).toArray(n -&gt; new String[n])));
91                      userBhv.insertOrUpdate(entity);
92                  });
93  
94      }
95  
96      protected void setupListCondition(final groupCB cb, final groupPager groupPager) {
97          if (groupPager.id != null) {
98              cb.query().docMeta().setId_Equal(groupPager.id);
99          }
100         // TODO Long, Integer, String supported only.
101 
102         // setup condition
103         cb.query().addOrderBy_Name_Asc();
104 
105         // search
106 
107     }
108 
109     public List<group&gt; getAvailablegroupList() {
110         return groupBhv.selectList(cb -&gt; {
111             cb.query().matchAll();
112             cb.query().addOrderBy_Name_Asc();
113             cb.paging(fessConfig.getPagegroupMaxFetchSizeAsInteger(), 1);
114         });
115     }
116 
117 }