1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class CountryServiceImpl extends CountryServiceBaseImpl {
45  
46      public Country addCountry(
47              String name, String a2, String a3, String number, String idd,
48              boolean active)
49          throws PortalException, SystemException {
50  
51          if (!getPermissionChecker().isOmniadmin()) {
52              throw new PrincipalException();
53          }
54  
55          if (Validator.isNull(name)) {
56              throw new CountryNameException();
57          }
58  
59          if (Validator.isNull(a2)) {
60              throw new CountryA2Exception();
61          }
62  
63          if (Validator.isNull(a3)) {
64              throw new CountryA3Exception();
65          }
66  
67          if (Validator.isNull(number)) {
68              throw new CountryNumberException();
69          }
70  
71          if (Validator.isNull(idd)) {
72              throw new CountryIddException();
73          }
74  
75          long countryId = counterLocalService.increment();
76  
77          Country country = countryPersistence.create(countryId);
78  
79          country.setName(name);
80          country.setA2(a2);
81          country.setA3(a3);
82          country.setNumber(number);
83          country.setIdd(idd);
84          country.setActive(active);
85  
86          countryPersistence.update(country, false);
87  
88          return country;
89      }
90  
91      public List<Country> getCountries() throws SystemException {
92          return countryPersistence.findAll();
93      }
94  
95      public List<Country> getCountries(boolean active) throws SystemException {
96          return countryPersistence.findByActive(active);
97      }
98  
99      public Country getCountry(long countryId)
100         throws PortalException, SystemException {
101 
102         return countryPersistence.findByPrimaryKey(countryId);
103     }
104 
105     public Country getCountryByA2(String a2)
106         throws PortalException, SystemException {
107 
108         return countryPersistence.findByA2(a2);
109     }
110 
111     public Country getCountryByA3(String a3)
112         throws PortalException, SystemException {
113 
114         return countryPersistence.findByA3(a3);
115     }
116 
117     public Country getCountryByName(String name)
118         throws PortalException, SystemException {
119 
120         return countryPersistence.findByName(name);
121     }
122 
123 }