Coverage Report - org.jtheque.films.services.impl.ActorService
 
Classes in this File Line Coverage Branch Coverage Complexity
ActorService
0 %
0/43
0 %
0/6
1.188
 
 1  
 package org.jtheque.films.services.impl;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.persistence.able.DataListener;
 20  
 import org.jtheque.films.persistence.od.able.Film;
 21  
 import org.jtheque.films.services.able.IActorService;
 22  
 import org.jtheque.films.services.able.IFilmsService;
 23  
 import org.jtheque.films.services.able.INotesService;
 24  
 import org.jtheque.films.services.impl.utils.Filmography;
 25  
 import org.jtheque.films.view.impl.fb.IPersonFormBean;
 26  
 import org.jtheque.primary.dao.able.IDaoPersons;
 27  
 import org.jtheque.primary.od.able.Person;
 28  
 import org.jtheque.primary.services.able.ICountriesService;
 29  
 import org.springframework.transaction.annotation.Transactional;
 30  
 
 31  
 import javax.annotation.Resource;
 32  
 import java.util.ArrayList;
 33  
 import java.util.Collection;
 34  
 
 35  
 /**
 36  
  * The implementation of the actor service.
 37  
  *
 38  
  * @author Baptiste Wicht
 39  
  */
 40  0
 public final class ActorService implements IActorService {
 41  
     private Person emptyActor;
 42  
 
 43  
     @Resource
 44  
     private ICountriesService countriesService;
 45  
 
 46  
     @Resource
 47  
     private INotesService notesService;
 48  
 
 49  
     @Resource
 50  
     private IDaoPersons daoPersons;
 51  
 
 52  
     @Resource
 53  
     private IFilmsService filmsService;
 54  
 
 55  
 
 56  
     @Override
 57  
     @Transactional
 58  
     public void edit(Person actor, IPersonFormBean infos) {
 59  0
         actor.setName(infos.getName());
 60  0
         actor.setFirstName(infos.getFirstName());
 61  0
         actor.setNote(infos.getNote());
 62  0
         actor.setTheCountry(infos.getCountry());
 63  
 
 64  0
         daoPersons.save(actor);
 65  0
     }
 66  
 
 67  
     @Override
 68  
     @Transactional
 69  
     public void create(Person actor) {
 70  0
         actor.setType(PERSON_TYPE);
 71  
 
 72  0
         daoPersons.create(actor);
 73  0
     }
 74  
 
 75  
     @Override
 76  
     @Transactional
 77  
     public void save(Person actor) {
 78  0
         actor.setType(PERSON_TYPE);
 79  
 
 80  0
         daoPersons.save(actor);
 81  0
     }
 82  
 
 83  
     @Override
 84  
     @Transactional
 85  
     public boolean delete(Person actor) {
 86  0
         return daoPersons.delete(actor);
 87  
     }
 88  
 
 89  
     @Override
 90  
     public boolean hasNoActor() {
 91  0
         return getActors().isEmpty();
 92  
     }
 93  
 
 94  
     @Override
 95  
     public Collection<Person> getActors() {
 96  0
         return daoPersons.getPersons(PERSON_TYPE);
 97  
     }
 98  
 
 99  
     @Override
 100  
     public boolean exist(Person actor) {
 101  0
         return daoPersons.exist(actor);
 102  
     }
 103  
 
 104  
     @Override
 105  
     public Person getActor(String firstName, String name) {
 106  0
         return daoPersons.getPerson(firstName, name, PERSON_TYPE);
 107  
     }
 108  
 
 109  
     @Override
 110  
     public boolean exist(String firstName, String name) {
 111  0
         return daoPersons.exists(firstName, name, PERSON_TYPE);
 112  
     }
 113  
 
 114  
     @Override
 115  
     public Collection<Person> getDatas() {
 116  0
         return getActors();
 117  
     }
 118  
 
 119  
     @Override
 120  
     public void addDataListener(DataListener listener) {
 121  0
         daoPersons.addDataListener(listener);
 122  0
     }
 123  
 
 124  
     @Override
 125  
     public Person getDefaultActor() {
 126  0
         if (emptyActor == null) {
 127  0
             emptyActor = getEmptyActor();
 128  
 
 129  0
             emptyActor.setName("");
 130  0
             emptyActor.setFirstName("");
 131  0
             emptyActor.setNote(notesService.getDefaultNote());
 132  0
             emptyActor.setTheCountry(countriesService.getDefaultCountry());
 133  
         }
 134  
 
 135  0
         return emptyActor;
 136  
     }
 137  
 
 138  
     @Override
 139  
     public Person getEmptyActor() {
 140  0
         Person person = daoPersons.createPerson();
 141  
 
 142  0
         person.setType(PERSON_TYPE);
 143  
 
 144  0
         return person;
 145  
     }
 146  
 
 147  
     @Override
 148  
     public Filmography getFilmography(Person actor) {
 149  0
         Filmography filmo = new Filmography();
 150  
 
 151  0
         filmo.setActor(actor.getDisplayableText());
 152  
 
 153  0
         Collection<String> films = new ArrayList<String>(15);
 154  
 
 155  0
         for (Film film : filmsService.getFilms()) {
 156  0
             if (film.containsActor(actor)) {
 157  0
                 films.add(film.getTitle());
 158  
             }
 159  
         }
 160  
 
 161  0
         filmo.setFilms(films);
 162  
 
 163  0
         return filmo;
 164  
     }
 165  
 
 166  
     @Override
 167  
     @Transactional
 168  
     public void clearAll() {
 169  0
         daoPersons.clearAll();
 170  0
     }
 171  
 
 172  
     @Override
 173  
     public String getDataType() {
 174  0
         return DATA_TYPE;
 175  
     }
 176  
 }