Пример #1
0
 private void populateModel(final Map<String, Object> model, final Actor actor) {
   if (actor == null) {
     model.put("actorName", "No actor found");
     model.put("kevinBaconNumber", "");
     model.put("movieTitles", Collections.emptyList());
   } else {
     model.put("actorName", actor.getName());
     final List<?> baconPathList = imdbService.getBaconPath(actor);
     model.put("kevinBaconNumber", baconPathList.size() / 2);
     final Collection<MovieInfo> movieInfo = new TreeSet<MovieInfo>();
     for (Movie movie : actor.getMovies()) {
       movieInfo.add(new MovieInfo(movie, actor.getRole(movie)));
     }
     model.put("movieInfo", movieInfo);
     final List<String> baconPath = new LinkedList<String>();
     for (Object actorOrMovie : baconPathList) {
       if (actorOrMovie instanceof Actor) {
         baconPath.add(((Actor) actorOrMovie).getName());
       } else if (actorOrMovie instanceof Movie) {
         baconPath.add(((Movie) actorOrMovie).getTitle());
       }
     }
     model.put("baconPath", baconPath);
   }
 }
Пример #2
0
 @Override
 @Transactional
 public void getModel(final Object command, final Map<String, Object> model)
     throws ServletException {
   final String name = ((ActorForm) command).getName();
   final Actor actor = imdbService.getActor(name);
   populateModel(model, actor);
 }