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 public Region addRegion(
034 long countryId, String regionCode, String name, boolean active)
035 throws PortalException, SystemException {
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, false);
061
062 return region;
063 }
064
065 public List<Region> getRegions() throws SystemException {
066 return regionPersistence.findAll();
067 }
068
069 public List<Region> getRegions(long countryId) throws SystemException {
070 return regionPersistence.findByCountryId(countryId);
071 }
072
073 public List<Region> getRegions(boolean active) throws SystemException {
074 return regionPersistence.findByActive(active);
075 }
076
077 public List<Region> getRegions(long countryId, boolean active)
078 throws SystemException {
079
080 return regionPersistence.findByC_A(countryId, active);
081 }
082
083 public Region getRegion(long regionId)
084 throws PortalException, SystemException {
085
086 return regionPersistence.findByPrimaryKey(regionId);
087 }
088
089 }