1
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
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 }