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.Collections;
19 import java.util.List;
20
21 import org.codelibs.core.beans.util.BeanUtil;
22 import org.codelibs.fess.Constants;
23 import org.codelibs.fess.app.pager.KuromojiPager;
24 import org.codelibs.fess.dict.DictionaryFile.PagingList;
25 import org.codelibs.fess.dict.DictionaryManager;
26 import org.codelibs.fess.dict.kuromoji.KuromojiFile;
27 import org.codelibs.fess.dict.kuromoji.KuromojiItem;
28 import org.codelibs.fess.mylasta.direction.FessConfig;
29 import org.dbflute.optional.OptionalEntity;
30
31 import jakarta.annotation.Resource;
32
33
34
35
36 public class KuromojiService {
37
38 @Resource
39 protected DictionaryManager dictionaryManager;
40
41
42 @Resource
43 protected FessConfig fessConfig;
44
45
46
47
48 public KuromojiService() {
49
50 }
51
52
53
54
55
56
57
58
59 public List<KuromojiItem> getKuromojiList(final String dictId, final KuromojiPager kuromojiPager) {
60 return getKuromojiFile(dictId).map(file -> {
61 final int pageSize = kuromojiPager.getPageSize();
62 final PagingList<KuromojiItem> kuromojiList = file.selectList((kuromojiPager.getCurrentPageNumber() - 1) * pageSize, pageSize);
63
64
65 BeanUtil.copyBeanToBean(kuromojiList, kuromojiPager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
66 kuromojiList.setPageRangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
67 kuromojiPager.setPageNumberList(kuromojiList.createPageNumberList());
68
69 return (List<KuromojiItem>) kuromojiList;
70 }).orElse(Collections.emptyList());
71 }
72
73
74
75
76
77
78
79 public OptionalEntity<KuromojiFile> getKuromojiFile(final String dictId) {
80 return dictionaryManager.getDictionaryFile(dictId)
81 .filter(KuromojiFile.class::isInstance)
82 .map(file -> OptionalEntity.of((KuromojiFile) file))
83 .orElse(OptionalEntity.empty());
84 }
85
86
87
88
89
90
91
92
93 public OptionalEntity<KuromojiItem> getKuromojiItem(final String dictId, final long id) {
94 return getKuromojiFile(dictId).map(file -> file.get(id).get());
95 }
96
97
98
99
100
101
102
103 public void store(final String dictId, final KuromojiItem kuromojiItem) {
104 getKuromojiFile(dictId).ifPresent(file -> {
105 if (kuromojiItem.getId() == 0) {
106 file.insert(kuromojiItem);
107 } else {
108 file.update(kuromojiItem);
109 }
110 });
111 }
112
113
114
115
116
117
118
119 public void delete(final String dictId, final KuromojiItem kuromojiItem) {
120 getKuromojiFile(dictId).ifPresent(file -> {
121 file.delete(kuromojiItem);
122 });
123 }
124 }