Search in sources :

Example 21 with BoardHistoryDTO

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

the class BoardHistoryMapperTest method testGetHistoryByRootBoardId.

@Test
public void testGetHistoryByRootBoardId() throws JsonProcessingException {
    int relatedCnt = 6;
    List<BoardHistoryDTO> createdSameRootList = new ArrayList<>(relatedCnt);
    boardHistoryDTO = createBoardHistoryIfNotExists();
    BoardHistoryDTO firstEle = boardHistoryMapper.getHistory(boardHistoryDTO);
    createdSameRootList.add(firstEle.clone());
    for (int i = 0; i < relatedCnt - 1; i++) {
        boardHistoryDTO.setParentNodePtrAndRoot(boardHistoryDTO);
        boardHistoryDTO.setVersion(boardHistoryDTO.getVersion() + 1);
        boardHistoryMapper.createHistory(boardHistoryDTO);
        BoardHistoryDTO dbEle = boardHistoryMapper.getHistory(boardHistoryDTO);
        createdSameRootList.add(dbEle.clone());
    }
    List<BoardHistoryDTO> sameRoot = boardHistoryMapper.getHistoryByRootBoardId(boardHistoryDTO.getRoot_board_id());
    assertEquals(relatedCnt, sameRoot.size());
    for (int i = 0; i < relatedCnt; i++) {
        BoardHistoryDTO createdEle = createdSameRootList.get(i);
        BoardHistoryDTO mapperEle = sameRoot.get(i);
        Utils.assertConvertToJsonObject(createdEle, mapperEle);
    }
}
Also used : ArrayList(java.util.ArrayList) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with BoardHistoryDTO

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

the class CompressTest method testDBEquals.

@Test
public void testDBEquals() throws IOException {
    HashMap<String, Integer> map = new HashMap<>();
    map.put("offset", 0);
    map.put("noOfRecords", 1000);
    List<BoardDTO> boardList = boardMapper.articleList(map);
    List<String> contentStrList = new ArrayList<>(boardList.size());
    List<byte[]> historyContentList = new ArrayList<>(boardList.size());
    List<Boolean> compressResult = new ArrayList<>(boardList.size());
    List<Boolean> decompressResult = new ArrayList<>(boardList.size());
    for (BoardDTO boardDTO : boardList) {
        contentStrList.add(boardDTO.getContent());
        BoardHistoryDTO historyDTO = boardHistoryMapper.getHistory(boardDTO);
        assertNotNull(historyDTO);
        historyContentList.add(historyDTO.getHistory_content());
    }
    for (int i = 0; i < boardList.size(); i++) {
        byte[] compressedBytes = Compress.compress(contentStrList.get(i));
        String deCompressed = Compress.deCompress(historyContentList.get(i));
        compressResult.add(Arrays.equals(compressedBytes, historyContentList.get(i)));
        decompressResult.add(deCompressed == null ? (contentStrList.get(i) == null ? true : false) : deCompressed.equals(contentStrList.get(i)));
    }
    boolean allResult = false;
    for (int i = 0; i < boardList.size(); i++) {
        if (!compressResult.get(i)) {
            System.out.println(i + "에러 인가??");
        // allResult = true;
        }
        if (!decompressResult.get(i)) {
            System.out.println(i + "에러");
            allResult = true;
        }
    }
    assertFalse(allResult);
}
Also used : HashMap(java.util.HashMap) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) ArrayList(java.util.ArrayList) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with BoardHistoryDTO

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

the class RestController method versionManagement.

/**
 * 버전관리 페이지 이동시 호출되는 메쏘드입니다.
 * @param board_id 버전관리를 원하는 LeafNode의 board_id
 * @param version 버전관리를 원하는 LeafNode의 version
 * @return modelAndView LeafNode의 이력 List를 프론트에 전송합니다.
 * @throws Exception
 */
@RequestMapping(value = "/boards/management/{board_id}/{version}", method = RequestMethod.GET)
public ModelAndView versionManagement(@PathVariable(value = "board_id") int board_id, @PathVariable(value = "version") int version) throws Exception {
    NodePtrDTO leapPtrDTO = new NodePtrDTO(board_id, version);
    List<BoardHistoryDTO> boardHistory = versionManagementService.getRelatedHistory(leapPtrDTO);
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("list", boardHistory);
    modelAndView.setViewName("versionManagement");
    return modelAndView;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) ModelAndView(org.springframework.web.servlet.ModelAndView) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with BoardHistoryDTO

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

the class RestController method versionDestory.

/**
 * 버전 삭제시 호출 되는 메쏘드 입니다.
 * @param board_id 버전 삭제를 원하는 이력의 board_id
 * @param version 버전 삭제를 원하는 이력의 version
 * @return 성공 했는지 실패 했는지를 알려주는 Map을 리턴합니다.
 */
@RequestMapping(value = "/boards/version/{board_id}/{version}", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, Object> versionDestory(@PathVariable(value = "board_id") int board_id, @PathVariable(value = "version") int version) {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    try {
        NodePtrDTO deletePtrDTO = new NodePtrDTO(board_id, version);
        BoardHistoryDTO deleteHistoryDTO = boardHistoryMapper.getHistory(deletePtrDTO);
        int file_id = deleteHistoryDTO.getFile_id();
        int fileCount = 0;
        if (file_id != 0) {
            fileCount = boardHistoryMapper.getFileCount(file_id);
        }
        if (fileCount == 1) {
            int deletedCnt2 = fileMapper.deleteFile(file_id);
            if (deletedCnt2 != 1) {
                throw new RuntimeException("파일 삭제 에러");
            }
            ;
        }
        versionManagementService.deleteVersion(deletePtrDTO);
        resultMap.put("result", "success");
    } catch (Exception e) {
        resultMap.put("result", e.getMessage());
        return resultMap;
    }
    return resultMap;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) HashMap(java.util.HashMap) 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 25 with BoardHistoryDTO

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

the class VersionManagementTest method testCreateArticle.

@Test
public void testCreateArticle() throws InterruptedException, ExecutionException, JsonProcessingException {
    BoardHistoryDTO dbHistoryDTO = defaultCreatedDTO;
    Utils.assertConvertToJsonObject(defaultCreatedDTO, dbHistoryDTO);
    defaultBoardDTO.setNodePtrDTO(dbHistoryDTO);
    BoardDTO dbBoardDTO = boardMapper.viewDetail(dbHistoryDTO.toMap());
    Utils.assertConvertToJsonObject(defaultBoardDTO, dbBoardDTO);
}
Also used : BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

BoardHistoryDTO (com.worksmobile.Assignment.Domain.BoardHistoryDTO)27 Test (org.junit.Test)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)17 NodePtrDTO (com.worksmobile.Assignment.Domain.NodePtrDTO)16 BoardDTO (com.worksmobile.Assignment.Domain.BoardDTO)12 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)3 Transactional (org.springframework.transaction.annotation.Transactional)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 FileDTO (com.worksmobile.Assignment.Domain.FileDTO)1