diff --git a/document/database/knowledge.a5er b/document/database/knowledge.a5er index 844845d27..9f2b80fc1 100755 --- a/document/database/knowledge.a5er +++ b/document/database/knowledge.a5er @@ -97,14 +97,14 @@ Fields1=KNOWLEDGE_ID Fields2=KNOWLEDGE_ID Cardinarity1= Cardinarity2= -Position="MAIN",0,7735,2265,7597,R,R +Position="MAIN",0,4383,2265,7690,R,R Dependence=0 Caption= PName= LineMode=0 -Bar1=774 +Bar1=438 Bar2=226 -Bar3=760 +Bar3=769 TermPos1=R TermPos2=R @@ -115,7 +115,7 @@ Comment= TableOption= Page=MAIN Left=100 -Top=1300 +Top=1350 Field="NO","NO","bigint","NOT NULL",0,"","",$FFFFFFFF,"AUTO_INCREMENT" Field="ナレッジID","KNOWLEDGE_ID","bigint","NOT NULL",,"","",$FFFFFFFF,"" Index=IDX_LIKES_KNOWLEDGE_ID=0,KNOWLEDGE_ID @@ -123,7 +123,7 @@ EffectMode=None Color=$000000 BkColor=$FFFFFF ModifiedDateTime=20150102013522 -Position="MAIN",100,1300 +Position="MAIN",100,1350 [Relation] Entity1=KNOWLEDGES @@ -152,7 +152,7 @@ LName=コメント Comment= TableOption= Page=MAIN -Left=1300 +Left=1500 Top=1550 Field="コメント番号","COMMENT_NO","bigint","NOT NULL",0,"","",$FFFFFFFF,"AUTO_INCREMENT" Field="ナレッジID","KNOWLEDGE_ID","bigint","NOT NULL",,"","",$FFFFFFFF,"" @@ -162,7 +162,7 @@ EffectMode=None Color=$000000 BkColor=$FFFFFF ModifiedDateTime=20150102013923 -Position="MAIN",1300,1550 +Position="MAIN",1500,1550 [Relation] Entity1=KNOWLEDGES @@ -173,14 +173,14 @@ Fields1=KNOWLEDGE_ID Fields2=KNOWLEDGE_ID Cardinarity1= Cardinarity2= -Position="MAIN",0,7100,4465,3310,R,R +Position="MAIN",0,7100,4465,3064,R,R Dependence=0 Caption= PName= LineMode=0 Bar1=710 Bar2=446 -Bar3=331 +Bar3=306 TermPos1=R TermPos2=R @@ -190,7 +190,7 @@ LName=投票 Comment= TableOption= Page=MAIN -Left=1250 +Left=1500 Top=1400 Field="VOTE_NO","VOTE_NO","bigint","NOT NULL",0,"","",$FFFFFFFF,"AUTO_INCREMENT" Field="ナレッジID","KNOWLEDGE_ID","bigint","NOT NULL",,"","",$FFFFFFFF,"" @@ -200,7 +200,7 @@ EffectMode=None Color=$000000 BkColor=$FFFFFF ModifiedDateTime=20150102013835 -Position="MAIN",1250,1400,435,89 +Position="MAIN",1500,1400,435,89 [Relation] Entity1=KNOWLEDGES @@ -229,7 +229,7 @@ LName=ナレッジの参照履歴 Comment= TableOption= Page=MAIN -Left=1150 +Left=1500 Top=850 Field="HISTORY_NO","HISTORY_NO","bigint","NOT NULL",0,"","",$FFFFFFFF,"AUTO_INCREMENT" Field="ナレッジID","KNOWLEDGE_ID","bigint","NOT NULL",,"","",$FFFFFFFF,"" @@ -239,7 +239,7 @@ EffectMode=None Color=$000000 BkColor=$FFFFFF ModifiedDateTime=20150102013703 -Position="MAIN",1150,850 +Position="MAIN",1500,850 [Relation] Entity1=KNOWLEDGES @@ -267,7 +267,7 @@ LName=ストックしたナレッジ Comment= TableOption= Page=MAIN -Left=1200 +Left=1500 Top=1250 Field="USER_ID","USER_ID","@INT","NOT NULL",0,"","",$FFFFFFFF,"" Field="ナレッジID","KNOWLEDGE_ID","bigint","NOT NULL",1,"","",$FFFFFFFF,"" @@ -276,7 +276,7 @@ EffectMode=None Color=$000000 BkColor=$FFFFFF ModifiedDateTime=20141222154849 -Position="MAIN",1200,1250 +Position="MAIN",1500,1250 [Relation] Entity1=KNOWLEDGES @@ -304,7 +304,7 @@ LName=アクセス可能なグループ Comment= TableOption= Page=MAIN -Left=1200 +Left=1500 Top=1100 Field="ナレッジID","KNOWLEDGE_ID","bigint","NOT NULL",0,"","",$FFFFFFFF,"" Field="GROUP_ID","GROUP_ID","@INT","NOT NULL",1,"","",$FFFFFFFF,"" @@ -312,7 +312,7 @@ EffectMode=None Color=$000000 BkColor=$FFFFFF ModifiedDateTime=20141222154841 -Position="MAIN",1200,1100 +Position="MAIN",1500,1100 [Relation] Entity1=KNOWLEDGES @@ -341,7 +341,7 @@ LName=アクセス可能なユーザ Comment= TableOption= Page=MAIN -Left=1200 +Left=1500 Top=1000 Field="ナレッジID","KNOWLEDGE_ID","bigint","NOT NULL",0,"","",$FFFFFFFF,"" Field="USER_ID","USER_ID","@INT","NOT NULL",1,"","",$FFFFFFFF,"" @@ -349,7 +349,7 @@ EffectMode=None Color=$000000 BkColor=$FFFFFF ModifiedDateTime=20141222154833 -Position="MAIN",1200,1000 +Position="MAIN",1500,1000 [Relation] Entity1=TAGS @@ -380,14 +380,14 @@ Fields1=KNOWLEDGE_ID Fields2=KNOWLEDGE_ID Cardinarity1= Cardinarity2= -Position="MAIN",0,4572,7878,5351,R,R +Position="MAIN",0,4572,7878,5786,R,R Dependence=1 Caption= PName= LineMode=0 Bar1=457 Bar2=788 -Bar3=535 +Bar3=579 TermPos1=R TermPos2=R @@ -432,15 +432,15 @@ Fields1=KNOWLEDGE_ID Fields2=KNOWLEDGE_ID Cardinarity1= Cardinarity2= -Position="MAIN",0,4961,5662,4736,R,R +Position="MAIN",0,4744,5662,4756,R,R Dependence=1 Caption= PName= ModifiedDateTime=20141222154815 LineMode=0 -Bar1=496 +Bar1=474 Bar2=566 -Bar3=474 +Bar3=476 TermPos1=R TermPos2=R @@ -451,7 +451,7 @@ Comment= TableOption= Page=MAIN Left=600 -Top=1600 +Top=1650 Field="添付ファイル番号","FILE_NO","bigint","NOT NULL",0,"","",$FFFFFFFF,"AUTO_INCREMENT" Field="ナレッジID","KNOWLEDGE_ID","bigint",,,"","",$FFFFFFFF,"" Field="ファイル名","FILE_NAME","@VARCHAR(256)",,,"","",$FFFFFFFF,"" @@ -463,7 +463,7 @@ EffectMode=None Color=$000000 BkColor=$FFFFFF ModifiedDateTime=20150102013438 -Position="MAIN",600,1600 +Position="MAIN",600,1650 [Entity] PName=KNOWLEDGES @@ -471,17 +471,21 @@ LName=ナレッジ Comment= TableOption= Page=MAIN -Left=600 +Left=650 Top=1300 Field="ナレッジID","KNOWLEDGE_ID","bigint","NOT NULL",0,"","",$FFFFFFFF,"AUTO_INCREMENT" Field="タイトル","TITLE","@VARCHAR(1024)","NOT NULL",,"","",$FFFFFFFF,"" Field="内容","CONTENT","text",,,"","",$FFFFFFFF,"" Field="公開区分","PUBLIC_FLAG","@INT",,,"","",$FFFFFFFF,"" +Field="タグID一覧","TAG_IDS","@VARCHAR(1024)",,,"","",$FFFFFFFF,"" +Field="タグ名称一覧","TAG_NAMES","text",,,"","",$FFFFFFFF,"" +Field="いいね件数","LIKE_COUNT","bigint",,,"","",$FFFFFFFF,"" +Field="コメント件数","COMMENT_COUNT","@INT",,,"","",$FFFFFFFF,"" EffectMode=None Color=$000000 BkColor=$FFFFFF -ModifiedDateTime=20150102012615 -Position="MAIN",600,1300 +ModifiedDateTime=20150219042038 +Position="MAIN",650,1300 [Comment] Comment=knowledge @@ -838,7 +842,7 @@ Page=Main Left=21 Top=794 Width=2203 -Height=1028 +Height=1148 BrushColor=$DEB2C7 BrushAlpha=50 ShapeType=Rectangle diff --git a/pom.xml b/pom.xml index 48959f94a..5c32b20e6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.support-project knowledge war - 0.4.3 + 0.4.4 webapp for knowledge https://support-project.org/ @@ -17,7 +17,7 @@ org.support-project web - 0.4.3 + 0.4.4 diff --git a/src/main/java/org/support/project/knowledge/control/admin/DatabaseControl.java b/src/main/java/org/support/project/knowledge/control/admin/DatabaseControl.java index 518ef09d2..db50aa991 100644 --- a/src/main/java/org/support/project/knowledge/control/admin/DatabaseControl.java +++ b/src/main/java/org/support/project/knowledge/control/admin/DatabaseControl.java @@ -7,12 +7,12 @@ import org.apache.commons.fileupload.FileItem; import org.support.project.common.bean.ValidateError; +import org.support.project.common.logic.H2DBServerLogic; import org.support.project.common.wrapper.FileInputStreamWithDeleteWrapper; import org.support.project.knowledge.control.Control; import org.support.project.knowledge.logic.DatabaseLogic; import org.support.project.web.annotation.Auth; import org.support.project.web.boundary.Boundary; -import org.support.project.web.logic.H2DBServerLogic; public class DatabaseControl extends Control { diff --git a/src/main/java/org/support/project/knowledge/control/open/KnowledgeControl.java b/src/main/java/org/support/project/knowledge/control/open/KnowledgeControl.java index 6b3b4d10e..4ecff3ef8 100644 --- a/src/main/java/org/support/project/knowledge/control/open/KnowledgeControl.java +++ b/src/main/java/org/support/project/knowledge/control/open/KnowledgeControl.java @@ -5,6 +5,8 @@ import javax.servlet.http.Cookie; +import org.owasp.validator.html.PolicyException; +import org.owasp.validator.html.ScanException; import org.support.project.common.log.Log; import org.support.project.common.log.LogFactory; import org.support.project.common.util.StringUtils; @@ -33,6 +35,8 @@ @DI(instance=Instance.Prototype) public class KnowledgeControl extends Control { + private static final int COOKIE_COUNT = 5; + /** ログ */ private static Log LOG = LogFactory.getLog(KnowledgeControl.class); @@ -60,11 +64,12 @@ public Boundary view() throws InvalidParamException { String history = cookie.getValue(); if (history.indexOf(",") != -1) { String[] historyIds = history.split(","); - for (int i = historyIds.length - 1; i >= 0; i--) { + //for (int i = historyIds.length - 1; i >= 0; i--) { + for (int i = 0; i < historyIds.length; i++) { if (!ids.contains(historyIds[i])) { ids.add(historyIds[i]); } - if (ids.size() >= 10) { + if (ids.size() >= COOKIE_COUNT) { break; } } @@ -75,14 +80,14 @@ public Boundary view() throws InvalidParamException { } } } + String cookieHistory = String.join(",", ids); + Cookie cookie = new Cookie("KNOWLEDGE_HISTORY", cookieHistory); + cookie.setPath(getRequest().getContextPath()); + cookie.setMaxAge(COOKIE_AGE); + getResponse().addCookie(cookie); } - String cookieHistory = String.join(",", ids); - Cookie cookie = new Cookie("KNOWLEDGE_HISTORY", cookieHistory); - cookie.setPath(getRequest().getContextPath()); - cookie.setMaxAge(COOKIE_AGE); - getResponse().addCookie(cookie); - KnowledgesEntity entity = knowledgeLogic.select(knowledgeId, getLoginedUser()); + KnowledgesEntity entity = knowledgeLogic.selectWithTags(knowledgeId, getLoginedUser()); if (entity == null) { return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND"); } @@ -125,6 +130,7 @@ public Boundary view() throws InvalidParamException { * @throws Exception */ public Boundary list() throws Exception { + LOG.trace("Call list"); TagsDao tagsDao = TagsDao.get(); KnowledgeLogic knowledgeLogic = KnowledgeLogic.get(); @@ -134,7 +140,6 @@ public Boundary list() throws Exception { String tag = getParam("tag"); String user = getParam("user"); - List knowledges = new ArrayList<>(); if (StringUtils.isInteger(tag)) { @@ -152,11 +157,12 @@ public Boundary list() throws Exception { usersEntity.setPassword(""); setAttribute("selectedUser", usersEntity); } else { - // その他 + // その他(キーワード検索) LOG.trace("search"); knowledges.addAll(knowledgeLogic.searchKnowledge(keyword, loginedUser, offset * PAGE_LIMIT, PAGE_LIMIT)); } setAttribute("knowledges", knowledges); + LOG.trace("検索終了"); int previous = offset -1; if (previous < 0) { @@ -173,6 +179,8 @@ public Boundary list() throws Exception { List tags = tagLogic.selectTagsWithCount(loginedUser, 0, PAGE_LIMIT); setAttribute("tags", tags); } + LOG.trace("タグ取得完了"); + // History表示 // TODO 履歴表示を毎回取得するのはイマイチ。いったんセッションに保存しておくのが良いかも @@ -195,12 +203,18 @@ public Boundary list() throws Exception { } } List histories = knowledgeLogic.getKnowledges(historyIds, loginedUser); - for (KnowledgesEntity knowledgesEntity : histories) { - knowledgesEntity.setContent(org.apache.commons.lang.StringUtils.abbreviate( - knowledgesEntity.getContent(), 40)); - knowledgesEntity.setContent(doSamy(knowledgesEntity.getContent())); - } + LOG.trace("履歴取得完了"); +// for (KnowledgesEntity knowledgesEntity : histories) { +// LOG.trace(" 文字数チェック"); +// knowledgesEntity.setContent(org.apache.commons.lang.StringUtils.abbreviate( +// knowledgesEntity.getContent(), 40)); +// LOG.trace(" 文字数チェック終了"); +// LOG.trace(" Samy"); +// knowledgesEntity.setContent(doSamy(knowledgesEntity.getContent())); +// LOG.trace(" Samy終了"); +// } setAttribute("histories", histories); + LOG.trace("履歴表示修正"); setAttribute("offset", offset); setAttribute("previous", previous); @@ -231,9 +245,13 @@ public Boundary like() throws InvalidParamException { * TODO クライアント側で出来ないか? * @param entity * @return + * @throws ScanException + * @throws PolicyException */ - public Boundary escape(KnowledgesEntity entity) { + public Boundary escape(KnowledgesEntity entity) throws PolicyException, ScanException { super.setSendEscapeHtml(false); + entity.setTitle(doSamy(entity.getTitle())); + entity.setContent(doSamy(entity.getContent())); return super.send(entity); } diff --git a/src/main/java/org/support/project/knowledge/control/protect/KnowledgeControl.java b/src/main/java/org/support/project/knowledge/control/protect/KnowledgeControl.java index b78c07ae9..876f7a842 100644 --- a/src/main/java/org/support/project/knowledge/control/protect/KnowledgeControl.java +++ b/src/main/java/org/support/project/knowledge/control/protect/KnowledgeControl.java @@ -60,7 +60,7 @@ public Boundary view_edit() throws InvalidParamException { setAttribute("offset", offset); Long knowledgeId = super.getPathLong(); - KnowledgesEntity entity = knowledgeLogic.select(knowledgeId, getLoginedUser()); + KnowledgesEntity entity = knowledgeLogic.selectWithTags(knowledgeId, getLoginedUser()); if (entity == null) { return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT_FOUND"); } @@ -131,7 +131,7 @@ public Boundary add(KnowledgesEntity entity) throws Exception { return forward("view_add.jsp"); } LOG.trace("save"); - String tags = super.getParam("tags"); + String tags = super.getParam("tagNames"); List tagList = knowledgeLogic.manegeTags(tags); entity = knowledgeLogic.insert(entity, tagList, fileNos, groups, super.getLoginedUser()); @@ -205,7 +205,7 @@ public Boundary update(KnowledgesEntity entity) throws Exception { } LOG.trace("save"); - String tags = super.getParam("tags"); + String tags = super.getParam("tagNames"); List tagList = knowledgeLogic.manegeTags(tags); entity = knowledgeLogic.update(entity, tagList, fileNos, groups, super.getLoginedUser()); @@ -260,7 +260,11 @@ public Boundary view() throws InvalidParamException { return super.redirect(getRequest().getContextPath() + "/open.knowledge/view/" + knowledgeId); } - + /** + * コメント追加 + * @return + * @throws InvalidParamException + */ public Boundary comment() throws InvalidParamException { Long knowledgeId = super.getPathLong(Long.valueOf(-1)); @@ -271,6 +275,9 @@ public Boundary comment() throws InvalidParamException { commentsEntity.setComment(comment); commentsDao.insert(commentsEntity); + // 一覧表示用の情報を更新 + KnowledgeLogic.get().updateKnowledgeExInfo(knowledgeId); + return super.redirect(getRequest().getContextPath() + "/open.knowledge/view/" + knowledgeId); } diff --git a/src/main/java/org/support/project/knowledge/dao/KnowledgesDao.java b/src/main/java/org/support/project/knowledge/dao/KnowledgesDao.java index 7ad02301b..3c3a245ae 100644 --- a/src/main/java/org/support/project/knowledge/dao/KnowledgesDao.java +++ b/src/main/java/org/support/project/knowledge/dao/KnowledgesDao.java @@ -67,15 +67,7 @@ public List selectKnowledge(int offset, int limit, Integer use public List selectKnowledges(List knowledgeIds) { StringBuilder sql = new StringBuilder(); sql.append("SELECT "); - sql.append(" KNOWLEDGES.KNOWLEDGE_ID"); - sql.append(" ,KNOWLEDGES.TITLE"); - sql.append(" ,KNOWLEDGES.CONTENT"); - sql.append(" ,KNOWLEDGES.PUBLIC_FLAG"); - sql.append(" ,KNOWLEDGES.INSERT_USER"); - sql.append(" ,KNOWLEDGES.INSERT_DATETIME"); - sql.append(" ,KNOWLEDGES.UPDATE_USER"); - sql.append(" ,KNOWLEDGES.UPDATE_DATETIME"); - sql.append(" ,KNOWLEDGES.DELETE_FLAG"); + sql.append(" KNOWLEDGES.*"); sql.append(" ,USERS.USER_NAME AS INSERT_USER_NAME"); sql.append(" FROM"); sql.append(" KNOWLEDGES"); diff --git a/src/main/java/org/support/project/knowledge/dao/gen/GenKnowledgesDao.java b/src/main/java/org/support/project/knowledge/dao/gen/GenKnowledgesDao.java index 0e6f3bd2a..aa1cd17f8 100644 --- a/src/main/java/org/support/project/knowledge/dao/gen/GenKnowledgesDao.java +++ b/src/main/java/org/support/project/knowledge/dao/gen/GenKnowledgesDao.java @@ -76,6 +76,10 @@ public KnowledgesEntity physicalInsert(KnowledgesEntity entity) { , entity.getTitle() , entity.getContent() , entity.getPublicFlag() + , entity.getTagIds() + , entity.getTagNames() + , entity.getLikeCount() + , entity.getCommentCount() , entity.getInsertUser() , entity.getInsertDatetime() , entity.getUpdateUser() @@ -116,6 +120,10 @@ public KnowledgesEntity physicalUpdate(KnowledgesEntity entity) { entity.getTitle() , entity.getContent() , entity.getPublicFlag() + , entity.getTagIds() + , entity.getTagNames() + , entity.getLikeCount() + , entity.getCommentCount() , entity.getInsertUser() , entity.getInsertDatetime() , entity.getUpdateUser() diff --git a/src/main/java/org/support/project/knowledge/deploy/InitDB.java b/src/main/java/org/support/project/knowledge/deploy/InitDB.java index 7eb09aff5..c077cf25f 100644 --- a/src/main/java/org/support/project/knowledge/deploy/InitDB.java +++ b/src/main/java/org/support/project/knowledge/deploy/InitDB.java @@ -3,10 +3,12 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import java.util.TimeZone; import org.support.project.common.log.Log; import org.support.project.common.log.LogFactory; import org.support.project.knowledge.deploy.v0_0_1.InitializeSystem; +import org.support.project.knowledge.deploy.v0_4_4.Migrate_0_4_4; import org.support.project.web.dao.SystemsDao; import org.support.project.web.entity.SystemsEntity; @@ -19,19 +21,19 @@ public class InitDB { private static final Map MAP = new LinkedHashMap<>(); private static final Migrate INIT = InitializeSystem.get(); - private static final String CURRENT = "0.3.1"; + private static final String CURRENT = "0.4.4"; public InitDB() { super(); - // MAP.put("0.0.1", InitializeSystem.get()); - // MAP.put("0.1.0", Migrate_0_1_0.get()); - // MAP.put("0.2.0", INIT); // 初期公開バージョン - // MAP.put("0.3.0", Migrate_0_3_0.get()); - // MAP.put("0.3.1", Migrate_0_3_1.get()); - MAP.put(CURRENT, INIT); // マイグレートできなかった + MAP.put("0.3.1", INIT); // 初期公開バージョン + MAP.put(CURRENT, Migrate_0_4_4.get()); // ナレッジ一覧の付加情報をナレッジテーブルに持つ } public static void main(String[] args) throws Exception { + // 内部的には、日付はGMTとして扱う + TimeZone zone = TimeZone.getTimeZone("GMT"); + TimeZone.setDefault(zone); + InitDB init = new InitDB(); init.start(); } @@ -43,21 +45,19 @@ public void start() throws Exception { SystemsDao dao = SystemsDao.get(); SystemsEntity entity = null; do { + boolean verup = false; migrate = null; - boolean finded = false; try { entity = dao.selectOnKey(SYSTEM_NAME); if (entity != null) { version = entity.getVersion(); - } else { - finded = true; + verup = true; } } catch (Exception e) { //テーブルが存在しない - finded = true; } - if (finded) { + if (!verup) { // テーブルが存在しない(初めての起動) version = CURRENT; migrate = INIT; @@ -67,14 +67,23 @@ public void start() throws Exception { // バージョンアップ Iterator versions = MAP.keySet().iterator(); + boolean finded = false; while (versions.hasNext()) { String v = (String) versions.next(); + if (finded) { + // 一致したものの次がバージョンアップするもの + version = v; + migrate = MAP.get(v); + break; + } if (version.equals(v)) { finded = true; + // System テーブルに書かれているバージョンをバージョンアップの一覧から一致するものを発見 } } if (migrate == null) { + // バージョンアップするものが見つからない break; } diff --git a/src/main/java/org/support/project/knowledge/deploy/InitializationListener.java b/src/main/java/org/support/project/knowledge/deploy/InitializationListener.java index 5764df5bb..aeaa8664b 100644 --- a/src/main/java/org/support/project/knowledge/deploy/InitializationListener.java +++ b/src/main/java/org/support/project/knowledge/deploy/InitializationListener.java @@ -28,15 +28,16 @@ public void contextDestroyed(ServletContextEvent contextEvent) { @Override public void contextInitialized(ServletContextEvent contextEvent) { LOG.debug("contextInitialized"); + // 内部的には、日付はGMTとして扱う + TimeZone zone = TimeZone.getTimeZone("GMT"); + TimeZone.setDefault(zone); + InitDB initDB = new InitDB(); try { initDB.start(); } catch (Exception e) { throw new SystemException(e); } - // 内部的には、日付はGMTとして扱う - TimeZone zone = TimeZone.getTimeZone("GMT"); - TimeZone.setDefault(zone); // 添付ファイル格納ディレクトリ(テンポラリディレクトリ)が存在しなければ生成 AppConfig appConfig = ConfigLoader.load(AppConfig.APP_CONFIG, AppConfig.class); diff --git a/src/main/java/org/support/project/knowledge/deploy/v0_4_4/Migrate_0_4_4.java b/src/main/java/org/support/project/knowledge/deploy/v0_4_4/Migrate_0_4_4.java new file mode 100644 index 000000000..9b24898be --- /dev/null +++ b/src/main/java/org/support/project/knowledge/deploy/v0_4_4/Migrate_0_4_4.java @@ -0,0 +1,38 @@ +package org.support.project.knowledge.deploy.v0_4_4; + +import java.util.List; + +import org.support.project.knowledge.dao.KnowledgesDao; +import org.support.project.knowledge.deploy.Migrate; +import org.support.project.knowledge.entity.KnowledgesEntity; +import org.support.project.knowledge.logic.KnowledgeLogic; +import org.support.project.ormapping.tool.dao.InitializeDao; + +public class Migrate_0_4_4 implements Migrate { + + public static Migrate_0_4_4 get() { + return org.support.project.di.Container.getComp(Migrate_0_4_4.class); + } + + @Override + public boolean doMigrate() throws Exception { + InitializeDao initializeDao = InitializeDao.get(); + String[] sqlpaths = { + "/org/support/project/knowledge/deploy/v0_4_4/migrate.sql" + }; + initializeDao.initializeDatabase(sqlpaths); + + KnowledgesDao knowledgesDao = KnowledgesDao.get(); + List knowledges = knowledgesDao.selectAll(); + + KnowledgeLogic knowledgeLogic = KnowledgeLogic.get(); + + for (KnowledgesEntity entity : knowledges) { + knowledgeLogic.updateKnowledgeExInfo(entity); + } + + return true; + } + + +} diff --git a/src/main/java/org/support/project/knowledge/entity/KnowledgesEntity.java b/src/main/java/org/support/project/knowledge/entity/KnowledgesEntity.java index 96183e213..9406b7cd4 100644 --- a/src/main/java/org/support/project/knowledge/entity/KnowledgesEntity.java +++ b/src/main/java/org/support/project/knowledge/entity/KnowledgesEntity.java @@ -1,13 +1,9 @@ package org.support.project.knowledge.entity; -import org.owasp.validator.html.PolicyException; -import org.owasp.validator.html.ScanException; -import org.support.project.common.exception.SystemException; import org.support.project.common.util.StringUtils; import org.support.project.di.Container; import org.support.project.di.DI; import org.support.project.di.Instance; -import org.support.project.knowledge.control.Control; import org.support.project.knowledge.entity.gen.GenKnowledgesEntity; @@ -68,11 +64,12 @@ public String getTitle() { if (StringUtils.isEmpty(super.getTitle())) { return super.getTitle(); } - try { - return Control.doSamy(super.getTitle()); - } catch (PolicyException | ScanException e) { - throw new SystemException(e); - } +// try { +// return Control.doSamy(super.getTitle()); +// } catch (PolicyException | ScanException e) { +// throw new SystemException(e); +// } + return super.getTitle(); } /* (non-Javadoc) @@ -83,11 +80,12 @@ public String getContent() { if (StringUtils.isEmpty(super.getContent())) { return super.getContent(); } - try { - return Control.doSamy(super.getContent()); - } catch (PolicyException | ScanException e) { - throw new SystemException(e); - } +// try { +// return Control.doSamy(super.getContent()); +// } catch (PolicyException | ScanException e) { +// throw new SystemException(e); +// } + return super.getContent(); } /** @@ -103,48 +101,6 @@ public String getInsertUserName() { public void setInsertUserName(String insertUserName) { this.insertUserName = insertUserName; } - - /** - * @return the tags - */ - public String getTags() { - return tags; - } - - /** - * @param tags the tags to set - */ - public void setTags(String tags) { - this.tags = tags; - } - - /** - * @return the likeCount - */ - public Long getLikeCount() { - return likeCount; - } - - /** - * @param likeCount the likeCount to set - */ - public void setLikeCount(Long likeCount) { - this.likeCount = likeCount; - } - - /** - * @return the commentsCount - */ - public int getCommentsCount() { - return commentsCount; - } - - /** - * @param commentsCount the commentsCount to set - */ - public void setCommentsCount(int commentsCount) { - this.commentsCount = commentsCount; - } diff --git a/src/main/java/org/support/project/knowledge/entity/gen/GenKnowledgesEntity.java b/src/main/java/org/support/project/knowledge/entity/gen/GenKnowledgesEntity.java index 8150fefe4..65ad852bb 100644 --- a/src/main/java/org/support/project/knowledge/entity/gen/GenKnowledgesEntity.java +++ b/src/main/java/org/support/project/knowledge/entity/gen/GenKnowledgesEntity.java @@ -58,6 +58,14 @@ public GenKnowledgesEntity(Long knowledgeId) { private String content; /** 公開区分 */ private Integer publicFlag; + /** タグID一覧 */ + private String tagIds; + /** タグ名称一覧 */ + private String tagNames; + /** いいね件数 */ + private Long likeCount; + /** コメント件数 */ + private Integer commentCount; /** 登録ユーザ */ private Integer insertUser; /** 登録日時 */ @@ -129,6 +137,66 @@ public GenKnowledgesEntity setPublicFlag(Integer publicFlag) { return this; } + /** + * タグID一覧 を取得する + */ + public String getTagIds() { + return this.tagIds; + } + /** + * タグID一覧 を設定する + * @param tagIds タグID一覧 + */ + public GenKnowledgesEntity setTagIds(String tagIds) { + this.tagIds = tagIds; + return this; + } + + /** + * タグ名称一覧 を取得する + */ + public String getTagNames() { + return this.tagNames; + } + /** + * タグ名称一覧 を設定する + * @param tagNames タグ名称一覧 + */ + public GenKnowledgesEntity setTagNames(String tagNames) { + this.tagNames = tagNames; + return this; + } + + /** + * いいね件数 を取得する + */ + public Long getLikeCount() { + return this.likeCount; + } + /** + * いいね件数 を設定する + * @param likeCount いいね件数 + */ + public GenKnowledgesEntity setLikeCount(Long likeCount) { + this.likeCount = likeCount; + return this; + } + + /** + * コメント件数 を取得する + */ + public Integer getCommentCount() { + return this.commentCount; + } + /** + * コメント件数 を設定する + * @param commentCount コメント件数 + */ + public GenKnowledgesEntity setCommentCount(Integer commentCount) { + this.commentCount = commentCount; + return this; + } + /** * 登録ユーザ を取得する */ @@ -252,6 +320,10 @@ public String toString() { builder.append("title = ").append(title).append("\n"); builder.append("content = ").append(content).append("\n"); builder.append("publicFlag = ").append(publicFlag).append("\n"); + builder.append("tagIds = ").append(tagIds).append("\n"); + builder.append("tagNames = ").append(tagNames).append("\n"); + builder.append("likeCount = ").append(likeCount).append("\n"); + builder.append("commentCount = ").append(commentCount).append("\n"); builder.append("insertUser = ").append(insertUser).append("\n"); builder.append("insertDatetime = ").append(insertDatetime).append("\n"); builder.append("updateUser = ").append(updateUser).append("\n"); @@ -287,6 +359,16 @@ public List validate() { if (error != null) { errors.add(error); } + validator = ValidatorFactory.getInstance(Validator.MAX_LENGTH); + error = validator.validate(this.tagIds, convLabelName("Tag Ids"), 1024); + if (error != null) { + errors.add(error); + } + validator = ValidatorFactory.getInstance(Validator.INTEGER); + error = validator.validate(this.commentCount, convLabelName("Comment Count")); + if (error != null) { + errors.add(error); + } validator = ValidatorFactory.getInstance(Validator.INTEGER); error = validator.validate(this.insertUser, convLabelName("Insert User")); if (error != null) { @@ -326,6 +408,16 @@ public List validate(Map values) { if (error != null) { errors.add(error); } + validator = ValidatorFactory.getInstance(Validator.MAX_LENGTH); + error = validator.validate(values.get("tagIds"), convLabelName("Tag Ids"), 1024); + if (error != null) { + errors.add(error); + } + validator = ValidatorFactory.getInstance(Validator.INTEGER); + error = validator.validate(values.get("commentCount"), convLabelName("Comment Count")); + if (error != null) { + errors.add(error); + } validator = ValidatorFactory.getInstance(Validator.INTEGER); error = validator.validate(values.get("insertUser"), convLabelName("Insert User")); if (error != null) { diff --git a/src/main/java/org/support/project/knowledge/logic/DatabaseLogic.java b/src/main/java/org/support/project/knowledge/logic/DatabaseLogic.java index ad881cbd0..335028062 100644 --- a/src/main/java/org/support/project/knowledge/logic/DatabaseLogic.java +++ b/src/main/java/org/support/project/knowledge/logic/DatabaseLogic.java @@ -32,7 +32,6 @@ import org.support.project.common.wrapper.FileInputStreamWithDeleteWrapper; import org.support.project.di.Container; import org.support.project.knowledge.config.AppConfig; -import org.support.project.web.logic.H2DBServerLogic; public class DatabaseLogic { /** ログ */ diff --git a/src/main/java/org/support/project/knowledge/logic/KnowledgeLogic.java b/src/main/java/org/support/project/knowledge/logic/KnowledgeLogic.java index 0f8e18d05..a187675da 100644 --- a/src/main/java/org/support/project/knowledge/logic/KnowledgeLogic.java +++ b/src/main/java/org/support/project/knowledge/logic/KnowledgeLogic.java @@ -2,7 +2,6 @@ import java.sql.Timestamp; import java.util.ArrayList; -import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -12,6 +11,7 @@ import org.support.project.common.log.Log; import org.support.project.common.log.LogFactory; import org.support.project.common.util.PropertyUtil; +import org.support.project.common.util.StringJoinBuilder; import org.support.project.common.util.StringUtils; import org.support.project.di.Container; import org.support.project.knowledge.bat.FileParseBat; @@ -25,7 +25,6 @@ import org.support.project.knowledge.dao.LikesDao; import org.support.project.knowledge.dao.TagsDao; import org.support.project.knowledge.dao.ViewHistoriesDao; -import org.support.project.knowledge.entity.CommentsEntity; import org.support.project.knowledge.entity.KnowledgeFilesEntity; import org.support.project.knowledge.entity.KnowledgeGroupsEntity; import org.support.project.knowledge.entity.KnowledgeTagsEntity; @@ -127,6 +126,9 @@ public KnowledgesEntity insert(KnowledgesEntity entity, List tags, L // 全文検索エンジンへ登録 saveIndex(entity, tags, groups, loginedUser); + + // 一覧表示用の情報を更新 + updateKnowledgeExInfo(entity); return entity; } @@ -163,6 +165,9 @@ public KnowledgesEntity update(KnowledgesEntity entity, List tags, L // 全文検索エンジンへ登録 saveIndex(entity, tags, groups, loginedUser); + + // 一覧表示用の情報を更新 + updateKnowledgeExInfo(entity); return entity; } @@ -239,6 +244,28 @@ private void saveIndex(KnowledgesEntity entity, List tags, List searchKnowledge(SearchingValue searchingValue) throws Exception { + if (LOG.isDebugEnabled()) { + LOG.debug("search params:" + PropertyUtil.reflectionToString(searchingValue)); + } + LOG.trace("検索開始"); + List list = IndexLogic.get().search(searchingValue); + LOG.trace("検索終了"); + LOG.trace("付加情報をセット開始"); + List result = getKnowledgeDatas(list); + LOG.trace("付加情報をセット終了"); + return result; + } + /** * ナレッジの検索 @@ -256,22 +283,23 @@ public List searchKnowledge(String keyword, LoginedUser logine searchingValue.setLimit(limit); if (loginedUser != null && loginedUser.isAdmin()) { - // 管理者の場合はユーザのアクセス権を考慮しない - if (StringUtils.isEmpty(keyword)) { - //キーワードが指定されていなければDBから直接取得 - // TODO 登録ユーザ名 - List list = knowledgesDao.selectKnowledge(offset, limit, loginedUser.getUserId()); - for (KnowledgesEntity entity : list) { - entity.setContent(org.apache.commons.lang.StringUtils.abbreviate(entity.getContent(), LuceneSearcher.CONTENTS_LIMIT_LENGTH)); - // タグを取得(1件づつ処理するのでパフォーマンス悪いかも?) - setTags(entity); - // いいねの回数 - setLikeCount(entity); - // コメント件数 - setCommentsCount(entity); - } - return list; - } + // 管理者の場合はユーザのアクセス権を考慮しないので、何もセットしない + +// DBからの直接取得はやめた +// if (StringUtils.isEmpty(keyword)) { +// //キーワードが指定されていなければDBから直接取得 +// List list = knowledgesDao.selectKnowledge(offset, limit, loginedUser.getUserId()); +// for (KnowledgesEntity entity : list) { +// entity.setContent(org.apache.commons.lang.StringUtils.abbreviate(entity.getContent(), LuceneSearcher.CONTENTS_LIMIT_LENGTH)); +// // タグを取得(1件づつ処理するのでパフォーマンス悪いかも?) +// setTags(entity); +// // いいねの回数 +// setLikeCount(entity); +// // コメント件数 +// setCommentsCount(entity); +// } +// return list; +// } } else { searchingValue.addUser(ALL_USER); Integer userId = null; @@ -287,12 +315,7 @@ public List searchKnowledge(String keyword, LoginedUser logine } } } - if (LOG.isDebugEnabled()) { - LOG.debug("search params:" + PropertyUtil.reflectionToString(searchingValue)); - } - List list = IndexLogic.get().search(searchingValue); - - return getKnowledgeDatas(list); + return searchKnowledge(searchingValue); } /** @@ -332,12 +355,7 @@ public List showKnowledgeOnTag(String tag, LoginedUser logined searchingValue.addTag(new Integer(tag)); } - if (LOG.isDebugEnabled()) { - LOG.debug("search params:" + PropertyUtil.reflectionToString(searchingValue)); - } - List list = IndexLogic.get().search(searchingValue); - - return getKnowledgeDatas(list); + return searchKnowledge(searchingValue); } /** @@ -349,7 +367,7 @@ public List showKnowledgeOnTag(String tag, LoginedUser logined * @return * @throws Exception */ - public Collection showKnowledgeOnUser(int targetUser, LoginedUser loginedUser, Integer offset, Integer limit) throws Exception { + public List showKnowledgeOnUser(int targetUser, LoginedUser loginedUser, Integer offset, Integer limit) throws Exception { SearchingValue searchingValue = new SearchingValue(); searchingValue.setOffset(offset); searchingValue.setLimit(limit); @@ -374,13 +392,9 @@ public Collection showKnowledgeOnUser(int targetUser } searchingValue.setCreator(targetUser); - if (LOG.isDebugEnabled()) { - LOG.debug("search params:" + PropertyUtil.reflectionToString(searchingValue)); - } - List list = IndexLogic.get().search(searchingValue); - - return getKnowledgeDatas(list); + return searchKnowledge(searchingValue); } + /** @@ -402,12 +416,14 @@ private List getKnowledgeDatas(List list) { // fileIds.add(new Long(id)); } } + LOG.trace("添付ファイル情報取得完了"); List dbs = knowledgesDao.selectKnowledges(knowledgeIds); Map map = new HashMap(); for (KnowledgesEntity knowledgesEntity : dbs) { map.put(knowledgesEntity.getKnowledgeId(), knowledgesEntity); } + LOG.trace("ナレッジ情報取得完了"); List knowledges = new ArrayList<>(); for (SearchResultValue searchResultValue : list) { @@ -421,15 +437,8 @@ private List getKnowledgeDatas(List list) { if (StringUtils.isNotEmpty(searchResultValue.getHighlightedContents())) { entity.setContent(searchResultValue.getHighlightedContents()); } else { - entity.setContent(org.apache.commons.lang.StringUtils.abbreviate(entity.getContent(), LuceneSearcher.CONTENTS_LIMIT_LENGTH)); + // entity.setContent(org.apache.commons.lang.StringUtils.abbreviate(entity.getContent(), LuceneSearcher.CONTENTS_LIMIT_LENGTH)); } - // タグを取得(1件づつ処理するのでパフォーマンス悪いかも?) - setTags(entity); - // いいねの回数 - setLikeCount(entity); - // コメント件数 - setCommentsCount(entity); - knowledges.add(entity); } } else if (searchResultValue.getType() == TYPE_FILE) { @@ -437,7 +446,7 @@ private List getKnowledgeDatas(List list) { String id = searchResultValue.getId().substring(FileParseBat.ID_PREFIX.length()); Long fileNo = new Long(id); KnowledgeFilesEntity filesEntity = filesDao.selectOnKeyWithoutBinary(fileNo); - if (filesEntity.getKnowledgeId() != null) { + if (filesEntity != null && filesEntity.getKnowledgeId() != null) { KnowledgesEntity entity = knowledgesDao.selectOnKeyWithUserName(filesEntity.getKnowledgeId()); entity.setTitle(entity.getTitle()); @@ -454,46 +463,67 @@ private List getKnowledgeDatas(List list) { builder.append(searchResultValue.getHighlightedContents()); } entity.setContent(builder.toString()); - // タグを取得(1件づつ処理するのでパフォーマンス悪いかも?) - setTags(entity); - // いいねの回数 - setLikeCount(entity); - // コメント件数 - setCommentsCount(entity); - knowledges.add(entity); } } } + +// 以下の付加情報は、ナレッジテーブルに持ち各テーブルに再取得しない +// for (KnowledgesEntity entity : knowledges) { +// // タグを取得(1件づつ処理するのでパフォーマンス悪いかも?) +// setTags(entity); +// // いいねの回数 +// setLikeCount(entity); +// // コメント件数 +// setCommentsCount(entity); +// } + + + LOG.trace("ナレッジ1件づつに、付加情報をセット完了"); + return knowledges; } - /** - * コメントの件数を取得 - * TODO 再度SQLを実行するのでは無く、ナレッジ取得時にカウントもjoinして取得したほうが早い - * - * @param entity - */ - private void setCommentsCount(KnowledgesEntity entity) { - CommentsDao commentsDao = CommentsDao.get(); - Integer count = commentsDao.countOnKnowledgeId(entity.getKnowledgeId()); - entity.setCommentsCount(count); - } +// /** +// * コメントの件数を取得 +// * TODO 再度SQLを実行するのでは無く、ナレッジ取得時にカウントもjoinして取得したほうが早い +// * +// * @param entity +// */ +// private void setCommentsCount(KnowledgesEntity entity) { +// CommentsDao commentsDao = CommentsDao.get(); +// Integer count = commentsDao.countOnKnowledgeId(entity.getKnowledgeId()); +// entity.setCommentCount(count); +// } +// +// /** +// * いいねの件数を取得 +// * TODO 再度SQLを実行するのでは無く、ナレッジ取得時にカウントもjoinして取得したほうが早い +// * +// * @param entity +// */ +// private void setLikeCount(KnowledgesEntity entity) { +// LikesDao likesDao = LikesDao.get(); +// Long count = likesDao.countOnKnowledgeId(entity.getKnowledgeId()); +// entity.setLikeCount(count); +// } /** - * いいねの件数を取得 - * TODO 再度SQLを実行するのでは無く、ナレッジ取得時にカウントもjoinして取得したほうが早い - * - * @param entity + * ナレッジの情報を取得 + * 取得する際にタグ情報も取得 */ - private void setLikeCount(KnowledgesEntity entity) { - LikesDao likesDao = LikesDao.get(); - Long count = likesDao.countOnKnowledgeId(entity.getKnowledgeId()); - entity.setLikeCount(count); + public KnowledgesEntity selectWithTags(Long knowledgeId, LoginedUser loginedUser) { + KnowledgesEntity entity = select(knowledgeId, loginedUser); + if (entity != null) { + //タグをセット + setTags(entity); + } + return entity; } - + + /** - * ナレッジを取得 + * ナレッジを取得(アクセス権のあるもののみ) * @param knowledgeId * @param loginedUser * @return @@ -504,8 +534,6 @@ public KnowledgesEntity select(Long knowledgeId, LoginedUser loginedUser) { if (entity == null) { return entity; } - //タグをセット - setTags(entity); if (entity.getPublicFlag() == null || entity.getPublicFlag().intValue() == PUBLIC_FLAG_PUBLIC) { return entity; @@ -544,6 +572,7 @@ public KnowledgesEntity select(Long knowledgeId, LoginedUser loginedUser) { } } } + // アクセス権がなかった return null; } @@ -563,7 +592,7 @@ private void setTags(KnowledgesEntity entity) { builder.append(tagsEntity.getTagName()); count++; } - entity.setTags(builder.toString()); + entity.setTagNames(builder.toString()); } /** @@ -691,9 +720,61 @@ public Long addLike(Long knowledgeId, LoginedUser loginedUser) { likesEntity.setKnowledgeId(knowledgeId); likesDao.insert(likesEntity); + updateKnowledgeExInfo(knowledgeId); + Long count = likesDao.countOnKnowledgeId(knowledgeId); return count; } + /** + * ナレッジテーブルの + * タグやイイネ件数、コメント件数などの付加情報を + * 更新する(一覧表示用) + * + * @param knowledgeId + */ + @Aspect(advice=org.support.project.ormapping.transaction.Transaction.class) + public void updateKnowledgeExInfo(Long knowledgeId) { + // 一覧表示用の情報を更新 + KnowledgesDao knowledgesDao = KnowledgesDao.get(); + KnowledgesEntity entity = knowledgesDao.selectOnKey(knowledgeId); + updateKnowledgeExInfo(entity); + } + + /** + * ナレッジテーブルの + * タグやイイネ件数、コメント件数などの付加情報を + * 更新する(一覧表示用) + * + * @param entity + */ + @Aspect(advice=org.support.project.ormapping.transaction.Transaction.class) + public void updateKnowledgeExInfo(KnowledgesEntity entity) { + // タグ情報 + TagsDao tagsDao = TagsDao.get(); + List tags = tagsDao.selectOnKnowledgeId(entity.getKnowledgeId()); + StringJoinBuilder ids = new StringJoinBuilder(); + StringJoinBuilder names = new StringJoinBuilder(); + for (TagsEntity tagsEntity : tags) { + ids.append(tagsEntity.getTagId()); + names.append(tagsEntity.getTagName()); + } + entity.setTagIds(ids.join(",")); + entity.setTagNames(names.join(",")); + // いいね件数 + LikesDao likesDao = LikesDao.get(); + Long likeCount = likesDao.countOnKnowledgeId(entity.getKnowledgeId()); + entity.setLikeCount(likeCount); + // コメント件数 + CommentsDao commentsDao = CommentsDao.get(); + Integer commentCount = commentsDao.countOnKnowledgeId(entity.getKnowledgeId()); + entity.setCommentCount(commentCount); + + // 更新 + KnowledgesDao knowledgesDao = KnowledgesDao.get(); + knowledgesDao.update(entity); + } + + } diff --git a/src/main/resources/appresource.properties b/src/main/resources/appresource.properties index eb1db9d40..a31622d14 100644 --- a/src/main/resources/appresource.properties +++ b/src/main/resources/appresource.properties @@ -51,7 +51,7 @@ message.success.save.target={1} was Saved. message.allready.updated=Allready updated. # Common Label -label.version=0.4.3 +label.version=0.4.4 label.login=Sign in label.previous = Previous label.next=Next diff --git a/src/main/resources/appresource_ja.properties b/src/main/resources/appresource_ja.properties index 003e19604..e80c511aa 100644 --- a/src/main/resources/appresource_ja.properties +++ b/src/main/resources/appresource_ja.properties @@ -51,7 +51,7 @@ message.success.save.target={1} \u4fdd\u5b58\u3057\u307e\u3057\u305f\u3002 message.allready.updated=\u3059\u3067\u306b\u66f4\u65b0\u3055\u308c\u3066\u3044\u307e\u3059 # Common Label -label.version=0.4.3 +label.version=0.4.4 label.login=\u30b5\u30a4\u30f3\u30a4\u30f3 label.previous = \u524d\u3078 label.next = \u6b21\u3078 diff --git a/src/main/resources/org/support/project/knowledge/dao/sql/KnowledgesDao/KnowledgesDao_insert.sql b/src/main/resources/org/support/project/knowledge/dao/sql/KnowledgesDao/KnowledgesDao_insert.sql index 7e339382d..c38942bce 100644 --- a/src/main/resources/org/support/project/knowledge/dao/sql/KnowledgesDao/KnowledgesDao_insert.sql +++ b/src/main/resources/org/support/project/knowledge/dao/sql/KnowledgesDao/KnowledgesDao_insert.sql @@ -4,6 +4,10 @@ KNOWLEDGE_ID , TITLE , CONTENT , PUBLIC_FLAG + , TAG_IDS + , TAG_NAMES + , LIKE_COUNT + , COMMENT_COUNT , INSERT_USER , INSERT_DATETIME , UPDATE_USER @@ -19,4 +23,8 @@ KNOWLEDGE_ID , ? , ? , ? + , ? + , ? + , ? + , ? ); diff --git a/src/main/resources/org/support/project/knowledge/dao/sql/KnowledgesDao/KnowledgesDao_update.sql b/src/main/resources/org/support/project/knowledge/dao/sql/KnowledgesDao/KnowledgesDao_update.sql index 89dc9ee3a..78ed56b9c 100644 --- a/src/main/resources/org/support/project/knowledge/dao/sql/KnowledgesDao/KnowledgesDao_update.sql +++ b/src/main/resources/org/support/project/knowledge/dao/sql/KnowledgesDao/KnowledgesDao_update.sql @@ -3,6 +3,10 @@ SET TITLE = ? , CONTENT = ? , PUBLIC_FLAG = ? + , TAG_IDS = ? + , TAG_NAMES = ? + , LIKE_COUNT = ? + , COMMENT_COUNT = ? , INSERT_USER = ? , INSERT_DATETIME = ? , UPDATE_USER = ? diff --git a/src/main/resources/org/support/project/knowledge/database/ddl.sql b/src/main/resources/org/support/project/knowledge/database/ddl.sql index 774eec645..472a1eb23 100644 --- a/src/main/resources/org/support/project/knowledge/database/ddl.sql +++ b/src/main/resources/org/support/project/knowledge/database/ddl.sql @@ -1,3 +1,9 @@ +-- Project Name : knowledge +-- Date/Time : 2015/02/19 4:22:27 +-- Author : ek003024 +-- RDBMS Type : PostgreSQL +-- Application : A5:SQL Mk-2 + -- アカウントの画像 drop table if exists ACCOUNT_IMAGES cascade; @@ -191,6 +197,10 @@ create table KNOWLEDGES ( , TITLE character varying(1024) not null , CONTENT text , PUBLIC_FLAG integer + , TAG_IDS character varying(1024) + , TAG_NAMES text + , LIKE_COUNT bigint + , COMMENT_COUNT integer , INSERT_USER integer , INSERT_DATETIME timestamp , UPDATE_USER integer @@ -316,6 +326,10 @@ comment on column KNOWLEDGES.KNOWLEDGE_ID is 'ナレッジID'; comment on column KNOWLEDGES.TITLE is 'タイトル'; comment on column KNOWLEDGES.CONTENT is '内容'; comment on column KNOWLEDGES.PUBLIC_FLAG is '公開区分'; +comment on column KNOWLEDGES.TAG_IDS is 'タグID一覧'; +comment on column KNOWLEDGES.TAG_NAMES is 'タグ名称一覧'; +comment on column KNOWLEDGES.LIKE_COUNT is 'いいね件数'; +comment on column KNOWLEDGES.COMMENT_COUNT is 'コメント件数'; comment on column KNOWLEDGES.INSERT_USER is '登録ユーザ'; comment on column KNOWLEDGES.INSERT_DATETIME is '登録日時'; comment on column KNOWLEDGES.UPDATE_USER is '更新ユーザ'; diff --git a/src/main/resources/org/support/project/knowledge/deploy/v0_4_4/migrate.sql b/src/main/resources/org/support/project/knowledge/deploy/v0_4_4/migrate.sql new file mode 100644 index 000000000..619138b76 --- /dev/null +++ b/src/main/resources/org/support/project/knowledge/deploy/v0_4_4/migrate.sql @@ -0,0 +1,9 @@ +ALTER TABLE KNOWLEDGES ADD COLUMN TAG_IDS character varying(1024); +ALTER TABLE KNOWLEDGES ADD COLUMN TAG_NAMES text; +ALTER TABLE KNOWLEDGES ADD COLUMN LIKE_COUNT bigint; +ALTER TABLE KNOWLEDGES ADD COLUMN COMMENT_COUNT integer; + +comment on column KNOWLEDGES.TAG_IDS is 'タグID一覧'; +comment on column KNOWLEDGES.TAG_NAMES is 'タグ名称一覧'; +comment on column KNOWLEDGES.LIKE_COUNT is 'いいね件数'; +comment on column KNOWLEDGES.COMMENT_COUNT is 'コメント件数'; diff --git a/src/main/webapp/WEB-INF/views/open/knowledge/list.jsp b/src/main/webapp/WEB-INF/views/open/knowledge/list.jsp index 0e9dc1622..886bf68ce 100644 --- a/src/main/webapp/WEB-INF/views/open/knowledge/list.jsp +++ b/src/main/webapp/WEB-INF/views/open/knowledge/list.jsp @@ -89,10 +89,11 @@ '<%= jspUtil.out("tag") %>', '<%= jspUtil.out("user") %>');">
"> show!
-

