Package org.cast.cwm.data

Examples of org.cast.cwm.data.Period


      // create a new site
      Site newSite = SiteService.get().newSite();
      newSite.setName("Site_" + user.getUsername()); // make this unique

      // create a new period
      Period newPeriod = SiteService.get().newPeriod();
      newPeriod.setSite(newSite);
      newPeriod.setName("Class_" + user.getUsername()); // make this unique
     
      // add the period to the user and the site
      SortedSet<Period> periodSet = new TreeSet<Period>();
      periodSet.add(newPeriod);
      user.getPeriods().add(newPeriod);
      newSite.getPeriods().add(newPeriod);     
     
      // a default student must be added to the new period
      User studentUser = UserService.get().newUser();
      studentUser.setRole(Role.STUDENT);
      studentUser.setFirstName("Student");
      studentUser.setLastName(newPeriod.getName());
      studentUser.setUsername(newPeriod.getName());
      studentUser.getPeriods().add(newPeriod);
      studentUser.setValid(true);
      studentUser.setCreateDate(new Date());
     
      // create a random number for the password
      Random randomNumber = new Random();
      Integer studentPasswordInteger = randomNumber.nextInt();
      studentPassword = studentPasswordInteger.toString().substring(0, 6);
      log.debug("this is the student password : {}", studentPassword);
      studentUser.setPassword(studentPassword);     
     
      // add the teacher and the default student to the new default class
      userSet.add(studentUser);
      newPeriod.setUsers(userSet);

      Databinder.getHibernateSession().save(newSite);
      Databinder.getHibernateSession().save(newPeriod);
      Databinder.getHibernateSession().save(studentUser);
    }
View Full Code Here


   
    @Override
    protected void onSubmit() {
      super.onSubmit();
      User currentUser = getModelObject();
      Period currentPeriod = currentUser.getPeriods().first();
      Period newPeriod = periodChoiceMove.getModelObject();
     
      // Ensure that someone else does not have the same first and last name in the destination period
      IModel<User> mOtherUser = UserService.get().getByFullnameFromPeriod(currentUser.getFirstName(), currentUser.getLastName(), periodChoiceMove.getModel());
      boolean error = false;
      if (mOtherUser != null && mOtherUser.getObject() != null && !mOtherUser.getObject().getId().equals(currentUser.getId()) ) {
        error("Move Failed: A student with that name already exists in " + newPeriod.getName() + ". \n");
        error = true;
      } else if (newPeriod == currentPeriod) {
        error("Cannot move student to the same period");
        error = true;     
      }

      if (!error) {
        currentUser.getPeriods().clear();
        currentUser.getPeriods().add(newPeriod);
       
        cwmService.flushChanges();
        eventService.saveEvent("student:periodmove", "Student: " + currentUser.getId() +
            "; From PeriodId " + currentPeriod.getId() + " to PeriodId " + newPeriod.getId(), getPageName());
     

    }   
View Full Code Here

    }


    @Override
    protected void onSubmit() {
      Period period = this.getModelObject();
      IModel<User> mUser = UserService.get().getById(ISISession.get().getUser().getId());

      // Add the new period
      period.setSite(ISISession.get().getCurrentSiteModel().getObject());
      SortedSet<User> userSet = new TreeSet<User>();
      userSet.add(mUser.getObject());
      period.setUsers(userSet);
      Databinder.getHibernateSession().save(period);
     
      // Update the teacher to connect with the new period
      User user = mUser.getObject();
      SortedSet<Period> periodSet = new TreeSet<Period>();
View Full Code Here

  /* (non-Javadoc)
   * @see org.cast.isi.service.IISIResponseService#setClassMessage(org.apache.wicket.model.IModel, java.lang.String)
   */
  public void setClassMessage(IModel<Period> mPeriod, String s) {
   
    Period p = mPeriod.getObject();
   
    ClassMessage m = new ClassMessage();
    m.setTimestamp(new Date());
    m.setPeriod(p);
    m.setCurrent(true);
    m.setMessage(s);
    m.setAuthor(ISISession.get().getUser());
   
    ClassMessage old = getClassMessage(mPeriod);
    if (old != null) {
      old.setCurrent(false);
    }
    Databinder.getHibernateSession().save(m);
    cwmService.flushChanges();
    eventService.saveEvent("classmessage:create", "Period Id: " + p.getId() + " Message Id: " + m.getId(), null);   
  }
View Full Code Here

  /* (non-Javadoc)
   * @see org.cast.isi.service.IISIResponseService#deleteClassMessage(org.apache.wicket.model.IModel)
   */
  public void deleteClassMessage(IModel<Period> mPeriod) {
   
    Period p = mPeriod.getObject();
    ClassMessage m = getClassMessage(mPeriod);
    if (m != null) {
      m.setCurrent(false);
      cwmService.flushChanges();
      eventService.saveEvent("classmessage:delete", "Period Id: " + p.getId() + " Message Id: " + m.getId(), null);
    }
  }
View Full Code Here

TOP

Related Classes of org.cast.cwm.data.Period

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.