diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index d63dcda..9ca34f0 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -3,7 +3,11 @@
+
+
+
+
\ No newline at end of file
diff --git a/MoviesWebApp/src/main/java/at/technikumwien/movies/MoviesService.java b/MoviesWebApp/src/main/java/at/technikumwien/movies/MoviesService.java
index d6878e8..f562a1f 100644
--- a/MoviesWebApp/src/main/java/at/technikumwien/movies/MoviesService.java
+++ b/MoviesWebApp/src/main/java/at/technikumwien/movies/MoviesService.java
@@ -68,64 +68,68 @@ public class MoviesService {
// TODO maybe check if the movie already exists?
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void save(Movies movie) {
+ public void save(List movies) {
- // TODO maybe get just the id and improve checking in for loop?
- // Get all actors and studios from the database
- List allActors = findAllActors();
- List allStudios = findAllStudios();
+ for (Movies movie : movies) {
- try {
- // Get studio for the movie from the database
- Studios movieStudio = movie.getStudio();
+ // TODO maybe get just the id and improve checking in for loop?
+ // Get all actors and studios from the database
+ List allActors = findAllActors();
+ List allStudios = findAllStudios();
- // If the studio is missing in the database, roll back only
- for (Studios studio : allStudios) {
- if (studio.getName().equals(movieStudio.getName()) & studio.getCountrycode().equals(movieStudio.getCountrycode())
- & studio.getPostcode().equals(movieStudio.getPostcode())) {
- // Set id
- movieStudio.setId(studio.getId());
- }
- }
- if (movieStudio.getId() == null) {
- LOGGER.info("Rollback! Movie studio: " + movieStudio);
- context.setRollbackOnly();
- return;
- }
+ try {
+ // Get studio for the movie from the database
+ Studios movieStudio = movie.getStudio();
- // TODO use also birthday
- // Get actor for the movie from the database
- for (Actors movieActor : movie.getActors()) {
- LOGGER.info("Get an actor " + movieActor);
- List actorListResult = em.createNamedQuery("Actors.getIdByProperties", Actors.class)
- .setParameter("firstname", movieActor.getFirstname())
- .setParameter("lastname", movieActor.getLastname())
- .setParameter("sex", movieActor.getSex())
- //.setParameter("birthdate", movieActor.getBirthdate())
- .getResultList();
-
- // If any actor is missing in the database, roll back only
- for (Actors actor : allActors) {
- if (actor.getFirstname().equals(movieActor.getFirstname())
- & actor.getLastname().equals(movieActor.getLastname())
- & actor.getSex().equals(movieActor.getSex())) {
- // & actor.getBirthdate().equals(movieActor.getBirthdate())) {
+ // If the studio is missing in the database, roll back only
+ for (Studios studio : allStudios) {
+ if (studio.getName().equals(movieStudio.getName()) & studio.getCountrycode().equals(movieStudio.getCountrycode())
+ & studio.getPostcode().equals(movieStudio.getPostcode())) {
// Set id
- movieActor.setId(actor.getId());
- }
- if (movieActor.getId() == null) {
- LOGGER.info("Rollback! Movie actor: " + movieActor);
- context.setRollbackOnly();
- return;
+ movieStudio.setId(studio.getId());
}
}
+ if (movieStudio.getId() == null) {
+ LOGGER.info("Rollback! Movie studio: " + movieStudio);
+ context.setRollbackOnly();
+ return;
+ }
- LOGGER.info("save() >> movies" + movie);
- em.merge(movie);
+ // TODO use also birthday
+ // Get actor for the movie from the database
+ for (Actors movieActor : movie.getActors()) {
+ LOGGER.info("Get an actor " + movieActor);
+ List actorListResult = em.createNamedQuery("Actors.getIdByProperties", Actors.class)
+ .setParameter("firstname", movieActor.getFirstname())
+ .setParameter("lastname", movieActor.getLastname())
+ .setParameter("sex", movieActor.getSex())
+ //.setParameter("birthdate", movieActor.getBirthdate())
+ .getResultList();
+
+ // If any actor is missing in the database, roll back only
+ for (Actors actor : allActors) {
+ if (actor.getFirstname().equals(movieActor.getFirstname())
+ & actor.getLastname().equals(movieActor.getLastname())
+ & actor.getSex().equals(movieActor.getSex())) {
+ // & actor.getBirthdate().equals(movieActor.getBirthdate())) {
+ // Set id
+ movieActor.setId(actor.getId());
+ }
+ if (movieActor.getId() == null) {
+ LOGGER.info("Rollback! Movie actor: " + movieActor);
+ context.setRollbackOnly();
+ return;
+ }
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
}
}
- catch (Exception e) {
- e.printStackTrace();
+ LOGGER.info("save() >> movies" + movies);
+ for (Movies movie : movies) {
+ em.merge(movie);
}
}
}
\ No newline at end of file
diff --git a/MoviesWebApp/src/main/java/at/technikumwien/movies/MoviesWebServiceImpl.java b/MoviesWebApp/src/main/java/at/technikumwien/movies/MoviesWebServiceImpl.java
index f2cc611..7f4622f 100644
--- a/MoviesWebApp/src/main/java/at/technikumwien/movies/MoviesWebServiceImpl.java
+++ b/MoviesWebApp/src/main/java/at/technikumwien/movies/MoviesWebServiceImpl.java
@@ -28,8 +28,6 @@ public class MoviesWebServiceImpl implements MoviesWebService {
@Override
public void importMovies(List movies) {
- for (Movies movie : movies) {
- moviesService.save(movie);
- }
+ moviesService.save(movies);
}
}