use of com.worksmobile.Assignment.Domain.NodePtrDTO in project Assignment by WMPeople.
the class VersionManagementTest method testMakeModifyHasChild.
@Test
public void testMakeModifyHasChild() throws JsonProcessingException {
NodePtrDTO parentPtrDTO = defaultCreatedDTO;
makeChild(parentPtrDTO);
makeChild(parentPtrDTO);
}
use of com.worksmobile.Assignment.Domain.NodePtrDTO 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;
}
use of com.worksmobile.Assignment.Domain.NodePtrDTO in project Assignment by WMPeople.
the class VersionManagementServiceMultiThreadTest method testModifyAndDeleteVersion.
@Test
public void testModifyAndDeleteVersion() throws JsonProcessingException {
int generationCnt = THREAD_COUNT;
List<NodePtrDTO> generation = new ArrayList<>(generationCnt);
generation.add(defaultCreatedDTO);
for (int i = 1; i < generationCnt; i++) {
NodePtrDTO parentPtr = generation.get(i - 1);
NodePtrDTO child = VersionManagementServiceMultiThreadTest.makeChild(versionManagementService, boardMapper, parentPtr);
generation.add(child);
}
BoardDTO modifiedBoardDTO = new BoardDTO();
modifiedBoardDTO.setSubject("modifiedSub");
modifiedBoardDTO.setSubject("modifiedContent");
int i = 0;
for (; i < THREAD_COUNT / 2; i++) {
Thread thread = new Thread(() -> {
int randIdx = (int) (Math.random() * THREAD_COUNT);
NodePtrDTO nodePtrDTO = generation.get(randIdx);
versionManagementService.modifyVersion(modifiedBoardDTO, nodePtrDTO);
});
threadList.add(thread);
}
HashMap<String, Integer> articleListParams = new HashMap<>();
articleListParams.put("offset", 0);
articleListParams.put("noOfRecords", Integer.MAX_VALUE);
int root_board_id = defaultCreatedDTO.getRoot_board_id();
for (; i < THREAD_COUNT; i++) {
Thread thread = new Thread(() -> {
List<BoardDTO> sameRoot = boardMapper.articleList(articleListParams);
sameRoot.removeIf(item -> {
return item.getRoot_board_id() != root_board_id;
});
int maxIdx = sameRoot.size() - 1;
int randIdx = (int) (Math.random() * maxIdx);
NodePtrDTO deletePtrDTO = sameRoot.get(randIdx);
versionManagementService.deleteVersion(deletePtrDTO);
});
threadList.add(thread);
}
}
use of com.worksmobile.Assignment.Domain.NodePtrDTO in project Assignment by WMPeople.
the class VersionManagementServiceMultiThreadTest method makeChild.
public static NodePtrDTO makeChild(VersionManagementService versionManagementService, BoardMapper boardMapper, NodePtrDTO parentPtrDTO) throws JsonProcessingException {
BoardDTO child = new BoardDTO();
child.setSubject("childSub");
child.setContent("childCont");
NodePtrDTO childPtrDTO = versionManagementService.modifyVersion(child, parentPtrDTO);
child.setNodePtrDTO(childPtrDTO);
BoardDTO leapBoardDTO = boardMapper.viewDetail(childPtrDTO.toMap());
assertNotNull(leapBoardDTO);
int parentVersion = parentPtrDTO.getVersion() == null ? 0 : parentPtrDTO.getVersion();
assertEquals((Integer) (parentVersion + 1), childPtrDTO.getVersion());
Utils.assertConvertToJsonObject(child, leapBoardDTO);
return childPtrDTO;
}
use of com.worksmobile.Assignment.Domain.NodePtrDTO in project Assignment by WMPeople.
the class VersionManagementTest method testDeleteArticle.
@Test
public void testDeleteArticle() throws JsonProcessingException, NotLeafNodeException {
NodePtrDTO rootPtrDTO = defaultCreatedDTO;
NodePtrDTO hasChildrenPtrDTO = makeChild(rootPtrDTO);
int childrenCnt = 2;
List<NodePtrDTO> childrenList = new ArrayList<>(childrenCnt);
for (int i = 0; i < childrenCnt; i++) {
childrenList.add(makeChild(hasChildrenPtrDTO));
}
NodePtrDTO hasChildPtrDTO = childrenList.get(0);
NodePtrDTO leapPtrDTO = makeChild(hasChildPtrDTO);
versionManagementService.deleteArticle(leapPtrDTO);
}
Aggregations