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