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