Skip to content

Commit

Permalink
#42 検索でタグを指定する場合、絞り込み条件とする(AND検索)
Browse files Browse the repository at this point in the history
    絞り込み条件を変更しながら操作するために、検索画面に遷移する際には検索条件を保持する
#59 コメント入力欄の大きさを大きくする
#73 コメントの修正・削除ができるようにする
    コメントは、登録したユーザか、もしくは、ナレッジを編集できるユーザが操作できるようにした
#79 バッチの起動間隔を長くし、バッチ終了時にシステム情報をログ出力してみる
  • Loading branch information
koda-masaru committed Aug 26, 2015
1 parent 044f25e commit 0f4c82c
Show file tree
Hide file tree
Showing 26 changed files with 485 additions and 69 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.support-project</groupId>
<artifactId>knowledge</artifactId>
<packaging>war</packaging>
<version>0.5.3</version>
<version>0.6.0-SNAPSHOT</version>
<name>webapp for knowledge</name>
<url>https://support-project.org/</url>

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>org.support-project</groupId>
<artifactId>web</artifactId>
<version>0.5.3</version>
<version>0.6.0-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ protected static void configInit(String batName) {
}
}

protected static void finishInfo() {
if (LOG.isDebugEnabled()) {
String sysinfo = org.support.project.common.util.SystemUtils.systemInfo();
LOG.debug(sysinfo);
}
LOG.info("Finished");
}


/**
* コネクションの接続先がカスタマイズされていたら、バッチでもカスタマイズ先を参照する
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static void main(String[] args) throws Exception {
FileParseBat bat = new FileParseBat();
bat.dbInit();
bat.start();
LOG.info("finished");

finishInfo();
}

private void start() throws Exception {
Expand All @@ -66,6 +67,7 @@ private void start() throws Exception {
List<KnowledgeFilesEntity> filesEntities = filesDao.selectWaitStateFiles();
AppConfig appConfig = ConfigLoader.load(AppConfig.APP_CONFIG, AppConfig.class);
File tmpDir = new File(appConfig.getTmpPath());
LOG.info("target count: " + filesEntities.size());

for (KnowledgeFilesEntity knowledgeFilesEntity : filesEntities) {
// ナレッジを取得
Expand Down Expand Up @@ -117,6 +119,7 @@ private void start() throws Exception {
Parser parser = ParserFactory.getParser(tmp.getAbsolutePath());
ParseResult result = parser.parse(tmp);
LOG.info("content text(length): " + result.getText().length());
LOG.info("content text : " + StringUtils.abbreviate(result.getText(), 300));

// 全文検索エンジンへ登録
IndexingValue value = new IndexingValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public static void main(String[] args) {
KnowledgeFileClearBat bat = new KnowledgeFileClearBat();
bat.dbInit();
bat.start();
LOG.info("finished");

finishInfo();
}

private void start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static void main(String[] args) throws Exception {
MailSendBat bat = new MailSendBat();
bat.dbInit();
bat.start();

finishInfo();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public static void main(String[] args) throws Exception {
NotifyMailBat bat = new NotifyMailBat();
bat.dbInit();
bat.start();
LOG.info("finished");

finishInfo();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ protected String setViewParam() {
params.append("&tag=").append(getParamWithDefault("tag", ""));
params.append("&user=").append(getParamWithDefault("user", ""));
params.append("&offset=").append(getParamWithDefault("offset", ""));
params.append("&tagNames=").append(getParamWithDefault("tagNames", ""));
setAttribute("params", params.toString());
return params.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.support.project.knowledge.control.protect;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import net.arnx.jsonic.JSONException;

import org.support.project.common.bean.ValidateError;
import org.support.project.common.exception.ParseException;
import org.support.project.common.log.Log;
Expand All @@ -13,8 +16,10 @@
import org.support.project.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.control.KnowledgeControlBase;
import org.support.project.knowledge.dao.CommentsDao;
import org.support.project.knowledge.dao.KnowledgesDao;
import org.support.project.knowledge.dao.TagsDao;
import org.support.project.knowledge.entity.CommentsEntity;
import org.support.project.knowledge.entity.KnowledgesEntity;
import org.support.project.knowledge.entity.TagsEntity;
import org.support.project.knowledge.logic.KnowledgeLogic;
Expand Down Expand Up @@ -368,6 +373,131 @@ public Boundary view_targets() throws InvalidParamException {
return super.send(groups);
}


/**
* コメント編集画面を表示
* @return
* @throws InvalidParamException
*/
@Get
public Boundary edit_comment() throws InvalidParamException {
Long commentNo = super.getPathLong(Long.valueOf(-1));
CommentsDao commentsDao = CommentsDao.get();
CommentsEntity commentsEntity = commentsDao.selectOnKey(commentNo);

if (commentsEntity == null) {
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT_FOUND");
}

// // 権限チェック(ナレッジが表示できること)
// KnowledgeLogic knowledgeLogic = KnowledgeLogic.get();
// KnowledgesEntity entity = knowledgeLogic.select(commentsEntity.getKnowledgeId(), getLoginedUser());
// if (entity == null) {
// return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
// }

// 権限チェック(コメントの編集は、システム管理者 or コメントの登録者
LoginedUser loginedUser = super.getLoginedUser();
if (loginedUser == null) {
// ログインしていないユーザに編集権限は無し
return sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}
if (!loginedUser.isAdmin() &&
loginedUser.getUserId().intValue() != commentsEntity.getInsertUser().intValue()) {
return sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}

setAttributeOnProperty(commentsEntity);
return forward("edit_comment.jsp");
}

