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