1
22
23 package com.liferay.portlet.tags.service.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.util.GetterUtil;
28 import com.liferay.portal.model.Company;
29 import com.liferay.portal.model.Group;
30 import com.liferay.portal.util.PortalUtil;
31 import com.liferay.portlet.tags.model.TagsAsset;
32 import com.liferay.portlet.tags.model.TagsAssetDisplay;
33 import com.liferay.portlet.tags.model.TagsAssetType;
34 import com.liferay.portlet.tags.service.base.TagsAssetServiceBaseImpl;
35 import com.liferay.util.RSSUtil;
36
37 import com.sun.syndication.feed.synd.SyndContent;
38 import com.sun.syndication.feed.synd.SyndContentImpl;
39 import com.sun.syndication.feed.synd.SyndEntry;
40 import com.sun.syndication.feed.synd.SyndEntryImpl;
41 import com.sun.syndication.feed.synd.SyndFeed;
42 import com.sun.syndication.feed.synd.SyndFeedImpl;
43 import com.sun.syndication.io.FeedException;
44
45 import java.io.IOException;
46
47 import java.util.ArrayList;
48 import java.util.Date;
49 import java.util.List;
50
51
58 public class TagsAssetServiceImpl extends TagsAssetServiceBaseImpl {
59
60 public void deleteAsset(long assetId)
61 throws PortalException, SystemException {
62
63 tagsAssetLocalService.deleteAsset(assetId);
64 }
65
66 public TagsAsset getAsset(long assetId)
67 throws PortalException, SystemException {
68
69 return tagsAssetLocalService.getAsset(assetId);
70 }
71
72 public String getAssetsRSS(
73 long groupId, long[] classNameIds, long[] entryIds,
74 long[] notEntryIds, boolean andOperator, String orderByCol1,
75 String orderByCol2, String orderByType1, String orderByType2,
76 boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
77 int max, String type, double version, String displayStyle,
78 String feedURL, String entryURL)
79 throws PortalException, SystemException {
80
81 Group group = groupPersistence.findByPrimaryKey(groupId);
82
83 String name = group.getName();
84
85 List<TagsAsset> assets = tagsAssetLocalService.getAssets(
86 groupId, classNameIds, entryIds, notEntryIds, andOperator,
87 orderByCol1, orderByCol2, orderByType1, orderByType2,
88 excludeZeroViewCount, publishDate, expirationDate, 0, max);
89
90 return exportToRSS(
91 name, null, type, version, displayStyle, feedURL, entryURL, assets);
92 }
93
94 public TagsAssetType[] getAssetTypes(String languageId) {
95 return tagsAssetLocalService.getAssetTypes(languageId);
96 }
97
98 public TagsAssetDisplay[] getCompanyAssetDisplays(
99 long companyId, int start, int end, String languageId)
100 throws SystemException {
101
102 return tagsAssetLocalService.getCompanyAssetDisplays(
103 companyId, start, end, languageId);
104 }
105
106 public List<TagsAsset> getCompanyAssets(long companyId, int start, int end)
107 throws SystemException {
108
109 return tagsAssetLocalService.getCompanyAssets(companyId, start, end);
110 }
111
112 public int getCompanyAssetsCount(long companyId) throws SystemException {
113 return tagsAssetLocalService.getCompanyAssetsCount(companyId);
114 }
115
116 public String getCompanyAssetsRSS(
117 long companyId, int max, String type, double version,
118 String displayStyle, String feedURL, String entryURL)
119 throws PortalException, SystemException {
120
121 Company company = companyPersistence.findByPrimaryKey(companyId);
122
123 String name = company.getName();
124
125 List<TagsAsset> assets = getCompanyAssets(companyId, 0, max);
126
127 return exportToRSS(
128 name, null, type, version, displayStyle, feedURL, entryURL, assets);
129 }
130
131 public TagsAsset incrementViewCounter(String className, long classPK)
132 throws SystemException {
133
134 return tagsAssetLocalService.incrementViewCounter(className, classPK);
135 }
136
137 public TagsAssetDisplay[] searchAssetDisplays(
138 long companyId, String portletId, String keywords,
139 String languageId, int start, int end)
140 throws SystemException {
141
142 return tagsAssetLocalService.searchAssetDisplays(
143 companyId, portletId, keywords, languageId, start, end);
144 }
145
146 public int searchAssetDisplaysCount(
147 long companyId, String portletId, String keywords,
148 String languageId)
149 throws SystemException {
150
151 return tagsAssetLocalService.searchAssetDisplaysCount(
152 companyId, portletId, keywords, languageId);
153 }
154
155 public TagsAsset updateAsset(
156 long groupId, String className, long classPK, String[] entryNames,
157 Date startDate, Date endDate, Date publishDate, Date expirationDate,
158 String mimeType, String title, String description, String summary,
159 String url, int height, int width, Integer priority)
160 throws PortalException, SystemException {
161
162 return tagsAssetLocalService.updateAsset(
163 getUserId(), groupId, className, classPK, entryNames, startDate,
164 endDate, publishDate, expirationDate, mimeType, title, description,
165 summary, url, height, width, priority);
166 }
167
168 protected String exportToRSS(
169 String name, String description, String type, double version,
170 String displayStyle, String feedURL, String entryURL,
171 List<TagsAsset> assets)
172 throws SystemException {
173
174 SyndFeed syndFeed = new SyndFeedImpl();
175
176 syndFeed.setFeedType(RSSUtil.getFeedType(type, version));
177 syndFeed.setTitle(name);
178 syndFeed.setLink(feedURL);
179 syndFeed.setDescription(GetterUtil.getString(description, name));
180
181 List<SyndEntry> entries = new ArrayList<SyndEntry>();
182
183 syndFeed.setEntries(entries);
184
185 for (TagsAsset asset : assets) {
186 String author = PortalUtil.getUserName(
187 asset.getUserId(), asset.getUserName());
188
189 String link = entryURL + "assetId=" + asset.getAssetId();
190
191 String value = asset.getSummary();
192
193 SyndEntry syndEntry = new SyndEntryImpl();
194
195 syndEntry.setAuthor(author);
196 syndEntry.setTitle(asset.getTitle());
197 syndEntry.setLink(link);
198 syndEntry.setPublishedDate(asset.getCreateDate());
199
200 SyndContent syndContent = new SyndContentImpl();
201
202 syndContent.setType(RSSUtil.DEFAULT_ENTRY_TYPE);
203 syndContent.setValue(value);
204
205 syndEntry.setDescription(syndContent);
206
207 entries.add(syndEntry);
208 }
209
210 try {
211 return RSSUtil.export(syndFeed);
212 }
213 catch (FeedException fe) {
214 throw new SystemException(fe);
215 }
216 catch (IOException ioe) {
217 throw new SystemException(ioe);
218 }
219 }
220
221 }