Skip to content

Commit b9c41ed

Browse files
authored
Merge pull request #299 from KWcapstone/bug/298-마인드맵-업데이트
[Fix] updated node 로직 고치기
2 parents 69f98ae + f3596e6 commit b9c41ed

1 file changed

Lines changed: 29 additions & 12 deletions

File tree

src/main/java/com/kwcapstone/Service/WebSocketService.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,23 @@ public void updateNode(NodeRequstDto nodeRequstDto){
528528
//파일에 덮어씌우기
529529
String result = "";
530530

531+
String projectId = nodeRequstDto.getProjectId();
531532
//node가 null이 아니라면
532533

533534
//1. 바뀐 노드에 대한 키워드도 다시 보내주기(이건 이후에 지워도 됨)
534535
sendMainKeywords(2, nodeRequstDto.getProjectId(), null, nodeRequstDto.getNodes());
535536
sendRecommendedKeywords(2, nodeRequstDto.getProjectId(), nodeRequstDto.getNodes());
536537
result = nodeRequstDto.getNodes();
537538

539+
// 2. nodes 문자열(JSON Array)을 파싱 → List<NodeDto>
540+
List<NodeDto> newNodes;
541+
ObjectMapper mapper = new ObjectMapper();
542+
try {
543+
newNodes = mapper.readValue(nodeRequstDto.getNodes(), new TypeReference<List<NodeDto>>() {});
544+
} catch (IOException e) {
545+
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "노드 JSON 파싱 실패", e);
546+
}
547+
538548

539549
//먼저 파일명부터 생성 및 찾기
540550
String filePath = System.getProperty("java.io.tmpdir") + "/node_" + nodeRequstDto.getProjectId() + ".txt";
@@ -558,23 +568,30 @@ public void updateNode(NodeRequstDto nodeRequstDto){
558568

559569
//덮어씌우기
560570
try (FileWriter writer = new FileWriter(file, false)) {
561-
writer.write(nodeRequstDto.getNodes());
571+
writer.write(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(newNodes));
562572
}
563573
catch (IOException e) {
564574
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "업데이트 노드 저장 중 오류가 발생하였습니다." + e);
565575
}
566576

567577

568-
String fileContent = null;
569-
try {
570-
fileContent = Files.readString(file.toPath(), StandardCharsets.UTF_8);
571-
} catch (IOException e) {
572-
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "변경사항 반영된 노드 스크립트를 읽어오는데 오류가 발생했습니다." + e);
573-
}
574-
575-
messagingTemplate.convertAndSend("/topic/conference/live_on",
576-
Map.of("event", "live_on",
577-
"projectId", nodeRequstDto.getProjectId(),
578-
"node", fileContent));
578+
// String fileContent = null;
579+
// try {
580+
// fileContent = Files.readString(file.toPath(), StandardCharsets.UTF_8);
581+
// } catch (IOException e) {
582+
// throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "변경사항 반영된 노드 스크립트를 읽어오는데 오류가 발생했습니다." + e);
583+
// }
584+
//
585+
// // 4. List<NodeDto>로 변환
586+
// List<NodeDto> newNodes;
587+
// try {
588+
// ObjectMapper mapper = new ObjectMapper();
589+
// newNodes = mapper.readValue(nodesJson, new TypeReference<List<NodeDto>>() {});
590+
// } catch (IOException e) {
591+
// throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "노드 역직렬화 실패", e);
592+
// }
593+
594+
messagingTemplate.convertAndSend("/topic/conference/"+ projectId,
595+
new NodeUpdateResponseDto("live_on_node", projectId, newNodes));
579596
}
580597
}

0 commit comments

Comments
 (0)