Rev 205 | Rev 470 | 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; |
||
163 | jmachado | 4 | import pt.estgp.estgweb.domain.*; |
90 | jmachado | 5 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
6 | import pt.estgp.estgweb.services.common.*; |
||
7 | import pt.estgp.estgweb.services.common.impl.DefaultSearchResults; |
||
8 | import pt.estgp.estgweb.services.common.impl.DefaultResult; |
||
156 | jmachado | 9 | import pt.estgp.estgweb.services.common.impl.DefaultToDo; |
90 | jmachado | 10 | import pt.estgp.estgweb.Globals; |
11 | import org.apache.log4j.Logger; |
||
12 | |||
13 | import java.util.List; |
||
14 | import java.util.ArrayList; |
||
15 | |||
16 | import jomm.dao.impl.AbstractDao; |
||
17 | |||
18 | /** |
||
19 | * @author Jorge Machado |
||
135 | jmachado | 20 | * @date 25/Apr/2008 |
21 | * @time 18:01:54 |
||
22 | * @see pt.estgp.estgweb.web |
||
90 | jmachado | 23 | */ |
457 | jmachado | 24 | public class AnnouncementsCommonServices extends SingleSearchResults implements IService, IModuleCommonServices |
135 | jmachado | 25 | { |
26 | |||
90 | jmachado | 27 | 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); |
28 | |||
135 | jmachado | 29 | public int countSearch(1.5.0/docs/api/java/lang/String.html">String search, SearchTypeEnum searchType, UserSession userSession) |
30 | { |
||
31 | return 0; // todo To change body of implemented methods use File | Settings | File Templates. |
||
90 | jmachado | 32 | } |
33 | |||
135 | jmachado | 34 | public ISearchResults search(1.5.0/docs/api/java/lang/String.html">String search, SearchTypeEnum searchType, int page, int maxResults, UserSession userSession) |
35 | { |
||
165 | jmachado | 36 | return search(null,search, searchType,page,maxResults,userSession); |
37 | } |
||
38 | |||
39 | public ISearchResults search(1.5.0/docs/api/java/lang/String.html">String from, 1.5.0/docs/api/java/lang/String.html">String search, SearchTypeEnum searchType, int page, int maxResults, UserSession userSession) |
||
40 | { |
||
90 | jmachado | 41 | DefaultSearchResults searchResults = new DefaultSearchResults(); |
42 | searchResults.setModule(ModuleEnum.Announcements); |
||
43 | List<String> roles; |
||
135 | jmachado | 44 | if (userSession == null || userSession.getUser() == null || ((UserImpl) userSession.getUser()).getRolesList() == null || ((UserImpl) userSession.getUser()).getRolesList().size() == 0) |
45 | { |
||
90 | jmachado | 46 | roles = new ArrayList<String>(); |
47 | roles.add(Globals.ALL_ROLE); |
||
48 | } |
||
49 | else |
||
92 | jmachado | 50 | roles = ((UserImpl) userSession.getUser()).getRolesList(); |
90 | jmachado | 51 | |
156 | jmachado | 52 | boolean internal = true; |
140 | fvelez | 53 | if (userSession.getUser() == null) |
54 | internal = false; |
||
55 | searchResults.setTotalResults(DaoFactory.getAnnouncementDaoImpl().countAnnouncements(search, searchType, roles, null,internal)); |
||
135 | jmachado | 56 | if (searchResults.getTotalResults() > 0) |
57 | { |
||
140 | fvelez | 58 | List<Announcement> announcements = DaoFactory.getAnnouncementDaoImpl().searchAnnouncements(search, searchType, maxResults, page, roles, null,internal); |
92 | jmachado | 59 | if (announcements == null) |
60 | return searchResults; |
||
135 | jmachado | 61 | for (Announcement a : announcements) |
62 | { |
||
92 | jmachado | 63 | DefaultResult defaultResult = new DefaultResult(); |
64 | defaultResult.setTitle(a.getTitle()); |
||
65 | defaultResult.setSubTitle("announcements.type." + a.getType()); |
||
66 | defaultResult.setSubTitleKey(true); |
||
67 | defaultResult.setText(a.getText()); |
||
165 | jmachado | 68 | if(from == null) |
205 | jmachado | 69 | defaultResult.setUrl("/startLoadAnnouncement.do?id=" + a.getId()); |
165 | jmachado | 70 | else |
205 | jmachado | 71 | defaultResult.setUrl("/user/startLoadAnnouncementFrom" + from + ".do?id=" + a.getId() + "&dispatch=load"); |
92 | jmachado | 72 | searchResults.addResult(defaultResult); |
73 | } |
||
90 | jmachado | 74 | } |
75 | return searchResults; |
||
76 | } |
||
77 | |||
457 | jmachado | 78 | |
79 | |||
135 | jmachado | 80 | public int countToDo(UserSession userSession) |
81 | { |
||
82 | return 0; //todo To change body of implemented methods use File | Settings | File Templates. |
||
90 | jmachado | 83 | } |
84 | |||
156 | jmachado | 85 | /** |
86 | * Not implemented |
||
87 | * @param userSession |
||
88 | * @return |
||
89 | */ |
||
135 | jmachado | 90 | public IToDoCat getToDo(UserSession userSession) |
91 | { |
||
156 | jmachado | 92 | return null; |
90 | jmachado | 93 | } |
94 | |||
156 | jmachado | 95 | public List<IToDo> getAllToDos(UserSession userSession) |
96 | { |
||
97 | List<IToDo> todos = new ArrayList<IToDo>(); |
||
98 | if(userSession.getUser().hasRole(Globals.ANNOUNCEMENTS_VALIDATOR_ROLES)) |
||
99 | { |
||
100 | List<Announcement> invalidAnnouncements = DaoFactory.getAnnouncementDaoImpl().loadInvalidAnnouncements(); |
||
101 | for(Announcement a: invalidAnnouncements) |
||
102 | { |
||
205 | jmachado | 103 | DefaultToDo defaultToDo = new DefaultToDo(a.getTitle(),a.getTargetRoles(),((UserImpl)a.getOwner()).getUsername(), "announcements.type." + a.getType(),"/user/startEditAnnouncementFromHome.do?id=" + a.getId()); |
156 | jmachado | 104 | todos.add(defaultToDo); |
105 | } |
||
106 | } |
||
107 | return todos; |
||
108 | } |
||
109 | |||
163 | jmachado | 110 | /*This method is invoked from object creation*/ |
111 | public void adviseNew(DomainObject object) |
||
112 | { |
||
113 | //To change body of implemented methods use File | Settings | File Templates. |
||
114 | } |
||
115 | |||
116 | public void adviseUpdate(DomainObject object) |
||
117 | { |
||
118 | //To change body of implemented methods use File | Settings | File Templates. |
||
119 | } |
||
120 | |||
135 | jmachado | 121 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) |
122 | { |
||
90 | jmachado | 123 | AbstractDao.getCurrentSession().beginTransaction(); |
124 | UserSession sess = new UserSessionImpl(); |
||
125 | sess.setUser(new UserImpl()); |
||
126 | sess.getUser().setRoles("all"); |
||
92 | jmachado | 127 | ISearchResults searchResults = new AnnouncementsCommonServices().search("teste", SearchTypeEnum.AllWords, 0, 10, sess); |
135 | jmachado | 128 | for (IResult result : searchResults.getResults()) |
129 | { |
||
92 | jmachado | 130 | 1.5.0/docs/api/java/lang/System.html">System.out.println("title:" + result.getTitle()); |
131 | 1.5.0/docs/api/java/lang/System.html">System.out.println("subTitle:" + result.getSubTitle()); |
||
132 | 1.5.0/docs/api/java/lang/System.html">System.out.println("text:" + result.getText()); |
||
90 | jmachado | 133 | 1.5.0/docs/api/java/lang/System.html">System.out.println("url" + result.getUrl()); |
134 | 1.5.0/docs/api/java/lang/System.html">System.out.println("bestFragments" + result.getBestFragments()); |
||
135 | } |
||
136 | AbstractDao.commit(); |
||
137 | } |
||
138 | } |