Package models

Examples of models.Event


        User user = getLoggedUser();
        if (!user.admin) {
            return forbidden();
        }

        Event event = Event.find.byId(idEvent);
        if (event != null) {
            List<Proposal> proposals = Proposal.findByEvent(event);
            if (proposals.isEmpty()) {
                event.delete();
            } else {
                Map<String, List<String>> errors = new HashMap<String, List<String>>();
                errors.put("event", Collections.singletonList(Messages.get("error.event.hasElement")));
                return badRequest(toJson(errors));
            }
View Full Code Here


        return user;
    }


    protected static Event getEvent() {
        Event event = Event.findByUrl(request().host());
        if (event == null) {
           // event = Event.getDefaut(request().host());
        }
        return event;
    }
View Full Code Here

@SecureSocial.SecuredAction(ajaxCall = true)
public class EventRestController extends BaseController {


    public static Result get(Long idEvent) {
        Event event = Event.find.byId(idEvent);
        if (event == null) {
            return noContent();
        }
        return ok(toJson(event));
    }
View Full Code Here

        }
        return ok(toJson(event));
    }

    public static Result organizers(Long idEvent) {
        Event event = Event.find.byId(idEvent);
        if (event == null) {
            return noContent();
        }
        return ok(toJson(event.getOrganizers()));
    }
View Full Code Here

        }
        return ok(toJson(event.getOrganizers()));
    }

    public static Result getCurrentEvent() {
        Event event = getEvent();
        if (event != null) {
            return ok(toJson(getEvent()));
        } else {
            return ok();
        }
View Full Code Here

        User user = getLoggedUser();
        if (!user.admin) {
            return forbidden();
        }

        Event event = Event.find.byId(idEvent);
        if (event != null) {

            //TODO gestion de l'agenda

            event.update();
            return ok(toJson(event));
        }
        // HTTP 204 en cas de succès (NO CONTENT)
        return noContent();
    }
View Full Code Here

        if (evenForm.hasErrors()) {
            return badRequest(toJson(TransformValidationErrors.transform(evenForm.errors())));
        }

        Event formEvent = evenForm.get();

        if (formEvent.getId() == null) {
            // Nouvel Evénement
            if (Event.findByName(formEvent.getName()) != null) {
                return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.event.already.exist"))));
            }
            formEvent.save();
            List<User> organizersInDb = new ArrayList<User>();
            for (User organizer : formEvent.getOrganizers()) {
                organizersInDb.add(User.findById(organizer.id));
            }
            formEvent.getOrganizers().clear();
            formEvent.getOrganizers().addAll(organizersInDb);
            formEvent.saveManyToManyAssociations("organizers");

            formEvent.update();

        } else {
            // Mise à jour d'un événement
            Event dbEvent = Event.find.byId(formEvent.getId());
            if (!formEvent.getName().equals(dbEvent.getName())
                    && Event.findByName(formEvent.getName()) != null) {
                return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.event.already.exist"))));
            }

            dbEvent.setUrl(formEvent.getUrl());
            dbEvent.setShortName(formEvent.getShortName());
            dbEvent.setCgu(formEvent.getCgu());
            dbEvent.logo = formEvent.logo;
            dbEvent.setDescription(formEvent.getDescription());
            dbEvent.update();

            updateOrganizers(formEvent, dbEvent);
        }

        // HTTP 204 en cas de succès (NO CONTENT)
View Full Code Here

    @Test
    public void deleteEventTest() {

      final Long originalCount = Event.count();
      final Event originalNextEvent = Event.find("order by date desc").first();
     
        Response response = DELETE("/event/" + originalNextEvent.id);
        assertStatus(302, response);
        assertHeaderEquals("Location", "/", response);
       
        assertEquals("There should be one less event", originalCount-1, Event.count());
       
        assertNotSame("The next event must have changed",
                originalNextEvent,
                Event.find("order by date desc").first()
        );

        final Event deletedEventByCondition = Event.find("id = ?", originalNextEvent.id).first();
        assertNull("The event should have been deleted", deletedEventByCondition);
    }
View Full Code Here

      List<Event> events = Event.find("order by date desc").fetch();
        render(events);
    }

    public static void delete(Long id) {
      Event event = Event.findById(id);
      event.delete();
     
      list();
    }
View Full Code Here

     
      list();
    }
   
    public static void form(Long id) {
      final Event event;
      if (id==null) {
        event = new Event();
      } else {
        event = Event.findById(id);
      }
      render(event);
    }
View Full Code Here

TOP

Related Classes of models.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.