1
14
15 package com.liferay.portal.service.impl;
16
17 import com.liferay.portal.CountryA2Exception;
18 import com.liferay.portal.CountryA3Exception;
19 import com.liferay.portal.CountryIddException;
20 import com.liferay.portal.CountryNameException;
21 import com.liferay.portal.CountryNumberException;
22 import com.liferay.portal.kernel.exception.PortalException;
23 import com.liferay.portal.kernel.exception.SystemException;
24 import com.liferay.portal.kernel.util.Validator;
25 import com.liferay.portal.model.Country;
26 import com.liferay.portal.security.auth.PrincipalException;
27 import com.liferay.portal.service.base.CountryServiceBaseImpl;
28
29 import java.util.List;
30
31
36 public class CountryServiceImpl extends CountryServiceBaseImpl {
37
38 public Country addCountry(
39 String name, String a2, String a3, String number, String idd,
40 boolean active)
41 throws PortalException, SystemException {
42
43 if (!getPermissionChecker().isOmniadmin()) {
44 throw new PrincipalException();
45 }
46
47 if (Validator.isNull(name)) {
48 throw new CountryNameException();
49 }
50
51 if (Validator.isNull(a2)) {
52 throw new CountryA2Exception();
53 }
54
55 if (Validator.isNull(a3)) {
56 throw new CountryA3Exception();
57 }
58
59 if (Validator.isNull(number)) {
60 throw new CountryNumberException();
61 }
62
63 if (Validator.isNull(idd)) {
64 throw new CountryIddException();
65 }
66
67 long countryId = counterLocalService.increment();
68
69 Country country = countryPersistence.create(countryId);
70
71 country.setName(name);
72 country.setA2(a2);
73 country.setA3(a3);
74 country.setNumber(number);
75 country.setIdd(idd);
76 country.setActive(active);
77
78 countryPersistence.update(country, false);
79
80 return country;
81 }
82
83 public List<Country> getCountries() throws SystemException {
84 return countryPersistence.findAll();
85 }
86
87 public List<Country> getCountries(boolean active) throws SystemException {
88 return countryPersistence.findByActive(active);
89 }
90
91 public Country getCountry(long countryId)
92 throws PortalException, SystemException {
93
94 return countryPersistence.findByPrimaryKey(countryId);
95 }
96
97 public Country getCountryByA2(String a2)
98 throws PortalException, SystemException {
99
100 return countryPersistence.findByA2(a2);
101 }
102
103 public Country getCountryByA3(String a3)
104 throws PortalException, SystemException {
105
106 return countryPersistence.findByA3(a3);
107 }
108
109 public Country getCountryByName(String name)
110 throws PortalException, SystemException {
111
112 return countryPersistence.findByName(name);
113 }
114
115 }