Coverage Report - org.jtheque.primary.services.impl.CountriesService
 
Classes in this File Line Coverage Branch Coverage Complexity
CountriesService
0 %
0/29
0 %
0/8
1.2
 
 1  
 package org.jtheque.primary.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.primary.dao.able.IDaoCountries;
 21  
 import org.jtheque.primary.od.able.Country;
 22  
 import org.jtheque.primary.services.able.ICountriesService;
 23  
 import org.springframework.stereotype.Service;
 24  
 import org.springframework.transaction.annotation.Transactional;
 25  
 
 26  
 import javax.annotation.Resource;
 27  
 import java.util.Collection;
 28  
 
 29  
 /**
 30  
  * A countries service implementation.
 31  
  *
 32  
  * @author Baptiste Wicht
 33  
  */
 34  
 @Service
 35  0
 public final class CountriesService implements ICountriesService {
 36  
     private Country defaultCountry;
 37  
 
 38  
     @Resource
 39  
     private IDaoCountries daoCountries;
 40  
 
 41  
     @Override
 42  
     public Country getDefaultCountry() {
 43  0
         if (defaultCountry == null) {
 44  0
             defaultCountry = daoCountries.getCountry("USA");
 45  
 
 46  0
             if (defaultCountry == null) {
 47  0
                 createDefaultCountry();
 48  
             }
 49  
         }
 50  
 
 51  0
         return defaultCountry;
 52  
     }
 53  
 
 54  
     /**
 55  
      * Create the default country.
 56  
      */
 57  
     @Transactional
 58  
     private void createDefaultCountry() {
 59  0
         defaultCountry = daoCountries.createCountry();
 60  0
         defaultCountry.setName("USA");
 61  0
         daoCountries.create(defaultCountry);
 62  0
     }
 63  
 
 64  
     @Override
 65  
     @Transactional
 66  
     public void save(Country country) {
 67  0
         daoCountries.save(country);
 68  0
     }
 69  
 
 70  
     @Override
 71  
     @Transactional
 72  
     public void create(Country country) {
 73  0
         daoCountries.create(country);
 74  0
     }
 75  
 
 76  
     @Override
 77  
     @Transactional
 78  
     public boolean delete(Country country) {
 79  0
         return daoCountries.delete(country);
 80  
     }
 81  
 
 82  
     @Override
 83  
     public Collection<Country> getCountries() {
 84  0
         return daoCountries.getCountries();
 85  
     }
 86  
 
 87  
     @Override
 88  
     public Country getCountry(String name) {
 89  0
         return daoCountries.getCountry(name);
 90  
     }
 91  
 
 92  
     @Override
 93  
     @Transactional
 94  
     public void createAll(Iterable<Country> countries) {
 95  0
         for (Country country : countries) {
 96  0
             daoCountries.create(country);
 97  
         }
 98  0
     }
 99  
 
 100  
     @Override
 101  
     public boolean exist(Country country) {
 102  0
         return daoCountries.exist(country);
 103  
     }
 104  
 
 105  
     @Override
 106  
     public Country getEmptyCountry() {
 107  0
         return daoCountries.createCountry();
 108  
     }
 109  
 
 110  
     @Override
 111  
     public boolean exist(String name) {
 112  0
         return getCountry(name) != null;
 113  
     }
 114  
 
 115  
     @Override
 116  
     public Collection<Country> getDatas() {
 117  0
         return getCountries();
 118  
     }
 119  
 
 120  
     @Override
 121  
     public void addDataListener(DataListener listener) {
 122  0
         daoCountries.addDataListener(listener);
 123  0
     }
 124  
 
 125  
     @Override
 126  
     @Transactional
 127  
     public void clearAll() {
 128  0
         daoCountries.clearAll();
 129  0
     }
 130  
 
 131  
     @Override
 132  
     public String getDataType() {
 133  0
         return DATA_TYPE;
 134  
     }
 135  
 }