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