Skip to content

Commit

Permalink
Release 0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
koda-masaru committed Feb 5, 2015
1 parent 696517d commit 470c360
Show file tree
Hide file tree
Showing 29 changed files with 725 additions and 52 deletions.
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"highlightjs": "8.3.0",
"bootbox": "4.3.0",
"bootstrap-tagsinput": "0.4.2",
"bootstrap-fileinput": "4.1.6",
"jquery-file-upload": "9.8.1",
"teambox.free-file-icons": "teambox/Free-file-icons",
"echojs": "1.6.0"
Expand Down
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.4.1</version>
<version>0.4.2</version>
<name>webapp for knowledge</name>
<url>https://support-project.org/</url>

Expand All @@ -17,7 +17,7 @@
<dependency>
<groupId>org.support-project</groupId>
<artifactId>web</artifactId>
<version>0.4.1</version>
<version>0.4.2</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.support.project.knowledge.control.admin;

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

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.support.project.common.bean.ValidateError;
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 {

/* (non-Javadoc)
* @see org.support.project.web.control.Control#index()
*/
@Override
public Boundary index() {
H2DBServerLogic h2dbServerLogic = H2DBServerLogic.get();
boolean active = h2dbServerLogic.isActive();
setAttribute("active", active);
return super.index();
}

@Auth(roles="admin")
public Boundary start() {
H2DBServerLogic h2dbServerLogic = H2DBServerLogic.get();
h2dbServerLogic.start();
boolean active = h2dbServerLogic.isActive();
setAttribute("active", active);
return super.index();
}
@Auth(roles="admin")
public Boundary stop() {
H2DBServerLogic h2dbServerLogic = H2DBServerLogic.get();
h2dbServerLogic.stop();
boolean active = h2dbServerLogic.isActive();
setAttribute("active", active);
return super.index();
}



/**
* データをバックアップ
* @return
* @throws IOException
*/
@Auth(roles="admin")
public Boundary backup() throws IOException {

HttpServletResponse res = getResponse();
res.setDateHeader("Expires",0);
res.setHeader("Pragma","no-cache");
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");

DatabaseLogic databaseLogic = DatabaseLogic.get();
FileInputStreamWithDeleteWrapper inputStream = databaseLogic.getData();

return download("knowledge.zip", inputStream, inputStream.size(), "application/zip");
}


@Auth(roles="admin")
public Boundary restore() throws IOException {
H2DBServerLogic h2dbServerLogic = H2DBServerLogic.get();
boolean active = h2dbServerLogic.isActive();
if (active) {
addMsgInfo("knowledge.data.label.msg.before.stop");
setAttribute("active", active);
return super.index();
}

FileItem fileItem = super.getParam("upload", FileItem.class);
if (fileItem == null || fileItem.getSize() == 0) {
addMsgWarn("knowledge.data.label.msg.empty");
} else if (!fileItem.getName().endsWith(".zip") && !fileItem.getName().endsWith(".ZIP")) {
addMsgWarn("knowledge.data.label.msg.invalid.file");
} else {
DatabaseLogic databaseLogic = DatabaseLogic.get();
List<ValidateError> errors = databaseLogic.restore(fileItem);
setResult("knowledge.data.label.msg.restore", errors);
}
active = h2dbServerLogic.isActive();
setAttribute("active", active);
return super.index();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,25 @@ public Boundary view() throws InvalidParamException {
List<String> ids = new ArrayList<String>();
ids.add(String.valueOf(knowledgeId));
Cookie[] cookies = getRequest().getCookies();
for (Cookie cookie : cookies) {
if (cookie.getName().equals("KNOWLEDGE_HISTORY")) {
String history = cookie.getValue();
if (history.indexOf(",") != -1) {
String[] historyIds = history.split(",");
for (int i = historyIds.length - 1; i >= 0; i--) {
if (!ids.contains(historyIds[i])) {
ids.add(historyIds[i]);
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("KNOWLEDGE_HISTORY")) {
String history = cookie.getValue();
if (history.indexOf(",") != -1) {
String[] historyIds = history.split(",");
for (int i = historyIds.length - 1; i >= 0; i--) {
if (!ids.contains(historyIds[i])) {
ids.add(historyIds[i]);
}
if (ids.size() >= 10) {
break;
}
}
if (ids.size() >= 10) {
break;
} else {
if (!ids.contains(history)) {
ids.add(history);
}
}
} else {
if (!ids.contains(history)) {
ids.add(history);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import org.support.project.knowledge.vo.UploadFile;
import org.support.project.knowledge.vo.UploadResults;
import org.support.project.web.bean.LoginedUser;
import org.support.project.web.bean.Msg;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.common.HttpUtil;
import org.support.project.web.dao.UsersDao;
import org.support.project.web.entity.UsersEntity;
import org.support.project.web.logic.AuthenticationLogic;
Expand Down Expand Up @@ -131,18 +133,20 @@ public Boundary iconupload() throws IOException {
Object obj = getParam("files[]", Object.class);
if (obj instanceof FileItem) {
FileItem fileItem = (FileItem) obj;
ValidateError error = checkExtension(fileItem.getName());
ValidateError error = checkFile(fileItem);
if (error != null) {
return send(HttpStatus.SC_400_BAD_REQUEST, error);
Msg msg = new Msg(error.getMsg(HttpUtil.getLocale(getRequest())));
return send(HttpStatus.SC_400_BAD_REQUEST, msg);
}
UploadFile file = logic.saveIconImage(fileItem, getLoginedUser(), getRequest().getContextPath());
files.add(file);
} else if (obj instanceof List) {
List<FileItem> fileItems = (List<FileItem>) obj;
for (FileItem fileItem : fileItems) {
ValidateError error = checkExtension(fileItem.getName());
ValidateError error = checkFile(fileItem);
if (error != null) {
return send(HttpStatus.SC_400_BAD_REQUEST, error);
Msg msg = new Msg(error.getMsg(HttpUtil.getLocale(getRequest())));
return send(HttpStatus.SC_400_BAD_REQUEST, msg);
}
UploadFile file = logic.saveIconImage(fileItem, getLoginedUser(), getRequest().getContextPath());
files.add(file);
Expand All @@ -152,11 +156,18 @@ public Boundary iconupload() throws IOException {
return send(HttpStatus.SC_200_OK, results);
}
/**
* アップロードされたファイルのチェック
* アイコン画像の拡張子チェック
* @param name
* @return
*/
private ValidateError checkExtension(String name) {
private ValidateError checkFile(FileItem fileItem) {
if (fileItem.getSize() > 5 * 1024 * 1024) {
ValidateError error = new ValidateError("errors.maxfilesize", "5MB");
return error;
}

String name = fileItem.getName();
Validator validator = ValidatorFactory.getInstance(Validator.EXTENSION);
return validator.validate(name, "icon", "png", "jpg", "jpeg", "gif");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import org.apache.commons.fileupload.FileItem;
import org.support.project.common.bean.ValidateError;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.di.DI;
Expand All @@ -14,9 +15,11 @@
import org.support.project.knowledge.logic.UploadedFileLogic;
import org.support.project.knowledge.vo.UploadFile;
import org.support.project.knowledge.vo.UploadResults;
import org.support.project.web.bean.Msg;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.boundary.JsonBoundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.common.HttpUtil;

@DI(instance=Instance.Prototype)
public class FileControl extends Control {
Expand All @@ -37,11 +40,21 @@ public Boundary upload() throws Exception {
Object obj = getParam("files[]", Object.class);
if (obj instanceof FileItem) {
FileItem fileItem = (FileItem) obj;
if (fileItem.getSize() > 10 * 1024 * 1024) {
ValidateError error = new ValidateError("errors.maxfilesize", "10MB");
Msg msg = new Msg(error.getMsg(HttpUtil.getLocale(getRequest())));
return send(HttpStatus.SC_400_BAD_REQUEST, msg);
}
UploadFile file = fileLogic.saveFile(fileItem, getLoginedUser(), getRequest().getContextPath());
files.add(file);
} else if (obj instanceof List) {
List<FileItem> fileItems = (List<FileItem>) obj;
for (FileItem fileItem : fileItems) {
if (fileItem.getSize() > 10 * 1024 * 1024) {
ValidateError error = new ValidateError("errors.maxfilesize", "10MB");
Msg msg = new Msg(error.getMsg(HttpUtil.getLocale(getRequest())));
return send(HttpStatus.SC_400_BAD_REQUEST, msg);
}
UploadFile file = fileLogic.saveFile(fileItem, getLoginedUser(), getRequest().getContextPath());
files.add(file);
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/support/project/knowledge/dao/CommentsDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public List<CommentsEntity> selectOnKnowledgeId(Long knowledgeId) {
builder.append("WHERE KNOWLEDGE_ID = ? ");
return executeQueryList(builder.toString(), CommentsEntity.class, knowledgeId);
}

/**
* ナレッジのコメントの件数を取得
* @param knowledgeId
* @return
*/
public Integer countOnKnowledgeId(Long knowledgeId) {
String sql = "SELECT COUNT(*) FROM COMMENTS WHERE KNOWLEDGE_ID = ?";
return super.executeQuerySingle(sql, Integer.class, knowledgeId);
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public static KnowledgesEntity get() {

/** いいねのカウント */
private Long likeCount;
/** コメントのカウント */
private int commentsCount;


/**
Expand Down Expand Up @@ -129,6 +131,20 @@ public Long getLikeCount() {
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;
}



Expand Down
Loading

0 comments on commit 470c360

Please sign in to comment.