001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.RegionCodeException;
018 import com.liferay.portal.RegionNameException;
019 import com.liferay.portal.kernel.exception.PortalException;
020 import com.liferay.portal.kernel.exception.SystemException;
021 import com.liferay.portal.kernel.util.Validator;
022 import com.liferay.portal.model.Region;
023 import com.liferay.portal.security.auth.PrincipalException;
024 import com.liferay.portal.service.base.RegionServiceBaseImpl;
025
026 import java.util.List;
027
028
031 public class RegionServiceImpl extends RegionServiceBaseImpl {
032
033 @Override
034 public Region addRegion(
035 long countryId, String regionCode, String name, boolean active)
036 throws PortalException, SystemException {
037
038 if (!getPermissionChecker().isOmniadmin()) {
039 throw new PrincipalException();
040 }
041
042 countryPersistence.findByPrimaryKey(countryId);
043
044 if (Validator.isNull(regionCode)) {
045 throw new RegionCodeException();
046 }
047
048 if (Validator.isNull(name)) {
049 throw new RegionNameException();
050 }
051
052 long regionId = counterLocalService.increment();
053
054 Region region = regionPersistence.create(regionId);
055
056 region.setCountryId(countryId);
057 region.setRegionCode(regionCode);
058 region.setName(name);
059 region.setActive(active);
060
061 regionPersistence.update(region, false);
062
063 return region;
064 }
065
066 @Override
067 public Region fetchRegion(long countryId, String regionCode)
068 throws SystemException {
069
070 return regionPersistence.fetchByC_R(countryId, regionCode);
071 }
072
073 @Override
074 public Region getRegion(long regionId)
075 throws PortalException, SystemException {
076
077 return regionPersistence.findByPrimaryKey(regionId);
078 }
079
080 @Override
081 public Region getRegion(long countryId, String regionCode)
082 throws PortalException, SystemException {
083
084 return regionPersistence.findByC_R(countryId, regionCode);
085 }
086
087 @Override
088 public List<Region> getRegions() throws SystemException {
089 return regionPersistence.findAll();
090 }
091
092 @Override
093 public List<Region> getRegions(boolean active) throws SystemException {
094 return regionPersistence.findByActive(active);
095 }
096
097 @Override
098 public List<Region> getRegions(long countryId) throws SystemException {
099 return regionPersistence.findByCountryId(countryId);
100 }
101
102 @Override
103 public List<Region> getRegions(long countryId, boolean active)
104 throws SystemException {
105
106 return regionPersistence.findByC_A(countryId, active);
107 }
108
109 }