/**
* コメントを更新
* @return
* @throws InvalidParamException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws JSONException
* @throws IOException
*/
@Post
public Boundary update_comment() throws InvalidParamException, InstantiationException, IllegalAccessException, JSONException, IOException {
CommentsEntity commentsEntity = getParamOnProperty(CommentsEntity.class);

CommentsDao commentsDao = CommentsDao.get();
CommentsEntity db = commentsDao.selectOnKey(commentsEntity.getCommentNo());

if (db == null) {
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT_FOUND");
}
// 権限チェック(コメントの編集は、システム管理者 or コメントの登録者 or ナレッジの編集可能ユーザ
LoginedUser loginedUser = super.getLoginedUser();
if (loginedUser == null) {
// ログインしていないユーザに編集権限は無し
return sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}
KnowledgesEntity check = KnowledgesDao.get().selectOnKey(db.getKnowledgeId());
if (check == null) {
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT_FOUND");
}
List<LabelValue> editors = TargetLogic.get().selectEditorsOnKnowledgeId(db.getKnowledgeId());
if (!loginedUser.isAdmin()) {
if (loginedUser.getUserId().intValue() != db.getInsertUser().intValue() &&
!knowledgeLogic.isEditor(super.getLoginedUser(), check, editors))
return sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}

db.setComment(commentsEntity.getComment());
commentsDao.update(db);
setAttributeOnProperty(db);

addMsgSuccess("message.success.update");
return forward("edit_comment.jsp");
}


