use of com.worksmobile.Assignment.Domain.BoardDTO 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);
}
use of com.worksmobile.Assignment.Domain.BoardDTO in project Assignment by WMPeople.
the class VersionManagementService method createVersionWithBranch.
private synchronized NodePtrDTO createVersionWithBranch(BoardDTO boardDTO, NodePtrDTO parentPtrDTO, final String status) {
BoardDTO board = boardMapper.viewDetail(parentPtrDTO.toMap());
if (board != null) {
int deletedCnt = boardMapper.boardDelete(parentPtrDTO.toMap());
if (deletedCnt != 1) {
throw new RuntimeException("delete cnt expected 1 but " + deletedCnt);
}
parentPtrDTO = board;
} else {
parentPtrDTO = boardHistoryMapper.getHistory(parentPtrDTO);
}
return createArticleAndHistory(boardDTO, parentPtrDTO.getVersion() + 1, status, parentPtrDTO);
}
use of com.worksmobile.Assignment.Domain.BoardDTO 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;
}
use of com.worksmobile.Assignment.Domain.BoardDTO 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;
}
use of com.worksmobile.Assignment.Domain.BoardDTO in project Assignment by WMPeople.
the class BoardTempMapperTest method makeDefaultBoardDTO.
@Before
public void makeDefaultBoardDTO() {
defaultBoardDTO = new BoardDTO();
defaultBoardDTO.setBoard_id(defaultNodePtr.getBoard_id());
defaultBoardDTO.setSubject("testSub");
defaultBoardDTO.setContent("testCont");
}
Aggregations