From a46ab1fca84fbbd6f5c52ff363c5a7ddf9687ada Mon Sep 17 00:00:00 2001 From: kms Date: Mon, 13 Nov 2023 13:09:31 +0900 Subject: [PATCH] :hammer: fix: add condition for keyword pdf #56 --- .../smart/watchboard/service/SseService.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/smart/watchboard/service/SseService.java b/src/main/java/com/smart/watchboard/service/SseService.java index 19e8031..09e1115 100644 --- a/src/main/java/com/smart/watchboard/service/SseService.java +++ b/src/main/java/com/smart/watchboard/service/SseService.java @@ -2,6 +2,7 @@ import com.itextpdf.text.DocumentException; import com.smart.watchboard.common.support.AwsS3Uploader; +import com.smart.watchboard.domain.Document; import com.smart.watchboard.domain.Note; import com.smart.watchboard.domain.SttData; import com.smart.watchboard.dto.*; @@ -103,14 +104,25 @@ private void sendKeywords(Long documentId, String path) { SseEmitter emitter = emitterRepository.get(documentId); if (emitter != null) { try { - ResponseEntity responseEntity = requestService.requestSTTKeywords(path); - //List keywords = keywordService.createKeywords(responseEntity, documentId); - if (keywordService.findKeywords(documentId) == null) { - keywordService.createKeywords(responseEntity, documentId); + Document document = whiteboardService.findDoc(documentId); + ResponseEntity responseEntity; + if (document.getDataType().equals("pdf")) { + responseEntity = requestService.requestPdfKeywords(path); + if (keywordService.findKeywords(documentId) == null) { + keywordService.createKeywords(responseEntity, documentId); + } else { + keywordService.renewKeywords(responseEntity, documentId); + } + emitter.send(SseEmitter.event().id(String.valueOf(documentId)).name("keywords").data(responseEntity.getBody().getKeywords())); } else { - keywordService.renewKeywords(responseEntity, documentId); + responseEntity = requestService.requestSTTKeywords(path); + if (keywordService.findKeywords(documentId) == null) { + keywordService.createKeywords(responseEntity, documentId); + } else { + keywordService.renewKeywords(responseEntity, documentId); + } + emitter.send(SseEmitter.event().id(String.valueOf(documentId)).name("keywords").data(responseEntity.getBody().getKeywords())); } - emitter.send(SseEmitter.event().id(String.valueOf(documentId)).name("keywords").data(responseEntity.getBody().getKeywords())); } catch (IOException exception) { emitterRepository.deleteById(documentId); emitter.completeWithError(exception);