1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.softwarecatalog.service.impl;
24  
25  import com.liferay.counter.service.CounterLocalServiceUtil;
26  import com.liferay.portal.PortalException;
27  import com.liferay.portal.SystemException;
28  import com.liferay.portal.kernel.util.Validator;
29  import com.liferay.portlet.softwarecatalog.LicenseNameException;
30  import com.liferay.portlet.softwarecatalog.model.SCLicense;
31  import com.liferay.portlet.softwarecatalog.service.base.SCLicenseLocalServiceBaseImpl;
32  import com.liferay.portlet.softwarecatalog.service.persistence.SCLicenseUtil;
33  import com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryUtil;
34  
35  import java.util.List;
36  
37  /**
38   * <a href="SCLicenseLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Jorge Ferrer
41   * @author Brian Wing Shun Chan
42   *
43   */
44  public class SCLicenseLocalServiceImpl extends SCLicenseLocalServiceBaseImpl {
45  
46      public SCLicense addLicense(
47              String name, String url, boolean openSource, boolean active,
48              boolean recommended)
49          throws PortalException, SystemException {
50  
51          validate(name);
52  
53          long licenseId = CounterLocalServiceUtil.increment();
54  
55          SCLicense license = SCLicenseUtil.create(licenseId);
56  
57          license.setName(name);
58          license.setUrl(url);
59          license.setOpenSource(openSource);
60          license.setActive(active);
61          license.setRecommended(recommended);
62  
63          SCLicenseUtil.update(license);
64  
65          return license;
66      }
67  
68      public void deleteLicense(long licenseId)
69          throws PortalException, SystemException {
70  
71          SCLicenseUtil.remove(licenseId);
72      }
73  
74      public SCLicense getLicense(long licenseId)
75          throws PortalException, SystemException {
76  
77          return SCLicenseUtil.findByPrimaryKey(licenseId);
78      }
79  
80      public List getLicenses() throws SystemException {
81          return SCLicenseUtil.findAll();
82      }
83  
84      public List getLicenses(int begin, int end) throws SystemException {
85          return SCLicenseUtil.findAll(begin, end);
86      }
87  
88      public List getLicenses(boolean active, boolean recommended)
89          throws SystemException {
90  
91          return SCLicenseUtil.findByA_R(active, recommended);
92      }
93  
94      public List getLicenses(
95              boolean active, boolean recommended, int begin, int end)
96          throws SystemException {
97  
98          return SCLicenseUtil.findByA_R(active, recommended, begin, end);
99      }
100 
101     public int getLicensesCount() throws SystemException {
102         return SCLicenseUtil.countAll();
103     }
104 
105     public int getLicensesCount(boolean active, boolean recommended)
106         throws SystemException {
107 
108         return SCLicenseUtil.countByA_R(active, recommended);
109     }
110 
111     public List getProductEntryLicenses(long productEntryId)
112         throws PortalException, SystemException {
113 
114         return SCProductEntryUtil.getSCLicenses(productEntryId);
115     }
116 
117     public SCLicense updateLicense(
118             long licenseId, String name, String url, boolean openSource,
119             boolean active, boolean recommended)
120         throws PortalException, SystemException {
121 
122         validate(name);
123 
124         SCLicense license = SCLicenseUtil.findByPrimaryKey(licenseId);
125 
126         license.setName(name);
127         license.setUrl(url);
128         license.setOpenSource(openSource);
129         license.setActive(active);
130         license.setRecommended(recommended);
131 
132         SCLicenseUtil.update(license);
133 
134         return license;
135     }
136 
137     protected void validate(String name) throws PortalException {
138         if (Validator.isNull(name)) {
139             throw new LicenseNameException();
140         }
141     }
142 
143 }