sessions/next24/books-genai-vertex-springai/src/main/java/services/web/DocumentEmbeddingController.java [155:181]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  public ResponseEntity<String> receiveMessage(
      @RequestBody Map<String, Object> body, @RequestHeader Map<String, String> headers) {
    String errorMsg = RequestValidationUtility.validateRequest(body,headers);
    if (!errorMsg.isBlank()) {
      return new ResponseEntity<>(errorMsg, HttpStatus.BAD_REQUEST);
    }

    // get document name and bucket
    String fileName = (String) body.get("name");
    String bucketName = (String) body.get("bucket");

    logger.info("New book uploaded for embedding:" + fileName);

    // read file from Cloud Storage
    long start = System.currentTimeMillis();
    BufferedReader br = cloudStorageService.readFile(bucketName, fileName);
    logger.info("Embedding flow - read book: " + (System.currentTimeMillis() - start) + "ms");

    // add embedding functionality here
    // persist book and pages to AlloyDB
    start = System.currentTimeMillis();
    Integer bookId = booksService.insertBook(fileName);
    booksService.insertPagesBook(br, bookId);
    logger.info("Embedding flow - insert book and pages: " + (System.currentTimeMillis() - start) + "ms");

    return new ResponseEntity<>(HttpStatus.OK);
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



sessions/next24/books-genai-vertex-langchain4j/src/main/java/services/web/DocumentEmbeddingController.java [153:180]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  public ResponseEntity<String> receiveMessage(
      @RequestBody Map<String, Object> body, @RequestHeader Map<String, String> headers) {
    String errorMsg = RequestValidationUtility.validateRequest(body,headers);
    if (!errorMsg.isBlank()) {
      return new ResponseEntity<>(errorMsg, HttpStatus.BAD_REQUEST);
    }

    // get document name and bucket
    String fileName = (String) body.get("name");
    String bucketName = (String) body.get("bucket");

    logger.info("New book uploaded for embedding:" + fileName);

    // read file from Cloud Storage
    long start = System.currentTimeMillis();
    BufferedReader br = cloudStorageService.readFile(bucketName, fileName);
    logger.info("Embedding flow - read book: " + (System.currentTimeMillis() - start) + "ms");

    // add embedding functionality here
    // persist book and pages to AlloyDB
    start = System.currentTimeMillis();
    Integer bookId = booksService.insertBook(fileName);
    booksService.insertPagesBook(br, bookId);
    logger.info("Embedding flow - insert book and pages: " + (System.currentTimeMillis() - start) + "ms");

    // success
    return new ResponseEntity<>(HttpStatus.OK);
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



sessions/fall24/books-genai-vertex-langchain4j/src/main/java/services/web/DocumentEmbeddingController.java [153:180]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  public ResponseEntity<String> receiveMessage(
      @RequestBody Map<String, Object> body, @RequestHeader Map<String, String> headers) {
    String errorMsg = RequestValidationUtility.validateRequest(body,headers);
    if (!errorMsg.isBlank()) {
      return new ResponseEntity<>(errorMsg, HttpStatus.BAD_REQUEST);
    }

    // get document name and bucket
    String fileName = (String) body.get("name");
    String bucketName = (String) body.get("bucket");

    logger.info("New book uploaded for embedding:" + fileName);

    // read file from Cloud Storage
    long start = System.currentTimeMillis();
    BufferedReader br = cloudStorageService.readFile(bucketName, fileName);
    logger.info("Embedding flow - read book: " + (System.currentTimeMillis() - start) + "ms");

    // add embedding functionality here
    // persist book and pages to AlloyDB
    start = System.currentTimeMillis();
    Integer bookId = booksService.insertBook(fileName);
    booksService.insertPagesBook(br, bookId);
    logger.info("Embedding flow - insert book and pages: " + (System.currentTimeMillis() - start) + "ms");

    // success
    return new ResponseEntity<>(HttpStatus.OK);
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



