001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.exception.RegionCodeException;
018 import com.liferay.portal.exception.RegionNameException;
019 import com.liferay.portal.kernel.exception.PortalException;
020 import com.liferay.portal.kernel.util.Validator;
021 import com.liferay.portal.model.Region;
022 import com.liferay.portal.security.auth.PrincipalException;
023 import com.liferay.portal.service.base.RegionServiceBaseImpl;
024
025 import java.util.List;
026
027
030 public class RegionServiceImpl extends RegionServiceBaseImpl {
031
032 @Override
033 public Region addRegion(
034 long countryId, String regionCode, String name, boolean active)
035 throws PortalException {
036
037 if (!getPermissionChecker().isOmniadmin()) {
038 throw new PrincipalException.MustBeOmniadmin(
039 getPermissionChecker());
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);
062
063 return region;
064 }
065
066 @Override
067 public Region fetchRegion(long regionId) {
068 return regionPersistence.fetchByPrimaryKey(regionId);
069 }
070
071 @Override
072 public Region fetchRegion(long countryId, String regionCode) {
073 return regionPersistence.fetchByC_R(countryId, regionCode);
074 }
075
076 @Override
077 public Region getRegion(long regionId) throws PortalException {
078 return regionPersistence.findByPrimaryKey(regionId);
079 }
080
081 @Override
082 public Region getRegion(long countryId, String regionCode)
083 throws PortalException {
084
085 return regionPersistence.findByC_R(countryId, regionCode);
086 }
087
088 @Override
089 public List<Region> getRegions() {
090 return regionPersistence.findAll();
091 }
092
093 @Override
094 public List<Region> getRegions(boolean active) {
095 return regionPersistence.findByActive(active);
096 }
097
098 @Override
099 public List<Region> getRegions(long countryId) {
100 return regionPersistence.findByCountryId(countryId);
101 }
102
103 @Override
104 public List<Region> getRegions(long countryId, boolean active) {
105 return regionPersistence.findByC_A(countryId, active);
106 }
107
108 }