Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
abbenhoumi
IntegrationProjet
Commits
bcf3760d
Commit
bcf3760d
authored
Apr 10, 2020
by
abbenhoumi
Browse files
Merge branch 'simulation-remplissage' into 'master'
Simulation remplissage See merge request
!6
parents
81039f00
dc88de0e
Pipeline
#6000
failed with stages
in 1 minute and 15 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
bcf3760d
...
...
@@ -59,9 +59,14 @@
<artifactId>
json
</artifactId>
<version>
20190722
</version>
</dependency>
</dependencies>
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
2.8.6
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
src/main/java/isima/f2/RamassagePoubleDepotApplication.java
View file @
bcf3760d
package
isima.f2
;
import
isima.f2.services.ThreadSimulation
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
@@ -8,6 +9,9 @@ public class RamassagePoubleDepotApplication {
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
RamassagePoubleDepotApplication
.
class
,
args
);
System
.
out
.
println
(
"=======================>Le nom du thread principal est "
+
Thread
.
currentThread
().
getName
());
ThreadSimulation
t
=
new
ThreadSimulation
();
t
.
start
();
}
}
src/main/java/isima/f2/contrats/IPoubelle.java
View file @
bcf3760d
...
...
@@ -12,4 +12,6 @@ public interface IPoubelle {
public
Optional
<
Poubelle
>
getPoubelle
(
Long
id
);
public
List
<
Poubelle
>
getPoubelles
();
public
void
viderPoubelle
(
long
id
);
public
void
updateContenuPoubelle
(
long
id
,
double
contenu
);
public
void
creerPoubelle
(
Poubelle
nouvellePoubelle
);
}
src/main/java/isima/f2/controllers/PoubelleController.java
View file @
bcf3760d
...
...
@@ -3,20 +3,16 @@ package isima.f2.controllers;
import
java.util.List
;
import
java.util.Map
;
import
com.google.gson.Gson
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
isima.f2.model.Poubelle
;
import
isima.f2.services.ImpPoubelle
;
@RestController
@RequestMapping
(
"poubelles"
)
@CrossOrigin
(
origins
=
"http://localhost:4200"
)
public
class
PoubelleController
{
@Autowired
...
...
@@ -45,4 +41,20 @@ public class PoubelleController {
public
String
testpost
(
@RequestParam
Map
<
String
,
String
>
allParams
)
{
return
"Les paramètres sont"
+
allParams
.
entrySet
();
}
@PostMapping
(
"/nouvelle"
)
@ResponseBody
public
String
creerPoubelle
(
@RequestParam
Map
<
String
,
String
>
allParams
)
{
String
poubelleJSON
=
allParams
.
get
(
"poubelle"
);
poubelleJSON
=
poubelleJSON
.
replace
(
"Poubelle"
,
""
);
System
.
out
.
println
(
"Poubellllllllllllleeeeeeeee ******** : "
+
poubelleJSON
);
Gson
gson
=
new
Gson
();
Poubelle
nouvellePoubelle
=
gson
.
fromJson
(
poubelleJSON
,
Poubelle
.
class
);
//update poubelle id ===> last id + 1
nouvellePoubelle
.
setId
((
long
)(
poubelles
.
getPoubelles
().
size
()+
1
));
//nouvellePoubelle.setId(6L);
System
.
out
.
println
(
"**************** "
+
nouvellePoubelle
.
toString
()
+
"****************"
);
poubelles
.
creerPoubelle
(
nouvellePoubelle
);
return
"La nouvelle poubelle a été créée avec succes"
;
}
}
src/main/java/isima/f2/dao/IPoubelleDAO.java
View file @
bcf3760d
...
...
@@ -15,4 +15,10 @@ public interface IPoubelleDAO extends JpaRepository<Poubelle, Long> {
@Query
(
"UPDATE Poubelle p SET p.contenu = 0 WHERE p.id = :id"
)
int
updatePoubelleSetCapacityZero
(
@Param
(
"id"
)
long
id
);
@Modifying
@Transactional
@Query
(
"UPDATE Poubelle p SET p.contenu = :contenu WHERE p.id = :id"
)
int
updatePoubelleSetCapacity
(
@Param
(
"id"
)
long
id
,
@Param
(
"contenu"
)
double
contenu
);
}
src/main/java/isima/f2/services/ImpPoubelle.java
View file @
bcf3760d
...
...
@@ -14,7 +14,11 @@ import isima.f2.model.Poubelle;
public
class
ImpPoubelle
implements
IPoubelle
{
@Autowired
IPoubelleDAO
poubelleDAO
;
IPoubelleDAO
poubelleDAO
;
public
ImpPoubelle
(){
}
@Override
public
Poubelle
ajouterPoubelle
(
Poubelle
poubelle
)
{
...
...
@@ -33,7 +37,7 @@ public class ImpPoubelle implements IPoubelle{
@Override
public
Optional
<
Poubelle
>
getPoubelle
(
Long
id
)
{
return
null
;
return
poubelleDAO
.
findById
(
id
)
;
}
@Override
...
...
@@ -46,4 +50,13 @@ public class ImpPoubelle implements IPoubelle{
poubelleDAO
.
updatePoubelleSetCapacityZero
(
id
);
}
@Override
public
void
updateContenuPoubelle
(
long
id
,
double
contenu
)
{
poubelleDAO
.
updatePoubelleSetCapacity
(
id
,
contenu
);
}
@Override
public
void
creerPoubelle
(
Poubelle
nouvellePoubelle
)
{
poubelleDAO
.
save
(
nouvellePoubelle
);
}
}
src/main/java/isima/f2/services/ThreadSimulation.java
0 → 100644
View file @
bcf3760d
package
isima.f2.services
;
import
isima.f2.model.Poubelle
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.Optional
;
public
class
ThreadSimulation
extends
Thread
{
@Autowired
ImpPoubelle
poubelleService
;
public
ThreadSimulation
()
{
super
();
}
public
void
run
()
{
long
nbGenere
;
/*int nbPoubelles = poubelleService.getPoubelles().size();
System.out.println("Le nombre de poubelle dans la base est : " + nbPoubelles);*/
while
(
true
){
//Generation du nombre aléatoire
nbGenere
=
(
long
)(
Math
.
random
()
*
((
5
-
1
)
+
1
))
+
1
;
//Optional<Poubelle> p = poubelleService.getPoubelle(nbGenere);
//System.out.println("Poubelle : " + p.toString());
System
.
out
.
println
(
"=================================> Nombrre generé : "
+
nbGenere
);
//poubelleService.updateContenuPoubelle();
try
{
Thread
.
sleep
(
2000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment