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.CountryA2Exception;
024: import com.liferay.portal.CountryA3Exception;
025: import com.liferay.portal.CountryIddException;
026: import com.liferay.portal.CountryNameException;
027: import com.liferay.portal.CountryNumberException;
028: import com.liferay.portal.PortalException;
029: import com.liferay.portal.SystemException;
030: import com.liferay.portal.kernel.util.Validator;
031: import com.liferay.portal.model.Country;
032: import com.liferay.portal.security.auth.PrincipalException;
033: import com.liferay.portal.service.base.CountryServiceBaseImpl;
034:
035: import java.util.List;
036:
037: /**
038: * <a href="CountryServiceImpl.java.html"><b><i>View Source</i></b></a>
039: *
040: * @author Brian Wing Shun Chan
041: *
042: */
043: public class CountryServiceImpl extends CountryServiceBaseImpl {
044:
045: public Country addCountry(String name, String a2, String a3,
046: String number, String idd, boolean active)
047: throws PortalException, SystemException {
048:
049: if (!getPermissionChecker().isOmniadmin()) {
050: throw new PrincipalException();
051: }
052:
053: if (Validator.isNull(name)) {
054: throw new CountryNameException();
055: }
056:
057: if (Validator.isNull(a2)) {
058: throw new CountryA2Exception();
059: }
060:
061: if (Validator.isNull(a3)) {
062: throw new CountryA3Exception();
063: }
064:
065: if (Validator.isNull(number)) {
066: throw new CountryNumberException();
067: }
068:
069: if (Validator.isNull(idd)) {
070: throw new CountryIddException();
071: }
072:
073: long countryId = counterLocalService.increment();
074:
075: Country country = countryPersistence.create(countryId);
076:
077: country.setName(name);
078: country.setA2(a2);
079: country.setA3(a3);
080: country.setNumber(number);
081: country.setIdd(idd);
082: country.setActive(active);
083:
084: countryPersistence.update(country);
085:
086: return country;
087: }
088:
089: public List getCountries() throws SystemException {
090: return countryPersistence.findAll();
091: }
092:
093: public List getCountries(boolean active) throws SystemException {
094: return countryPersistence.findByActive(active);
095: }
096:
097: public Country getCountry(long countryId) throws PortalException,
098: SystemException {
099:
100: return countryPersistence.findByPrimaryKey(countryId);
101: }
102:
103: }
|