Skip to content

Commit

Permalink
Ajout des modeles et test de récupération des données
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannBouge committed Jan 26, 2022
1 parent 165f1a3 commit 6f63c06
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 5 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
<groupId>org.example</groupId>
<artifactId>bda-tortoises-races</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.13</version>
</dependency>
</dependencies>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/App.java

This file was deleted.

22 changes: 22 additions & 0 deletions src/main/java/fr/univlyon1/bda/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.univlyon1.bda;


import fr.univlyon1.bda.extern.RaceServiceREST;
import fr.univlyon1.bda.modele.RaceMoment;

public class App {

public static void main(String[] args) {
System.out.println("START APPLICATION...");

RaceServiceREST raceServiceREST = new RaceServiceREST();

try {
RaceMoment raceMoment = raceServiceREST.getRaceMoment();
raceMoment.print();
} catch (Exception e) {
e.printStackTrace();
}

}
}
18 changes: 18 additions & 0 deletions src/main/java/fr/univlyon1/bda/extern/RaceServiceREST.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.univlyon1.bda.extern;

import fr.univlyon1.bda.modele.RaceMoment;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;


public class RaceServiceREST {

RestTemplate restTemplate = new RestTemplate();

public RaceMoment getRaceMoment() throws Exception {
ResponseEntity<RaceMoment> response
= restTemplate.getForEntity("http:https://tortues.ecoquery.os.univ-lyon1.fr/race/tiny", RaceMoment.class);

return response.getBody();
}
}
57 changes: 57 additions & 0 deletions src/main/java/fr/univlyon1/bda/modele/RaceMoment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package fr.univlyon1.bda.modele;


public class RaceMoment {

private float quality;
private float temperature;
private Tortoise[] tortoises;


public RaceMoment(float quality, float temperature, Tortoise[] tortoises) {
this.quality = quality;
this.temperature = temperature;
this.tortoises = tortoises;
}

public void print() {
int i = 0;
String str = "";
while(i < tortoises.length || i < 10) {
str += " { \"id\": "+tortoises[i].getId()+", \"top\": "+tortoises[i].getTop()+", \"position\": "+tortoises[i].getPosition()+" },\n";
i++;
}
System.out.println("\n" +
"{\n" +
" tortoises : [\n" +
str +
" ]," +
" qualite : " + quality + "\n" +
" temperature : " + temperature + "\n" +
"}");
}

public float getQuality() {
return quality;
}

public void setQuality(float quality) {
this.quality = quality;
}

public float getTemperature() {
return temperature;
}

public void setTemperature(float temperature) {
this.temperature = temperature;
}

public Tortoise[] getTortoises() {
return tortoises;
}

public void setTortoises(Tortoise[] tortoises) {
this.tortoises = tortoises;
}
}
38 changes: 38 additions & 0 deletions src/main/java/fr/univlyon1/bda/modele/Tortoise.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fr.univlyon1.bda.modele;

public class Tortoise {

private int id;
private int top;
private int position;

public Tortoise(int id, int top, int position) {
this.id = id;
this.top = top;
this.position = position;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getTop() {
return top;
}

public void setTop(int top) {
this.top = top;
}

public int getPosition() {
return position;
}

public void setPosition(int position) {
this.position = position;
}
}

0 comments on commit 6f63c06

Please sign in to comment.