1
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
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 }