Skip to content

Commit

Permalink
Merge pull request #778 from support-project/feature/issue760_get_attach
Browse files Browse the repository at this point in the history
#760 Add a web api to get attachments
  • Loading branch information
koda-masaru authored Jul 1, 2017
2 parents cf84713 + 670d36d commit f3e2920
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.support.project.knowledge.control.api;

import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.knowledge.entity.KnowledgeFilesEntity;
import org.support.project.knowledge.logic.UploadedFileLogic;
import org.support.project.web.bean.ApiParams;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.control.ApiControl;
import org.support.project.web.control.service.Get;

public class AttachControl extends ApiControl {
/** ログ */
private static final Log LOG = LogFactory.getLog(AttachControl.class);

@Get(path="api/attachments")
public Boundary index() {
return get();
}

@Override
public Boundary getList(ApiParams params) {
return sendError(HttpStatus.SC_501_NOT_IMPLEMENTED);
}

@Override
public Boundary getSingle(String id) {
try {
Long fileNo = Long.parseLong(id);
KnowledgeFilesEntity entity = UploadedFileLogic.get().getFile(fileNo, getLoginedUser());
if (entity == null) {
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
}
if (entity.getFileBinary() == null) {
LOG.debug("File binary is null. [fileNo] " + fileNo);
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
}
return download(entity.getFileName(), entity.getFileBinary(), entity.getFileSize().longValue());
} catch (Exception e) {
return sendError(HttpStatus.SC_500_INTERNAL_SERVER_ERROR);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private Knowledge conv(KnowledgesEntity entity, int type) {

// 添付ファイル
List<AttachedFile> attachedFiles = getAttachedFiles(entity);
detail.setAttachedFiles(attachedFiles);
detail.setAttachments(attachedFiles);

// 共同編集者
Target editors = getEditors(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class KnowledgeDetail extends Knowledge {
/** コメント */
private List<Comment> comments;
/** 添付ファイル */
private List<AttachedFile> attachedFiles;
private List<AttachedFile> attachments;

/** 編集可能な対象(共同編集者) */
private Target editors;
Expand Down Expand Up @@ -39,18 +39,6 @@ public List<Comment> getComments() {
public void setComments(List<Comment> comments) {
this.comments = comments;
}
/**
* @return the attachedFiles
*/
public List<AttachedFile> getAttachedFiles() {
return attachedFiles;
}
/**
* @param attachedFiles the attachedFiles to set
*/
public void setAttachedFiles(List<AttachedFile> attachedFiles) {
this.attachedFiles = attachedFiles;
}
/**
* @return the editors
*/
Expand All @@ -63,14 +51,16 @@ public Target getEditors() {
public void setEditors(Target editors) {
this.editors = editors;
}










/**
* @return the attachments
*/
public List<AttachedFile> getAttachments() {
return attachments;
}
/**
* @param attachments the attachments to set
*/
public void setAttachments(List<AttachedFile> attachments) {
this.attachments = attachments;
}
}

0 comments on commit f3e2920

Please sign in to comment.