1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.impl;
24  
25  import com.liferay.portal.CountryA2Exception;
26  import com.liferay.portal.CountryA3Exception;
27  import com.liferay.portal.CountryIddException;
28  import com.liferay.portal.CountryNameException;
29  import com.liferay.portal.CountryNumberException;
30  import com.liferay.portal.PortalException;
31  import com.liferay.portal.SystemException;
32  import com.liferay.portal.kernel.util.Validator;
33  import com.liferay.portal.model.Country;
34  import com.liferay.portal.security.auth.PrincipalException;
35  import com.liferay.portal.service.base.CountryServiceBaseImpl;
36  
37  import java.util.List;
38  
39  /**
40   * <a href="CountryServiceImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class CountryServiceImpl extends CountryServiceBaseImpl {
46  
47      public Country addCountry(
48              String name, String a2, String a3, String number, String idd,
49              boolean active)
50          throws PortalException, SystemException {
51  
52          if (!getPermissionChecker().isOmniadmin()) {
53              throw new PrincipalException();
54          }
55  
56          if (Validator.isNull(name)) {
57              throw new CountryNameException();
58          }
59  
60          if (Validator.isNull(a2)) {
61              throw new CountryA2Exception();
62          }
63  
64          if (Validator.isNull(a3)) {
65              throw new CountryA3Exception();
66          }
67  
68          if (Validator.isNull(number)) {
69              throw new CountryNumberException();
70          }
71  
72          if (Validator.isNull(idd)) {
73              throw new CountryIddException();
74          }
75  
76          long countryId = counterLocalService.increment();
77  
78          Country country = countryPersistence.create(countryId);
79  
80          country.setName(name);
81          country.setA2(a2);
82          country.setA3(a3);
83          country.setNumber(number);
84          country.setIdd(idd);
85          country.setActive(active);
86  
87          countryPersistence.update(country, false);
88  
89          return country;
90      }
91  
92      public List<Country> getCountries() throws SystemException {
93          return countryPersistence.findAll();
94      }
95  
96      public List<Country> getCountries(boolean active) throws SystemException {
97          return countryPersistence.findByActive(active);
98      }
99  
100     public Country getCountry(long countryId)
101         throws PortalException, SystemException {
102 
103         return countryPersistence.findByPrimaryKey(countryId);
104     }
105 
106     public Country getCountryByA2(String a2)
107         throws PortalException, SystemException {
108 
109         return countryPersistence.findByA2(a2);
110     }
111 
112     public Country getCountryByA3(String a3)
113         throws PortalException, SystemException {
114 
115         return countryPersistence.findByA3(a3);
116     }
117 
118     public Country getCountryByName(String name)
119         throws PortalException, SystemException {
120 
121         return countryPersistence.findByName(name);
122     }
123 
124 }