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.portlet.softwarecatalog.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.Validator;
026: import com.liferay.portlet.softwarecatalog.LicenseNameException;
027: import com.liferay.portlet.softwarecatalog.model.SCLicense;
028: import com.liferay.portlet.softwarecatalog.service.base.SCLicenseLocalServiceBaseImpl;
029:
030: import java.util.List;
031:
032: /**
033: * <a href="SCLicenseLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
034: *
035: * @author Jorge Ferrer
036: * @author Brian Wing Shun Chan
037: *
038: */
039: public class SCLicenseLocalServiceImpl extends
040: SCLicenseLocalServiceBaseImpl {
041:
042: public SCLicense addLicense(String name, String url,
043: boolean openSource, boolean active, boolean recommended)
044: throws PortalException, SystemException {
045:
046: validate(name);
047:
048: long licenseId = counterLocalService.increment();
049:
050: SCLicense license = scLicensePersistence.create(licenseId);
051:
052: license.setName(name);
053: license.setUrl(url);
054: license.setOpenSource(openSource);
055: license.setActive(active);
056: license.setRecommended(recommended);
057:
058: scLicensePersistence.update(license);
059:
060: return license;
061: }
062:
063: public void deleteLicense(long licenseId) throws PortalException,
064: SystemException {
065:
066: scLicensePersistence.remove(licenseId);
067: }
068:
069: public SCLicense getLicense(long licenseId) throws PortalException,
070: SystemException {
071:
072: return scLicensePersistence.findByPrimaryKey(licenseId);
073: }
074:
075: public List getLicenses() throws SystemException {
076: return scLicensePersistence.findAll();
077: }
078:
079: public List getLicenses(int begin, int end) throws SystemException {
080: return scLicensePersistence.findAll(begin, end);
081: }
082:
083: public List getLicenses(boolean active, boolean recommended)
084: throws SystemException {
085:
086: return scLicensePersistence.findByA_R(active, recommended);
087: }
088:
089: public List getLicenses(boolean active, boolean recommended,
090: int begin, int end) throws SystemException {
091:
092: return scLicensePersistence.findByA_R(active, recommended,
093: begin, end);
094: }
095:
096: public int getLicensesCount() throws SystemException {
097: return scLicensePersistence.countAll();
098: }
099:
100: public int getLicensesCount(boolean active, boolean recommended)
101: throws SystemException {
102:
103: return scLicensePersistence.countByA_R(active, recommended);
104: }
105:
106: public List getProductEntryLicenses(long productEntryId)
107: throws PortalException, SystemException {
108:
109: return scProductEntryPersistence.getSCLicenses(productEntryId);
110: }
111:
112: public SCLicense updateLicense(long licenseId, String name,
113: String url, boolean openSource, boolean active,
114: boolean recommended) throws PortalException,
115: SystemException {
116:
117: validate(name);
118:
119: SCLicense license = scLicensePersistence
120: .findByPrimaryKey(licenseId);
121:
122: license.setName(name);
123: license.setUrl(url);
124: license.setOpenSource(openSource);
125: license.setActive(active);
126: license.setRecommended(recommended);
127:
128: scLicensePersistence.update(license);
129:
130: return license;
131: }
132:
133: protected void validate(String name) throws PortalException {
134: if (Validator.isNull(name)) {
135: throw new LicenseNameException();
136: }
137: }
138:
139: }
|