Source Code Cross Referenced for TagsAssetLocalServiceImpl.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portlet » tags » service » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » liferay portal 4.4.2 » com.liferay.portlet.tags.service.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003:         *
004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
005:         * of this software and associated documentation files (the "Software"), to deal
006:         * in the Software without restriction, including without limitation the rights
007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008:         * copies of the Software, and to permit persons to whom the Software is
009:         * furnished to do so, subject to the following conditions:
010:         *
011:         * The above copyright notice and this permission notice shall be included in
012:         * all copies or substantial portions of the Software.
013:         *
014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019:         * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020:         * SOFTWARE.
021:         */package com.liferay.portlet.tags.service.impl;
022:
023:        import com.liferay.portal.PortalException;
024:        import com.liferay.portal.SystemException;
025:        import com.liferay.portal.kernel.search.Document;
026:        import com.liferay.portal.kernel.search.Hits;
027:        import com.liferay.portal.kernel.util.GetterUtil;
028:        import com.liferay.portal.kernel.util.InstancePool;
029:        import com.liferay.portal.kernel.util.StringPool;
030:        import com.liferay.portal.kernel.util.StringUtil;
031:        import com.liferay.portal.kernel.util.Validator;
032:        import com.liferay.portal.lucene.LuceneFields;
033:        import com.liferay.portal.lucene.LuceneUtil;
034:        import com.liferay.portal.model.User;
035:        import com.liferay.portal.util.PortalInstances;
036:        import com.liferay.portal.util.PortalUtil;
037:        import com.liferay.portal.util.PortletKeys;
038:        import com.liferay.portal.util.PropsValues;
039:        import com.liferay.portlet.blogs.model.BlogsEntry;
040:        import com.liferay.portlet.bookmarks.model.BookmarksEntry;
041:        import com.liferay.portlet.documentlibrary.model.DLFileEntry;
042:        import com.liferay.portlet.imagegallery.model.IGImage;
043:        import com.liferay.portlet.journal.model.JournalArticle;
044:        import com.liferay.portlet.messageboards.model.MBMessage;
045:        import com.liferay.portlet.tags.model.TagsAsset;
046:        import com.liferay.portlet.tags.model.TagsAssetDisplay;
047:        import com.liferay.portlet.tags.model.TagsAssetType;
048:        import com.liferay.portlet.tags.model.TagsEntry;
049:        import com.liferay.portlet.tags.service.base.TagsAssetLocalServiceBaseImpl;
050:        import com.liferay.portlet.tags.util.TagsAssetValidator;
051:        import com.liferay.portlet.tags.util.TagsUtil;
052:        import com.liferay.portlet.wiki.model.WikiPage;
053:        import com.liferay.util.ListUtil;
054:        import com.liferay.util.lucene.HitsImpl;
055:
056:        import java.util.ArrayList;
057:        import java.util.Date;
058:        import java.util.List;
059:
060:        import org.apache.commons.logging.Log;
061:        import org.apache.commons.logging.LogFactory;
062:        import org.apache.lucene.index.Term;
063:        import org.apache.lucene.search.BooleanClause;
064:        import org.apache.lucene.search.BooleanQuery;
065:        import org.apache.lucene.search.Searcher;
066:        import org.apache.lucene.search.TermQuery;
067:
068:        /**
069:         * <a href="TagsAssetLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
070:         *
071:         * @author Brian Wing Shun Chan
072:         *
073:         */
074:        public class TagsAssetLocalServiceImpl extends
075:                TagsAssetLocalServiceBaseImpl {
076:
077:            public void deleteAsset(long assetId) throws PortalException,
078:                    SystemException {
079:
080:                TagsAsset asset = tagsAssetPersistence
081:                        .findByPrimaryKey(assetId);
082:
083:                deleteAsset(asset);
084:            }
085:
086:            public void deleteAsset(String className, long classPK)
087:                    throws PortalException, SystemException {
088:
089:                long classNameId = PortalUtil.getClassNameId(className);
090:
091:                TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId,
092:                        classPK);
093:
094:                if (asset != null) {
095:                    deleteAsset(asset);
096:                }
097:            }
098:
099:            public void deleteAsset(TagsAsset asset) throws PortalException,
100:                    SystemException {
101:
102:                tagsAssetPersistence.remove(asset.getAssetId());
103:            }
104:
105:            public TagsAsset getAsset(long assetId) throws PortalException,
106:                    SystemException {
107:
108:                return tagsAssetPersistence.findByPrimaryKey(assetId);
109:            }
110:
111:            public TagsAsset getAsset(String className, long classPK)
112:                    throws PortalException, SystemException {
113:
114:                long classNameId = PortalUtil.getClassNameId(className);
115:
116:                return tagsAssetPersistence.findByC_C(classNameId, classPK);
117:            }
118:
119:            public TagsAssetType[] getAssetTypes(String languageId) {
120:                TagsAssetType[] assetTypes = new TagsAssetType[TagsUtil.ASSET_TYPE_CLASS_NAMES.length];
121:
122:                for (int i = 0; i < TagsUtil.ASSET_TYPE_CLASS_NAMES.length; i++) {
123:                    assetTypes[i] = getAssetType(
124:                            TagsUtil.ASSET_TYPE_CLASS_NAMES[i], languageId);
125:                }
126:
127:                return assetTypes;
128:            }
129:
130:            public List getAssets(long[] entryIds, long[] notEntryIds,
131:                    boolean andOperator, boolean excludeZeroViewCount,
132:                    int begin, int end) throws SystemException {
133:
134:                return getAssets(0, new long[0], entryIds, notEntryIds,
135:                        andOperator, excludeZeroViewCount, null, null, begin,
136:                        end);
137:            }
138:
139:            public List getAssets(long groupId, long[] classNameIds,
140:                    long[] entryIds, long[] notEntryIds, boolean andOperator,
141:                    boolean excludeZeroViewCount, int begin, int end)
142:                    throws SystemException {
143:
144:                return getAssets(groupId, classNameIds, entryIds, notEntryIds,
145:                        andOperator, excludeZeroViewCount, null, null, begin,
146:                        end);
147:            }
148:
149:            public List getAssets(long[] entryIds, long[] notEntryIds,
150:                    boolean andOperator, boolean excludeZeroViewCount,
151:                    Date publishDate, Date expirationDate, int begin, int end)
152:                    throws SystemException {
153:
154:                return getAssets(0, new long[0], entryIds, notEntryIds,
155:                        andOperator, excludeZeroViewCount, null, null, begin,
156:                        end);
157:            }
158:
159:            public List getAssets(long groupId, long[] classNameIds,
160:                    long[] entryIds, long[] notEntryIds, boolean andOperator,
161:                    boolean excludeZeroViewCount, Date publishDate,
162:                    Date expirationDate, int begin, int end)
163:                    throws SystemException {
164:
165:                if (andOperator) {
166:                    return tagsAssetFinder.findByAndEntryIds(groupId,
167:                            classNameIds, entryIds, notEntryIds, null, null,
168:                            null, null, excludeZeroViewCount, publishDate,
169:                            expirationDate, begin, end);
170:                } else {
171:                    return tagsAssetFinder.findByOrEntryIds(groupId,
172:                            classNameIds, entryIds, notEntryIds, null, null,
173:                            null, null, excludeZeroViewCount, publishDate,
174:                            expirationDate, begin, end);
175:                }
176:            }
177:
178:            public List getAssets(long[] entryIds, long[] notEntryIds,
179:                    boolean andOperator, String orderByCol1,
180:                    String orderByCol2, String orderByType1,
181:                    String orderByType2, boolean excludeZeroViewCount,
182:                    Date publishDate, Date expirationDate, int begin, int end)
183:                    throws SystemException {
184:
185:                return getAssets(0, new long[0], entryIds, notEntryIds,
186:                        andOperator, excludeZeroViewCount, publishDate,
187:                        expirationDate, begin, end);
188:            }
189:
190:            public List getAssets(long groupId, long[] classNameIds,
191:                    long[] entryIds, long[] notEntryIds, boolean andOperator,
192:                    String orderByCol1, String orderByCol2,
193:                    String orderByType1, String orderByType2,
194:                    boolean excludeZeroViewCount, Date publishDate,
195:                    Date expirationDate, int begin, int end)
196:                    throws SystemException {
197:
198:                if (andOperator) {
199:                    return tagsAssetFinder.findByAndEntryIds(groupId,
200:                            classNameIds, entryIds, notEntryIds, orderByCol1,
201:                            orderByCol2, orderByType1, orderByType2,
202:                            excludeZeroViewCount, publishDate, expirationDate,
203:                            begin, end);
204:                } else {
205:                    return tagsAssetFinder.findByOrEntryIds(groupId,
206:                            classNameIds, entryIds, notEntryIds, orderByCol1,
207:                            orderByCol2, orderByType1, orderByType2,
208:                            excludeZeroViewCount, publishDate, expirationDate,
209:                            begin, end);
210:                }
211:            }
212:
213:            public int getAssetsCount(long[] entryIds, long[] notEntryIds,
214:                    boolean andOperator, boolean excludeZeroViewCount)
215:                    throws SystemException {
216:
217:                return getAssetsCount(0, new long[0], entryIds, notEntryIds,
218:                        andOperator, excludeZeroViewCount, null, null);
219:            }
220:
221:            public int getAssetsCount(long groupId, long[] entryIds,
222:                    long[] notEntryIds, boolean andOperator,
223:                    boolean excludeZeroViewCount) throws SystemException {
224:
225:                return getAssetsCount(groupId, new long[0], entryIds,
226:                        notEntryIds, andOperator, excludeZeroViewCount, null,
227:                        null);
228:            }
229:
230:            public int getAssetsCount(long[] entryIds, long[] notEntryIds,
231:                    boolean andOperator, boolean excludeZeroViewCount,
232:                    Date publishDate, Date expirationDate)
233:                    throws SystemException {
234:
235:                return getAssetsCount(0, new long[0], entryIds, notEntryIds,
236:                        andOperator, excludeZeroViewCount, publishDate,
237:                        expirationDate);
238:            }
239:
240:            public int getAssetsCount(long groupId, long[] classNameIds,
241:                    long[] entryIds, long[] notEntryIds, boolean andOperator,
242:                    boolean excludeZeroViewCount, Date publishDate,
243:                    Date expirationDate) throws SystemException {
244:
245:                if (andOperator) {
246:                    return tagsAssetFinder.countByAndEntryIds(groupId,
247:                            classNameIds, entryIds, notEntryIds,
248:                            excludeZeroViewCount, publishDate, expirationDate);
249:                } else {
250:                    return tagsAssetFinder.countByOrEntryIds(groupId,
251:                            classNameIds, entryIds, notEntryIds,
252:                            excludeZeroViewCount, publishDate, expirationDate);
253:                }
254:            }
255:
256:            public TagsAssetDisplay[] getCompanyAssetDisplays(long companyId,
257:                    int begin, int end, String languageId)
258:                    throws PortalException, SystemException {
259:
260:                return getAssetDisplays(
261:                        getCompanyAssets(companyId, begin, end), languageId);
262:            }
263:
264:            public List getCompanyAssets(long companyId, int begin, int end)
265:                    throws SystemException {
266:
267:                return tagsAssetPersistence.findByCompanyId(companyId, begin,
268:                        end);
269:            }
270:
271:            public int getCompanyAssetsCount(long companyId)
272:                    throws SystemException {
273:                return tagsAssetPersistence.countByCompanyId(companyId);
274:            }
275:
276:            public List getTopViewedAssets(String className, boolean asc,
277:                    int begin, int end) throws SystemException {
278:
279:                return getTopViewedAssets(new String[] { className }, asc,
280:                        begin, end);
281:            }
282:
283:            public List getTopViewedAssets(String[] className, boolean asc,
284:                    int begin, int end) throws SystemException {
285:
286:                long[] classNameIds = new long[className.length];
287:
288:                for (int i = 0; i < className.length; i++) {
289:                    classNameIds[i] = PortalUtil.getClassNameId(className[i]);
290:                }
291:
292:                return tagsAssetFinder.findByViewCount(classNameIds, asc,
293:                        begin, end);
294:            }
295:
296:            public TagsAsset incrementViewCounter(String className, long classPK)
297:                    throws PortalException, SystemException {
298:
299:                if (classPK <= 0) {
300:                    return null;
301:                }
302:
303:                long classNameId = PortalUtil.getClassNameId(className);
304:
305:                TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId,
306:                        classPK);
307:
308:                if (asset != null) {
309:                    asset.setViewCount(asset.getViewCount() + 1);
310:
311:                    tagsAssetPersistence.update(asset);
312:                }
313:
314:                return asset;
315:            }
316:
317:            public Hits search(long companyId, String portletId, String keywords)
318:                    throws SystemException {
319:
320:                Searcher searcher = null;
321:
322:                try {
323:                    HitsImpl hits = new HitsImpl();
324:
325:                    BooleanQuery contextQuery = new BooleanQuery();
326:
327:                    if (Validator.isNotNull(portletId)) {
328:                        LuceneUtil.addRequiredTerm(contextQuery,
329:                                LuceneFields.PORTLET_ID, portletId);
330:                    } else {
331:                        BooleanQuery portletIdsQuery = new BooleanQuery();
332:
333:                        for (int i = 0; i < TagsUtil.ASSET_TYPE_PORTLET_IDS.length; i++) {
334:
335:                            Term term = new Term(LuceneFields.PORTLET_ID,
336:                                    TagsUtil.ASSET_TYPE_PORTLET_IDS[i]);
337:                            TermQuery termQuery = new TermQuery(term);
338:
339:                            portletIdsQuery.add(termQuery,
340:                                    BooleanClause.Occur.SHOULD);
341:                        }
342:
343:                        contextQuery.add(portletIdsQuery,
344:                                BooleanClause.Occur.MUST);
345:                    }
346:
347:                    BooleanQuery searchQuery = new BooleanQuery();
348:
349:                    if (Validator.isNotNull(keywords)) {
350:                        LuceneUtil.addTerm(searchQuery, LuceneFields.TITLE,
351:                                keywords);
352:                        LuceneUtil.addTerm(searchQuery, LuceneFields.CONTENT,
353:                                keywords);
354:                        LuceneUtil.addTerm(searchQuery,
355:                                LuceneFields.DESCRIPTION, keywords);
356:                        LuceneUtil.addTerm(searchQuery,
357:                                LuceneFields.PROPERTIES, keywords);
358:                        LuceneUtil.addTerm(searchQuery, LuceneFields.TAG_ENTRY,
359:                                keywords);
360:                    }
361:
362:                    BooleanQuery fullQuery = new BooleanQuery();
363:
364:                    fullQuery.add(contextQuery, BooleanClause.Occur.MUST);
365:
366:                    if (searchQuery.clauses().size() > 0) {
367:                        fullQuery.add(searchQuery, BooleanClause.Occur.MUST);
368:                    }
369:
370:                    searcher = LuceneUtil.getSearcher(companyId);
371:
372:                    hits.recordHits(searcher.search(fullQuery), searcher);
373:
374:                    return hits;
375:                } catch (Exception e) {
376:                    return LuceneUtil.closeSearcher(searcher, keywords, e);
377:                }
378:            }
379:
380:            public TagsAssetDisplay[] searchAssetDisplays(long companyId,
381:                    String portletId, String keywords, String languageId,
382:                    int begin, int end) throws PortalException, SystemException {
383:
384:                List assets = new ArrayList();
385:
386:                Hits hits = search(companyId, portletId, keywords);
387:
388:                hits = hits.subset(begin, end);
389:
390:                List hitsList = hits.toList();
391:
392:                for (int i = 0; i < hitsList.size(); i++) {
393:                    Document doc = (Document) hitsList.get(i);
394:
395:                    try {
396:                        TagsAsset asset = getAsset(doc);
397:
398:                        if (asset != null) {
399:                            assets.add(asset);
400:                        }
401:                    } catch (Exception e) {
402:                        if (_log.isWarnEnabled()) {
403:                            _log.warn(e);
404:                        }
405:                    }
406:                }
407:
408:                return getAssetDisplays(assets, languageId);
409:            }
410:
411:            public int searchAssetDisplaysCount(long companyId,
412:                    String portletId, String keywords, String languageId)
413:                    throws SystemException {
414:
415:                Hits hits = search(companyId, portletId, keywords);
416:
417:                return hits.getLength();
418:            }
419:
420:            public TagsAsset updateAsset(long userId, long groupId,
421:                    String className, long classPK, String[] entryNames)
422:                    throws PortalException, SystemException {
423:
424:                return updateAsset(userId, groupId, className, classPK,
425:                        entryNames, null, null, null, null, null, null, null,
426:                        null, null, 0, 0, null);
427:            }
428:
429:            public TagsAsset updateAsset(long userId, long groupId,
430:                    String className, long classPK, String[] entryNames,
431:                    Date startDate, Date endDate, Date publishDate,
432:                    Date expirationDate, String mimeType, String title,
433:                    String description, String summary, String url, int height,
434:                    int width, Integer priority) throws PortalException,
435:                    SystemException {
436:
437:                return updateAsset(userId, groupId, className, classPK,
438:                        entryNames, startDate, endDate, publishDate,
439:                        expirationDate, mimeType, title, description, summary,
440:                        url, height, width, priority, true);
441:            }
442:
443:            public TagsAsset updateAsset(long userId, long groupId,
444:                    String className, long classPK, String[] entryNames,
445:                    Date startDate, Date endDate, Date publishDate,
446:                    Date expirationDate, String mimeType, String title,
447:                    String description, String summary, String url, int height,
448:                    int width, Integer priority, boolean sync)
449:                    throws PortalException, SystemException {
450:
451:                // Asset
452:
453:                User user = userPersistence.findByPrimaryKey(userId);
454:                long classNameId = PortalUtil.getClassNameId(className);
455:
456:                if (entryNames == null) {
457:                    entryNames = new String[0];
458:                }
459:
460:                title = StringUtil.shorten(title, 300, StringPool.BLANK);
461:                Date now = new Date();
462:
463:                validate(className, entryNames);
464:
465:                TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId,
466:                        classPK);
467:
468:                if (asset == null) {
469:                    long assetId = counterLocalService.increment();
470:
471:                    asset = tagsAssetPersistence.create(assetId);
472:
473:                    asset.setCompanyId(user.getCompanyId());
474:                    asset.setUserId(user.getUserId());
475:                    asset.setUserName(user.getFullName());
476:                    asset.setCreateDate(now);
477:                    asset.setClassNameId(classNameId);
478:                    asset.setClassPK(classPK);
479:                    asset.setPublishDate(publishDate);
480:                    asset.setExpirationDate(expirationDate);
481:
482:                    if (priority == null) {
483:                        asset.setPriority(0);
484:                    }
485:
486:                    asset.setViewCount(0);
487:                }
488:
489:                asset.setGroupId(groupId);
490:                asset.setModifiedDate(now);
491:                asset.setStartDate(startDate);
492:                asset.setEndDate(endDate);
493:                asset.setPublishDate(publishDate);
494:                asset.setExpirationDate(expirationDate);
495:                asset.setMimeType(mimeType);
496:                asset.setTitle(title);
497:                asset.setDescription(description);
498:                asset.setSummary(summary);
499:                asset.setUrl(url);
500:                asset.setHeight(height);
501:                asset.setWidth(width);
502:
503:                if (priority != null) {
504:                    asset.setPriority(priority.intValue());
505:                }
506:
507:                tagsAssetPersistence.update(asset);
508:
509:                // Entries
510:
511:                List entries = new ArrayList(entryNames.length);
512:
513:                for (int i = 0; i < entryNames.length; i++) {
514:                    String name = entryNames[i].trim().toLowerCase();
515:
516:                    TagsEntry entry = tagsEntryPersistence.fetchByC_N(user
517:                            .getCompanyId(), name);
518:
519:                    if (entry == null) {
520:                        entry = tagsEntryLocalService.addEntry(
521:                                user.getUserId(), entryNames[i],
522:                                TagsEntryLocalServiceImpl.DEFAULT_PROPERTIES);
523:                    }
524:
525:                    entries.add(entry);
526:                }
527:
528:                tagsAssetPersistence
529:                        .setTagsEntries(asset.getAssetId(), entries);
530:
531:                // Synchronize
532:
533:                if (!sync) {
534:                    return asset;
535:                }
536:
537:                if (className.equals(BlogsEntry.class.getName())) {
538:                    BlogsEntry entry = blogsEntryPersistence
539:                            .findByPrimaryKey(classPK);
540:
541:                    entry.setTitle(title);
542:
543:                    blogsEntryPersistence.update(entry);
544:                } else if (className.equals(BookmarksEntry.class.getName())) {
545:                    BookmarksEntry entry = bookmarksEntryPersistence
546:                            .findByPrimaryKey(classPK);
547:
548:                    entry.setName(title);
549:                    entry.setComments(description);
550:                    entry.setUrl(url);
551:
552:                    bookmarksEntryPersistence.update(entry);
553:                } else if (className.equals(DLFileEntry.class.getName())) {
554:                    DLFileEntry fileEntry = dlFileEntryPersistence
555:                            .findByPrimaryKey(classPK);
556:
557:                    fileEntry.setTitle(title);
558:                    fileEntry.setDescription(description);
559:
560:                    dlFileEntryPersistence.update(fileEntry);
561:                } else if (className.equals(JournalArticle.class.getName())) {
562:                    JournalArticle article = journalArticlePersistence
563:                            .findByPrimaryKey(classPK);
564:
565:                    article.setTitle(title);
566:                    article.setDescription(description);
567:
568:                    journalArticlePersistence.update(article);
569:                } else if (className.equals(MBMessage.class.getName())) {
570:                    MBMessage message = mbMessagePersistence
571:                            .findByPrimaryKey(classPK);
572:
573:                    message.setSubject(title);
574:
575:                    mbMessagePersistence.update(message);
576:                } else if (className.equals(WikiPage.class.getName())) {
577:                    WikiPage page = wikiPagePersistence
578:                            .findByPrimaryKey(classPK);
579:
580:                    page.setTitle(title);
581:
582:                    wikiPagePersistence.update(page);
583:                }
584:
585:                return asset;
586:            }
587:
588:            public void validate(String className, String[] entryNames)
589:                    throws PortalException {
590:
591:                TagsAssetValidator validator = (TagsAssetValidator) InstancePool
592:                        .get(PropsValues.TAGS_ASSET_VALIDATOR);
593:
594:                validator.validate(className, entryNames);
595:            }
596:
597:            protected TagsAsset getAsset(Document doc) throws PortalException,
598:                    SystemException {
599:
600:                String portletId = GetterUtil.getString(doc
601:                        .get(LuceneFields.PORTLET_ID));
602:
603:                if (portletId.equals(PortletKeys.BLOGS)) {
604:                    long entryId = GetterUtil.getLong(doc.get("entryId"));
605:
606:                    long classNameId = PortalUtil
607:                            .getClassNameId(BlogsEntry.class.getName());
608:                    long classPK = entryId;
609:
610:                    return tagsAssetPersistence.findByC_C(classNameId, classPK);
611:                } else if (portletId.equals(PortletKeys.BOOKMARKS)) {
612:                    long entryId = GetterUtil.getLong(doc.get("entryId"));
613:
614:                    long classNameId = PortalUtil
615:                            .getClassNameId(BookmarksEntry.class.getName());
616:                    long classPK = entryId;
617:
618:                    return tagsAssetPersistence.findByC_C(classNameId, classPK);
619:                } else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
620:                    long folderId = GetterUtil.getLong(doc.get("repositoryId"));
621:                    String name = doc.get("path");
622:
623:                    DLFileEntry fileEntry = dlFileEntryLocalService
624:                            .getFileEntry(folderId, name);
625:
626:                    long classNameId = PortalUtil
627:                            .getClassNameId(DLFileEntry.class.getName());
628:                    long classPK = fileEntry.getFileEntryId();
629:
630:                    return tagsAssetPersistence.findByC_C(classNameId, classPK);
631:                } else if (portletId.equals(PortletKeys.IMAGE_GALLERY)) {
632:                    long imageId = GetterUtil.getLong(doc.get("imageId"));
633:
634:                    long classNameId = PortalUtil.getClassNameId(IGImage.class
635:                            .getName());
636:                    long classPK = imageId;
637:
638:                    return tagsAssetPersistence.findByC_C(classNameId, classPK);
639:                } else if (portletId.equals(PortletKeys.JOURNAL)) {
640:                    long groupId = GetterUtil.getLong(doc
641:                            .get(LuceneFields.GROUP_ID));
642:                    String articleId = doc.get("articleId");
643:                    //double version = GetterUtil.getDouble(doc.get("version"));
644:
645:                    long articleResourcePrimKey = journalArticleResourceLocalService
646:                            .getArticleResourcePrimKey(groupId, articleId);
647:
648:                    long classNameId = PortalUtil
649:                            .getClassNameId(JournalArticle.class.getName());
650:                    long classPK = articleResourcePrimKey;
651:
652:                    return tagsAssetPersistence.findByC_C(classNameId, classPK);
653:                } else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
654:                    long messageId = GetterUtil.getLong(doc.get("messageId"));
655:
656:                    long classNameId = PortalUtil
657:                            .getClassNameId(MBMessage.class.getName());
658:                    long classPK = messageId;
659:
660:                    return tagsAssetPersistence.findByC_C(classNameId, classPK);
661:                } else if (portletId.equals(PortletKeys.WIKI)) {
662:                    long nodeId = GetterUtil.getLong(doc.get("nodeId"));
663:                    String title = doc.get(LuceneFields.TITLE);
664:
665:                    long pageResourcePrimKey = wikiPageResourceLocalService
666:                            .getPageResourcePrimKey(nodeId, title);
667:
668:                    long classNameId = PortalUtil.getClassNameId(WikiPage.class
669:                            .getName());
670:                    long classPK = pageResourcePrimKey;
671:
672:                    return tagsAssetPersistence.findByC_C(classNameId, classPK);
673:                }
674:
675:                return null;
676:            }
677:
678:            protected TagsAssetDisplay[] getAssetDisplays(List assets,
679:                    String languageId) throws PortalException, SystemException {
680:
681:                TagsAssetDisplay[] assetDisplays = new TagsAssetDisplay[assets
682:                        .size()];
683:
684:                for (int i = 0; i < assets.size(); i++) {
685:                    TagsAsset asset = (TagsAsset) assets.get(i);
686:
687:                    String className = PortalUtil.getClassName(asset
688:                            .getClassNameId());
689:                    String portletId = PortalUtil
690:                            .getClassNamePortletId(className);
691:                    String portletTitle = PortalUtil.getPortletTitle(portletId,
692:                            asset.getCompanyId(), languageId);
693:
694:                    List tagsEntriesList = tagsAssetPersistence
695:                            .getTagsEntries(asset.getAssetId());
696:
697:                    String tagsEntries = ListUtil.toString(tagsEntriesList,
698:                            "name", ", ");
699:
700:                    TagsAssetDisplay assetDisplay = new TagsAssetDisplay();
701:
702:                    assetDisplay.setAssetId(asset.getAssetId());
703:                    assetDisplay.setCompanyId(asset.getCompanyId());
704:                    assetDisplay.setUserId(asset.getUserId());
705:                    assetDisplay.setUserName(asset.getUserName());
706:                    assetDisplay.setCreateDate(asset.getCreateDate());
707:                    assetDisplay.setModifiedDate(asset.getModifiedDate());
708:                    assetDisplay.setClassNameId(asset.getClassNameId());
709:                    assetDisplay.setClassName(className);
710:                    assetDisplay.setClassPK(asset.getClassPK());
711:                    assetDisplay.setPortletId(portletId);
712:                    assetDisplay.setPortletTitle(portletTitle);
713:                    assetDisplay.setStartDate(asset.getStartDate());
714:                    assetDisplay.setEndDate(asset.getEndDate());
715:                    assetDisplay.setPublishDate(asset.getPublishDate());
716:                    assetDisplay.setExpirationDate(asset.getExpirationDate());
717:                    assetDisplay.setMimeType(asset.getMimeType());
718:                    assetDisplay.setTitle(asset.getTitle());
719:                    assetDisplay.setDescription(asset.getDescription());
720:                    assetDisplay.setSummary(asset.getSummary());
721:                    assetDisplay.setUrl(asset.getUrl());
722:                    assetDisplay.setHeight(asset.getHeight());
723:                    assetDisplay.setWidth(asset.getWidth());
724:                    assetDisplay.setPriority(asset.getPriority());
725:                    assetDisplay.setViewCount(asset.getViewCount());
726:                    assetDisplay.setTagsEntries(tagsEntries);
727:
728:                    assetDisplays[i] = assetDisplay;
729:                }
730:
731:                return assetDisplays;
732:            }
733:
734:            protected TagsAssetType getAssetType(String className,
735:                    String languageId) {
736:                long companyId = PortalInstances.getDefaultCompanyId();
737:
738:                long classNameId = PortalUtil.getClassNameId(className);
739:
740:                String portletId = PortalUtil.getClassNamePortletId(className);
741:                String portletTitle = PortalUtil.getPortletTitle(portletId,
742:                        companyId, languageId);
743:
744:                TagsAssetType assetType = new TagsAssetType();
745:
746:                assetType.setClassNameId(classNameId);
747:                assetType.setClassName(className);
748:                assetType.setPortletId(portletId);
749:                assetType.setPortletTitle(portletTitle);
750:
751:                return assetType;
752:            }
753:
754:            private static Log _log = LogFactory
755:                    .getLog(TagsAssetLocalServiceImpl.class);
756:
757:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.