/**
* コメントを削除
* @return
* @throws InvalidParamException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws JSONException
* @throws IOException
*/
@Get
public Boundary delete_comment() throws InvalidParamException, InstantiationException, IllegalAccessException, JSONException, IOException {
Long commentNo = super.getPathLong(Long.valueOf(-1));
CommentsDao commentsDao = CommentsDao.get();
CommentsEntity db = commentsDao.selectOnKey(commentNo);

if (db == null) {
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT_FOUND");
}
// 権限チェック(コメントの削除は、システム管理者 or コメントの登録者 or ナレッジの編集可能ユーザ
LoginedUser loginedUser = super.getLoginedUser();
if (loginedUser == null) {
// ログインしていないユーザに編集権限は無し
return sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}
KnowledgesEntity check = KnowledgesDao.get().selectOnKey(db.getKnowledgeId());
if (check == null) {
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT_FOUND");
}
List<LabelValue> editors = TargetLogic.get().selectEditorsOnKnowledgeId(db.getKnowledgeId());

if (!loginedUser.isAdmin()) {
if (loginedUser.getUserId().intValue() != db.getInsertUser().intValue() &&
!knowledgeLogic.isEditor(super.getLoginedUser(), check, editors))
return sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}
commentsDao.delete(db);
addMsgSuccess("message.success.delete.target", getResource("label.comment"));
return devolution(HttpMethod.get, "open.Knowledge/view", String.valueOf(db.getKnowledgeId()));
}



}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public static CommentsDao get() {

public List<CommentsEntity> selectOnKnowledgeId(Long knowledgeId) {
StringBuilder builder = new StringBuilder();
builder.append("SELECT *, USERS.USER_NAME AS UPDATE_USER_NAME FROM COMMENTS ");
builder.append("LEFT OUTER JOIN USERS ON USERS.USER_ID = COMMENTS.UPDATE_USER ");
builder.append("WHERE KNOWLEDGE_ID = ? ");
builder.append("SELECT COMMENTS.*, UPDATE_USER.USER_NAME AS UPDATE_USER_NAME, INSERT_USER.USER_NAME AS INSERT_USER_NAME FROM COMMENTS ");
builder.append("LEFT OUTER JOIN USERS AS UPDATE_USER ON UPDATE_USER.USER_ID = COMMENTS.UPDATE_USER ");
builder.append("LEFT OUTER JOIN USERS AS INSERT_USER ON INSERT_USER.USER_ID = COMMENTS.INSERT_USER ");
builder.append("WHERE COMMENTS.KNOWLEDGE_ID = ? AND COMMENTS.DELETE_FLAG = 0 ");
builder.append("ORDER BY COMMENTS.INSERT_DATETIME ");
return executeQueryList(builder.toString(), CommentsEntity.class, knowledgeId);
}
Expand All @@ -40,7 +41,7 @@ public List<CommentsEntity> selectOnKnowledgeId(Long knowledgeId) {
* @return
*/
public Integer countOnKnowledgeId(Long knowledgeId) {
String sql = "SELECT COUNT(*) FROM COMMENTS WHERE KNOWLEDGE_ID = ?";
String sql = "SELECT COUNT(*) FROM COMMENTS WHERE KNOWLEDGE_ID = ? AND DELETE_FLAG = 0 ";
return super.executeQuerySingle(sql, Integer.class, knowledgeId);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.support.project.knowledge.entity;

import java.util.List;
import java.util.Map;
import java.sql.Timestamp;

import org.support.project.common.bean.ValidateError;
import org.support.project.di.Container;
import org.support.project.di.DI;
import org.support.project.di.Instance;
Expand All @@ -20,9 +15,17 @@ public class CommentsEntity extends GenCommentsEntity {
/** SerialVersion */
private static final long serialVersionUID = 1L;

/** 登録ユーザ名 */
private String insertUserName;
/** 更新ユーザ名 */
private String updateUserName;

public boolean isUpdate() {
if (getInsertDatetime().getTime() != getUpdateDatetime().getTime()) {
return true;
}
return false;
}

/**
* インスタンス取得
Expand Down Expand Up @@ -63,4 +66,18 @@ public void setUpdateUserName(String updateUserName) {
this.updateUserName = updateUserName;
}

/**
* @return the insertUserName
*/
public String getInsertUserName() {
return insertUserName;
}

/**
* @param insertUserName the insertUserName to set
*/
public void setInsertUserName(String insertUserName) {
this.insertUserName = insertUserName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public static KnowledgesEntity get() {
*/
private String updateUserName;

/** スコア(検索した際のスコア) */
private Float score;

/**
* コンストラクタ
*/
Expand Down Expand Up @@ -109,6 +112,20 @@ public String getUpdateUserName() {
public void setUpdateUserName(String updateUserName) {
this.updateUserName = updateUserName;
}

/**
* @return the score
*/
public Float getScore() {
return score;
}

/**
* @param score the score to set
*/
public void setScore(Float score) {
this.score = score;
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class LuceneIndexer implements Indexer {

private String getIndexPath() {
AppConfig appConfig = ConfigLoader.load(AppConfig.APP_CONFIG, AppConfig.class);
log.debug("lucene index: " + appConfig.getIndexPath());
return appConfig.getIndexPath();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.support.project.knowledge.listener;

import java.io.File;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -92,7 +90,7 @@ public void run() {
LOG.error("Faild parse.", e);
}
}
}, 70, 60, TimeUnit.SECONDS); // 60秒毎に実行
}, 5, 5, TimeUnit.MINUTES); // 5分毎に実行

mailfuture = service.scheduleAtFixedRate(new Runnable() {
@Override
Expand All @@ -119,7 +117,7 @@ public void run() {
LOG.error("Failed send mail.", e);
}
}
}, 50, 60, TimeUnit.SECONDS); // 60秒毎に実行
}, 180, 180, TimeUnit.SECONDS); // 180秒毎に実行

notifyfuture = service.scheduleAtFixedRate(new Runnable() {
@Override
Expand All @@ -146,7 +144,7 @@ public void run() {
LOG.error("Failed to Notify", e);
}
}
}, 40, 60, TimeUnit.SECONDS); // 60秒毎に実行
}, 90, 180, TimeUnit.SECONDS); // 180秒毎に実行
}

@Override
Expand Down
Loading

0 comments on commit 0f4c82c

Please sign in to comment.