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