1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.service.impl;
21  
22  import com.liferay.portal.CountryA2Exception;
23  import com.liferay.portal.CountryA3Exception;
24  import com.liferay.portal.CountryIddException;
25  import com.liferay.portal.CountryNameException;
26  import com.liferay.portal.CountryNumberException;
27  import com.liferay.portal.PortalException;
28  import com.liferay.portal.SystemException;
29  import com.liferay.portal.kernel.util.Validator;
30  import com.liferay.portal.model.Country;
31  import com.liferay.portal.security.auth.PrincipalException;
32  import com.liferay.portal.service.base.CountryServiceBaseImpl;
33  
34  import java.util.List;
35  
36  /**
37   * <a href="CountryServiceImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class CountryServiceImpl extends CountryServiceBaseImpl {
43  
44      public Country addCountry(
45              String name, String a2, String a3, String number, String idd,
46              boolean active)
47          throws PortalException, SystemException {
48  
49          if (!getPermissionChecker().isOmniadmin()) {
50              throw new PrincipalException();
51          }
52  
53          if (Validator.isNull(name)) {
54              throw new CountryNameException();
55          }
56  
57          if (Validator.isNull(a2)) {
58              throw new CountryA2Exception();
59          }
60  
61          if (Validator.isNull(a3)) {
62              throw new CountryA3Exception();
63          }
64  
65          if (Validator.isNull(number)) {
66              throw new CountryNumberException();
67          }
68  
69          if (Validator.isNull(idd)) {
70              throw new CountryIddException();
71          }
72  
73          long countryId = counterLocalService.increment();
74  
75          Country country = countryPersistence.create(countryId);
76  
77          country.setName(name);
78          country.setA2(a2);
79          country.setA3(a3);
80          country.setNumber(number);
81          country.setIdd(idd);
82          country.setActive(active);
83  
84          countryPersistence.update(country, false);
85  
86          return country;
87      }
88  
89      public List<Country> getCountries() throws SystemException {
90          return countryPersistence.findAll();
91      }
92  
93      public List<Country> getCountries(boolean active) throws SystemException {
94          return countryPersistence.findByActive(active);
95      }
96  
97      public Country getCountry(long countryId)
98          throws PortalException, SystemException {
99  
100         return countryPersistence.findByPrimaryKey(countryId);
101     }
102 
103     public Country getCountryByA2(String a2)
104         throws PortalException, SystemException {
105 
106         return countryPersistence.findByA2(a2);
107     }
108 
109     public Country getCountryByA3(String a3)
110         throws PortalException, SystemException {
111 
112         return countryPersistence.findByA3(a3);
113     }
114 
115     public Country getCountryByName(String name)
116         throws PortalException, SystemException {
117 
118         return countryPersistence.findByName(name);
119     }
120 
121 }