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