1
22
23 package com.liferay.portal.service.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.RegionCodeException;
27 import com.liferay.portal.RegionNameException;
28 import com.liferay.portal.SystemException;
29 import com.liferay.portal.kernel.util.Validator;
30 import com.liferay.portal.model.Country;
31 import com.liferay.portal.model.Region;
32 import com.liferay.portal.security.auth.PrincipalException;
33 import com.liferay.portal.service.base.RegionServiceBaseImpl;
34
35 import java.util.List;
36
37
43 public class RegionServiceImpl extends RegionServiceBaseImpl {
44
45 public Region addRegion(
46 long countryId, String regionCode, String name, boolean active)
47 throws PortalException, SystemException {
48
49 if (!getPermissionChecker().isOmniadmin()) {
50 throw new PrincipalException();
51 }
52
53 Country country = countryPersistence.findByPrimaryKey(countryId);
54
55 if (Validator.isNull(regionCode)) {
56 throw new RegionCodeException();
57 }
58
59 if (Validator.isNull(name)) {
60 throw new RegionNameException();
61 }
62
63 long regionId = counterLocalService.increment();
64
65 Region region = regionPersistence.create(regionId);
66
67 region.setCountryId(countryId);
68 region.setRegionCode(regionCode);
69 region.setName(name);
70 region.setActive(active);
71
72 regionPersistence.update(region);
73
74 return region;
75 }
76
77 public List getRegions() throws SystemException {
78 return regionPersistence.findAll();
79 }
80
81 public List getRegions(long countryId) throws SystemException {
82 return regionPersistence.findByCountryId(countryId);
83 }
84
85 public List getRegions(boolean active) throws SystemException {
86 return regionPersistence.findByActive(active);
87 }
88
89 public List getRegions(long countryId, boolean active)
90 throws SystemException {
91
92 return regionPersistence.findByC_A(countryId, active);
93 }
94
95 public Region getRegion(long regionId)
96 throws PortalException, SystemException {
97
98 return regionPersistence.findByPrimaryKey(regionId);
99 }
100
101 }