-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c7e3e3
commit baabbdf
Showing
9 changed files
with
229 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/org/support/project/knowledge/control/open/api/KnowledgeSearchControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.support.project.knowledge.control.open.api; | ||
|
||
import org.support.project.web.bean.Msg; | ||
import org.support.project.web.boundary.JsonBoundary; | ||
import org.support.project.web.control.ApiControl; | ||
import org.support.project.web.control.service.Get; | ||
|
||
/** | ||
* Knowledgeの一覧を取得するためのAPI | ||
*/ | ||
public class KnowledgeSearchControl extends ApiControl { | ||
|
||
@Get(path="open.api/knowledges", publishToken="") | ||
public JsonBoundary index() { | ||
return send(new Msg("aaa")); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/org/support/project/web/control/GetApiControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.support.project.web.control; | ||
|
||
import org.support.project.common.util.StringUtils; | ||
import org.support.project.web.bean.ApiParams; | ||
import org.support.project.web.boundary.Boundary; | ||
|
||
public abstract class GetApiControl extends ApiControl { | ||
|
||
public abstract Boundary getList(ApiParams params); | ||
public abstract Boundary getSingle(String id); | ||
public int maxLimit() { | ||
return 50; | ||
} | ||
|
||
protected ApiParams getApiParams() { | ||
// 一覧取得 | ||
int limit = 10; | ||
int offset = 0; | ||
String limitStr = getParam("limit"); | ||
if (StringUtils.isInteger(limitStr)) { | ||
limit = Integer.parseInt(limitStr); | ||
} | ||
if (limit > maxLimit()) { | ||
limit = maxLimit(); | ||
} | ||
String offsetStr = getParam("offset"); | ||
if (StringUtils.isInteger(offsetStr)) { | ||
offset = Integer.parseInt(offsetStr); | ||
} | ||
ApiParams params = new ApiParams(); | ||
params.setLimit(limit); | ||
params.setOffset(offset); | ||
return params; | ||
} | ||
|
||
/** | ||
* APIの基本的なGetのパターンを処理 | ||
* 上の getList or getSingle が呼び出される | ||
* @return | ||
*/ | ||
protected Boundary get() { | ||
String id = super.getPathString(""); | ||
if (StringUtils.isEmpty(id)) { | ||
ApiParams params = getApiParams(); | ||
return getList(params); | ||
} else { | ||
// 1件取得 | ||
return getSingle(id); | ||
} | ||
} | ||
} | ||
|
134 changes: 134 additions & 0 deletions
134
src/test/java/org/support/project/knowledge/searcher/SearchConditionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package org.support.project.knowledge.searcher; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.support.project.common.config.ConfigLoader; | ||
import org.support.project.common.log.Log; | ||
import org.support.project.common.log.LogFactory; | ||
import org.support.project.common.util.DateUtils; | ||
import org.support.project.common.util.FileUtil; | ||
import org.support.project.common.util.PropertyUtil; | ||
import org.support.project.common.util.RandomUtil; | ||
import org.support.project.di.Container; | ||
import org.support.project.knowledge.config.AppConfig; | ||
import org.support.project.knowledge.indexer.Indexer; | ||
import org.support.project.knowledge.indexer.IndexingValue; | ||
import org.support.project.knowledge.logic.TemplateLogic; | ||
|
||
import java.io.File; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class SearchConditionTest { | ||
/** ログ */ | ||
private static final Log LOG = LogFactory.getLog(SearchConditionTest.class); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
// テスト毎にインデックスを初期化する | ||
AppConfig appConfig = ConfigLoader.load(AppConfig.APP_CONFIG, AppConfig.class); | ||
File f = new File(appConfig.getIndexPath()); | ||
FileUtil.delete(f); | ||
LOG.info("インデックスを削除しました"); | ||
} | ||
|
||
/** | ||
* インデックスにアイテム追加 | ||
* @param title タイトル | ||
* @param contents コンテンツ | ||
* @param type 種類(記事、添付ファイル、コメントなど) | ||
* @param template テンプレート | ||
* @param creator 作成者 | ||
* @param updateDateTime 更新日時 | ||
* @param tagIds タグのID | ||
* @param viewUsers 閲覧可能ユーザ | ||
* @param viewGroups 閲覧可能グループ | ||
* @return 登録した情報のID | ||
*/ | ||
private String addItem(String title, String contents, int type, int template, int creator, Date updateDateTime, | ||
int[] tagIds, int[] viewUsers, int[] viewGroups) throws Exception { | ||
String id = String.valueOf(RandomUtil.randamNum(0, 999999)); | ||
IndexingValue indexingValue = new IndexingValue(); | ||
indexingValue.setType(type); | ||
indexingValue.setId(id); | ||
indexingValue.setTitle(title); | ||
indexingValue.setContents(contents); | ||
indexingValue.setTemplate(template); | ||
indexingValue.setCreator(creator); | ||
indexingValue.setTime(updateDateTime.getTime()); | ||
|
||
if (tagIds != null) { | ||
for (int tagId : tagIds) { | ||
indexingValue.addTag(tagId); | ||
} | ||
} | ||
if (viewUsers != null) { | ||
for (int user : viewUsers) { | ||
indexingValue.addUser(user); | ||
} | ||
} | ||
if (viewGroups != null) { | ||
for (int group : viewGroups) { | ||
indexingValue.addGroup(group); | ||
} | ||
} | ||
Indexer indexer = Container.getComp(Indexer.class); | ||
indexer.writeIndex(indexingValue); | ||
return id; | ||
} | ||
|
||
@Test | ||
public void testTemplateFilter() throws Exception { | ||
String id1 = addItem("title:testTemplateFilter", "contents:testTemplateFilter", 0, TemplateLogic.TYPE_ID_KNOWLEDGE, | ||
100, DateUtils.now(), null, null, null); | ||
String id2 = addItem("title:testTemplateFilter", "contents:testTemplateFilter", 0, TemplateLogic.TYPE_ID_EVENT, | ||
100, DateUtils.now(), null, null, null); | ||
String id3 = addItem("title:testTemplateFilter", "contents:testTemplateFilter", 0, TemplateLogic.TYPE_ID_BOOKMARK, | ||
100, DateUtils.now(), null, null, null); | ||
|
||
Searcher searcher = Container.getComp(Searcher.class); | ||
|
||
SearchingValue searchingValue = new SearchingValue(); | ||
searchingValue.addTemplate(TemplateLogic.TYPE_ID_KNOWLEDGE); | ||
List<SearchResultValue> results = searcher.search(searchingValue, 1); | ||
for (SearchResultValue searchResultValue : results) { | ||
LOG.info(PropertyUtil.reflectionToString(searchResultValue)); | ||
} | ||
assertEquals(1, results.size()); | ||
SearchResultValue result = results.get(0); | ||
assertEquals(id1, result.getId()); | ||
|
||
searchingValue.addTemplate(TemplateLogic.TYPE_ID_EVENT); | ||
results = searcher.search(searchingValue, 1); | ||
for (SearchResultValue searchResultValue : results) { | ||
LOG.info(PropertyUtil.reflectionToString(searchResultValue)); | ||
} | ||
assertEquals(2, results.size()); | ||
} | ||
|
||
@Test | ||
public void testSearchCreator() throws Exception { | ||
String id1 = addItem("title:testTemplateFilter", "contents:testTemplateFilter", 0, TemplateLogic.TYPE_ID_KNOWLEDGE, | ||
100, DateUtils.now(), null, null, null); | ||
String id2 = addItem("title:testTemplateFilter", "contents:testTemplateFilter", 0, TemplateLogic.TYPE_ID_EVENT, | ||
101, DateUtils.now(), null, null, null); | ||
String id3 = addItem("title:testTemplateFilter", "contents:testTemplateFilter", 0, TemplateLogic.TYPE_ID_BOOKMARK, | ||
102, DateUtils.now(), null, null, null); | ||
|
||
Searcher searcher = Container.getComp(Searcher.class); | ||
|
||
SearchingValue searchingValue = new SearchingValue(); | ||
searchingValue.setCreator(100); | ||
List<SearchResultValue> results = searcher.search(searchingValue, 1); | ||
for (SearchResultValue searchResultValue : results) { | ||
LOG.info(PropertyUtil.reflectionToString(searchResultValue)); | ||
} | ||
assertEquals(1, results.size()); | ||
SearchResultValue result = results.get(0); | ||
assertEquals(id1, result.getId()); | ||
|
||
} | ||
|
||
} |