1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.softwarecatalog.service.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.kernel.util.Validator;
25  import com.liferay.portlet.softwarecatalog.LicenseNameException;
26  import com.liferay.portlet.softwarecatalog.model.SCLicense;
27  import com.liferay.portlet.softwarecatalog.service.base.SCLicenseLocalServiceBaseImpl;
28  
29  import java.util.List;
30  
31  /**
32   * <a href="SCLicenseLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Jorge Ferrer
35   * @author Brian Wing Shun Chan
36   *
37   */
38  public class SCLicenseLocalServiceImpl extends SCLicenseLocalServiceBaseImpl {
39  
40      public SCLicense addLicense(
41              String name, String url, boolean openSource, boolean active,
42              boolean recommended)
43          throws PortalException, SystemException {
44  
45          validate(name);
46  
47          long licenseId = counterLocalService.increment();
48  
49          SCLicense license = scLicensePersistence.create(licenseId);
50  
51          license.setName(name);
52          license.setUrl(url);
53          license.setOpenSource(openSource);
54          license.setActive(active);
55          license.setRecommended(recommended);
56  
57          scLicensePersistence.update(license, false);
58  
59          return license;
60      }
61  
62      public void deleteLicense(long licenseId)
63          throws PortalException, SystemException {
64  
65          scLicensePersistence.remove(licenseId);
66      }
67  
68      public SCLicense getLicense(long licenseId)
69          throws PortalException, SystemException {
70  
71          return scLicensePersistence.findByPrimaryKey(licenseId);
72      }
73  
74      public List<SCLicense> getLicenses() throws SystemException {
75          return scLicensePersistence.findAll();
76      }
77  
78      public List<SCLicense> getLicenses(int start, int end)
79          throws SystemException {
80  
81          return scLicensePersistence.findAll(start, end);
82      }
83  
84      public List<SCLicense> getLicenses(boolean active, boolean recommended)
85          throws SystemException {
86  
87          return scLicensePersistence.findByA_R(active, recommended);
88      }
89  
90      public List<SCLicense> getLicenses(
91              boolean active, boolean recommended, int start, int end)
92          throws SystemException {
93  
94          return scLicensePersistence.findByA_R(active, recommended, start, end);
95      }
96  
97      public int getLicensesCount() throws SystemException {
98          return scLicensePersistence.countAll();
99      }
100 
101     public int getLicensesCount(boolean active, boolean recommended)
102         throws SystemException {
103 
104         return scLicensePersistence.countByA_R(active, recommended);
105     }
106 
107     public List<SCLicense> getProductEntryLicenses(long productEntryId)
108         throws SystemException {
109 
110         return scProductEntryPersistence.getSCLicenses(productEntryId);
111     }
112 
113     public SCLicense updateLicense(
114             long licenseId, String name, String url, boolean openSource,
115             boolean active, boolean recommended)
116         throws PortalException, SystemException {
117 
118         validate(name);
119 
120         SCLicense license = scLicensePersistence.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, false);
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 }