1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.portlet.softwarecatalog.LicenseNameException;
29  import com.liferay.portlet.softwarecatalog.model.SCLicense;
30  import com.liferay.portlet.softwarecatalog.service.base.SCLicenseLocalServiceBaseImpl;
31  
32  import java.util.List;
33  
34  /**
35   * <a href="SCLicenseLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Jorge Ferrer
38   * @author Brian Wing Shun Chan
39   */
40  public class SCLicenseLocalServiceImpl extends SCLicenseLocalServiceBaseImpl {
41  
42      public SCLicense addLicense(
43              String name, String url, boolean openSource, boolean active,
44              boolean recommended)
45          throws PortalException, SystemException {
46  
47          validate(name);
48  
49          long licenseId = counterLocalService.increment();
50  
51          SCLicense license = scLicensePersistence.create(licenseId);
52  
53          license.setName(name);
54          license.setUrl(url);
55          license.setOpenSource(openSource);
56          license.setActive(active);
57          license.setRecommended(recommended);
58  
59          scLicensePersistence.update(license, false);
60  
61          return license;
62      }
63  
64      public void deleteLicense(long licenseId)
65          throws PortalException, SystemException {
66  
67          scLicensePersistence.remove(licenseId);
68      }
69  
70      public SCLicense getLicense(long licenseId)
71          throws PortalException, SystemException {
72  
73          return scLicensePersistence.findByPrimaryKey(licenseId);
74      }
75  
76      public List<SCLicense> getLicenses() throws SystemException {
77          return scLicensePersistence.findAll();
78      }
79  
80      public List<SCLicense> getLicenses(int start, int end)
81          throws SystemException {
82  
83          return scLicensePersistence.findAll(start, end);
84      }
85  
86      public List<SCLicense> getLicenses(boolean active, boolean recommended)
87          throws SystemException {
88  
89          return scLicensePersistence.findByA_R(active, recommended);
90      }
91  
92      public List<SCLicense> getLicenses(
93              boolean active, boolean recommended, int start, int end)
94          throws SystemException {
95  
96          return scLicensePersistence.findByA_R(active, recommended, start, end);
97      }
98  
99      public int getLicensesCount() throws SystemException {
100         return scLicensePersistence.countAll();
101     }
102 
103     public int getLicensesCount(boolean active, boolean recommended)
104         throws SystemException {
105 
106         return scLicensePersistence.countByA_R(active, recommended);
107     }
108 
109     public List<SCLicense> getProductEntryLicenses(long productEntryId)
110         throws SystemException {
111 
112         return scProductEntryPersistence.getSCLicenses(productEntryId);
113     }
114 
115     public SCLicense updateLicense(
116             long licenseId, String name, String url, boolean openSource,
117             boolean active, boolean recommended)
118         throws PortalException, SystemException {
119 
120         validate(name);
121 
122         SCLicense license = scLicensePersistence.findByPrimaryKey(licenseId);
123 
124         license.setName(name);
125         license.setUrl(url);
126         license.setOpenSource(openSource);
127         license.setActive(active);
128         license.setRecommended(recommended);
129 
130         scLicensePersistence.update(license, false);
131 
132         return license;
133     }
134 
135     protected void validate(String name) throws PortalException {
136         if (Validator.isNull(name)) {
137             throw new LicenseNameException();
138         }
139     }
140 
141 }