Search in sources :

Example 1 with FileDTO

use of com.worksmobile.Assignment.Domain.FileDTO in project Assignment by WMPeople.

the class RestController method history.

/**
 * 이력 상세보기 입니다.
 * @param board_id 상세 조회 할 게시물의 board_id
 * @param version 상세 조회 할 게시물의 version
 * @return modelAndView 이력의 상세 내용, board-boardHistory 구분자 , file 데이터 , viewName을 리턴합니다.
 */
@RequestMapping(value = "/history/{board_id}/{version}", method = RequestMethod.GET)
@ResponseBody
public ModelAndView history(@PathVariable(value = "board_id") int board_id, @PathVariable(value = "version") int version) {
    NodePtrDTO node = new NodePtrDTO(board_id, version);
    BoardHistoryDTO boardHistory = boardHistoryMapper.getHistory(node);
    BoardDTO board = new BoardDTO(boardHistory);
    FileDTO file = fileMapper.getFile(board.getFile_id());
    String deCompreesedContent = "";
    try {
        deCompreesedContent = Compress.deCompress(boardHistory.getHistory_content());
    } catch (IOException e) {
        e.printStackTrace();
        deCompreesedContent = "압축 해제 실패";
        throw new RuntimeException(e);
    }
    board.setContent(deCompreesedContent);
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("board", board);
    modelAndView.addObject("isHistory", 1);
    modelAndView.addObject("file", file);
    modelAndView.setViewName("boardDetail");
    return modelAndView;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) FileDTO(com.worksmobile.Assignment.Domain.FileDTO) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) ModelAndView(org.springframework.web.servlet.ModelAndView) IOException(java.io.IOException) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with FileDTO

use of com.worksmobile.Assignment.Domain.FileDTO in project Assignment by WMPeople.

the class RestController method show.

/**
 * 게시물 상세보기 입니다.
 * @param board_id 상세 조회 할 게시물의 board_id
 * @param version 상세 조회 할 게시물의 version
 * @return 상세보기 화면과 게시물 내용이 맵 형태로 리턴됩니다.
 */
@RequestMapping(value = "/boards/{board_id}/{version}", method = RequestMethod.GET)
@ResponseBody
public ModelAndView show(@PathVariable(value = "board_id") int board_id, @PathVariable(value = "version") int version) {
    HashMap<String, Integer> params = new HashMap<String, Integer>();
    params.put("board_id", board_id);
    params.put("version", version);
    BoardDTO board = boardMapper.viewDetail(params);
    if (board == null) {
        String json = Utils.jsonStringIfExceptionToString(board);
        throw new RuntimeException("show 메소드에서 viewDetail 메소드 실행 에러" + json);
    }
    String dirty = board.getContent();
    String clean = XssPreventer.escape(dirty);
    board.setContent(clean);
    FileDTO file = fileMapper.getFile(board.getFile_id());
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("board", board);
    modelAndView.addObject("isHistory", 0);
    modelAndView.addObject("file", file);
    modelAndView.setViewName("boardDetail");
    return modelAndView;
}
Also used : FileDTO(com.worksmobile.Assignment.Domain.FileDTO) HashMap(java.util.HashMap) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with FileDTO

use of com.worksmobile.Assignment.Domain.FileDTO in project Assignment by WMPeople.

the class RestController method updateWithoutAttachment.

/**
 * 게시물에 첨부파일을 유지하고 싶은 경우를 제외하고는 글수정 데이터를 받아 DB에 등록합니다.
 * @param board 사용자가 수정한 board 데이터를 받습니다.
 * @param attachment 첨부파일 데이터를 받습니다.
 */
