Search in sources :

Example 11 with BoardHistoryDTO

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

the class VersionManagementTest method testDeleteWhenHasChildNode.

@Test
public void testDeleteWhenHasChildNode() throws JsonProcessingException {
    NodePtrDTO rootPtrDTO = defaultCreatedDTO;
    NodePtrDTO middlePtrDTO = makeChild(rootPtrDTO);
    NodePtrDTO childPtrDTO = makeChild(middlePtrDTO);
    versionManagementService.deleteVersion(middlePtrDTO);
    BoardHistoryDTO childHistoryDTO = boardHistoryMapper.getHistory(childPtrDTO);
    NodePtrDTO childParentPtrDTO = childHistoryDTO.getParentPtrAndRoot();
    assertEquals(rootPtrDTO, childParentPtrDTO);
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with BoardHistoryDTO

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

the class VersionManagementTest method testGetRelatedHistoryWhenDifferentBoardId.

@Test
public void testGetRelatedHistoryWhenDifferentBoardId() throws JsonProcessingException, NotLeafNodeException {
    List<NodePtrDTO> leafToRoot = new ArrayList<>();
    NodePtrDTO rootPtrDTO = defaultCreatedDTO;
    leafToRoot.add(rootPtrDTO);
    @SuppressWarnings("unused") NodePtrDTO middle1 = makeChild(rootPtrDTO);
    NodePtrDTO middle2 = makeChild(rootPtrDTO);
    leafToRoot.add(middle2);
    NodePtrDTO child = makeChild(middle2);
    leafToRoot.add(child);
    List<BoardHistoryDTO> relatedHistoryList = versionManagementService.getRelatedHistory(child);
    assertEquals(relatedHistoryList.size(), leafToRoot.size());
    leafToRoot.sort(compareNodePtrDTO);
    relatedHistoryList.sort(compareNodePtrDTO);
    for (int i = 0; i < relatedHistoryList.size(); i++) {
        NodePtrDTO relatedEle = relatedHistoryList.get(i);
        NodePtrDTO addedEle = leafToRoot.get(i);
        assertEquals(relatedEle, addedEle);
    }
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) ArrayList(java.util.ArrayList) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with BoardHistoryDTO

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

the class VersionManagementTest method testCreateSevenHundredThousandTextContentArticle.

@Test
public void testCreateSevenHundredThousandTextContentArticle() throws JsonProcessingException, InterruptedException, ExecutionException {
    StringBuilder sevenHundredContent = new StringBuilder();
    for (int i = 0; i < 700000; i++) {
        sevenHundredContent.append(i % 10);
    }
    defaultBoardDTO = new BoardDTO();
    defaultBoardDTO.setSubject("칠십만자가 들어가있습니다");
    defaultBoardDTO.setContent(sevenHundredContent.toString());
    defaultCreatedDTO = versionManagementService.createArticle(defaultBoardDTO);
    NodePtrDTO nodePtr = defaultCreatedDTO;
    BoardHistoryDTO dbHistoryDTO = boardHistoryMapper.getHistory(nodePtr);
    Utils.assertConvertToJsonObject(defaultCreatedDTO, dbHistoryDTO);
    defaultBoardDTO.setNodePtrDTO(nodePtr);
    defaultBoardDTO.setCreated(dbHistoryDTO.getCreated());
    BoardDTO dbBoardDTO = boardMapper.viewDetail(nodePtr.toMap());
    Utils.assertConvertToJsonObject(defaultBoardDTO, dbBoardDTO);
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with BoardHistoryDTO

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

the class VersionManagementService method createArticleAndHistory.

/**
 *  충돌 영역! 게시판 DB 와 이력 DB 에 둘다 등록합니다.
 *  게시판 id를 1증가 시켜 작성합니다.
 * @param article 등록할 게시물의 제목, 내용, 첨부파일이 사용됩니다.
 * @param version 새로운 게시물의 버전
 * @param status 게시물 이력의 상태에 들어갈 내용
 * @param compressedContent 압축된 내용
 * @param parentNodePtr 게시물의 부모 노드 포인터
 * @return 새롭게 생성된 게시글 이력 DTO
 */
private synchronized BoardHistoryDTO createArticleAndHistory(BoardDTO article, int version, final String status, final byte[] compressedContent, final NodePtrDTO parentNodePtr) {
    int last_board_id = boardMapper.getMaxBoardId() + 1;
    NodePtrDTO newNodePtrDTO = new NodePtrDTO(last_board_id, version);
    if (parentNodePtr.getRoot_board_id() == 0) {
        parentNodePtr.setRoot_board_id(last_board_id);
    }
    BoardHistoryDTO boardHistoryDTO;
    if (version == 0) {
        BoardHistoryDTO rootHistoryDTO = new BoardHistoryDTO(new BoardDTO(), newNodePtrDTO, BoardHistoryDTO.STATUS_ROOT);
        int insertedRowCnt = boardHistoryMapper.createHistory(rootHistoryDTO);
        if (insertedRowCnt != 1) {
            String json = Utils.jsonStringIfExceptionToString(rootHistoryDTO);
            throw new RuntimeException("createArticleAndHistory메소드에서 게시글 이력 추가 에러 insertedRowCnt : " + insertedRowCnt + "\ndeletePtrDTO : " + json);
        }
        boardHistoryDTO = new BoardHistoryDTO(article, newNodePtrDTO, status);
        boardHistoryDTO.setVersion(1);
        boardHistoryDTO.setHistory_content(compressedContent);
        boardHistoryDTO.setParentNodePtrAndRoot(rootHistoryDTO);
        boardHistoryDTO.setRoot_board_id(newNodePtrDTO.getBoard_id());
        insertedRowCnt = boardHistoryMapper.createHistory(boardHistoryDTO);
        if (insertedRowCnt != 1) {
            String json = Utils.jsonStringIfExceptionToString(rootHistoryDTO);
            throw new RuntimeException("createArticleAndHistory메소드에서 게시글 이력 추가 에러 insertedRowCnt : " + insertedRowCnt + "\ndeletePtrDTO : " + json);
        }
    } else {
        boardHistoryDTO = new BoardHistoryDTO(article, newNodePtrDTO, status);
        boardHistoryDTO.setHistory_content(compressedContent);
        boardHistoryDTO.setParentNodePtrAndRoot(parentNodePtr);
        int insertedRowCnt = boardHistoryMapper.createHistory(boardHistoryDTO);
        if (insertedRowCnt == 0) {
            throw new RuntimeException("createArticle메소드에서 createHistory error" + boardHistoryDTO);
        }
    }
    NodePtrDTO nodePtr = boardHistoryDTO;
    article.setNodePtrDTO(nodePtr);
    article.setCreated(boardHistoryDTO.getCreated());
    int insertedRowCnt = boardMapper.boardCreate(article);
    if (insertedRowCnt == 0) {
        throw new RuntimeException("createArticle메소드에서 boardCreate error" + boardHistoryDTO);
    }
    return boardHistoryDTO;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO)

Example 15 with BoardHistoryDTO

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

the class VersionManagementService method getHistoryMap.

private Map<Map.Entry<Integer, Integer>, BoardHistoryDTO> getHistoryMap(int root_board_id) {
    List<BoardHistoryDTO> historyList = boardHistoryMapper.getHistoryByRootBoardId(root_board_id);
    Map<Map.Entry<Integer, Integer>, BoardHistoryDTO> historyMap = new HashMap<>();
    for (BoardHistoryDTO ele : historyList) {
        historyMap.put(ele.toBoardIdAndVersionEntry(), ele);
    }
    return historyMap;
}
Also used : HashMap(java.util.HashMap) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO)

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