1
19
20 package com.liferay.portlet.softwarecatalog.service.impl;
21
22 import com.liferay.portal.PortalException;
23 import com.liferay.portal.SystemException;
24 import com.liferay.portal.kernel.util.Validator;
25 import com.liferay.portlet.softwarecatalog.LicenseNameException;
26 import com.liferay.portlet.softwarecatalog.model.SCLicense;
27 import com.liferay.portlet.softwarecatalog.service.base.SCLicenseLocalServiceBaseImpl;
28
29 import java.util.List;
30
31
38 public class SCLicenseLocalServiceImpl extends SCLicenseLocalServiceBaseImpl {
39
40 public SCLicense addLicense(
41 String name, String url, boolean openSource, boolean active,
42 boolean recommended)
43 throws PortalException, SystemException {
44
45 validate(name);
46
47 long licenseId = counterLocalService.increment();
48
49 SCLicense license = scLicensePersistence.create(licenseId);
50
51 license.setName(name);
52 license.setUrl(url);
53 license.setOpenSource(openSource);
54 license.setActive(active);
55 license.setRecommended(recommended);
56
57 scLicensePersistence.update(license, false);
58
59 return license;
60 }
61
62 public void deleteLicense(long licenseId)
63 throws PortalException, SystemException {
64
65 scLicensePersistence.remove(licenseId);
66 }
67
68 public SCLicense getLicense(long licenseId)
69 throws PortalException, SystemException {
70
71 return scLicensePersistence.findByPrimaryKey(licenseId);
72 }
73
74 public List<SCLicense> getLicenses() throws SystemException {
75 return scLicensePersistence.findAll();
76 }
77
78 public List<SCLicense> getLicenses(int start, int end)
79 throws SystemException {
80
81 return scLicensePersistence.findAll(start, end);
82 }
83
84 public List<SCLicense> getLicenses(boolean active, boolean recommended)
85 throws SystemException {
86
87 return scLicensePersistence.findByA_R(active, recommended);
88 }
89
90 public List<SCLicense> getLicenses(
91 boolean active, boolean recommended, int start, int end)
92 throws SystemException {
93
94 return scLicensePersistence.findByA_R(active, recommended, start, end);
95 }
96
97 public int getLicensesCount() throws SystemException {
98 return scLicensePersistence.countAll();
99 }
100
101 public int getLicensesCount(boolean active, boolean recommended)
102 throws SystemException {
103
104 return scLicensePersistence.countByA_R(active, recommended);
105 }
106
107 public List<SCLicense> getProductEntryLicenses(long productEntryId)
108 throws SystemException {
109
110 return scProductEntryPersistence.getSCLicenses(productEntryId);
111 }
112
113 public SCLicense updateLicense(
114 long licenseId, String name, String url, boolean openSource,
115 boolean active, boolean recommended)
116 throws PortalException, SystemException {
117
118 validate(name);
119
120 SCLicense license = scLicensePersistence.findByPrimaryKey(licenseId);
121
122 license.setName(name);
123 license.setUrl(url);
124 license.setOpenSource(openSource);
125 license.setActive(active);
126 license.setRecommended(recommended);
127
128 scLicensePersistence.update(license, false);
129
130 return license;
131 }
132
133 protected void validate(String name) throws PortalException {
134 if (Validator.isNull(name)) {
135 throw new LicenseNameException();
136 }
137 }
138
139 }