RegisterAction.java
001 package com.bea.medrec.actions;
002 
003 import com.bea.medrec.beans.PatientBean;
004 import com.bea.medrec.beans.RegistrationBean;
005 import com.bea.medrec.utils.ClientException;
006 import com.bea.medrec.utils.MedRecLog4jFactory;
007 import com.bea.medrec.utils.MedRecWebAppUtils;
008 import java.util.HashMap;
009 import java.util.Map;
010 import javax.servlet.http.HttpServletRequest;
011 import javax.servlet.http.HttpServletResponse;
012 import org.apache.log4j.Logger;
013 import org.apache.struts.action.ActionForm;
014 import org.apache.struts.action.ActionForward;
015 import org.apache.struts.action.ActionMapping;
016 
017 import javax.ejb.FinderException;
018 
019 /**
020  <p>Handles all request during the registration process.</p<
021  *
022  @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
023  */
024 public class RegisterAction extends PatientBaseLookupDispatchAction {
025 
026   private static Logger logger =
027       MedRecLog4jFactory.getLogger(RegisterAction.class.getName());
028 
029   /**
030    <p>Mapping of action to method.</p>
031    *
032    @return Map
033    */
034   protected Map getKeyMethodMap() {
035     Map<String,String> map = new HashMap<String,String>();
036     map.put("button.Cancel""cancel");
037     map.put("button.Register""register");
038     return map;
039   }
040 
041   /**
042    <p>Default behavior.</p>
043    *
044    @return ActionForward
045    */
046   public ActionForward defaultMethod(ActionMapping mapping,
047                                      ActionForm form,
048                                      HttpServletRequest request,
049                                      HttpServletResponse response)
050       throws Exception {
051     // First time thru.
052     logger.debug("Default method executions.");
053     setupLocale(request);
054     return mapping.findForward("register.home");
055   }
056 
057   /**
058    <p>Cancel edit patient profile.</p>
059    *
060    @return ActionForward
061    */
062   public ActionForward cancel(ActionMapping mapping,
063                               ActionForm form,
064                               HttpServletRequest request,
065                               HttpServletResponse response)
066       throws Exception {
067     logger.info("Cancel registration.");
068     ActionForward forward = null;
069     try {
070       form.reset(mapping, request);
071       // Return to MedRec start page.
072       forward = new ActionForward("medrec.startpage"true);
073     catch (Exception e) {
074       return handleException(e, request, mapping);
075     }
076     return forward;
077   }
078 
079   /**
080    <p>Register new patient user.</p>
081    *
082    @return ActionForward
083    */
084   public ActionForward register(ActionMapping mapping,
085                                 ActionForm form,
086                                 HttpServletRequest request,
087                                 HttpServletResponse response)
088       throws ClientException, Exception {
089     logger.info("New user registration.");
090     RegistrationBean registrationBean = (RegistrationBeanform;
091     PatientBean patientBean = registrationBean.getPatientBean();
092 
093     // The email address is the username.
094     patientBean.setEmail(registrationBean.getUserBean().getUsername());
095 
096     try {
097       getAdminSession().getUserByUsername(registrationBean.getUserBean().getUsername());
098     catch (FinderException fe) {
099       // If the user does not exist
100       try {
101         // Send registration to be processed.
102         getAdminSession().processRegistration(registrationBean.toRegistration());
103       catch (Exception e) {
104         throwClientException(e, mapping, "validate.registration.failure");
105       }
106       return mapping.findForward("register.success");
107     catch (Exception e) {
108       // Naming Exception or some other exception
109       return mapping.findForward("register.failure");
110     
111     return mapping.findForward("register.failure")// Duplicate Account  
112   }
113 
114 }