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