Rev 90 | Rev 135 | 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 Goncalo Luiz gedl [AT] rnl [DOT] ist [DOT] utl [DOT] pt |
||
24 | * |
||
25 | * |
||
26 | * Created at 17/Out/2003 , 23:45:24 |
||
27 | * |
||
28 | */ |
||
29 | /** |
||
30 | * @author Jorge Machado |
||
92 | jmachado | 31 | * <p/> |
32 | * <p/> |
||
33 | * Created at 17/Out/2003 , 23:45:24 |
||
90 | jmachado | 34 | */ |
92 | jmachado | 35 | public class AnnouncementsCommonServices implements IService, IModuleCommonServices { |
90 | jmachado | 36 | 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); |
37 | |||
92 | jmachado | 38 | public int countSearch(1.5.0/docs/api/java/lang/String.html">String search, SearchTypeEnum searchType, UserSession userSession) { |
90 | jmachado | 39 | return 0; //To change body of implemented methods use File | Settings | File Templates. |
40 | } |
||
41 | |||
92 | jmachado | 42 | public ISearchResults search(1.5.0/docs/api/java/lang/String.html">String search, SearchTypeEnum searchType, int page, int maxResults, UserSession userSession) { |
90 | jmachado | 43 | DefaultSearchResults searchResults = new DefaultSearchResults(); |
44 | searchResults.setModule(ModuleEnum.Announcements); |
||
45 | List<String> roles; |
||
92 | jmachado | 46 | if (userSession == null || userSession.getUser() == null || ((UserImpl) userSession.getUser()).getRolesList() == null || ((UserImpl) userSession.getUser()).getRolesList().size() == 0) { |
90 | jmachado | 47 | roles = new ArrayList<String>(); |
48 | roles.add(Globals.ALL_ROLE); |
||
49 | } |
||
50 | else |
||
92 | jmachado | 51 | roles = ((UserImpl) userSession.getUser()).getRolesList(); |
90 | jmachado | 52 | |
92 | jmachado | 53 | searchResults.setTotalResults(DaoFactory.getAnnouncementDaoImpl().countAnnouncements(search, searchType, roles, null)); |
54 | if (searchResults.getTotalResults() > 0) { |
||
55 | List<Announcement> announcements = DaoFactory.getAnnouncementDaoImpl().searchAnnouncements(search, searchType, maxResults, page, roles, null); |
||
56 | if (announcements == null) |
||
57 | return searchResults; |
||
58 | for (Announcement a : announcements) { |
||
59 | DefaultResult defaultResult = new DefaultResult(); |
||
60 | defaultResult.setTitle(a.getTitle()); |
||
61 | defaultResult.setSubTitle("announcements.type." + a.getType()); |
||
62 | defaultResult.setSubTitleKey(true); |
||
63 | defaultResult.setText(a.getText()); |
||
64 | defaultResult.setUrl("/loadAnnouncement.do?id=" + a.getId() + "&dispatch=load"); |
||
65 | searchResults.addResult(defaultResult); |
||
66 | } |
||
90 | jmachado | 67 | } |
68 | return searchResults; |
||
69 | } |
||
70 | |||
92 | jmachado | 71 | public int countToDo(UserSession userSession) { |
90 | jmachado | 72 | return 0; //To change body of implemented methods use File | Settings | File Templates. |
73 | } |
||
74 | |||
92 | jmachado | 75 | public IToDoCat getToDo(UserSession userSession) { |
90 | jmachado | 76 | return null; //To change body of implemented methods use File | Settings | File Templates. |
77 | } |
||
78 | |||
92 | jmachado | 79 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) { |
90 | jmachado | 80 | AbstractDao.getCurrentSession().beginTransaction(); |
81 | UserSession sess = new UserSessionImpl(); |
||
82 | sess.setUser(new UserImpl()); |
||
83 | sess.getUser().setRoles("all"); |
||
92 | jmachado | 84 | ISearchResults searchResults = new AnnouncementsCommonServices().search("teste", SearchTypeEnum.AllWords, 0, 10, sess); |
85 | for (IResult result : searchResults.getResults()) { |
||
86 | 1.5.0/docs/api/java/lang/System.html">System.out.println("title:" + result.getTitle()); |
||
87 | 1.5.0/docs/api/java/lang/System.html">System.out.println("subTitle:" + result.getSubTitle()); |
||
88 | 1.5.0/docs/api/java/lang/System.html">System.out.println("text:" + result.getText()); |
||
90 | jmachado | 89 | 1.5.0/docs/api/java/lang/System.html">System.out.println("url" + result.getUrl()); |
90 | 1.5.0/docs/api/java/lang/System.html">System.out.println("bestFragments" + result.getBestFragments()); |
||
91 | } |
||
92 | AbstractDao.commit(); |
||
93 | } |
||
94 | } |