View Javadoc

1   package edu.drexel.cms.interceptors;
2   
3   import static edu.drexel.cms.commons.MessageKeys.PLEASE_LOGIN;
4   
5   import java.util.List;
6   
7   import javax.servlet.http.HttpServletRequest;
8   
9   import org.apache.commons.logging.Log;
10  import org.apache.commons.logging.LogFactory;
11  import org.apache.struts2.ServletActionContext;
12  
13  import com.opensymphony.xwork2.ActionInvocation;
14  import com.opensymphony.xwork2.ActionSupport;
15  import com.opensymphony.xwork2.ValidationAware;
16  import com.opensymphony.xwork2.interceptor.Interceptor;
17  
18  import edu.drexel.cms.actions.SessionConstants;
19  import edu.drexel.cms.commons.CommonsUtils;
20  import edu.drexel.cms.data.CmsDAO;
21  import edu.drexel.cmsDb.datamodel.Conference;
22  import edu.drexel.cmsDb.datamodel.User;
23  import edu.drexel.cmsDb.ejb.SearchConferenceCriteriaVo;
24  
25  public class ConferencePageInterceptor extends ActionSupport implements Interceptor{
26    private static final long serialVersionUID = 20070504L;
27    private static final Log LOG = LogFactory.getLog(ConferencePageInterceptor.class);
28    
29    private static final String NO_RESULT_ERROR = "error.conference.no.result";
30    private static final String PAGE_ERROR = "error.conference.page";
31    
32    public void destroy() {}
33    public void init() {}
34  
35    public String intercept(ActionInvocation ai) throws Exception {
36      HttpServletRequest request = ServletActionContext.getRequest();
37      try{
38        User user = (User)request.getSession().getAttribute(SessionConstants.USER_ATTRIBUTE);
39        if(user == null){
40          addErrors(ai, getText(PLEASE_LOGIN));
41          return ActionSupport.LOGIN;
42        }
43        List<List<Conference>> conferences = CmsDAO.searchConference(user, new SearchConferenceCriteriaVo());
44        request.setAttribute(SessionConstants.AUTHOR_CONFERENCES, conferences.get(0));
45        request.setAttribute(SessionConstants.REVIEWER_CONFERENCES, conferences.get(1));
46        request.setAttribute(SessionConstants.EDITOR_CONFERENCES, conferences.get(2));
47        request.setAttribute(SessionConstants.OTHER_CONFERENCES, conferences.get(3));
48        if(CommonsUtils.IsDeepEmpty(conferences)){
49          addErrors(ai, getText(NO_RESULT_ERROR));
50        }
51      }catch (Exception e) {
52        LOG.error(getText(PAGE_ERROR), e);
53        addErrors(ai, getText(PAGE_ERROR));
54      }
55      return ai.invoke();
56    }
57    private void addErrors(ActionInvocation ai, String message){
58      if (ai.getAction() instanceof ValidationAware) {
59        ValidationAware action = (ValidationAware) ai.getAction();
60        action.addActionError(message);
61      }
62    }
63  }