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