Coverage Report - org.jtheque.films.services.impl.utils.search.FilmSearcher
 
Classes in this File Line Coverage Branch Coverage Complexity
FilmSearcher
0 %
0/30
0 %
0/40
11
 
 1  
 package org.jtheque.films.services.impl.utils.search;
 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.Managers;
 20  
 import org.jtheque.core.managers.log.ILoggingManager;
 21  
 import org.jtheque.core.managers.beans.IBeansManager;
 22  
 import org.jtheque.core.utils.db.EntityUtils;
 23  
 import org.jtheque.films.persistence.od.FilmImpl;
 24  
 import org.jtheque.films.services.able.IFilmsService;
 25  
 
 26  
 import javax.annotation.Resource;
 27  
 import java.util.ArrayList;
 28  
 import java.util.List;
 29  
 
 30  
 /**
 31  
  * A searcher for the films. This classe permit a search of films with an objet Search.
 32  
  *
 33  
  * @author Baptiste Wicht
 34  
  */
 35  
 public final class FilmSearcher implements Searcher<FilmImpl> {
 36  
     @Resource
 37  
     private IFilmsService filmsService;
 38  
 
 39  
     /**
 40  
      * Construct a new FilmSearcher.
 41  
      */
 42  
     public FilmSearcher() {
 43  0
         super();
 44  
 
 45  0
         Managers.getManager(IBeansManager.class).inject(this);
 46  0
     }
 47  
 
 48  
     @Override
 49  
     public List<FilmImpl> search(Search<FilmImpl> research) {
 50  0
         List<FilmImpl> list = new ArrayList<FilmImpl>(20);
 51  0
         FilmSearch search = (FilmSearch) research;
 52  
 
 53  0
         for (FilmImpl film : filmsService.getFilms()) {
 54  0
             boolean correct = true;
 55  
 
 56  0
             if (search.isMustCheckActor() &&
 57  
                     !EntityUtils.containsID(film.getActors(), search.getActor().getId())) {
 58  0
                 correct = false;
 59  
             }
 60  
 
 61  0
             if (search.isMustCheckKind() && !film.getKinds().contains(search.getKind())) {
 62  0
                 correct = false;
 63  
             }
 64  
 
 65  0
             if (search.isMustCheckType() && !film.getTheType().equals(search.getType())) {
 66  0
                 correct = false;
 67  
             }
 68  
 
 69  0
             if (search.isMustCheckYear()) {
 70  0
                 Managers.getManager(ILoggingManager.class).getLogger(getClass()).debug("Check annee");
 71  0
                 if (film.getYear() < search.getStartYear() || film.getYear() > search.getEndYear()) {
 72  0
                     correct = false;
 73  0
                     Managers.getManager(ILoggingManager.class).getLogger(getClass()).debug("Annee false");
 74  
                 }
 75  
             }
 76  
 
 77  0
             if (search.isMustCheckRealizer() && !film.getTheRealizer().equals(search.getRealizer())) {
 78  0
                 correct = false;
 79  
             }
 80  
 
 81  0
             if (search.isMustCheckLanguage() && !film.getTheLanguage().equals(search.getLanguage())) {
 82  0
                 correct = false;
 83  
             }
 84  
 
 85  0
             if (search.isMustCheckNote() && !film.getNote().equals(search.getNote())) {
 86  0
                 correct = false;
 87  
             }
 88  
 
 89  0
             if (search.isMustCheckDuration() &&
 90  
                     (film.getDuration() < search.getStartDuration() ||
 91  
                             film.getDuration() > search.getEndDuration())) {
 92  0
                 correct = false;
 93  
             }
 94  
 
 95  0
             if (correct) {
 96  0
                 list.add(film);
 97  
             }
 98  0
         }
 99  
 
 100  0
         return list;
 101  
     }
 102  
 }