[<%= jspUtil.out("knowledge.knowledgeId") %>] <%= jspUtil.out("knowledge.title", JspUtil.ESCAPE_CLEAR) %>

- +

[<%= jspUtil.out("knowledge.knowledgeId") %>]  + <%= jspUtil.out("knowledge.title", JspUtil.ESCAPE_CLEAR) %>

+

- " disabled="disabled"/> + " disabled="disabled"/>

@@ -113,7 +114,7 @@      × <%= jspUtil.out("knowledge.likeCount") %>     -  × <%= jspUtil.out("knowledge.commentsCount") %> +  × <%= jspUtil.out("knowledge.commentCount") %>

@@ -182,9 +183,10 @@ ?offset=<%= jspUtil.out("offset") %>&keyword=<%= jspUtil.out("keyword") %>" class="list-group-item"> -

 [<%= jspUtil.out("history.knowledgeId") %>] <%= jspUtil.out("history.title") %>
+
  + [<%= jspUtil.out("history.knowledgeId") %>] <%= jspUtil.out("history.title") %>

- <%= jspUtil.out("history.content") %> + <%= jspUtil.out("history.content", 0, 40) %>

diff --git a/src/main/webapp/WEB-INF/views/open/knowledge/view.jsp b/src/main/webapp/WEB-INF/views/open/knowledge/view.jsp index cae7923ee..a9d848305 100644 --- a/src/main/webapp/WEB-INF/views/open/knowledge/view.jsp +++ b/src/main/webapp/WEB-INF/views/open/knowledge/view.jsp @@ -43,10 +43,10 @@ var LABEL_LIKE = '<%= jspUtil.label("knowledge.view.like") %>'; [<%= jspUtil.out("knowledgeId") %>] <%= jspUtil.out("title") %> - +

