Rev 135 | Rev 156 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
90 | jmachado | 1 | package pt.estgp.estgweb.services.announcements; |
2 | |||
3 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
4 | import pt.estgp.estgweb.domain.views.AnnouncementView; |
||
5 | import pt.estgp.estgweb.domain.UserSession; |
||
6 | import pt.estgp.estgweb.domain.Announcement; |
||
7 | import pt.estgp.estgweb.domain.UserImpl; |
||
8 | import pt.estgp.estgweb.domain.UserSessionImpl; |
||
9 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
10 | import pt.estgp.estgweb.services.common.*; |
||
11 | import pt.estgp.estgweb.services.common.impl.DefaultSearchResults; |
||
12 | import pt.estgp.estgweb.services.common.impl.DefaultResult; |
||
13 | import pt.estgp.estgweb.Globals; |
||
14 | import org.apache.log4j.Logger; |
||
15 | |||
16 | import java.io.Serializable; |
||
17 | import java.util.List; |
||
18 | import java.util.ArrayList; |
||
19 | |||
20 | import jomm.dao.impl.AbstractDao; |
||
21 | |||
22 | /** |
||
23 | * @author Jorge Machado |
||
135 | jmachado | 24 | * @date 25/Apr/2008 |
25 | * @time 18:01:54 |
||
26 | * @see pt.estgp.estgweb.web |
||
90 | jmachado | 27 | */ |
135 | jmachado | 28 | public class AnnouncementsCommonServices implements IService, IModuleCommonServices |
29 | { |
||
30 | |||
90 | jmachado | 31 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(AnnouncementsCommonServices.class); |
32 | |||
135 | jmachado | 33 | public int countSearch(1.5.0/docs/api/java/lang/String.html">String search, SearchTypeEnum searchType, UserSession userSession) |
34 | { |
||
35 | return 0; // todo To change body of implemented methods use File | Settings | File Templates. |
||
90 | jmachado | 36 | } |
37 | |||
135 | jmachado | 38 | public ISearchResults search(1.5.0/docs/api/java/lang/String.html">String search, SearchTypeEnum searchType, int page, int maxResults, UserSession userSession) |
39 | { |
||
90 | jmachado | 40 | DefaultSearchResults searchResults = new DefaultSearchResults(); |
41 | searchResults.setModule(ModuleEnum.Announcements); |
||
42 | List<String> roles; |
||
135 | jmachado | 43 | if (userSession == null || userSession.getUser() == null || ((UserImpl) userSession.getUser()).getRolesList() == null || ((UserImpl) userSession.getUser()).getRolesList().size() == 0) |
44 | { |
||
90 | jmachado | 45 | roles = new ArrayList<String>(); |
46 | roles.add(Globals.ALL_ROLE); |
||
47 | } |
||
48 | else |
||
92 | jmachado | 49 | roles = ((UserImpl) userSession.getUser()).getRolesList(); |
90 | jmachado | 50 | |
140 | fvelez | 51 | boolean internal = true; |
52 | if (userSession.getUser() == null) |
||
53 | internal = false; |
||
54 | searchResults.setTotalResults(DaoFactory.getAnnouncementDaoImpl().countAnnouncements(search, searchType, roles, null,internal)); |
||
135 | jmachado | 55 | if (searchResults.getTotalResults() > 0) |
56 | { |
||
140 | fvelez | 57 | List<Announcement> announcements = DaoFactory.getAnnouncementDaoImpl().searchAnnouncements(search, searchType, maxResults, page, roles, null,internal); |
92 | jmachado | 58 | if (announcements == null) |
59 | return searchResults; |
||
135 | jmachado | 60 | for (Announcement a : announcements) |
61 | { |
||
92 | jmachado | 62 | DefaultResult defaultResult = new DefaultResult(); |
63 | defaultResult.setTitle(a.getTitle()); |
||
64 | defaultResult.setSubTitle("announcements.type." + a.getType()); |
||
65 | defaultResult.setSubTitleKey(true); |
||
66 | defaultResult.setText(a.getText()); |
||
67 | defaultResult.setUrl("/loadAnnouncement.do?id=" + a.getId() + "&dispatch=load"); |
||
68 | searchResults.addResult(defaultResult); |
||
69 | } |
||
90 | jmachado | 70 | } |
71 | return searchResults; |
||
72 | } |
||
73 | |||
135 | jmachado | 74 | public int countToDo(UserSession userSession) |
75 | { |
||
76 | return 0; //todo To change body of implemented methods use File | Settings | File Templates. |
||
90 | jmachado | 77 | } |
78 | |||
135 | jmachado | 79 | public IToDoCat getToDo(UserSession userSession) |
80 | { |
||
81 | return null; //todo To change body of implemented methods use File | Settings | File Templates. |
||
90 | jmachado | 82 | } |
83 | |||
135 | jmachado | 84 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) |
85 | { |
||
90 | jmachado | 86 | AbstractDao.getCurrentSession().beginTransaction(); |
87 | UserSession sess = new UserSessionImpl(); |
||
88 | sess.setUser(new UserImpl()); |
||
89 | sess.getUser().setRoles("all"); |
||
92 | jmachado | 90 | ISearchResults searchResults = new AnnouncementsCommonServices().search("teste", SearchTypeEnum.AllWords, 0, 10, sess); |
135 | jmachado | 91 | for (IResult result : searchResults.getResults()) |
92 | { |
||
92 | jmachado | 93 | 1.5.0/docs/api/java/lang/System.html">System.out.println("title:" + result.getTitle()); |
94 | 1.5.0/docs/api/java/lang/System.html">System.out.println("subTitle:" + result.getSubTitle()); |
||
95 | 1.5.0/docs/api/java/lang/System.html">System.out.println("text:" + result.getText()); |
||
90 | jmachado | 96 | 1.5.0/docs/api/java/lang/System.html">System.out.println("url" + result.getUrl()); |
97 | 1.5.0/docs/api/java/lang/System.html">System.out.println("bestFragments" + result.getBestFragments()); |
||
98 | } |
||
99 | AbstractDao.commit(); |
||
100 | } |
||
101 | } |