use of com.worksmobile.Assignment.Domain.NodePtrDTO 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;
}
}
use of com.worksmobile.Assignment.Domain.NodePtrDTO 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.NodePtrDTO 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.NodePtrDTO in project Assignment by WMPeople.
the class VersionManagementServiceMultiThreadTest method testCreateArticle.
@Test
public void testCreateArticle() throws InterruptedException, ExecutionException, JsonProcessingException {
for (int i = 0; i < THREAD_COUNT; i++) {
Thread thread = new Thread(() -> {
try {
BoardDTO copyedBoardDTO = new BoardDTO();
copyedBoardDTO.setSubject(defaultBoardDTO.getSubject());
copyedBoardDTO.setContent(defaultBoardDTO.getContent());
BoardHistoryDTO createdHistoryDTO = versionManagementService.createArticle(copyedBoardDTO);
NodePtrDTO nodePtr = createdHistoryDTO;
BoardHistoryDTO dbHistoryDTO = boardHistoryMapper.getHistory(nodePtr);
Utils.assertConvertToJsonObject(createdHistoryDTO, dbHistoryDTO);
copyedBoardDTO.setNodePtrDTO(nodePtr);
copyedBoardDTO.setCreated(dbHistoryDTO.getCreated());
BoardDTO dbBoardDTO = boardMapper.viewDetail(nodePtr.toMap());
assertEquals(copyedBoardDTO, dbBoardDTO);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
});
threadList.add(thread);
}
}
use of com.worksmobile.Assignment.Domain.NodePtrDTO in project Assignment by WMPeople.
the class VersionManagementServiceMultiThreadTest method testMakeChildWithMultiThread.
@Test
public void testMakeChildWithMultiThread() {
for (int i = 0; i < THREAD_COUNT; i++) {
Thread thread = new Thread(() -> {
try {
for (int j = 0; j < 10; j++) {
NodePtrDTO child = VersionManagementServiceMultiThreadTest.makeChild(versionManagementService, boardMapper, defaultCreatedDTO);
}
} catch (JsonProcessingException e) {
e.printStackTrace();
}
});
threadList.add(thread);
}
}
Aggregations