1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.softwarecatalog.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.portlet.softwarecatalog.LicenseNameException;
21  import com.liferay.portlet.softwarecatalog.model.SCLicense;
22  import com.liferay.portlet.softwarecatalog.service.base.SCLicenseLocalServiceBaseImpl;
23  
24  import java.util.List;
25  
26  /**
27   * <a href="SCLicenseLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Jorge Ferrer
30   * @author Brian Wing Shun Chan
31   */
32  public class SCLicenseLocalServiceImpl extends SCLicenseLocalServiceBaseImpl {
33  
34      public SCLicense addLicense(
35              String name, String url, boolean openSource, boolean active,
36              boolean recommended)
37          throws PortalException, SystemException {
38  
39          validate(name);
40  
41          long licenseId = counterLocalService.increment();
42  
43          SCLicense license = scLicensePersistence.create(licenseId);
44  
45          license.setName(name);
46          license.setUrl(url);
47          license.setOpenSource(openSource);
48          license.setActive(active);
49          license.setRecommended(recommended);
50  
51          scLicensePersistence.update(license, false);
52  
53          return license;
54      }
55  
56      public void deleteLicense(long licenseId)
57          throws PortalException, SystemException {
58  
59          scLicensePersistence.remove(licenseId);
60      }
61  
62      public SCLicense getLicense(long licenseId)
63          throws PortalException, SystemException {
64  
65          return scLicensePersistence.findByPrimaryKey(licenseId);
66      }
67  
68      public List<SCLicense> getLicenses() throws SystemException {
69          return scLicensePersistence.findAll();
70      }
71  
72      public List<SCLicense> getLicenses(boolean active, boolean recommended)
73          throws SystemException {
74  
75          return scLicensePersistence.findByA_R(active, recommended);
76      }
77  
78      public List<SCLicense> getLicenses(
79              boolean active, boolean recommended, int start, int end)
80          throws SystemException {
81  
82          return scLicensePersistence.findByA_R(active, recommended, start, end);
83      }
84  
85      public List<SCLicense> getLicenses(int start, int end)
86          throws SystemException {
87  
88          return scLicensePersistence.findAll(start, end);
89      }
90  
91      public int getLicensesCount() throws SystemException {
92          return scLicensePersistence.countAll();
93      }
94  
95      public int getLicensesCount(boolean active, boolean recommended)
96          throws SystemException {
97  
98          return scLicensePersistence.countByA_R(active, recommended);
99      }
100 
101     public List<SCLicense> getProductEntryLicenses(long productEntryId)
102         throws SystemException {
103 
104         return scProductEntryPersistence.getSCLicenses(productEntryId);
105     }
106 
107     public SCLicense updateLicense(
108             long licenseId, String name, String url, boolean openSource,
109             boolean active, boolean recommended)
110         throws PortalException, SystemException {
111 
112         validate(name);
113 
114         SCLicense license = scLicensePersistence.findByPrimaryKey(licenseId);
115 
116         license.setName(name);
117         license.setUrl(url);
118         license.setOpenSource(openSource);
119         license.setActive(active);
120         license.setRecommended(recommended);
121 
122         scLicensePersistence.update(license, false);
123 
124         return license;
125     }
126 
127     protected void validate(String name) throws PortalException {
128         if (Validator.isNull(name)) {
129             throw new LicenseNameException();
130         }
131     }
132 
133 }