001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.CountryA2Exception;
018 import com.liferay.portal.CountryA3Exception;
019 import com.liferay.portal.CountryIddException;
020 import com.liferay.portal.CountryNameException;
021 import com.liferay.portal.CountryNumberException;
022 import com.liferay.portal.kernel.exception.PortalException;
023 import com.liferay.portal.kernel.exception.SystemException;
024 import com.liferay.portal.kernel.util.Validator;
025 import com.liferay.portal.model.Country;
026 import com.liferay.portal.security.auth.PrincipalException;
027 import com.liferay.portal.service.base.CountryServiceBaseImpl;
028
029 import java.util.List;
030
031
034 public class CountryServiceImpl extends CountryServiceBaseImpl {
035
036 public Country addCountry(
037 String name, String a2, String a3, String number, String idd,
038 boolean active)
039 throws PortalException, SystemException {
040
041 if (!getPermissionChecker().isOmniadmin()) {
042 throw new PrincipalException();
043 }
044
045 if (Validator.isNull(name)) {
046 throw new CountryNameException();
047 }
048
049 if (Validator.isNull(a2)) {
050 throw new CountryA2Exception();
051 }
052
053 if (Validator.isNull(a3)) {
054 throw new CountryA3Exception();
055 }
056
057 if (Validator.isNull(number)) {
058 throw new CountryNumberException();
059 }
060
061 if (Validator.isNull(idd)) {
062 throw new CountryIddException();
063 }
064
065 long countryId = counterLocalService.increment();
066
067 Country country = countryPersistence.create(countryId);
068
069 country.setName(name);
070 country.setA2(a2);
071 country.setA3(a3);
072 country.setNumber(number);
073 country.setIdd(idd);
074 country.setActive(active);
075
076 countryPersistence.update(country, false);
077
078 return country;
079 }
080
081 public Country fetchCountry(long countryId) throws SystemException {
082 return countryPersistence.fetchByPrimaryKey(countryId);
083 }
084
085 public List<Country> getCountries() throws SystemException {
086 return countryPersistence.findAll();
087 }
088
089 public List<Country> getCountries(boolean active) throws SystemException {
090 return countryPersistence.findByActive(active);
091 }
092
093 public Country getCountry(long countryId)
094 throws PortalException, SystemException {
095
096 return countryPersistence.findByPrimaryKey(countryId);
097 }
098
099 public Country getCountryByA2(String a2)
100 throws PortalException, SystemException {
101
102 return countryPersistence.findByA2(a2);
103 }
104
105 public Country getCountryByA3(String a3)
106 throws PortalException, SystemException {
107
108 return countryPersistence.findByA3(a3);
109 }
110
111 public Country getCountryByName(String name)
112 throws PortalException, SystemException {
113
114 return countryPersistence.findByName(name);
115 }
116
117 }