Skip to content

simulations v1.0

Albert edited this page May 6, 2024 · 45 revisions

Project overview

  • Add MongoDB NoSQL to Spring Boot simulations
  • player @Entity 1:n imagePlayer @Document
  • MongoDB dependency
  • application.properties configuration: string connection
  • MongoRepository and Service
  • H2 local (download install and create a local H2 DB)

Project structure

image

image

Commit with new changes

image

H2 DB Local

  1. Download the H2 database: Go to the H2 database website at H2 DB and download the latest version of the H2 database for Linux. You can download either the ZIP or the TAR package.

  2. Extract the downloaded file: Open the terminal and navigate to the folder where you downloaded the H2 database. Extract the contents of the downloaded file using the following command:

tar -zxvf h2-*.tar.gz
  1. Start the H2 database server: Navigate to the H2 database directory and start the H2 database server by running the following command:
java -jar h2*.jar
cd <download directory>
unzip h2*.zip
cd h2/bin
chmod +x h2.s

This will start the H2 database server and display the URL where the H2 database can be accessed.

  1. Check the H2 database console: Open a web browser and enter the URL displayed in the terminal. The H2 database web interface will open in the browser.

  2. Create a new database: In the H2 database web interface, click on the "Create a new database" button and follow the prompts to create a new database

image

once the button is clicked the db is created, remember the data configuration, you will need to configure application.properties:

image

  1. Connect to the new database: Once the new database is created, click on the "Connect" button in the H2 database web interface and introduce the right parameters.

image

Saved Settings: Generic H2 (Server)
Setting Name: Generic H2 (Server)
  
Driver Class: org.h2.Driver
JDBC URL: jdbc:h2:/home/albert/MyProjects/DataBase/db-instances/simulationsdb

User Name: albert
Password: ••••
  1. Use the H2 database: Now you can start using the H2 database. You can create tables, insert data, and perform queries using SQL commands. Configure the application.properties file.

image

and after that spring.jpa.hibernate.ddl-auto=none

image

because schema db has already created!

image

MongoDB

Create DB & Collection

String Connection

SRV Connection Format MongoDB supports a DNS-constructed seed list. Using DNS to construct the available servers list allows more flexibility of deployment and the ability to change the servers in rotation without reconfiguring clients.

Network access

image

Database Access

image

image

POM

pom.xml

  • dependencies: mongoDB
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-data-mongodb</artifactId>
	</dependency>
	
#MongoDB_DATASOURCE
spring.data.mongodb.uri=mongodb+srv://simulationUser:1234@clustertest.138fac.mongodb.net/
spring.data.mongodb.database=simulations

image

  1. protocol: mongodb+srv:
  2. user: simulationUser
  3. password: 1234
  4. cluster: clustertest
  5. Hash cluster: 138fac
  6. DB: simulations

Model

Entities

imagePlayer

package com.example.demo.model;
import org.bson.types.Binary;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "imagePlayer")
public class ImagePlayer {

    @Id
    private String id;
    private String playerId;
    //private String nameImage;
    private String imageName;
    private String type;
    private Double size;
    //private Binary dataImage;
    private Binary imageData;
}

Player

// imports ....
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Player {

    @Id
    private String id;
    private String player;
    private int age;
    private boolean active;

    private List<String> imagePlayerIds = new ArrayList<>();

// methods ...

player 1:n imagePlayer

image

image

Note

To populate the db we should modify RunnerFillingDB and update schema. Once we have fake-data on local and cloud we MUST set DDL to none.

We are going to create upload method: both classes, Player and ImagePlayer will share ids in a one-to-many relationship.

  • Player will be stored at local H2 SQL DB.
  • ImagePlayer will be stored at MongoDB Cloud noSQL DB.

The code is designed to:

  • retrieve a player by its ID from a player repository.
  • It then checks if the player exists and sets the player ID for the new imagePlayer @Document.
  • If the player exists, it saves the imagePLayer @Document to the imagePlayer repository and adds the imagePlayer ID to the player’s list of imagePlayer IDs,
  • and then saves the updated player.

Repository

package com.example.demo.repository;

import com.example.demo.model.ImagePlayer;
import org.springframework.data.mongodb.repository.MongoRepository;

public interface ImagePlayerRepository  extends MongoRepository<ImagePlayer, String> {

    //WE SHOULD MAKE SOME DERIVATED QUERIES
}

RestController

uploadImage

// imports ...

@RestController
@RequestMapping("/api/v1/imagePlayer")
public class ImagePlayerController {

    @Autowired
    PlayerRepository playerRepository;
    @Autowired
    ImagePlayerRepository imagePlayerRepository;
    @Autowired
    ImagePlayerService imagePlayerService;

    //https://github.com/AlbertProfe/CifoJava2023/blob/1ae3bdbc654df8f25658acf177e8d6b65e6c6c55/LibraryManagementRest/src/main/java/com/example/myFirstSpring/restcontroller/BookImageRestController.java
    @PostMapping("/uploadImage")
    public ResponseEntity<ImagePlayer> uploadImage(@RequestParam String playerId,
                                                   @RequestParam String imageName,
                                                   @RequestParam MultipartFile file) throws IOException {
        //to do: add headers
        //HttpHeaders headers = new HttpHeaders();
        // Finds a playerId in the player repository by its ID, if present.
        Optional<Player> player = playerRepository.findById(playerId);
        //check playerId exist ....
        if (player.isPresent()) {
            //create object
            ImagePlayer imagePlayer = new ImagePlayer();
            // create UUID and set object
            String imagePlayerId = UUID.randomUUID().toString();
            imagePlayer.setId(imagePlayerId);
            imagePlayer.setPlayerId(playerId);
            imagePlayer.setImageName(imageName);
            //set file to field
            //to do: try & catch
            imagePlayer.setImageData(new Binary(file.getBytes()));
            //assign UUID imagePlayer created to player within ids list
            player.get().addImagePlayerId(imagePlayerId);
            //save Document to mongoDB
            imagePlayerRepository.save(imagePlayer);
            //save Entity to H2 local
            playerRepository.save(player.get());

            //return imagePlayer to API rest
            return ResponseEntity.accepted().body(imagePlayer);

        } else {
            return ResponseEntity.notFound().build();

        }

    }

// other methods restcontroller ...

}

getImageById

   @GetMapping("/getImageById")
    public ResponseEntity<byte[]> getImage(@RequestParam String id){

        Optional<ImagePlayer> imagePlayer = imagePlayerRepository.findById(id);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.IMAGE_PNG);

        if (imagePlayer.isPresent())
            return new ResponseEntity<>( imagePlayer.get().getImageData().getData(), headers, HttpStatus.OK );
        else  return ResponseEntity.notFound().build();
    }

