Source Code Cross Referenced for SCProductEntryLocalServiceImpl.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portlet » softwarecatalog » 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.softwarecatalog.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.softwarecatalog.service.impl;
022:
023:        import com.liferay.portal.PortalException;
024:        import com.liferay.portal.SystemException;
025:        import com.liferay.portal.kernel.search.Hits;
026:        import com.liferay.portal.kernel.servlet.ImageServletTokenUtil;
027:        import com.liferay.portal.kernel.util.GetterUtil;
028:        import com.liferay.portal.kernel.util.OrderByComparator;
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.model.impl.ResourceImpl;
036:        import com.liferay.portal.plugin.ModuleId;
037:        import com.liferay.portal.service.impl.ImageLocalUtil;
038:        import com.liferay.portal.util.PortalUtil;
039:        import com.liferay.portlet.softwarecatalog.DuplicateProductEntryModuleIdException;
040:        import com.liferay.portlet.softwarecatalog.NoSuchProductEntryException;
041:        import com.liferay.portlet.softwarecatalog.ProductEntryAuthorException;
042:        import com.liferay.portlet.softwarecatalog.ProductEntryLicenseException;
043:        import com.liferay.portlet.softwarecatalog.ProductEntryNameException;
044:        import com.liferay.portlet.softwarecatalog.ProductEntryPageURLException;
045:        import com.liferay.portlet.softwarecatalog.ProductEntryScreenshotsException;
046:        import com.liferay.portlet.softwarecatalog.ProductEntryShortDescriptionException;
047:        import com.liferay.portlet.softwarecatalog.ProductEntryTypeException;
048:        import com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion;
049:        import com.liferay.portlet.softwarecatalog.model.SCLicense;
050:        import com.liferay.portlet.softwarecatalog.model.SCProductEntry;
051:        import com.liferay.portlet.softwarecatalog.model.SCProductScreenshot;
052:        import com.liferay.portlet.softwarecatalog.model.SCProductVersion;
053:        import com.liferay.portlet.softwarecatalog.service.base.SCProductEntryLocalServiceBaseImpl;
054:        import com.liferay.portlet.softwarecatalog.util.Indexer;
055:        import com.liferay.util.Time;
056:        import com.liferay.util.Version;
057:        import com.liferay.util.lucene.HitsImpl;
058:        import com.liferay.util.xml.DocUtil;
059:
060:        import java.io.IOException;
061:
062:        import java.net.MalformedURLException;
063:        import java.net.URL;
064:
065:        import java.util.Date;
066:        import java.util.Iterator;
067:        import java.util.List;
068:        import java.util.Properties;
069:
070:        import org.apache.commons.logging.Log;
071:        import org.apache.commons.logging.LogFactory;
072:        import org.apache.lucene.index.IndexWriter;
073:        import org.apache.lucene.search.BooleanClause;
074:        import org.apache.lucene.search.BooleanQuery;
075:        import org.apache.lucene.search.Searcher;
076:
077:        import org.dom4j.Document;
078:        import org.dom4j.DocumentHelper;
079:        import org.dom4j.Element;
080:
081:        /**
082:         * <a href="SCProductEntryLocalServiceImpl.java.html"><b><i>View Source</i></b>
083:         * </a>
084:         *
085:         * @author Jorge Ferrer
086:         * @author Brian Wing Shun Chan
087:         *
088:         */
089:        public class SCProductEntryLocalServiceImpl extends
090:                SCProductEntryLocalServiceBaseImpl {
091:
092:            public SCProductEntry addProductEntry(long userId, long plid,
093:                    String name, String type, String tags,
094:                    String shortDescription, String longDescription,
095:                    String pageURL, String author, String repoGroupId,
096:                    String repoArtifactId, long[] licenseIds, List thumbnails,
097:                    List fullImages, boolean addCommunityPermissions,
098:                    boolean addGuestPermissions) throws PortalException,
099:                    SystemException {
100:
101:                return addProductEntry(userId, plid, name, type, tags,
102:                        shortDescription, longDescription, pageURL, author,
103:                        repoGroupId, repoArtifactId, licenseIds, thumbnails,
104:                        fullImages, Boolean.valueOf(addCommunityPermissions),
105:                        Boolean.valueOf(addGuestPermissions), null, null);
106:            }
107:
108:            public SCProductEntry addProductEntry(long userId, long plid,
109:                    String name, String type, String tags,
110:                    String shortDescription, String longDescription,
111:                    String pageURL, String author, String repoGroupId,
112:                    String repoArtifactId, long[] licenseIds, List thumbnails,
113:                    List fullImages, String[] communityPermissions,
114:                    String[] guestPermissions) throws PortalException,
115:                    SystemException {
116:
117:                return addProductEntry(userId, plid, name, type, tags,
118:                        shortDescription, longDescription, pageURL, author,
119:                        repoGroupId, repoArtifactId, licenseIds, thumbnails,
120:                        fullImages, null, null, communityPermissions,
121:                        guestPermissions);
122:            }
123:
124:            public SCProductEntry addProductEntry(long userId, long plid,
125:                    String name, String type, String tags,
126:                    String shortDescription, String longDescription,
127:                    String pageURL, String author, String repoGroupId,
128:                    String repoArtifactId, long[] licenseIds, List thumbnails,
129:                    List fullImages, Boolean addCommunityPermissions,
130:                    Boolean addGuestPermissions, String[] communityPermissions,
131:                    String[] guestPermissions) throws PortalException,
132:                    SystemException {
133:
134:                // Product entry
135:
136:                User user = userPersistence.findByPrimaryKey(userId);
137:                long groupId = PortalUtil.getPortletGroupId(plid);
138:                tags = getTags(tags);
139:                repoGroupId = repoGroupId.trim().toLowerCase();
140:                repoArtifactId = repoArtifactId.trim().toLowerCase();
141:                Date now = new Date();
142:
143:                validate(0, name, type, shortDescription, pageURL, author,
144:                        repoGroupId, repoArtifactId, licenseIds, thumbnails,
145:                        fullImages);
146:
147:                long productEntryId = counterLocalService.increment();
148:
149:                SCProductEntry productEntry = scProductEntryPersistence
150:                        .create(productEntryId);
151:
152:                productEntry.setGroupId(groupId);
153:                productEntry.setCompanyId(user.getCompanyId());
154:                productEntry.setUserId(user.getUserId());
155:                productEntry.setUserName(user.getFullName());
156:                productEntry.setCreateDate(now);
157:                productEntry.setModifiedDate(now);
158:                productEntry.setName(name);
159:                productEntry.setType(type);
160:                productEntry.setTags(tags);
161:                productEntry.setShortDescription(shortDescription);
162:                productEntry.setLongDescription(longDescription);
163:                productEntry.setPageURL(pageURL);
164:                productEntry.setAuthor(author);
165:                productEntry.setRepoGroupId(repoGroupId);
166:                productEntry.setRepoArtifactId(repoArtifactId);
167:
168:                scProductEntryPersistence.update(productEntry);
169:
170:                // Resources
171:
172:                if ((addCommunityPermissions != null)
173:                        && (addGuestPermissions != null)) {
174:
175:                    addProductEntryResources(productEntry,
176:                            addCommunityPermissions.booleanValue(),
177:                            addGuestPermissions.booleanValue());
178:                } else {
179:                    addProductEntryResources(productEntry,
180:                            communityPermissions, guestPermissions);
181:                }
182:
183:                // Licenses
184:
185:                scProductEntryPersistence.setSCLicenses(productEntryId,
186:                        licenseIds);
187:
188:                // Product screenshots
189:
190:                saveProductScreenshots(productEntry, thumbnails, fullImages);
191:
192:                // Lucene
193:
194:                try {
195:                    Indexer.addProductEntry(productEntry.getCompanyId(),
196:                            groupId, userId, user.getFullName(),
197:                            productEntryId, name, now, StringPool.BLANK, type,
198:                            shortDescription, longDescription, pageURL,
199:                            repoGroupId, repoArtifactId);
200:                } catch (IOException ioe) {
201:                    _log.error("Indexing " + productEntryId, ioe);
202:                }
203:
204:                return productEntry;
205:            }
206:
207:            public void addProductEntryResources(long productEntryId,
208:                    boolean addCommunityPermissions, boolean addGuestPermissions)
209:                    throws PortalException, SystemException {
210:
211:                SCProductEntry productEntry = scProductEntryPersistence
212:                        .findByPrimaryKey(productEntryId);
213:
214:                addProductEntryResources(productEntry, addCommunityPermissions,
215:                        addGuestPermissions);
216:            }
217:
218:            public void addProductEntryResources(SCProductEntry productEntry,
219:                    boolean addCommunityPermissions, boolean addGuestPermissions)
220:                    throws PortalException, SystemException {
221:
222:                resourceLocalService.addResources(productEntry.getCompanyId(),
223:                        productEntry.getGroupId(), productEntry.getUserId(),
224:                        SCProductEntry.class.getName(), productEntry
225:                                .getProductEntryId(), false,
226:                        addCommunityPermissions, addGuestPermissions);
227:            }
228:
229:            public void addProductEntryResources(long productEntryId,
230:                    String[] communityPermissions, String[] guestPermissions)
231:                    throws PortalException, SystemException {
232:
233:                SCProductEntry productEntry = scProductEntryPersistence
234:                        .findByPrimaryKey(productEntryId);
235:
236:                addProductEntryResources(productEntry, communityPermissions,
237:                        guestPermissions);
238:            }
239:
240:            public void addProductEntryResources(SCProductEntry productEntry,
241:                    String[] communityPermissions, String[] guestPermissions)
242:                    throws PortalException, SystemException {
243:
244:                resourceLocalService.addModelResources(productEntry
245:                        .getCompanyId(), productEntry.getGroupId(),
246:                        productEntry.getUserId(), SCProductEntry.class
247:                                .getName(), productEntry.getProductEntryId(),
248:                        communityPermissions, guestPermissions);
249:            }
250:
251:            public void deleteProductEntries(long groupId)
252:                    throws PortalException, SystemException {
253:
254:                Iterator itr = scProductEntryPersistence.findByGroupId(groupId)
255:                        .iterator();
256:
257:                while (itr.hasNext()) {
258:                    SCProductEntry productEntry = (SCProductEntry) itr.next();
259:
260:                    deleteProductEntry(productEntry);
261:                }
262:            }
263:
264:            public void deleteProductEntry(long productEntryId)
265:                    throws PortalException, SystemException {
266:
267:                SCProductEntry productEntry = scProductEntryPersistence
268:                        .findByPrimaryKey(productEntryId);
269:
270:                deleteProductEntry(productEntry);
271:            }
272:
273:            public void deleteProductEntry(SCProductEntry productEntry)
274:                    throws PortalException, SystemException {
275:
276:                // Lucene
277:
278:                try {
279:                    Indexer.deleteProductEntry(productEntry.getCompanyId(),
280:                            productEntry.getProductEntryId());
281:                } catch (IOException ioe) {
282:                    _log.error("Deleting index "
283:                            + productEntry.getProductEntryId(), ioe);
284:                }
285:
286:                // Product screenshots
287:
288:                scProductScreenshotLocalService
289:                        .deleteProductScreenshots(productEntry
290:                                .getProductEntryId());
291:
292:                // Product versions
293:
294:                scProductVersionLocalService.deleteProductVersions(productEntry
295:                        .getProductEntryId());
296:
297:                // Ratings
298:
299:                ratingsStatsLocalService.deleteStats(SCProductEntry.class
300:                        .getName(), productEntry.getProductEntryId());
301:
302:                // Message boards
303:
304:                mbMessageLocalService.deleteDiscussionMessages(
305:                        SCProductEntry.class.getName(), productEntry
306:                                .getProductEntryId());
307:
308:                // Resources
309:
310:                resourceLocalService.deleteResource(
311:                        productEntry.getCompanyId(), SCProductEntry.class
312:                                .getName(), ResourceImpl.SCOPE_INDIVIDUAL,
313:                        productEntry.getProductEntryId());
314:
315:                // Product entry
316:
317:                scProductEntryPersistence.remove(productEntry);
318:            }
319:
320:            public SCProductEntry getProductEntry(long productEntryId)
321:                    throws PortalException, SystemException {
322:
323:                return scProductEntryPersistence
324:                        .findByPrimaryKey(productEntryId);
325:            }
326:
327:            public List getProductEntries(long groupId, int begin, int end)
328:                    throws SystemException {
329:
330:                return scProductEntryPersistence.findByGroupId(groupId, begin,
331:                        end);
332:            }
333:
334:            public List getProductEntries(long groupId, int begin, int end,
335:                    OrderByComparator obc) throws SystemException {
336:
337:                return scProductEntryPersistence.findByGroupId(groupId, begin,
338:                        end, obc);
339:            }
340:
341:            public List getProductEntries(long groupId, long userId, int begin,
342:                    int end) throws SystemException {
343:
344:                return scProductEntryPersistence.findByG_U(groupId, userId,
345:                        begin, end);
346:            }
347:
348:            public List getProductEntries(long groupId, long userId, int begin,
349:                    int end, OrderByComparator obc) throws SystemException {
350:
351:                return scProductEntryPersistence.findByG_U(groupId, userId,
352:                        begin, end, obc);
353:            }
354:
355:            public int getProductEntriesCount(long groupId)
356:                    throws SystemException {
357:
358:                return scProductEntryPersistence.countByGroupId(groupId);
359:            }
360:
361:            public int getProductEntriesCount(long groupId, long userId)
362:                    throws SystemException {
363:
364:                return scProductEntryPersistence.countByG_U(groupId, userId);
365:            }
366:
367:            public String getRepositoryXML(long groupId, String baseImageURL,
368:                    Date oldestDate, int maxNumOfVersions,
369:                    Properties repoSettings) throws PortalException,
370:                    SystemException {
371:
372:                return getRepositoryXML(groupId, null, baseImageURL,
373:                        oldestDate, maxNumOfVersions, repoSettings);
374:            }
375:
376:            public String getRepositoryXML(long groupId, String version,
377:                    String baseImageURL, Date oldestDate, int maxNumOfVersions,
378:                    Properties repoSettings) throws PortalException,
379:                    SystemException {
380:
381:                Document doc = DocumentHelper.createDocument();
382:
383:                doc.setXMLEncoding("UTF-8");
384:
385:                Element root = doc.addElement("plugin-repository");
386:
387:                Element settingsEl = root.addElement("settings");
388:
389:                populateSettingsElement(settingsEl, repoSettings);
390:
391:                List productEntries = scProductEntryPersistence
392:                        .findByGroupId(groupId);
393:
394:                Iterator itr = productEntries.iterator();
395:
396:                while (itr.hasNext()) {
397:                    SCProductEntry productEntry = (SCProductEntry) itr.next();
398:
399:                    if (Validator.isNull(productEntry.getRepoGroupId())
400:                            || Validator.isNull(productEntry
401:                                    .getRepoArtifactId())) {
402:
403:                        continue;
404:                    }
405:
406:                    List productVersions = scProductVersionPersistence
407:                            .findByProductEntryId(productEntry
408:                                    .getProductEntryId());
409:
410:                    Iterator itr2 = productVersions.iterator();
411:
412:                    for (int i = 1; itr2.hasNext(); i++) {
413:                        SCProductVersion productVersion = (SCProductVersion) itr2
414:                                .next();
415:
416:                        if ((maxNumOfVersions > 0) && (maxNumOfVersions < i)) {
417:                            break;
418:                        }
419:
420:                        if (!productVersion.isRepoStoreArtifact()) {
421:                            continue;
422:                        }
423:
424:                        if ((oldestDate != null)
425:                                && (oldestDate.after(productVersion
426:                                        .getModifiedDate()))) {
427:
428:                            continue;
429:                        }
430:
431:                        if (Validator.isNotNull(version)
432:                                && !isVersionSupported(version, productVersion
433:                                        .getFrameworkVersions())) {
434:
435:                            continue;
436:                        }
437:
438:                        Element el = root.addElement("plugin-package");
439:
440:                        populatePluginPackageElement(el, productEntry,
441:                                productVersion, baseImageURL);
442:                    }
443:                }
444:
445:                return doc.asXML();
446:            }
447:
448:            public void reIndex(String[] ids) throws SystemException {
449:                if (LuceneUtil.INDEX_READ_ONLY) {
450:                    return;
451:                }
452:
453:                long companyId = GetterUtil.getLong(ids[0]);
454:
455:                IndexWriter writer = null;
456:
457:                try {
458:                    writer = LuceneUtil.getWriter(companyId);
459:
460:                    Iterator itr = scProductEntryPersistence.findByCompanyId(
461:                            companyId).iterator();
462:
463:                    while (itr.hasNext()) {
464:                        SCProductEntry productEntry = (SCProductEntry) itr
465:                                .next();
466:
467:                        long productEntryId = productEntry.getProductEntryId();
468:
469:                        String version = StringPool.BLANK;
470:
471:                        SCProductVersion latestProductVersion = productEntry
472:                                .getLatestVersion();
473:
474:                        if (latestProductVersion != null) {
475:                            version = latestProductVersion.getVersion();
476:                        }
477:
478:                        try {
479:                            org.apache.lucene.document.Document doc = Indexer
480:                                    .getAddProductEntryDocument(companyId,
481:                                            productEntry.getGroupId(),
482:                                            productEntry.getUserId(),
483:                                            productEntry.getUserName(),
484:                                            productEntryId, productEntry
485:                                                    .getName(), productEntry
486:                                                    .getModifiedDate(),
487:                                            version, productEntry.getType(),
488:                                            productEntry.getShortDescription(),
489:                                            productEntry.getLongDescription(),
490:                                            productEntry.getPageURL(),
491:                                            productEntry.getRepoGroupId(),
492:                                            productEntry.getRepoArtifactId());
493:
494:                            writer.addDocument(doc);
495:                        } catch (Exception e1) {
496:                            _log.error("Reindexing " + productEntryId, e1);
497:                        }
498:                    }
499:                } catch (SystemException se) {
500:                    throw se;
501:                } catch (Exception e2) {
502:                    throw new SystemException(e2);
503:                } finally {
504:                    try {
505:                        if (writer != null) {
506:                            LuceneUtil.write(companyId);
507:                        }
508:                    } catch (Exception e) {
509:                        _log.error(e);
510:                    }
511:                }
512:            }
513:
514:            public Hits search(long companyId, long groupId, String keywords,
515:                    String type) throws SystemException {
516:
517:                Searcher searcher = null;
518:
519:                try {
520:                    HitsImpl hits = new HitsImpl();
521:
522:                    BooleanQuery contextQuery = new BooleanQuery();
523:
524:                    LuceneUtil.addRequiredTerm(contextQuery,
525:                            LuceneFields.PORTLET_ID, Indexer.PORTLET_ID);
526:                    LuceneUtil.addRequiredTerm(contextQuery,
527:                            LuceneFields.GROUP_ID, groupId);
528:
529:                    BooleanQuery fullQuery = new BooleanQuery();
530:
531:                    fullQuery.add(contextQuery, BooleanClause.Occur.MUST);
532:
533:                    if (Validator.isNotNull(keywords)) {
534:                        BooleanQuery searchQuery = new BooleanQuery();
535:
536:                        LuceneUtil.addTerm(searchQuery, LuceneFields.TITLE,
537:                                keywords);
538:                        LuceneUtil.addTerm(searchQuery, LuceneFields.CONTENT,
539:                                keywords);
540:
541:                        fullQuery.add(searchQuery, BooleanClause.Occur.MUST);
542:                    }
543:
544:                    if (Validator.isNotNull(type)) {
545:                        BooleanQuery searchQuery = new BooleanQuery();
546:
547:                        LuceneUtil.addRequiredTerm(searchQuery, "type", type);
548:
549:                        fullQuery.add(searchQuery, BooleanClause.Occur.MUST);
550:                    }
551:
552:                    searcher = LuceneUtil.getSearcher(companyId);
553:
554:                    hits.recordHits(searcher.search(fullQuery), searcher);
555:
556:                    return hits;
557:                } catch (Exception e) {
558:                    return LuceneUtil.closeSearcher(searcher, keywords, e);
559:                }
560:            }
561:
562:            public SCProductEntry updateProductEntry(long productEntryId,
563:                    String name, String type, String tags,
564:                    String shortDescription, String longDescription,
565:                    String pageURL, String author, String repoGroupId,
566:                    String repoArtifactId, long[] licenseIds, List thumbnails,
567:                    List fullImages) throws PortalException, SystemException {
568:
569:                // Product entry
570:
571:                tags = getTags(tags);
572:                repoGroupId = repoGroupId.trim().toLowerCase();
573:                repoArtifactId = repoArtifactId.trim().toLowerCase();
574:                Date now = new Date();
575:
576:                validate(productEntryId, name, type, shortDescription, pageURL,
577:                        author, repoGroupId, repoArtifactId, licenseIds,
578:                        thumbnails, fullImages);
579:
580:                SCProductEntry productEntry = scProductEntryPersistence
581:                        .findByPrimaryKey(productEntryId);
582:
583:                productEntry.setModifiedDate(now);
584:                productEntry.setName(name);
585:                productEntry.setType(type);
586:                productEntry.setTags(tags);
587:                productEntry.setShortDescription(shortDescription);
588:                productEntry.setLongDescription(longDescription);
589:                productEntry.setPageURL(pageURL);
590:                productEntry.setAuthor(author);
591:                productEntry.setRepoGroupId(repoGroupId);
592:                productEntry.setRepoArtifactId(repoArtifactId);
593:
594:                scProductEntryPersistence.update(productEntry);
595:
596:                // Licenses
597:
598:                scProductEntryPersistence.setSCLicenses(productEntryId,
599:                        licenseIds);
600:
601:                // Product screenshots
602:
603:                if (thumbnails.size() == 0) {
604:                    scProductScreenshotLocalService
605:                            .deleteProductScreenshots(productEntryId);
606:                } else {
607:                    saveProductScreenshots(productEntry, thumbnails, fullImages);
608:                }
609:
610:                // Latest product version
611:
612:                String version = StringPool.BLANK;
613:
614:                List productVersions = scProductVersionPersistence
615:                        .findByProductEntryId(productEntryId, 0, 1);
616:
617:                if (productVersions.size() > 0) {
618:                    SCProductVersion productVersion = (SCProductVersion) productVersions
619:                            .get(0);
620:
621:                    productVersion.setModifiedDate(now);
622:
623:                    scProductVersionPersistence.update(productVersion);
624:
625:                    version = productVersion.getVersion();
626:                }
627:
628:                // Lucene
629:
630:                try {
631:                    Indexer.updateProductEntry(productEntry.getCompanyId(),
632:                            productEntry.getGroupId(),
633:                            productEntry.getUserId(), productEntry
634:                                    .getUserName(), productEntryId, name, now,
635:                            version, type, shortDescription, longDescription,
636:                            pageURL, repoGroupId, repoArtifactId);
637:                } catch (IOException ioe) {
638:                    _log.error("Indexing " + productEntryId, ioe);
639:                }
640:
641:                return productEntry;
642:            }
643:
644:            protected String getTags(String tags) {
645:                tags = tags.trim().toLowerCase();
646:
647:                return StringUtil.merge(StringUtil.split(tags), ", ");
648:            }
649:
650:            protected boolean isVersionSupported(String version,
651:                    List supportedVersions) {
652:
653:                Version currentVersion = Version.getInstance(version);
654:
655:                Iterator iterator = supportedVersions.iterator();
656:
657:                while (iterator.hasNext()) {
658:                    SCFrameworkVersion frameworkVersion = (SCFrameworkVersion) iterator
659:                            .next();
660:
661:                    Version supportedVersion = Version
662:                            .getInstance(frameworkVersion.getName());
663:
664:                    if (supportedVersion.includes(currentVersion)) {
665:                        return true;
666:                    }
667:                }
668:
669:                return false;
670:            }
671:
672:            protected void populatePluginPackageElement(Element el,
673:                    SCProductEntry productEntry,
674:                    SCProductVersion productVersion, String baseImageURL)
675:                    throws PortalException, SystemException {
676:
677:                DocUtil.add(el, "name", productEntry.getName());
678:
679:                String moduleId = ModuleId.toString(productEntry
680:                        .getRepoGroupId(), productEntry.getRepoArtifactId(),
681:                        productVersion.getVersion(), "war");
682:
683:                DocUtil.add(el, "module-id", moduleId);
684:
685:                DocUtil.add(el, "modified-date", Time.getRFC822(productVersion
686:                        .getModifiedDate()));
687:
688:                Element typesEl = el.addElement("types");
689:
690:                DocUtil.add(typesEl, "type", productEntry.getType());
691:
692:                Element tagsEl = el.addElement("tags");
693:
694:                String[] tags = StringUtil.split(productEntry.getTags());
695:
696:                for (int i = 0; i < tags.length; i++) {
697:                    DocUtil.add(tagsEl, "tag", tags[i]);
698:                }
699:
700:                DocUtil.add(el, "short-description", productEntry
701:                        .getShortDescription());
702:
703:                if (Validator.isNotNull(productEntry.getLongDescription())) {
704:                    DocUtil.add(el, "long-description", productEntry
705:                            .getLongDescription());
706:                }
707:
708:                if (Validator.isNotNull(productVersion.getChangeLog())) {
709:                    DocUtil
710:                            .add(el, "change-log", productVersion
711:                                    .getChangeLog());
712:                }
713:
714:                if (Validator.isNotNull(productVersion.getDirectDownloadURL())) {
715:                    DocUtil.add(el, "download-url", productVersion
716:                            .getDirectDownloadURL());
717:                }
718:
719:                DocUtil.add(el, "author", productEntry.getAuthor());
720:
721:                Element screenshotsEl = el.addElement("screenshots");
722:
723:                Iterator itr = productEntry.getScreenshots().iterator();
724:
725:                while (itr.hasNext()) {
726:                    SCProductScreenshot screenshot = (SCProductScreenshot) itr
727:                            .next();
728:
729:                    long thumbnailId = screenshot.getThumbnailId();
730:                    long fullImageId = screenshot.getFullImageId();
731:
732:                    Element screenshotEl = screenshotsEl
733:                            .addElement("screenshot");
734:
735:                    DocUtil.add(screenshotEl, "thumbnail-url", baseImageURL
736:                            + "?img_id=" + thumbnailId + "&t="
737:                            + ImageServletTokenUtil.getToken(thumbnailId));
738:                    DocUtil.add(screenshotEl, "large-image-url", baseImageURL
739:                            + "?img_id=" + fullImageId + "&t="
740:                            + ImageServletTokenUtil.getToken(fullImageId));
741:                }
742:
743:                Element licensesEl = el.addElement("licenses");
744:
745:                itr = productEntry.getLicenses().iterator();
746:
747:                while (itr.hasNext()) {
748:                    SCLicense license = (SCLicense) itr.next();
749:
750:                    Element licenseEl = licensesEl.addElement("license");
751:
752:                    licenseEl.addText(license.getName());
753:                    licenseEl.addAttribute("osi-approved", String
754:                            .valueOf(license.isOpenSource()));
755:                }
756:
757:                Element liferayVersionsEl = el.addElement("liferay-versions");
758:
759:                itr = productVersion.getFrameworkVersions().iterator();
760:
761:                while (itr.hasNext()) {
762:                    SCFrameworkVersion frameworkVersion = (SCFrameworkVersion) itr
763:                            .next();
764:
765:                    DocUtil.add(liferayVersionsEl, "liferay-version",
766:                            frameworkVersion.getName());
767:                }
768:            }
769:
770:            protected void populateSettingsElement(Element el,
771:                    Properties repoSettings) {
772:
773:                if (repoSettings == null) {
774:                    return;
775:                }
776:
777:                Iterator itr = repoSettings.keySet().iterator();
778:
779:                while (itr.hasNext()) {
780:                    String key = (String) itr.next();
781:
782:                    Element settingEl = el.addElement("setting");
783:
784:                    settingEl.addAttribute("name", key);
785:                    settingEl.addAttribute("value", repoSettings
786:                            .getProperty(key));
787:                }
788:            }
789:
790:            protected void saveProductScreenshots(SCProductEntry productEntry,
791:                    List thumbnails, List fullImages) throws SystemException {
792:
793:                long productEntryId = productEntry.getProductEntryId();
794:
795:                List productScreenshots = scProductScreenshotPersistence
796:                        .findByProductEntryId(productEntryId);
797:
798:                if (thumbnails.size() < productScreenshots.size()) {
799:                    for (int i = thumbnails.size(); i < productScreenshots
800:                            .size(); i++) {
801:
802:                        SCProductScreenshot productScreenshot = (SCProductScreenshot) productScreenshots
803:                                .get(i);
804:
805:                        scProductScreenshotLocalService
806:                                .deleteProductScreenshot(productScreenshot);
807:                    }
808:                }
809:
810:                for (int i = 0; i < thumbnails.size(); i++) {
811:                    int priority = i;
812:
813:                    byte[] thumbnail = (byte[]) thumbnails.get(i);
814:                    byte[] fullImage = (byte[]) fullImages.get(i);
815:
816:                    SCProductScreenshot productScreenshot = scProductScreenshotPersistence
817:                            .fetchByP_P(productEntryId, priority);
818:
819:                    if (productScreenshot == null) {
820:                        long productScreenshotId = counterLocalService
821:                                .increment();
822:
823:                        long thumbnailId = counterLocalService.increment();
824:                        long fullImageId = counterLocalService.increment();
825:
826:                        productScreenshot = scProductScreenshotPersistence
827:                                .create(productScreenshotId);
828:
829:                        productScreenshot.setCompanyId(productEntry
830:                                .getCompanyId());
831:                        productScreenshot.setGroupId(productEntry.getGroupId());
832:                        productScreenshot.setProductEntryId(productEntryId);
833:                        productScreenshot.setThumbnailId(thumbnailId);
834:                        productScreenshot.setFullImageId(fullImageId);
835:                        productScreenshot.setPriority(priority);
836:
837:                        scProductScreenshotPersistence
838:                                .update(productScreenshot);
839:                    }
840:
841:                    ImageLocalUtil.updateImage(productScreenshot
842:                            .getThumbnailId(), thumbnail);
843:                    ImageLocalUtil.updateImage(productScreenshot
844:                            .getFullImageId(), fullImage);
845:                }
846:            }
847:
848:            protected void validate(long productEntryId, String name,
849:                    String type, String shortDescription, String pageURL,
850:                    String author, String repoGroupId, String repoArtifactId,
851:                    long[] licenseIds, List thumbnails, List fullImages)
852:                    throws PortalException, SystemException {
853:
854:                if (Validator.isNull(name)) {
855:                    throw new ProductEntryNameException();
856:                }
857:
858:                if (Validator.isNull(type)) {
859:                    throw new ProductEntryTypeException();
860:                }
861:
862:                if (Validator.isNull(shortDescription)) {
863:                    throw new ProductEntryShortDescriptionException();
864:                }
865:
866:                if (Validator.isNull(pageURL)) {
867:                    throw new ProductEntryPageURLException();
868:                } else {
869:                    try {
870:                        new URL(pageURL);
871:                    } catch (MalformedURLException murle) {
872:                        throw new ProductEntryPageURLException();
873:                    }
874:                }
875:
876:                if (Validator.isNull(author)) {
877:                    throw new ProductEntryAuthorException();
878:                }
879:
880:                try {
881:                    SCProductEntry productEntry = scProductEntryPersistence
882:                            .findByRG_RA(repoGroupId, repoArtifactId);
883:
884:                    if (productEntry.getProductEntryId() != productEntryId) {
885:                        throw new DuplicateProductEntryModuleIdException();
886:                    }
887:                } catch (NoSuchProductEntryException nspee) {
888:                }
889:
890:                if (licenseIds.length == 0) {
891:                    throw new ProductEntryLicenseException();
892:                }
893:
894:                if (thumbnails.size() != fullImages.size()) {
895:                    throw new ProductEntryScreenshotsException();
896:                } else {
897:                    Iterator itr = thumbnails.iterator();
898:
899:                    while (itr.hasNext()) {
900:                        if (itr.next() == null) {
901:                            throw new ProductEntryScreenshotsException();
902:                        }
903:                    }
904:
905:                    itr = fullImages.iterator();
906:
907:                    while (itr.hasNext()) {
908:                        if (itr.next() == null) {
909:                            throw new ProductEntryScreenshotsException();
910:                        }
911:                    }
912:                }
913:            }
914:
915:            private static Log _log = LogFactory
916:                    .getLog(SCProductEntryLocalServiceImpl.class);
917:
918:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.