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.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();
039 }
040
041 countryPersistence.findByPrimaryKey(countryId);
042
043 if (Validator.isNull(regionCode)) {
044 throw new RegionCodeException();
045 }
046
047 if (Validator.isNull(name)) {
048 throw new RegionNameException();
049 }
050
051 long regionId = counterLocalService.increment();
052
053 Region region = regionPersistence.create(regionId);
054
055 region.setCountryId(countryId);
056 region.setRegionCode(regionCode);
057 region.setName(name);
058 region.setActive(active);
059
060 regionPersistence.update(region);
061
062 return region;
063 }
064
065 @Override
066 public Region fetchRegion(long regionId) {
067 return regionPersistence.fetchByPrimaryKey(regionId);
068 }
069
070 @Override
071 public Region fetchRegion(long countryId, String regionCode) {
072 return regionPersistence.fetchByC_R(countryId, regionCode);
073 }
074
075 @Override
076 public Region getRegion(long regionId) throws PortalException {
077 return regionPersistence.findByPrimaryKey(regionId);
078 }
079
080 @Override
081 public Region getRegion(long countryId, String regionCode)
082 throws PortalException {
083
084 return regionPersistence.findByC_R(countryId, regionCode);
085 }
086
087 @Override
088 public List<Region> getRegions() {
089 return regionPersistence.findAll();
090 }
091
092 @Override
093 public List<Region> getRegions(boolean active) {
094 return regionPersistence.findByActive(active);
095 }
096
097 @Override
098 public List<Region> getRegions(long countryId) {
099 return regionPersistence.findByCountryId(countryId);
100 }
101
102 @Override
103 public List<Region> getRegions(long countryId, boolean active) {
104 return regionPersistence.findByC_A(countryId, active);
105 }
106
107 }