Package domain

Examples of domain.Event


   * and then add the new event to the database
   */
  @Override
  protected Response internalExecute(HttpServletRequest request, Session databaseSession) {
    Response response = null;
    Event event = null;
    HttpSession httpSession = request.getSession();
   
    User userObject = (User) httpSession.getAttribute("currentUser");
    if( null == userObject ) {
      return new Response(ResponseStatus.FAIL, "Problem identifying user");
    }

    Date fromDate = DateOperator.stringToDate(from);
    Date toDate = DateOperator.stringToDate(to);
   
    if( (null == fromDate) || (null == toDate) ) {
      return new Response(ResponseStatus.FAIL, "Dates parsing problem" );
    }
    if( !DateOperator.date1IsBeforeDate2(fromDate, toDate) ) {
      return new Response(ResponseStatus.FAIL, "Start date need to be before end date");
    }
   
    else {
      try {
        EventType eventTypeObject = (EventType) databaseSession.createCriteria(EventType.class).add(Restrictions.eq("id", this.eventType)).uniqueResult();
        if(null == eventTypeObject) {
          return new Response(ResponseStatus.FAIL, "Not valid event type");
        }
       
        EventId eventIdObject = new EventId()
        eventIdObject.setFrom(fromDate);
        eventIdObject.setTo(toDate);
        eventIdObject.setOwner(userObject);
        eventIdObject.setType(eventTypeObject);
       
        PermissionType permisssionTypeObject = (PermissionType) databaseSession.createCriteria(PermissionType.class).add(Restrictions.eq("id", this.permissionType)).uniqueResult();
        if(null == permisssionTypeObject) {
          return new Response(ResponseStatus.FAIL, "Not valid permisssion type");
        }
       
        RepetitionType repetitionTypeObject = (RepetitionType) databaseSession.createCriteria(RepetitionType.class).add(Restrictions.eq("id", this.repetitionType)).uniqueResult();
        if(null == repetitionTypeObject) {
          return new Response(ResponseStatus.FAIL, "Not valid repetition type");
        }
        if( !DateOperator.isRepetitionPossible(fromDate, toDate, repetitionTypeObject) ) {
          return new Response(ResponseStatus.FAIL, "Repetition is not possible. Make sure there is a sense in the repetition type you choose");
        }
       
        this.description = XssHandler.escape(this.description);
       
        event = new Event();
        event.setDescription(this.description);
        event.setPermission(permisssionTypeObject);
        event.setRepetition(repetitionTypeObject);
        event.setId(eventIdObject);
       
        Transaction transaction = databaseSession.beginTransaction();
        try {
          databaseSession.save(event);
          transaction.commit();
View Full Code Here


  protected Response internalExecute(HttpServletRequest request, Session databaseSession) {
   
    Response response = null;
   
    try {
      Event oldEvent = null;
      Date fromDate = DateOperator.stringToDate(from);
      Date toDate = DateOperator.stringToDate(to);

     
      if( null == fromDate || null == toDate ) {
         throw new IllegalArgumentException("Dates parsing problem" );
      }
     
      if( !DateOperator.date1IsBeforeDate2(fromDate, toDate) ) {
        throw new IllegalArgumentException("Start date need to be before end date");
      }
     
      if (oldFrom != null && oldTo != null) { // if we need to exclude old event, get it.   
        EventType oldEventTypeObj = (EventType) databaseSession.get(EventType.class, oldEventType);
        User oldOwnerObj = (User) databaseSession.get(User.class, oldOwner);
       
        oldEvent = (Event) databaseSession.createCriteria(Event.class)
          .add(Restrictions.eq("id.from", DateOperator.stringToDate(this.oldFrom) ))
          .add(Restrictions.eq("id.to", DateOperator.stringToDate(this.oldTo)))
          .add(Restrictions.eq("id.type", oldEventTypeObj))
          .add(Restrictions.eq("id.owner", oldOwnerObj))
          .uniqueResult();
      }
     
      RepetitionType noRepeat = (RepetitionType) databaseSession.get(RepetitionType.class, new Long(1));
     
      // Get not repeated event that overlap
      Criteria notRepeatedOverlapCriteria = databaseSession.createCriteria(Event.class)
                          .add(Restrictions.conjunction() // AND
                            .add(Restrictions.eq("repetition", noRepeat))
                            .add(Restrictions.disjunction() // OR
                                .add(Restrictions.conjunction()
                                    .add(Restrictions.between("id.from", fromDate, toDate))
                                    .add(Restrictions.between("id.to", fromDate, toDate))
                                )
                                .add(Restrictions.conjunction() // AND
                                    .add(Restrictions.le("id.from", fromDate))
                                    .add(Restrictions.ge("id.to", toDate))
                                )
                                .add(Restrictions.conjunction() // AND
                                    .add(Restrictions.ge("id.from", fromDate))
                                    .add(Restrictions.le("id.to", toDate))
                                )
                              )
                           );
     

      if (oldEvent != null) { // skip old event in overlap check
        notRepeatedOverlapCriteria.add(Restrictions.not(Restrictions.idEq(oldEvent.getId())));
      }
     
      List<Event> notRepeatedOverlap = notRepeatedOverlapCriteria.list();
           
      List<Event> repeatedEvents = databaseSession.createCriteria(Event.class)
View Full Code Here

        eventIdObject.setFrom(fromDate);
        eventIdObject.setTo(toDate);
        eventIdObject.setOwner(eventOwner);
        eventIdObject.setType(eventTypeObject);
       
        Event eventObject = (Event) databaseSession.get(Event.class, eventIdObject);
       
        if (eventObject == null) {
          throw new IllegalArgumentException("Could not locate event in question!");
        }
       
        // get current user
        User currentUser = (User) request.getSession().getAttribute("currentUser");
       
        // get permission types from database (very very dumb):
        PermissionType publicPermission = (PermissionType) databaseSession.get(PermissionType.class, new Long(1));
       
        // get admin role, yep, dumb as well.
        Role adminRole = (Role) databaseSession.get(Role.class, new Long(2));
       
        // who can edit the event:
        // 1. the owner
        // 2. Not owner but admin if the event is public
        if ( !eventObject.getId().getOwner().equals(currentUser)
           ||  (eventObject.getPermission().equals(publicPermission) && currentUser.getRole().equals(adminRole)) ) ) {
          throw new SecurityException("Permission to delete is denied.");
        }
       
        Transaction transaction = databaseSession.beginTransaction();
        transaction.begin();
View Full Code Here

     
      if (oldEventType == null) {
        throw new IllegalArgumentException("Couldn't locate old type of the event");
      }
     
      Event oldEvent = (Event) databaseSession.createCriteria(Event.class)
                    .add(Restrictions.eq("id.from", DateOperator.stringToDate(this.oldFrom) ))
                    .add(Restrictions.eq("id.to", DateOperator.stringToDate(this.oldTo)))
                    .add(Restrictions.eq("id.type", oldEventType))
                    .add(Restrictions.eq("id.owner", oldOwner))
                    .uniqueResult();
     
      if (oldEvent == null) {
        throw new IllegalArgumentException("Could not locate event in question!");
      }
     
      User currentUser = (User) request.getSession().getAttribute("currentUser");
     
      if (currentUser == null) {
        throw new SecurityException("You're not logged in");
      }

      // get permission types from database (very very dumb):
      PermissionType publicPermission = (PermissionType) databaseSession.get(PermissionType.class, new Long(1));
     
      // get admin role, yep, dumb as well.
      Role adminRole = (Role) databaseSession.get(Role.class, new Long(2));
     
      // who can edit the event:
      // 1. the owner
      // 2. Not owner but admin if the event is public
      if ( !(oldEvent.getId().getOwner().equals(currentUser)
         ||  (oldEvent.getPermission().equals(publicPermission) && currentUser.getRole().equals(adminRole)) ) ) {
        throw new SecurityException("Permission to edit is denied.");
      }
     
      if (null == oldEvent) {
        throw new IllegalArgumentException("The event you are editing was not found.");
      }


      this.description = XssHandler.escape(this.description);
     
      Transaction transaction = databaseSession.beginTransaction();     

      databaseSession.delete(oldEvent);
     
      Event newEvent = new Event();
      newEvent.setId( new EventId() );
      newEvent.getId().setType(eventTypeObject);
      newEvent.getId().setOwner(oldOwner);
      newEvent.getId().setFrom(fromDate);
      newEvent.getId().setTo(toDate);
      newEvent.setDescription(this.description);
      newEvent.setPermission(permisssionTypeObject);
      newEvent.setRepetition(repetitionTypeObject);

      databaseSession.save(newEvent);
     
      transaction.commit();
      response = new Response(ResponseStatus.OK);
View Full Code Here

TOP

Related Classes of domain.Event

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.