in sessions/next24/books-genai-vertex-langchain4j/src/main/java/services/domain/BooksService.java [93:121]
public Integer insertPagesBook(String filePath, String bookTitle) {
//0 = failure, 1 = success
Integer success = 0;
if( filePath == null || filePath.equals("") || bookTitle==null || bookTitle.equals("")) {
return success;
}
Map<String, Object> book = dao.findBook(bookTitle);
if(book.isEmpty()){
return success;
}
BufferedReader reader = null;
Integer bookId = (Integer) book.get("book_id");
logger.info(filePath+" "+bookTitle+" bookId:"+bookId);
try {
//replace with cloud storage eventually
ClassPathResource classPathResource = new ClassPathResource(filePath);
InputStream inputStream = classPathResource.getInputStream();
reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
success = insertPagesBook(reader, bookTitle);
}catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
return success;
}