Service

package com.example.demo.service;

import com.example.demo.model.ImagePlayer;
import com.example.demo.repository.ImagePlayerRepository;
import com.github.javafaker.Faker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Service
public class ImagePlayerService {

    @Autowired
    ImagePlayerRepository imagePlayerRepository;


    public List<ImagePlayer> findAllImages (){
        return imagePlayerRepository.findAll();
    }

    public Optional<ImagePlayer> findById (String id){
        return imagePlayerRepository.findById(id);
    }

    public ImagePlayer createImagePlayer (ImagePlayer imagePlayer){
        return imagePlayerRepository.save(imagePlayer);
    }

    public void deleteAll (){
        imagePlayerRepository.deleteAll();
    }

    public void deleteById (String id){
        imagePlayerRepository.deleteById(id);
    }

    // to-do: update ImagePlayer

    public List<ImagePlayer> populate (){

        List<ImagePlayer> imagePlayers = new ArrayList<>();

        Faker faker = new Faker();

        for (int i= 0; i < 10; i++){

            ImagePlayer imagePlayer = new ImagePlayer();
            imagePlayer.setId( UUID.randomUUID().toString());
            imagePlayer.setNameImage(faker.funnyName().name());
            imagePlayer.setType("BYTE RAW BASE64");
            imagePlayer.setSize(faker.number().randomDouble(2, 100, 300));

            imagePlayers.add(imagePlayer);
            imagePlayerRepository.save(imagePlayer);


        }

        return imagePlayers;

    }

}

RunningFillingDB

Note

To populate the db we should modify RunnerFillingDB

image

Output

Create connection and populate mongoDB

Sprint Boot console

image

MongoDB console

image

upload Image from Postman

First at all, we are working with local/cloud DB, so once DBs are populated we don't need to populate anymore:

public void run(ApplicationArguments args) throws Exception {

        //populate_H2_DB();
        //testSimulationsMongoDB();
    }

player whom to add an image avatar:

TRUE	37	13b67b18-5718-4ed2-ac1c-c95c47558ab7	Raphael

select image Request from Postman

then, from Postam we select a PNG from local machine.

So, we need a image png.

image

Then in Postman we set the request params:

image

And set file type to upload:

image

image

image

image

send Request

Eventually, when params and image are set, we send the request:

image

JSON response

{
    "id": "c8521e15-5d4d-4991-8242-27fc10a8ec9f",
    "imageName": "avatar raphael",
    "type": null,
    "size": null,
    "imageData": {
        "type": 0,
        "data": "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8t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e9KcAwTFi6f7TnUArkVooSTPgTg/2odacHCGAS1ALvBjFi9aRGkksBlpT668Xjx+UywGRUJUKZdd/akJvBXx7s/fFfzZeX9zm9PNOQuVyvwI1QMHGkvIiJM6m5B8v4Uk0GAynwpBEcGrhLmuPd8BqayEI8xq7MSjBBn3Mz77WnAl5XNn2MfFLNUhKrivw77v9L92IViXg0MkmHwlgjGySoOQwLh4m8otWWi6XM83fXxJPy8AluY+tB+G92xM8j/SfBZlhh5wYUkUsjmrf8Tsb+FP1bedN34B+vhoxA26jNNjPYBJqbkfSC961+LePOtK2TcvAZ8Sa0355YPcfVQnODu6B6fiTZg3gUsqtu6GZ/fxJvjEnZh9Kvnn1XxDnIo8uDnGr6f8Ap8S9aBbyfYVejgvEfp8S8zHUQ/fBN/3EP8+JepF+7LH7rMKXq+JEs9Iv64IeY8R/q2XWOWMa6OzvXT8H9r/Mf2v81/a/w39p/wCA/tDoiCiL/v8AF/gvJXU9a/E5nG1P1wR9WeB/bdO9nG4Xl7PxDDJiUpTzZ+JD/wAaH/eCE8nqv1bp3s41C8h7+fJ/2g/xwJIs5fFunezjUNyT8f8A/9k="
    },
    "playerId": "13b67b18-5718-4ed2-ac1c-c95c47558ab7"
}

imagePlayer on mongoDB:

_id
"c8521e15-5d4d-4991-8242-27fc10a8ec9f"
imageName
"avatar raphael"
imageData
Binary.createFromBase64('/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYn…', 0)
playerId
"13b67b18-5718-4ed2-ac1c-c95c47558ab7"
_class
"com.example.demo.model.ImagePlayer"

image

player updated on H2 local:

image

getImageById

imagePlayerId to find: c8521e15-5d4d-4991-8242-27fc10a8ec9f

http://localhost:8089/api/v1/imagePlayer/getImageById?id=c8521e15-5d4d-4991-8242-27fc10a8ec9f

image