1   /**
2    * Copyright (c) 2000-2008 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.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   */
41  public class SCLicenseLocalServiceImpl extends SCLicenseLocalServiceBaseImpl {
42  
43      public SCLicense addLicense(
44              String name, String url, boolean openSource, boolean active,
45              boolean recommended)
46          throws PortalException, SystemException {
47  
48          validate(name);
49  
50          long licenseId = counterLocalService.increment();
51  
52          SCLicense license = scLicensePersistence.create(licenseId);
53  
54          license.setName(name);
55          license.setUrl(url);
56          license.setOpenSource(openSource);
57          license.setActive(active);
58          license.setRecommended(recommended);
59  
60          scLicensePersistence.update(license);
61  
62          return license;
63      }
64  
65      public void deleteLicense(long licenseId)
66          throws PortalException, SystemException {
67  
68          scLicensePersistence.remove(licenseId);
69      }
70  
71      public SCLicense getLicense(long licenseId)
72          throws PortalException, SystemException {
73  
74          return scLicensePersistence.findByPrimaryKey(licenseId);
75      }
76  
77      public List getLicenses() throws SystemException {
78          return scLicensePersistence.findAll();
79      }
80  
81      public List getLicenses(int begin, int end) throws SystemException {
82          return scLicensePersistence.findAll(begin, end);
83      }
84  
85      public List getLicenses(boolean active, boolean recommended)
86          throws SystemException {
87  
88          return scLicensePersistence.findByA_R(active, recommended);
89      }
90  
91      public List getLicenses(
92              boolean active, boolean recommended, int begin, int end)
93          throws SystemException {
94  
95          return scLicensePersistence.findByA_R(active, recommended, begin, end);
96      }
97  
98      public int getLicensesCount() throws SystemException {
99          return scLicensePersistence.countAll();
100     }
101 
102     public int getLicensesCount(boolean active, boolean recommended)
103         throws SystemException {
104 
105         return scLicensePersistence.countByA_R(active, recommended);
106     }
107 
108     public List getProductEntryLicenses(long productEntryId)
109         throws PortalException, SystemException {
110 
111         return scProductEntryPersistence.getSCLicenses(productEntryId);
112     }
113 
114     public SCLicense updateLicense(
115             long licenseId, String name, String url, boolean openSource,
116             boolean active, boolean recommended)
117         throws PortalException, SystemException {
118 
119         validate(name);
120 
121         SCLicense license = scLicensePersistence.findByPrimaryKey(licenseId);
122 
123         license.setName(name);
124         license.setUrl(url);
125         license.setOpenSource(openSource);
126         license.setActive(active);
127         license.setRecommended(recommended);
128 
129         scLicensePersistence.update(license);
130 
131         return license;
132     }
133 
134     protected void validate(String name) throws PortalException {
135         if (Validator.isNull(name)) {
136             throw new LicenseNameException();
137         }
138     }
139 
140 }