" disabled="disabled"/> + value="<%= jspUtil.out("tagNames") %>" disabled="disabled"/>

diff --git a/src/main/webapp/WEB-INF/views/protect/knowledge/view_add.jsp b/src/main/webapp/WEB-INF/views/protect/knowledge/view_add.jsp index 0de1fa89b..390f17cc9 100644 --- a/src/main/webapp/WEB-INF/views/protect/knowledge/view_add.jsp +++ b/src/main/webapp/WEB-INF/views/protect/knowledge/view_add.jsp @@ -126,8 +126,8 @@ selectedGroups.push({label: '<%= jspUtil.out("group.groupName") %>', value: '<%=

- " value="<%= jspUtil.out("tags") %>" /> + " value="<%= jspUtil.out("tagNames") %>" />

diff --git a/src/main/webapp/WEB-INF/views/protect/knowledge/view_edit.jsp b/src/main/webapp/WEB-INF/views/protect/knowledge/view_edit.jsp index 38e8fadaa..0068186fc 100644 --- a/src/main/webapp/WEB-INF/views/protect/knowledge/view_edit.jsp +++ b/src/main/webapp/WEB-INF/views/protect/knowledge/view_edit.jsp @@ -129,8 +129,8 @@ selectedGroups.push({label: '<%= jspUtil.out("group.groupName") %>', value: '<%=

- " value="<%= jspUtil.out("tags") %>" /> + " value="<%= jspUtil.out("tagNames") %>" />

diff --git a/src/test/java/org/support/project/knowledge/control/open/KnowledgeControlTest.java b/src/test/java/org/support/project/knowledge/control/open/KnowledgeControlTest.java new file mode 100644 index 000000000..cadfb4545 --- /dev/null +++ b/src/test/java/org/support/project/knowledge/control/open/KnowledgeControlTest.java @@ -0,0 +1,59 @@ +package org.support.project.knowledge.control.open; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.Cookie; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.support.project.common.test.Order; +import org.support.project.common.test.TestCase; +import org.support.project.web.exception.InvalidParamException; +import org.support.project.web.test.stub.ControlContainer; +import org.support.project.web.test.stub.StubCookie; + +public class KnowledgeControlTest extends TestCase { + private ControlContainer container; + @Before + public void setUp() throws Exception { + container = new ControlContainer(); + container.setContextPath("/knowledge"); + List cookies = new ArrayList<>(); + cookies.add(new StubCookie("KNOWLEDGE_HISTORY", "1,2,3,4,5,6,7,8")); + container.setCookies(cookies); + } + @After + public void tearDown() throws Exception { + } + @Test + @Order(order= 1) + public void testView() throws InvalidParamException { + KnowledgeControl control = container.getComp(KnowledgeControl.class); + control.view(); + } + + @Test + @Order(order= 2) + public void testList() throws Exception { + KnowledgeControl control = container.getComp(KnowledgeControl.class); + control.list(); + } + + // @Test + // public void testLike() { + // fail("Not yet implemented"); + // } + // + // @Test + // public void testEscape() { + // fail("Not yet implemented"); + // } + // + // @Test + // public void testSearch() { + // fail("Not yet implemented"); + // } + +} diff --git a/src/test/java/org/support/project/knowledge/logic/KnowledgeLogicTest.java b/src/test/java/org/support/project/knowledge/logic/KnowledgeLogicTest.java index 34cdff09b..fa6e1fa8d 100644 --- a/src/test/java/org/support/project/knowledge/logic/KnowledgeLogicTest.java +++ b/src/test/java/org/support/project/knowledge/logic/KnowledgeLogicTest.java @@ -120,7 +120,7 @@ public void testSearchKnowledge() throws Exception { eqdb(checks, entities); checks = new ArrayList(); - list.get(1).setContent(StringUtils.abbreviate(list.get(1).getContent(), LuceneSearcher.CONTENTS_LIMIT_LENGTH)); + list.get(1).setContent(list.get(1).getContent()); checks.add(list.get(1)); //スコア上 checks.add(list.get(0));