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