@RequestMapping(value = "/boards/update2", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updateWithoutAttachment(BoardDTO board, MultipartHttpServletRequest attachment) {
    Map<String, Object> resultMap = new HashMap<>();
    MultipartFile mFile = null;
    Iterator<String> iter = attachment.getFileNames();
    while (iter.hasNext()) {
        String uploadFile_name = iter.next();
        mFile = attachment.getFile(uploadFile_name);
    }
    try {
        if (mFile != null) {
            if (!mFile.getOriginalFilename().equals("")) {
                FileDTO file = new FileDTO();
                file.setFile_name(mFile.getOriginalFilename());
                file.setFile_data(mFile.getBytes());
                file.setFile_size(mFile.getSize());
                fileMapper.createFile(file);
                board.setFile_id(file.getFile_id());
            }
        }
        NodePtrDTO leapPtrDTO = new NodePtrDTO(board.getBoard_id(), board.getVersion());
        NodePtrDTO newNode = versionManagementService.modifyVersion(board, leapPtrDTO);
        if (newNode == null) {
            resultMap.put("result", "수정 실패");
        } else {
            resultMap.put("result", "success");
        }
    } catch (Exception e) {
        resultMap.put("result", e.getMessage());
        e.printStackTrace();
        return resultMap;
    }
    return resultMap;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) MultipartFile(org.springframework.web.multipart.MultipartFile) FileDTO(com.worksmobile.Assignment.Domain.FileDTO) HashMap(java.util.HashMap) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with FileDTO

use of com.worksmobile.Assignment.Domain.FileDTO in project Assignment by WMPeople.

the class RestController method create.

/**
 * 글 생성을 합니다. VersionManagementService의 createArticle 함수를 호출하여 board_histry 테이블과 board 테이블에 데이터를 삽입합니다.
 * @param board 사용자가 작성한 board 데이터를 받습니다.
 * @param attachment 첨부파일 데이터를 받습니다.
 */
@RequestMapping(value = "/boards", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> create(BoardDTO board, MultipartHttpServletRequest attachment) {
    Map<String, Object> resultMap = new HashMap<>();
    MultipartFile mFile = null;
    Iterator<String> iter = attachment.getFileNames();
    while (iter.hasNext()) {
        String uploadFile_name = iter.next();
        mFile = attachment.getFile(uploadFile_name);
    }
    try {
        if (mFile != null) {
            if (!mFile.getOriginalFilename().equals("")) {
                FileDTO file = new FileDTO();
                file.setFile_name(mFile.getOriginalFilename());
                file.setFile_data(mFile.getBytes());
                file.setFile_size(mFile.getSize());
                fileMapper.createFile(file);
                board.setFile_id(file.getFile_id());
            } else {
                board.setFile_id(0);
            }
        }
        versionManagementService.createArticle(board);
        resultMap.put("result", "success");
    } catch (Exception e) {
        // TODO: handle exception
        resultMap.put("result", e.getMessage());
        e.printStackTrace();
    }
    return resultMap;
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) FileDTO(com.worksmobile.Assignment.Domain.FileDTO) HashMap(java.util.HashMap) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with FileDTO

use of com.worksmobile.Assignment.Domain.FileDTO in project Assignment by WMPeople.

the class RestController method boardFileDownload.

/**
 * 파일 다온로드 함수 입니다. 게시물 상세보기 기능에서 사용됩니다.
 * @param board_id 첨부파일이 있는 게시물의 board_id
 * @param version 첨부파일이 있는 게시물의 version
 * @param request 요청
 * @param response 응답
 */
@RequestMapping(value = "/boards/download/{file_id}", method = RequestMethod.GET)
public void boardFileDownload(@PathVariable(value = "file_id") int file_id, HttpServletRequest request, HttpServletResponse response) throws Exception {
    FileDTO file = fileMapper.getFile(file_id);
    byte[] fileByte = file.getFile_data();
    response.setContentType("application/octet-stream");
    response.setContentLength(fileByte.length);
    response.setHeader("Content-Disposition", "attachment; fileName=\"" + URLEncoder.encode(file.getFile_name(), "UTF-8") + "\";");
    response.setHeader("Content-Transfer-Encoding", "binary");
    response.getOutputStream().write(fileByte);
    response.getOutputStream().flush();
    response.getOutputStream().close();
}
Also used : FileDTO(com.worksmobile.Assignment.Domain.FileDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

FileDTO (com.worksmobile.Assignment.Domain.FileDTO)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 BoardDTO (com.worksmobile.Assignment.Domain.BoardDTO)2 NodePtrDTO (com.worksmobile.Assignment.Domain.NodePtrDTO)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 BoardHistoryDTO (com.worksmobile.Assignment.Domain.BoardHistoryDTO)1