-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #778 from support-project/feature/issue760_get_attach
#760 Add a web api to get attachments
- Loading branch information
Showing
3 changed files
with
59 additions
and
24 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/main/java/org/support/project/knowledge/control/api/AttachControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters