Search in sources :

Example 1 with BoardHistoryDTO

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

the class VersionManagementService method deleteArticle.

/**
 * 특정 게시글을 삭제합니다. 부모를 모두 삭제합니다. (단, 형제 노드가 존재 할때까지)
 * @param leafPtrDTO 리프 노드만 주어야합니다.
 * @throws NotLeafNodeException 리프 노드가 아닌 것을 삭제할때 발생됨.
 */
@Transactional
public void deleteArticle(NodePtrDTO leafPtrDTO) throws NotLeafNodeException {
    boolean deleteFileBoolean = false;
    if (!isLeaf(leafPtrDTO)) {
        String leafPtrJson = Utils.jsonStringIfExceptionToString(leafPtrDTO);
        throw new NotLeafNodeException("node 정보" + leafPtrJson);
    }
    int deletedCnt = boardMapper.boardDelete(leafPtrDTO.toMap());
    if (deletedCnt != 1) {
        String leafPtrJson = Utils.jsonStringIfExceptionToString(leafPtrDTO);
        throw new RuntimeException("deleteArticle에서 게시글 삭제 실패 leafPtrJson : " + leafPtrJson);
    }
    while (true) {
        BoardHistoryDTO deleteHistoryDTO = boardHistoryMapper.getHistory(leafPtrDTO);
        if (deleteHistoryDTO == null) {
            break;
        }
        NodePtrDTO parentPtrDTO = deleteHistoryDTO.getParentPtrAndRoot();
        int file_id = deleteHistoryDTO.getFile_id();
        if (file_id != 0) {
            int fileCount = boardHistoryMapper.getFileCount(file_id);
            if (fileCount == 1) {
                deleteFileBoolean = true;
            }
        }
        deletedCnt = boardHistoryMapper.deleteHistory(leafPtrDTO);
        if (deletedCnt == 0) {
            throw new RuntimeException("deleteArticle메소드에서 게시글이력 테이블 삭제 에러 deletedCnt : " + deletedCnt);
        }
        if (deleteFileBoolean) {
            deletedCnt = fileMapper.deleteFile(file_id);
            if (deletedCnt != 1) {
                throw new RuntimeException("파일 삭제 에러");
            }
            ;
        }
        List<BoardHistoryDTO> children = boardHistoryMapper.getChildren(parentPtrDTO);
        if (children.size() >= 1) {
            break;
        }
        leafPtrDTO = parentPtrDTO;
    }
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with BoardHistoryDTO

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

the class VersionManagementService method recoverVersion.

// TODO : 생성시에 잎 노드 인지 보장을 하지 않음.
// TODO : 충돌 관리?? 만약 잎 노드가 아닌경우 새로운 게시물 번호로 만들어짐을 유의할것.
/**
 * 버전 복구 기능입니다. board DB및  boardHistory 둘다 등록 됩니다.
 * @param recoverPtr 복구할 버전에 대한 포인터.
 * @param leafPtr 복구 후 부모가 될 리프 포인터.
 * @return 새롭게 등록된 버전에 대한 포인터.
 */
@Transactional
public NodePtrDTO recoverVersion(final NodePtrDTO recoverPtr, final NodePtrDTO leafPtr) {
    BoardHistoryDTO recoverHistoryDTO = null;
    BoardHistoryDTO leafHistoryDTO = null;
    recoverHistoryDTO = boardHistoryMapper.getHistory(recoverPtr);
    leafHistoryDTO = boardHistoryMapper.getHistory(leafPtr);
    if (leafHistoryDTO == null || recoverHistoryDTO == null) {
        String json = "";
        try {
            json = Utils.jsonStringFromObject(leafHistoryDTO);
            json.concat(Utils.jsonStringFromObject(recoverHistoryDTO));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            json = leafHistoryDTO.toString();
            json += recoverHistoryDTO.toString();
        }
        throw new RuntimeException("recoverVersion에서 복구할 게시글 이력이 존재하지 않습니다. \nleafHistoryDTO : " + json);
    }
    BoardDTO recoveredBoardDTO = new BoardDTO(recoverHistoryDTO);
    try {
        recoveredBoardDTO.setContent(Compress.deCompress(recoverHistoryDTO.getHistory_content()));
    } catch (IOException e) {
        e.printStackTrace();
        String json = Utils.jsonStringIfExceptionToString(recoveredBoardDTO);
        throw new RuntimeException("recoverVersion에서 게시글 내용을 압축해제 중 에러 발생. \nrecoveredBoardDTO : " + json);
    }
    String status = String.format("%s(%s)", BoardHistoryDTO.STATUS_RECOVERED, recoverPtr.toString());
    return createVersionWithBranch(recoveredBoardDTO, leafPtr, status);
}
Also used : BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with BoardHistoryDTO

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

the class VersionManagementService method getRelatedHistory.

/**
 * 한 게시글과 연관된 모든 게시글 이력을 반환합니다.
 * @param leafPtrDTO 가져올 리프 노드 포인터.(board_id, version만 사용)
 * @return 연관된 게시글 히스토리들
 * @throws NotLeafNodeException 리프 노드가 아닌 것을 삭제할때 발생됩.
 */
public List<BoardHistoryDTO> getRelatedHistory(NodePtrDTO leafPtrDTO) throws NotLeafNodeException {
    BoardDTO board = boardMapper.viewDetail(leafPtrDTO.toMap());
    if (board == null) {
        String leafPtrJson = Utils.jsonStringIfExceptionToString(leafPtrDTO);
        throw new NotLeafNodeException("leaf node 정보" + leafPtrJson);
    }
    Map<Map.Entry<Integer, Integer>, BoardHistoryDTO> boardHisotryMap = getHistoryMap(board.getRoot_board_id());
    List<BoardHistoryDTO> relatedHistoryList = new ArrayList<>(boardHisotryMap.size());
    NodePtrDTO curPosPtrDTO = leafPtrDTO;
    BoardHistoryDTO leafHistoryDTO;
    do {
        leafHistoryDTO = boardHisotryMap.get(curPosPtrDTO.toBoardIdAndVersionEntry());
        if (leafHistoryDTO == null) {
            String curPosJson = Utils.jsonStringIfExceptionToString(curPosPtrDTO);
            String historyListJson = Utils.jsonStringIfExceptionToString(boardHisotryMap);
            throw new RuntimeException("getRelatedHistory에서 노드 포인트가 history에 존재하지 않음" + curPosJson + "\n" + "listCnt : " + relatedHistoryList.size() + ", content : " + historyListJson);
        }
        relatedHistoryList.add(leafHistoryDTO);
        curPosPtrDTO = leafHistoryDTO.getParentPtrAndRoot();
    } while (leafHistoryDTO.getParent_version() != 0);
    return relatedHistoryList;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) ArrayList(java.util.ArrayList) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO)

Example 4 with BoardHistoryDTO

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

the class VersionManagementService method deleteVersion.

/**
 * 특정 버전에 대한 이력 1개를 삭제합니다. leaf노드이면 게시글도 삭제 됩니다.
 * 부모의 이력은 삭제되지 않음을 유의 해야 합니다.
 * 루트 삭제시에는 루트가 2개 되는 결과를 초래할 수 있습니다.
 * @param deletePtrDTO 삭제할 버전에 대한 정보.
 * @return 새로운 리프 노드의 주소. 새로운 리프노드를 생성하지 않았으면 null을 반환함.
 */
@Transactional
public NodePtrDTO deleteVersion(final NodePtrDTO deletePtrDTO) {
    BoardHistoryDTO deleteHistoryDTO = boardHistoryMapper.getHistory(deletePtrDTO);
    NodePtrDTO parentPtrDTO = deleteHistoryDTO.getParentPtrAndRoot();
    List<BoardHistoryDTO> deleteNodeChildren = boardHistoryMapper.getChildren(deletePtrDTO);
    if (deleteNodeChildren.size() == 0) {
        // 리프 노드라면
        BoardHistoryDTO parentHistoryDTO = boardHistoryMapper.getHistory(parentPtrDTO);
        int deletedCnt = boardMapper.boardDelete(deletePtrDTO.toMap());
        if (deletedCnt != 1) {
            String json = Utils.jsonStringIfExceptionToString(deletePtrDTO);
            throw new RuntimeException("deleteVersion메소드에서 게시글 테이블 삭제 에러 deletedCnt : " + deletedCnt + "\ndeletePtrDTO : " + json);
        }
        ;
        deletedCnt = boardHistoryMapper.deleteHistory(deletePtrDTO);
        if (deletedCnt != 1) {
            String json = Utils.jsonStringIfExceptionToString(deletePtrDTO);
            throw new RuntimeException("deleteVersion메소드에서 게시글이력 테이블 삭제 에러 deletedCnt : " + deletedCnt + "\ndeletePtrDTO : " + json);
        }
        BoardDTO parentDTO = new BoardDTO(parentHistoryDTO);
        List<BoardHistoryDTO> parentChildren = boardHistoryMapper.getChildren(parentDTO);
        if (parentChildren.size() == 0 && parentHistoryDTO.isRoot()) {
            // 루트만 존재하는 경우에는 루트를 지워줍니다.
            deletedCnt = boardHistoryMapper.deleteHistory(parentHistoryDTO);
            if (deletedCnt != 1) {
                String json = Utils.jsonStringIfExceptionToString(parentHistoryDTO);
                throw new RuntimeException("deleteVersion메소드에서 게시글이력 테이블 삭제 에러 deletedCnt : " + deletedCnt + "\ndeletePtrDTO : " + json);
            }
        } else if (parentChildren.size() == 0 && !parentHistoryDTO.isRoot()) {
            // 루트가 아닌 리프 노드는 게시물 게시판에 존재해야 함.
            try {
                String content = Compress.deCompress(parentHistoryDTO.getHistory_content());
                parentDTO.setContent(content);
            } catch (IOException e) {
                e.printStackTrace();
                String history = Utils.jsonStringIfExceptionToString(parentHistoryDTO);
                throw new RuntimeException("deleteVersion메소드에서 압축 해제 실패 \nhistoryDTO : " + history);
            }
            int createdCnt = boardMapper.boardCreate(parentDTO);
            if (createdCnt == 0) {
                throw new RuntimeException("deleteVersion메소드에서 DB의 board테이블 리프 노드를 갱신(board에서)시 발생" + "deleteRowCnt : " + deletedCnt + " createdCnt : " + createdCnt);
            }
            return parentDTO;
        }
    } else // 리프 노드일때 끝
    if (deleteHistoryDTO.isRoot()) {
        throw new RuntimeException("루트는 삭제할 수 없습니다.");
    // TODO : 한꺼번에 업데이트 하는 방법?
    } else {
        // 중간노드 일 경우
        for (BoardHistoryDTO childHistoryDTO : deleteNodeChildren) {
            childHistoryDTO.setParentNodePtrAndRoot(parentPtrDTO);
            updateHistoryParentPtr(childHistoryDTO);
        }
        int deletedCnt = boardHistoryMapper.deleteHistory(deletePtrDTO);
        if (deletedCnt != 1) {
            String json = Utils.jsonStringIfExceptionToString(deletePtrDTO);
            throw new RuntimeException("deleteVersion메소드에서 게시글이력 테이블 삭제 에러 deletedCnt : " + deletedCnt + "\ndeletePtrDTO : " + json);
        }
    }
    return null;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) IOException(java.io.IOException) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with BoardHistoryDTO

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

the class BoardHistoryMapperTest method testUpdateHistory.

@Test
public void testUpdateHistory() throws JsonProcessingException {
    boardHistoryDTO = createBoardHistoryIfNotExists();
    if (boardHistoryDTO.getParent_version() != null) {
        boardHistoryDTO.setParent_version(null);
    } else {
        boardHistoryDTO.setParent_version(1);
    }
    if (boardHistoryDTO.getRoot_board_id() != 1) {
        boardHistoryDTO.setRoot_board_id(1);
    } else {
        boardHistoryDTO.setRoot_board_id(0);
    }
    int updateRtn = boardHistoryMapper.updateHistoryParentAndRoot(boardHistoryDTO);
    assertEquals(1, updateRtn);
    BoardHistoryDTO dbHistoryDTO = boardHistoryMapper.getHistory(defaultNodePtrDTO);
    Utils.assertConvertToJsonObject(boardHistoryDTO, dbHistoryDTO);
}
Also used : 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