Skip to content

Commit

Permalink
Merge pull request #178 from support-project/develop
Browse files Browse the repository at this point in the history
Release v0.7.0 pre2
  • Loading branch information
koda-masaru committed Dec 3, 2015
2 parents efe1a3b + c104c42 commit 5ba46e9
Show file tree
Hide file tree
Showing 17 changed files with 333 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private void sendCommentMail(CommentsEntity comment, KnowledgesEntity knowledge,
private void notifyKnowledgeUpdate(NotifyQueuesEntity notifyQueuesEntity) {
// ナレッジが登録/更新された
KnowledgesDao knowledgesDao = KnowledgesDao.get();
KnowledgesEntity knowledge = knowledgesDao.selectOnKey(notifyQueuesEntity.getId());
KnowledgesEntity knowledge = knowledgesDao.selectOnKeyWithUserName(notifyQueuesEntity.getId());
if (null == knowledge) {
LOG.warn("Knowledge record not found. id: " + notifyQueuesEntity.getId());
return;
Expand Down Expand Up @@ -469,6 +469,7 @@ private void insertNotifyKnowledgeUpdateMailQue(KnowledgesEntity knowledge, User
String contents = config.getContents();
contents = contents.replace("{KnowledgeId}", knowledge.getKnowledgeId().toString());
contents = contents.replace("{KnowledgeTitle}", knowledge.getTitle());
contents = contents.replace("{User}", knowledge.getUpdateUserName());
contents = contents.replace("{Contents}", knowledge.getContent());
contents = contents.replace("{URL}", NotifyLogic.get().makeURL(knowledge.getKnowledgeId()));

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

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -34,7 +37,6 @@
import org.support.project.knowledge.logic.MarkdownLogic;
import org.support.project.knowledge.logic.TagLogic;
import org.support.project.knowledge.logic.TargetLogic;
import org.support.project.knowledge.logic.TemplateLogic;
import org.support.project.knowledge.logic.UploadedFileLogic;
import org.support.project.knowledge.vo.LikeCount;
import org.support.project.knowledge.vo.MarkDown;
Expand Down Expand Up @@ -62,6 +64,8 @@ public class KnowledgeControl extends KnowledgeControlBase {
public static final int FAV_PAGE_LIMIT = 10;
public static final int COOKIE_AGE = 60 * 60 * 24 * 31;

private static final String COOKIE_SEPARATOR = "-";

/**
* ナレッジを表示
* @return
Expand All @@ -78,19 +82,25 @@ public Boundary view() throws InvalidParamException, ParseException {
KnowledgeLogic knowledgeLogic = KnowledgeLogic.get();

// 今見たナレッジの情報をCookieに保存
// TODO セッションのデータを操作
List<String> ids = new ArrayList<String>();
ids.add(String.valueOf(knowledgeId));
Cookie[] cookies = getRequest().getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("KNOWLEDGE_HISTORY")) {
try {
List<String> ids = new ArrayList<String>();
ids.add(String.valueOf(knowledgeId));
Cookie[] cookies = getRequest().getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (!cookie.getName().equals("KNOWLEDGE_HISTORY")) {
continue;
}
String history = cookie.getValue();
if (history.indexOf(",") != -1) {
String[] historyIds = history.split(",");
//for (int i = historyIds.length - 1; i >= 0; i--) {
history = history.replaceAll(",", COOKIE_SEPARATOR); // 旧閲覧履歴情報が存在すれば、変換する
} else {
history = URLDecoder.decode(history, "UTF-8");
}
if (history.indexOf(COOKIE_SEPARATOR) != -1) {
String[] historyIds = history.split(COOKIE_SEPARATOR);
for (int i = 0; i < historyIds.length; i++) {
if (!ids.contains(historyIds[i])) {
if (!ids.contains(historyIds[i]) && StringUtils.isLong(historyIds[i])) {
ids.add(historyIds[i]);
}
if (ids.size() >= COOKIE_COUNT) {
Expand All @@ -103,12 +113,15 @@ public Boundary view() throws InvalidParamException, ParseException {
}
}
}
String cookieHistory = String.join(COOKIE_SEPARATOR, ids);
cookieHistory = URLEncoder.encode(cookieHistory, "UTF-8");
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);
} catch (UnsupportedEncodingException e) {
LOG.error("Cokkie error.", e);
}

KnowledgesEntity entity = knowledgeLogic.selectWithTags(knowledgeId, getLoginedUser());
Expand Down Expand Up @@ -336,37 +349,41 @@ public Boundary list() throws Exception {

// History表示
// TODO 履歴表示を毎回取得するのはイマイチ。いったんセッションに保存しておくのが良いかも
Cookie[] cookies = getRequest().getCookies();
List<String> historyIds = new ArrayList<>();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("KNOWLEDGE_HISTORY")) {
try {
Cookie[] cookies = getRequest().getCookies();
List<String> historyIds = new ArrayList<>();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (!cookie.getName().equals("KNOWLEDGE_HISTORY")) {
continue;
}
String history = cookie.getValue();
LOG.debug("history: " + history);
if (history.indexOf(",") != -1) {
String[] splits = history.split(",");
history = history.replaceAll(",", COOKIE_SEPARATOR);
} else {
history = URLDecoder.decode(history, "UTF-8");
}
LOG.debug("history: " + history);
if (history.indexOf(COOKIE_SEPARATOR) != -1) {
String[] splits = history.split(COOKIE_SEPARATOR);
for (String string : splits) {
historyIds.add(string);
if (StringUtils.isLong(string)) {
historyIds.add(string);
}
}
} else {
historyIds.add(history);
if (StringUtils.isLong(history)) {
historyIds.add(history);
}
}
}
}
List<KnowledgesEntity> histories = knowledgeLogic.getKnowledges(historyIds, loginedUser);
LOG.trace("履歴取得完了");
setAttribute("histories", histories);
} catch (UnsupportedEncodingException e) {
LOG.error("Cokkie error.", e);
}
List<KnowledgesEntity> histories = knowledgeLogic.getKnowledges(historyIds, loginedUser);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public Boundary view_edit() throws InvalidParamException {

/**
* 登録する
* APIによる保存とし、画面遷移は行わない
* @return
* @throws Exception
* @throws ParseException
Expand All @@ -157,20 +158,12 @@ public Boundary add(KnowledgesEntity entity) throws Exception, ParseException {
setAttribute("tagitems", tagitems);

List<Long> fileNos = new ArrayList<Long>();
Object obj = getParam("files", Object.class);
if (obj != null) {
if (obj instanceof String) {
String string = (String) obj;
String[] filesArray = getParam("files", String[].class);
if (filesArray != null) {
for (String string : filesArray) {
if (StringUtils.isLong(string)) {
fileNos.add(new Long(string));
}
} else if (obj instanceof List) {
List<String> strings = (List<String>) obj;
for (String string : strings) {
if (StringUtils.isLong(string)) {
fileNos.add(new Long(string));
}
}
}
}

Expand All @@ -191,20 +184,8 @@ public Boundary add(KnowledgesEntity entity) throws Exception, ParseException {

List<ValidateError> errors = entity.validate();
if (!errors.isEmpty()) {
setResult(null, errors);
// バリデーションエラーが発生した場合、設定されていた添付ファイルの情報は再取得
List<UploadFile> files = fileLogic.selectOnFileNos(fileNos, getRequest().getContextPath());
Iterator<UploadFile> iterator = files.iterator();
while (iterator.hasNext()) {
UploadFile uploadFile = (UploadFile) iterator.next();
if (uploadFile.getKnowlegeId() != null) {
// 新規登録なのに、添付ファイルが既にナレッジに紐づいている(おかしい)
iterator.remove();
}
}
setAttribute("files", files);

return forward("view_add.jsp");
//入力エラー
return sendValidateError(errors);
}
LOG.trace("save");
String tags = super.getParam("tagNames");
Expand All @@ -217,11 +198,13 @@ public Boundary add(KnowledgesEntity entity) throws Exception, ParseException {
setAttribute("files", files);

addMsgSuccess("message.success.insert");
return forward("view_edit.jsp");
// return forward("view_edit.jsp");
return sendMsg(MessageStatus.Success, HttpStatus.SC_200_OK, String.valueOf(entity.getKnowledgeId()), "message.success.insert");
}

/**
* 更新する
* APIによる保存とし、画面遷移は行わない
* @return
* @throws Exception
*/
Expand All @@ -244,20 +227,12 @@ public Boundary update(KnowledgesEntity entity) throws Exception {
setAttribute("tagitems", tagitems);

List<Long> fileNos = new ArrayList<Long>();
Object obj = getParam("files", Object.class);
if (obj != null) {
if (obj instanceof String) {
String string = (String) obj;
String[] filesArray = getParam("files", String[].class);
if (filesArray != null) {
for (String string : filesArray) {
if (StringUtils.isLong(string)) {
fileNos.add(new Long(string));
}
} else if (obj instanceof List) {
List<String> strings = (List<String>) obj;
for (String string : strings) {
if (StringUtils.isLong(string)) {
fileNos.add(new Long(string));
}
}
}
}

Expand All @@ -279,22 +254,8 @@ public Boundary update(KnowledgesEntity entity) throws Exception {
KnowledgesDao dao = Container.getComp(KnowledgesDao.class);
List<ValidateError> errors = entity.validate();
if (!errors.isEmpty()) {
setResult(null, errors);

// バリデーションエラーが発生した場合、設定されていた添付ファイルの情報は再取得
List<UploadFile> files = fileLogic.selectOnFileNos(fileNos, getRequest().getContextPath());
Iterator<UploadFile> iterator = files.iterator();
while (iterator.hasNext()) {
UploadFile uploadFile = (UploadFile) iterator.next();
if (uploadFile.getKnowlegeId() != null
&& uploadFile.getKnowlegeId().longValue() != entity.getKnowledgeId().longValue()) {
// ナレッジIDが空でなく、かつ、更新中のナレッジ以外に紐づいている添付ファイルはおかしいので削除
iterator.remove();
}
}
setAttribute("files", files);

return forward("view_edit.jsp");
//入力エラー
return sendValidateError(errors);
}

KnowledgesEntity check = dao.selectOnKey(entity.getKnowledgeId());
Expand All @@ -305,8 +266,11 @@ public Boundary update(KnowledgesEntity entity) throws Exception {
if (!knowledgeLogic.isEditor(super.getLoginedUser(), check, editors)) {
setAttribute("edit", false);
addMsgWarn("knowledge.edit.noaccess");
//return forward("/open/knowledge/view.jsp");
return devolution(HttpMethod.get, "open.Knowledge/view", String.valueOf(entity.getKnowledgeId()));
// return devolution(HttpMethod.get, "open.Knowledge/view", String.valueOf(entity.getKnowledgeId()));

errors = new ArrayList<>();
errors.add(new ValidateError("knowledge.edit.noaccess"));
return sendValidateError(errors);
}

LOG.trace("save");
Expand All @@ -320,7 +284,8 @@ public Boundary update(KnowledgesEntity entity) throws Exception {
List<UploadFile> files = fileLogic.selectOnKnowledgeIdWithoutCommentFiles(entity.getKnowledgeId(), getRequest().getContextPath());
setAttribute("files", files);

return forward("view_edit.jsp");
// return forward("view_edit.jsp");
return sendMsg(MessageStatus.Success, HttpStatus.SC_200_OK, String.valueOf(entity.getKnowledgeId()), "message.success.update");
}

/**
Expand Down Expand Up @@ -677,7 +642,53 @@ public Boundary stock() throws IOException, InvalidParamException {
}
}
return sendMsg(MessageStatus.Success, HttpStatus.SC_200_OK, "saved", "message.success.save");
};
};


/**
* コメントを折りたたみ
* @return
* @throws IOException
* @throws InvalidParamException
*/
@Post
public Boundary collapse() throws IOException, InvalidParamException {
Long commentNo = getParam("commentNo", Long.class);
Integer collapse = getParam("collapse", Integer.class);

CommentsDao commentsDao = CommentsDao.get();
CommentsEntity db = commentsDao.selectOnKey(commentNo);

// 権限チェック(コメントの編集は、システム管理者 or コメントの登録者 or ナレッジ編集者
LoginedUser loginedUser = super.getLoginedUser();
if (loginedUser == null) {
// ログインしていないユーザに編集権限は無し
return sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}
if (!loginedUser.isAdmin() &&
loginedUser.getUserId().intValue() != db.getInsertUser().intValue()) {
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 (!knowledgeLogic.isEditor(super.getLoginedUser(), check, editors)) {
return sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}
}

// ステータス更新
db.setCommentStatus(collapse);
commentsDao.physicalUpdate(db); // 更新履歴は付けないで更新

if (collapse == 1) {
return sendMsg(MessageStatus.Success, HttpStatus.SC_200_OK, String.valueOf(commentNo), "knowledge.view.comment.collapse.on");
} else {
return sendMsg(MessageStatus.Success, HttpStatus.SC_200_OK, String.valueOf(commentNo), "knowledge.view.comment.collapse.off");
}
}



}

Expand Down
Loading

0 comments on commit 5ba46e9

Please sign in to comment.