Rev 156 | Rev 165 | 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 | */ |
135 | jmachado | 24 | public class AnnouncementsCommonServices implements IService, IModuleCommonServices |
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 | { |
||
90 | jmachado | 36 | DefaultSearchResults searchResults = new DefaultSearchResults(); |
37 | searchResults.setModule(ModuleEnum.Announcements); |
||
38 | List<String> roles; |
||
135 | jmachado | 39 | if (userSession == null || userSession.getUser() == null || ((UserImpl) userSession.getUser()).getRolesList() == null || ((UserImpl) userSession.getUser()).getRolesList().size() == 0) |
40 | { |
||
90 | jmachado | 41 | roles = new ArrayList<String>(); |
42 | roles.add(Globals.ALL_ROLE); |
||
43 | } |
||
44 | else |
||
92 | jmachado | 45 | roles = ((UserImpl) userSession.getUser()).getRolesList(); |
90 | jmachado | 46 | |
156 | jmachado | 47 | boolean internal = true; |
140 | fvelez | 48 | if (userSession.getUser() == null) |
49 | internal = false; |
||
50 | searchResults.setTotalResults(DaoFactory.getAnnouncementDaoImpl().countAnnouncements(search, searchType, roles, null,internal)); |
||
135 | jmachado | 51 | if (searchResults.getTotalResults() > 0) |
52 | { |
||
140 | fvelez | 53 | List<Announcement> announcements = DaoFactory.getAnnouncementDaoImpl().searchAnnouncements(search, searchType, maxResults, page, roles, null,internal); |
92 | jmachado | 54 | if (announcements == null) |
55 | return searchResults; |
||
135 | jmachado | 56 | for (Announcement a : announcements) |
57 | { |
||
92 | jmachado | 58 | DefaultResult defaultResult = new DefaultResult(); |
59 | defaultResult.setTitle(a.getTitle()); |
||
60 | defaultResult.setSubTitle("announcements.type." + a.getType()); |
||
61 | defaultResult.setSubTitleKey(true); |
||
62 | defaultResult.setText(a.getText()); |
||
63 | defaultResult.setUrl("/loadAnnouncement.do?id=" + a.getId() + "&dispatch=load"); |
||
64 | searchResults.addResult(defaultResult); |
||
65 | } |
||
90 | jmachado | 66 | } |
67 | return searchResults; |
||
68 | } |
||
69 | |||
135 | jmachado | 70 | public int countToDo(UserSession userSession) |
71 | { |
||
72 | return 0; //todo To change body of implemented methods use File | Settings | File Templates. |
||
90 | jmachado | 73 | } |
74 | |||
156 | jmachado | 75 | /** |
76 | * Not implemented |
||
77 | * @param userSession |
||
78 | * @return |
||
79 | */ |
||
135 | jmachado | 80 | public IToDoCat getToDo(UserSession userSession) |
81 | { |
||
156 | jmachado | 82 | return null; |
90 | jmachado | 83 | } |
84 | |||
156 | jmachado | 85 | public List<IToDo> getAllToDos(UserSession userSession) |
86 | { |
||
87 | List<IToDo> todos = new ArrayList<IToDo>(); |
||
88 | if(userSession.getUser().hasRole(Globals.ANNOUNCEMENTS_VALIDATOR_ROLES)) |
||
89 | { |
||
90 | List<Announcement> invalidAnnouncements = DaoFactory.getAnnouncementDaoImpl().loadInvalidAnnouncements(); |
||
91 | for(Announcement a: invalidAnnouncements) |
||
92 | { |
||
93 | DefaultToDo defaultToDo = new DefaultToDo(a.getTitle(),a.getTargetRoles(),((UserImpl)a.getOwner()).getUsername(), "announcements.type." + a.getType(),"/user/loadAnnouncementFromServiceZone.do?dispatch=edit&separator=4&id=" + a.getId()); |
||
94 | todos.add(defaultToDo); |
||
95 | } |
||
96 | } |
||
97 | return todos; |
||
98 | } |
||
99 | |||
163 | jmachado | 100 | /*This method is invoked from object creation*/ |
101 | public void adviseNew(DomainObject object) |
||
102 | { |
||
103 | //To change body of implemented methods use File | Settings | File Templates. |
||
104 | } |
||
105 | |||
106 | public void adviseUpdate(DomainObject object) |
||
107 | { |
||
108 | //To change body of implemented methods use File | Settings | File Templates. |
||
109 | } |
||
110 | |||
135 | jmachado | 111 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) |
112 | { |
||
90 | jmachado | 113 | AbstractDao.getCurrentSession().beginTransaction(); |
114 | UserSession sess = new UserSessionImpl(); |
||
115 | sess.setUser(new UserImpl()); |
||
116 | sess.getUser().setRoles("all"); |
||
92 | jmachado | 117 | ISearchResults searchResults = new AnnouncementsCommonServices().search("teste", SearchTypeEnum.AllWords, 0, 10, sess); |
135 | jmachado | 118 | for (IResult result : searchResults.getResults()) |
119 | { |
||
92 | jmachado | 120 | 1.5.0/docs/api/java/lang/System.html">System.out.println("title:" + result.getTitle()); |
121 | 1.5.0/docs/api/java/lang/System.html">System.out.println("subTitle:" + result.getSubTitle()); |
||
122 | 1.5.0/docs/api/java/lang/System.html">System.out.println("text:" + result.getText()); |
||
90 | jmachado | 123 | 1.5.0/docs/api/java/lang/System.html">System.out.println("url" + result.getUrl()); |
124 | 1.5.0/docs/api/java/lang/System.html">System.out.println("bestFragments" + result.getBestFragments()); |
||
125 | } |
||
126 | AbstractDao.commit(); |
||
127 | } |
||
128 | } |