Subversion Repositories bacoAlunos

Rev

Rev 165 | Rev 457 | 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
    {
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
 
135 jmachado 78
    public int countToDo(UserSession userSession)
79
    {
80
        return 0;  //todo To change body of implemented methods use File | Settings | File Templates.
90 jmachado 81
    }
82
 
156 jmachado 83
    /**
84
     * Not implemented
85
     * @param userSession
86
     * @return
87
     */
135 jmachado 88
    public IToDoCat getToDo(UserSession userSession)
89
    {
156 jmachado 90
        return null;
90 jmachado 91
    }
92
 
156 jmachado 93
    public List<IToDo> getAllToDos(UserSession userSession)
94
    {
95
        List<IToDo> todos = new ArrayList<IToDo>();
96
        if(userSession.getUser().hasRole(Globals.ANNOUNCEMENTS_VALIDATOR_ROLES))
97
        {
98
            List<Announcement> invalidAnnouncements = DaoFactory.getAnnouncementDaoImpl().loadInvalidAnnouncements();
99
            for(Announcement a: invalidAnnouncements)
100
            {
205 jmachado 101
                DefaultToDo defaultToDo = new DefaultToDo(a.getTitle(),a.getTargetRoles(),((UserImpl)a.getOwner()).getUsername(), "announcements.type." + a.getType(),"/user/startEditAnnouncementFromHome.do?id=" + a.getId());
156 jmachado 102
                todos.add(defaultToDo);
103
            }
104
        }
105
        return todos;
106
    }
107
 
163 jmachado 108
    /*This method is invoked from object creation*/
109
    public void adviseNew(DomainObject object)
110
    {
111
        //To change body of implemented methods use File | Settings | File Templates.
112
    }
113
 
114
    public void adviseUpdate(DomainObject object)
115
    {
116
        //To change body of implemented methods use File | Settings | File Templates.
117
    }
118
 
135 jmachado 119
    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args)
120
    {
90 jmachado 121
        AbstractDao.getCurrentSession().beginTransaction();
122
        UserSession sess = new UserSessionImpl();
123
        sess.setUser(new UserImpl());
124
        sess.getUser().setRoles("all");
92 jmachado 125
        ISearchResults searchResults = new AnnouncementsCommonServices().search("teste", SearchTypeEnum.AllWords, 0, 10, sess);
135 jmachado 126
        for (IResult result : searchResults.getResults())
127
        {
92 jmachado 128
            1.5.0/docs/api/java/lang/System.html">System.out.println("title:" + result.getTitle());
129
            1.5.0/docs/api/java/lang/System.html">System.out.println("subTitle:" + result.getSubTitle());
130
            1.5.0/docs/api/java/lang/System.html">System.out.println("text:" + result.getText());
90 jmachado 131
            1.5.0/docs/api/java/lang/System.html">System.out.println("url" + result.getUrl());
132
            1.5.0/docs/api/java/lang/System.html">System.out.println("bestFragments" + result.getBestFragments());
133
        }
134
        AbstractDao.commit();
135
    }
136
}