1   /**
2    * Copyright (c) 2000-2009 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, false);
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<SCLicense> getLicenses() throws SystemException {
78          return scLicensePersistence.findAll();
79      }
80  
81      public List<SCLicense> getLicenses(int start, int end)
82          throws SystemException {
83  
84          return scLicensePersistence.findAll(start, end);
85      }
86  
87      public List<SCLicense> getLicenses(boolean active, boolean recommended)
88          throws SystemException {
89  
90          return scLicensePersistence.findByA_R(active, recommended);
91      }
92  
93      public List<SCLicense> getLicenses(
94              boolean active, boolean recommended, int start, int end)
95          throws SystemException {
96  
97          return scLicensePersistence.findByA_R(active, recommended, start, end);
98      }
99  
100     public int getLicensesCount() throws SystemException {
101         return scLicensePersistence.countAll();
102     }
103 
104     public int getLicensesCount(boolean active, boolean recommended)
105         throws SystemException {
106 
107         return scLicensePersistence.countByA_R(active, recommended);
108     }
109 
110     public List<SCLicense> getProductEntryLicenses(long productEntryId)
111         throws SystemException {
112 
113         return scProductEntryPersistence.getSCLicenses(productEntryId);
114     }
115 
116     public SCLicense updateLicense(
117             long licenseId, String name, String url, boolean openSource,
118             boolean active, boolean recommended)
119         throws PortalException, SystemException {
120 
121         validate(name);
122 
123         SCLicense license = scLicensePersistence.findByPrimaryKey(licenseId);
124 
125         license.setName(name);
126         license.setUrl(url);
127         license.setOpenSource(openSource);
128         license.setActive(active);
129         license.setRecommended(recommended);
130 
131         scLicensePersistence.update(license, false);
132 
133         return license;
134     }
135 
136     protected void validate(String name) throws PortalException {
137         if (Validator.isNull(name)) {
138             throw new LicenseNameException();
139         }
140     }
141 
142 }