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