001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.RegionCodeException;
025: import com.liferay.portal.RegionNameException;
026: import com.liferay.portal.SystemException;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.model.Country;
029: import com.liferay.portal.model.Region;
030: import com.liferay.portal.security.auth.PrincipalException;
031: import com.liferay.portal.service.base.RegionServiceBaseImpl;
032:
033: import java.util.List;
034:
035: /**
036: * <a href="RegionServiceImpl.java.html"><b><i>View Source</i></b></a>
037: *
038: * @author Brian Wing Shun Chan
039: *
040: */
041: public class RegionServiceImpl extends RegionServiceBaseImpl {
042:
043: public Region addRegion(long countryId, String regionCode,
044: String name, boolean active) throws PortalException,
045: SystemException {
046:
047: if (!getPermissionChecker().isOmniadmin()) {
048: throw new PrincipalException();
049: }
050:
051: Country country = countryPersistence
052: .findByPrimaryKey(countryId);
053:
054: if (Validator.isNull(regionCode)) {
055: throw new RegionCodeException();
056: }
057:
058: if (Validator.isNull(name)) {
059: throw new RegionNameException();
060: }
061:
062: long regionId = counterLocalService.increment();
063:
064: Region region = regionPersistence.create(regionId);
065:
066: region.setCountryId(countryId);
067: region.setRegionCode(regionCode);
068: region.setName(name);
069: region.setActive(active);
070:
071: regionPersistence.update(region);
072:
073: return region;
074: }
075:
076: public List getRegions() throws SystemException {
077: return regionPersistence.findAll();
078: }
079:
080: public List getRegions(long countryId) throws SystemException {
081: return regionPersistence.findByCountryId(countryId);
082: }
083:
084: public List getRegions(boolean active) throws SystemException {
085: return regionPersistence.findByActive(active);
086: }
087:
088: public List getRegions(long countryId, boolean active)
089: throws SystemException {
090:
091: return regionPersistence.findByC_A(countryId, active);
092: }
093:
094: public Region getRegion(long regionId) throws PortalException,
095: SystemException {
096:
097: return regionPersistence.findByPrimaryKey(regionId);
098: }
099:
100: }
|