Package databeans

Examples of databeans.User


  }

  public void create(User user) throws DAOException {
    try {
      Transaction.begin();
      User dbUser = factory.create(user.getEmailAddress());
      factory.copyInto(user,dbUser);
      Transaction.commit();
    } catch (DuplicateKeyException e) {
      throw new DAOException("A user named "+user.getEmailAddress()+" already exists");
    } catch (RollbackException e) {
View Full Code Here


  }

  public void updateUser(User user) throws DAOException {
    try {
      Transaction.begin();
      User dbUser = factory.lookup(user.getEmailAddress());

      if (dbUser == null){
        throw new DAOException("User "+user.getEmailAddress()+" no longer exists");
      }
      dbUser.setFirstName(user.getFirstName());    
      dbUser.setLastName(user.getLastName());
      dbUser.setGender(user.getGender());
      Transaction.commit();
    } catch (RollbackException e) {
      throw new DAOException(e);
    } finally {
      if (Transaction.isActive()) Transaction.rollback();
View Full Code Here

  public String perform(HttpServletRequest request) {
    List<String> errors = new ArrayList<String>();
    request.setAttribute("errors",errors);
    HttpSession session = request.getSession();
    User user = (User) request.getSession().getAttribute("user");
       
    if(user == null){
      LoginForm form = new LoginForm();
      form.setRedirect("/login.do");
      request.setAttribute("loginform", form);
      errors.add("please login");
      synchronized(session){
      session.setAttribute("user", user);
      session.setAttribute("redirectTo",redirectTo);
      }
      return "homepage.jsp";
    }
    SideEffect[] SideEffectsList = sideDAO.getSideEffectsList(user.getEmailAddress());
    session.setAttribute("redirectTo",redirectTo);
    if(SideEffectsList!= null){
      synchronized(session){session.setAttribute("user", user);}
      request.setAttribute("sideeffectslist", SideEffectsList);
      return "showAddSide.jsp";
View Full Code Here

  public String getName() { return "addSide.do"; }

  @SuppressWarnings("unchecked")
  public String perform(HttpServletRequest request) {
      //must be logged in for this one.
      User user = (User) request.getSession().getAttribute("user");
      if(user == null){
        LoginForm form = new LoginForm();
        form.setRedirect("/addSide.do");
        request.setAttribute("loginform", form);
        return "homePage.jsp";
      }
      /*
       * if the user has already logged in.
       * */
 
    SideEffect[] sideEffectslist;
    List<String> delListside = new ArrayList<String>();
    String delSide = null;
    //error list for error mention function.
    List<String> errors = new ArrayList<String>();
    String button;
    button = request.getParameter("button");
    if(button != null){
    if(button.equals("Add side effect")){
    try{
      AddSideForm form = formBeanFactory.create(request);
          request.setAttribute("addsideform", form);
          if(!form.isPresent()){
            return "homepage.jsp";
          }
          HttpSession session = request.getSession(false);
          //check the errors.
          errors.addAll(form.getValidationErrors());
          if (errors.size()!= 0) {
            request.setAttribute("errors",errors);
            return "logSide.jsp";
        }   
          int allNum = sideDAO.size();
          if(allNum != 0){
          delListside = (List<String>) session.getAttribute("deletelistside");
          if(delListside != null){
          if(!delListside.isEmpty()){
            delSide = delListside.get(delListside.size()-1);
            delListside.remove(delListside.size()-1);
            synchronized(session){session.setAttribute("deletelistside", delListside);}
          }else{
            System.out.println("The dellist is zero");
            delSide = null;
            synchronized(session){session.setAttribute("deletelistside", null);}
          }
        }else{
          delSide = null;
          synchronized(session){session.setAttribute("deletelistside", null);}
        }
          }
          String newSide;
          //if user want some side effects  be deleted.
          if(delSide != null){
            newSide = delSide;
            addSide = new SideEffect(Integer.parseInt(newSide));
            addSide.setName(form.getName());
            addSide.setOwner(user.getEmailAddress());
            //addSide.setAllNum(allNum + 1); 
            //create a new user.
            sideDAO.create(addSide);
            synchronized(session){session.setAttribute("deletelistside",delListside);}
          //if no scheduled medication be deleted.
          }else{
            int allSize = sideDAO.size();
            //initialization situation.
            if(allSize == 0){
              newSide = Integer.toString(allSize);
              addSide = new SideEffect(Integer.parseInt(newSide));
              addSide.setName(form.getName());
                addSide.setOwner(user.getEmailAddress());
                sideDAO.create(addSide);
                synchronized(session){session.setAttribute("deletelistside",delListside);}
            }else{
              allSize = sideDAO.getLastId();
              newSide = Integer.toString(allSize);
              addSide = new SideEffect(Integer.parseInt(newSide) + 1);
              addSide.setName(form.getName());
                addSide.setOwner(user.getEmailAddress());
                sideDAO.create(addSide);
                synchronized(session){session.setAttribute("deletelistside",delListside);}
            }
          }
         
        session.setAttribute("deleteid", null);
            session.setAttribute("user", user);
            String redirectTo = (String) session.getAttribute("redirectTo");
            sideEffectslist = sideDAO.getSideEffectsList(user.getEmailAddress());
            if(redirectTo != null){
              request.setAttribute("sideeffectslist",sideEffectslist);
              return redirectTo;
            }
        request.setAttribute("sideeffectslist", sideEffectslist);
View Full Code Here

    sunday = new ArrayList();

    List<String> errors = new ArrayList<String>();
    request.setAttribute("errors",errors);
    HttpSession session = request.getSession();
    User user = (User) request.getSession().getAttribute("user");

    if(user == null){
      LoginForm form = new LoginForm();
      form.setRedirect("/login.do");
      request.setAttribute("loginform", form);
      errors.add("Please login");
      synchronized(session){
      session.setAttribute("redirectTo",redirectTo);
      session.setAttribute("user", user);
      }
      return "homepage.jsp";
    }

    Medication[] medlist = medDAO.getMedicationList(user.getEmailAddress());
    if(medlist!=null) {
      for(int i = 0; i < medlist.length; i++) {
        // create new schedule object for each medication time
        Medication m = medlist[i];
        int freq1 = getFreq1(m); // number of times
View Full Code Here

  public String perform(HttpServletRequest request) {
    List<String> errors = new ArrayList<String>();
    request.setAttribute("errors",errors);
    HttpSession session = request.getSession();
    User user = (User) request.getSession().getAttribute("user");
       
    if(user == null){
      LoginForm form = new LoginForm();
      form.setRedirect("/login.do");
      request.setAttribute("loginform", form);
      errors.add("please login");
      synchronized(session){
      session.setAttribute("redirectTo",redirectTo);
      session.setAttribute("user", user);
      }
      return "homepage.jsp";
    }
    Medication[] MedicationList = medDAO.getMedicationList(user.getEmailAddress());
    //System.out.println("the class attribute is " + ("class"));
    //request.setAttribute("class", "active");
    if(MedicationList!= null){
      synchronized(session){session.setAttribute("user", user);}
      request.setAttribute("medicationlist", MedicationList);
View Full Code Here

  public String getName() { return "addMed.do"; }

  @SuppressWarnings("unchecked")
  public String perform(HttpServletRequest request) {
      //must be logged in for this one.
      User user = (User) request.getSession().getAttribute("user");
      if(user == null){
        LoginForm form = new LoginForm();
        form.setRedirect("/addmed.do");
        request.setAttribute("loginform", form);
        return "homePage.jsp";
      }
      /*
       * if the user has already logged in.
       * */
 
    Medication[] medicationlist_1;
    List<String> delList = new ArrayList<String>();
    String delMed = null;
    //error list for error mention function.
    List<String> errors = new ArrayList<String>();
    String button;
    button = request.getParameter("button");
    if(button != null){
    if(button.equals("Add medication")){
    try{
      AddMedForm form = formBeanFactory.create(request);
          request.setAttribute("addmedform", form);
          if(!form.isPresent()){
            return "homepage.jsp";
          }
          HttpSession session = request.getSession(false);
          //check the errors.
          errors.addAll(form.getValidationErrors());
          if (errors.size()!= 0) {
            request.setAttribute("errors",errors);
            return "addMed.jsp";
        }   
          int allNum = medDAO.size();
          if(allNum != 0){
            delList = (List<String>) session.getAttribute("deletelist");
            if(delList != null){
              if(!delList.isEmpty()){
                delMed = delList.get(delList.size()-1);
                System.out.println("the demed is " + delMed);
                delList.remove(delList.size()-1);
                synchronized(session) {session.setAttribute("deletelist", delList);}
              }else{
                System.out.println("The dellist is zero");
                delMed = null;
                synchronized(session){session.setAttribute("deletelist", null);}
              }
            }else{
              delMed = null;
              synchronized(session){session.setAttribute("deletelist", null);}
            }
          }
          String newMed;
          /*
           * For Multiple Selection options.
           * */
          String[] dayCheckList = request.getParameterValues("dayChecks");
          String dayCheckDL = null;
          for(String daychecks : dayCheckList){
                   dayCheckDL = dayCheckDL + daychecks;
          }
          dayCheckDL = dayCheckDL.substring(4,dayCheckDL.length());
          //if user want some medication schedule be deleted.
          if(delMed != null){
            newMed = delMed;
            addMed = new Medication(Integer.parseInt(newMed));
            createMed(addMed,form);
            addMed.setUsername(user.getEmailAddress());
            addMed.setDayChecks(dayCheckDL);
            //addMed.setAllNum(allNum + 1); 
            //create a new user.
            medDAO.create(addMed);
            synchronized(session){
        session.setAttribute("deletelist",delList);
        request.setAttribute("addmedform", null);
        request.setAttribute("message","Successfully added " + form.getName()+ ". ");
        }
          //if no scheduled medication be deleted.
          }else{
            int allSize = medDAO.size();
            //System.out.println("all size is " + Integer.toString(allSize));
            //initialization situation.
            if(allSize == 0){
              newMed = Integer.toString(allSize);
                System.out.println("all size is " + newMed);
              addMed = new Medication(Integer.parseInt(newMed));
              createMed(addMed,form);
                addMed.setUsername(user.getEmailAddress());
                addMed.setDayChecks(dayCheckDL);
                medDAO.create(addMed);
                synchronized(session){
            session.setAttribute("deletelist", null);
            request.setAttribute("addmedform", null);
            request.setAttribute("message","Successfully added " + form.getName() + ".");
                }
            }else{
              allSize = medDAO.getLastId();
              newMed = Integer.toString(allSize);
              addMed = new Medication(Integer.parseInt(newMed) + 1);
              createMed(addMed,form);
                addMed.setUsername(user.getEmailAddress());
                addMed.setDayChecks(dayCheckDL);
                medDAO.create(addMed);
                synchronized(session){
            session.setAttribute("deletelist", null);
            request.setAttribute("addmedform", null);
            request.setAttribute("message","Successfully added " + form.getName()+ ".");
            }
            }
          }
          synchronized(session){
          session.setAttribute("redirectto", null);
        session.setAttribute("deleteid", null);
            session.setAttribute("user", user);
          }
            String redirectTo = (String) session.getAttribute("redirectto");
            medicationlist_1 = medDAO.getMedicationList(user.getEmailAddress());
            if(redirectTo != null){
              request.setAttribute("medicationlist",medicationlist_1);
              return redirectTo;
            }
        request.setAttribute("medicationlist", medicationlist_1);
        synchronized(session){
        session.setAttribute("pagenumber", 1);
        }
        return "addMed.jsp";
  }catch(DAOException e1){
    e1.printStackTrace();
  } catch (FormBeanException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  }//if user did not add any new medication.
    medicationlist_1 = medDAO.getMedicationList(user.getEmailAddress());
     request.setAttribute("medicationlist", medicationlist_1);
    return "addMed.jsp";
  }else{
    medicationlist_1 = medDAO.getMedicationList(user.getEmailAddress());
    request.setAttribute("medicationlist", medicationlist_1);
    return "addMed.jsp";
  }
}
View Full Code Here

    public String perform(HttpServletRequest request) {
        List<String> errors = new ArrayList<String>();
        request.setAttribute("errors",errors);
        //check session attribution.
        User registeruser = (User) request.getSession(true).getAttribute("user");
      if (registeruser != null) {
        //errors.add("You are already logged in.");
        return "haslogin.jsp";
      }
       
      try {
          RegisterForm form = formBeanFactory.create(request);
          request.setAttribute("registerform",form);
          if (!form.isPresent()) {
              return "register.jsp";
          }
          /*
           * If there are something wrong with the user input,
           * e.g. no password, fail to repeat password ,
           *
           */
          //System.out.println("the eamil address is " + form.getUserName());
          errors.addAll(form.registerCheckErrors());
          if (errors.size()!= 0) {
              return "register.jsp";
          }
          //check duplicated registration.
          User checkuser = userDAO.lookup(form.getUserName());
          if( checkuser != null){
            errors.add("User with that email already exists.");
            return "register.jsp";
          }
          // Create the user bean
          User user = new User(form.getUserName());
          user.setPassword(form.getPassword());
      user.setFirstName(form.getFirstName());
      user.setLastName(form.getLastName());
      user.setGender(form.getGender());
          userDAO.create(user);  
      /*
       * After successful registration, redirectTo personal page.
       */
          HttpSession session = request.getSession(false);
View Full Code Here

  public String perform(HttpServletRequest request) {
    List<String> errors = new ArrayList<String>();
    request.setAttribute("errors",errors);
    HttpSession session = request.getSession();
    User user = (User) request.getSession().getAttribute("user");

    if(user == null){
      LoginForm form = new LoginForm();
      form.setRedirect("/login.do");
      request.setAttribute("loginform", form);
      errors.add("please login");
      synchronized(session){
      session.setAttribute("redirectTo",redirectTo);
      session.setAttribute("user", user);
      }
      return "homepage.jsp";
    }
   
    String button = request.getParameter("button");
    String med = request.getParameter("med");
    String side = request.getParameter("side");
   
    // for dropdown menus
    Medication[] medicationlist = medDAO.getMedicationList(user.getEmailAddress());
    SideEffect[] sidelist = sideDAO.getSideEffectsList(user.getEmailAddress());
    // get medication and sides
    MedLog[] medlog = logMedDAO.getLogMedicationList(user.getEmailAddress());
    SideEffectLog[] sidelog = logSideDAO.getLogSideList(user.getEmailAddress());
    int medLength = 0;
    int sideLength = 0;
    if(med != null) {
      medlog = logMedDAO.getLogMedication(user.getEmailAddress(), med);
      if(medlog != null) {
        medLength = medlog.length;
      }
    }
    if(side != null) {
      sidelog = logSideDAO.getLogSide(user.getEmailAddress(), side);
      if (sidelog != null) {
        sideLength = sidelog.length;
      }
    }
    int arraySize = medLength + sideLength;
View Full Code Here

  }
  public String getName() { return "logSide.do"; }

  public String perform(HttpServletRequest request) {
      //must be logged in for this one.
      User user = (User) request.getSession().getAttribute("user");
      if(user == null){
        LoginForm form = new LoginForm();
        form.setRedirect("/logSide.do");
        request.setAttribute("loginform", form);
        return "homePage.jsp";
      }
      /*
       * if the user has already logged in.
       * */
 
    //SideEffectLog[] LogSidelist;
    SideEffect[] sidelist;
    //error list for error mention function.
    List<String> errors = new ArrayList<String>();
    String button;
    button = request.getParameter("button");
    if(button != null){
    if(button.equals("Log side effect")){
    try{
      LogSideForm form = formBeanFactory.create(request);
          request.setAttribute("logsideform", form);
          if(!form.isPresent()){
            return "homepage.jsp";
          }
          HttpSession session = request.getSession(false);
          //check the errors.
          errors.addAll(form.getValidationErrors());
          if (errors.size()!= 0) {
            sidelist = sideDAO.getSideEffectsList(user.getEmailAddress());
              request.setAttribute("sideeffectslist",sidelist);
            request.setAttribute("errors",errors);
            return "logSide.jsp";
        }   
          System.out.println("the loged sideeffect name is " + form.getName());
          String delMed = (String) session.getAttribute("deletid");
          String newMed;
          //if user want some medication schedule be deleted.
          if(delMed != null){
            newMed = delMed;
            logSideMed = new SideEffectLog(Integer.parseInt(newMed));
            logSideMed.setOwner(user.getEmailAddress());
            createLogSide(logSideMed,form);
            //create a new user.
            logsideDAO.create(logSideMed);
          //if no scheduled medication be deleted.
          }else{
            int allSize = logsideDAO.size();
            //initialization situation.
            if(allSize == 0){
              newMed = Integer.toString(allSize);
              logSideMed = new SideEffectLog(Integer.parseInt(newMed));
                logSideMed.setOwner(user.getEmailAddress());
                createLogSide(logSideMed,form);
                //create a new user.
                logsideDAO.create(logSideMed);
            }else{
              allSize = logsideDAO.getLastId();
              newMed = Integer.toString(allSize);
              logSideMed = new SideEffectLog(Integer.parseInt(newMed) + 1);
                logSideMed.setOwner(user.getEmailAddress());
                createLogSide(logSideMed,form);
                //create a new user.
                logsideDAO.create(logSideMed);
            }
          }
          synchronized(session){
          session.setAttribute("redirectto", null);
        session.setAttribute("deleteid", null);
            session.setAttribute("user", user);
          }
            String redirectTo = (String) session.getAttribute("redirectto");
            //LogSidelist = logsideDAO.getLogSideList(user.getEmailAddress());
            sidelist = sideDAO.getSideEffectsList(user.getEmailAddress());
            if(redirectTo != null){
              request.setAttribute("sideeffectslist",sidelist);
              return redirectTo;
            }
        request.setAttribute("sideeffectslist", sidelist);
        return "logSide.jsp";
  }catch(DAOException e1){
    e1.printStackTrace();
  } catch (FormBeanException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  }//if user did not add any new side effect.
        sidelist = sideDAO.getSideEffectsList(user.getEmailAddress());
    request.setAttribute("sideeffectslist", sidelist);
    return "logSide.jsp";
  }else{
    sidelist = sideDAO.getSideEffectsList(user.getEmailAddress());
      request.setAttribute("sideeffectslist", sidelist);
    return "logSide.jsp";
  }
}
View Full Code Here

TOP

Related Classes of databeans.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.