Package com.google.devrel.training.conference.domain

Examples of com.google.devrel.training.conference.domain.Conference


    )
    public Conference getConference(
            @Named("websafeConferenceKey") final String websafeConferenceKey)
            throws NotFoundException {
        Key<Conference> conferenceKey = Key.create(websafeConferenceKey);
        Conference conference = ofy().load().key(conferenceKey).now();
        if (conference == null) {
            throw new NotFoundException("No Conference found with key: " + websafeConferenceKey);
        }
        return conference;
    }
View Full Code Here


                // Get the conference key
                // Will throw ForbiddenException if the key cannot be created
                Key<Conference> conferenceKey = Key.create(websafeConferenceKey);

                // Get the Conference entity from the datastore
                Conference conference = ofy().load().key(conferenceKey).now();

                // 404 when there is no Conference with the given conferenceId.
                if (conference == null) {
                    return new WrappedBoolean (false,
                            "No Conference found with key: "
                                    + websafeConferenceKey);
                }

                // Get the user's Profile entity
                Profile profile = getProfileFromUser(user);

                // Has the user already registered to attend this conference?
                if (profile.getConferenceKeysToAttend().contains(
                        websafeConferenceKey)) {
                    return new WrappedBoolean (false, "Already registered");
                } else if (conference.getSeatsAvailable() <= 0) {
                    return new WrappedBoolean (false, "No seats available");
                } else {
                    // All looks good, go ahead and book the seat
                    profile.addToConferenceKeysToAttend(websafeConferenceKey);
                    conference.bookSeats(1);

                    // Save the Conference and Profile entities
                    ofy().save().entities(profile, conference).now();
                    // We are booked!
                    return new WrappedBoolean(true, "Registration successful");
View Full Code Here

        WrappedBoolean result = ofy().transact(new Work<WrappedBoolean>() {
            @Override
            public WrappedBoolean run() {
                Key<Conference> conferenceKey = Key.create(websafeConferenceKey);
                Conference conference = ofy().load().key(conferenceKey).now();
                // 404 when there is no Conference with the given conferenceId.
                if (conference == null) {
                    return new  WrappedBoolean(false,
                            "No Conference found with key: " + websafeConferenceKey);
                }

                // Un-registering from the Conference.
                Profile profile = getProfileFromUser(user);
                if (profile.getConferenceKeysToAttend().contains(websafeConferenceKey)) {
                    profile.unregisterFromConference(websafeConferenceKey);
                    conference.giveBackSeats(1);
                    ofy().save().entities(profile, conference).now();
                    return new WrappedBoolean(true);
                } else {
                    return new WrappedBoolean(false, "You are not registered for this conference");
                }
View Full Code Here

        topics.add("Google");
        topics.add("Cloud");
        topics.add("Platform");
        ConferenceForm conferenceForm = new ConferenceForm(
                NAME, DESCRIPTION, topics, CITY, startDate, endDate, CAP);
        Conference conference = conferenceApi.createConference(user, conferenceForm);
        // Check the return value.
        assertEquals(NAME, conference.getName());
        assertEquals(DESCRIPTION, conference.getDescription());
        assertEquals(topics, conference.getTopics());
        assertEquals(USER_ID, conference.getOrganizerUserId());
        assertEquals(CITY, conference.getCity());
        assertEquals(startDate, conference.getStartDate());
        assertEquals(endDate, conference.getEndDate());
        assertEquals(CAP, conference.getMaxAttendees());
        assertEquals(CAP, conference.getSeatsAvailable());
        assertEquals(MONTH, conference.getMonth());
        // Check if a new Profile is created
        Profile profile = ofy().load().key(Key.create(Profile.class, user.getUserId())).now();
        assertEquals(USER_ID, profile.getUserId());
        assertEquals(EMAIL, profile.getMainEmail());
        assertEquals(TEE_SHIRT_SIZE, profile.getTeeShirtSize());
View Full Code Here

        topics.add("Google");
        topics.add("Cloud");
        topics.add("Platform");
        ConferenceForm conferenceForm = new ConferenceForm(
                NAME, DESCRIPTION, topics, CITY, startDate, endDate, CAP);
        Conference conference = conferenceApi.createConference(user, conferenceForm);

        List<Conference> conferencesCreated = conferenceApi.getConferencesCreated(user);
        assertEquals(1, conferencesCreated.size());
        assertTrue("The result should contain a conference",
                conferencesCreated.contains(conference));
View Full Code Here

        topics.add("Google");
        topics.add("Cloud");
        topics.add("Platform");
        ConferenceForm conferenceForm = new ConferenceForm(
                NAME, DESCRIPTION, topics, CITY, startDate, endDate, CAP);
        Conference conference = conferenceApi.createConference(user, conferenceForm);
        conference = conferenceApi.getConference(conference.getWebsafeKey());
        // Check the return value.
        assertEquals(NAME, conference.getName());
        assertEquals(DESCRIPTION, conference.getDescription());
        assertEquals(topics, conference.getTopics());
        assertEquals(USER_ID, conference.getOrganizerUserId());
        assertEquals(CITY, conference.getCity());
        assertEquals(startDate, conference.getStartDate());
        assertEquals(endDate, conference.getEndDate());
        assertEquals(CAP, conference.getMaxAttendees());
        assertEquals(CAP, conference.getSeatsAvailable());
        assertEquals(MONTH, conference.getMonth());
    }
View Full Code Here

        topics.add("Google");
        topics.add("Cloud");
        topics.add("Platform");
        ConferenceForm conferenceForm = new ConferenceForm(
                NAME, DESCRIPTION, topics, CITY, startDate, endDate, CAP);
        Conference conference = conferenceApi.createConference(user, conferenceForm);
        Long conferenceId = conference.getId();

        // Registration
        Boolean result = conferenceApi.registerForConference(
                user, conference.getWebsafeKey()).getResult();
        conference = conferenceApi.getConference(conference.getWebsafeKey());
        Profile profile = ofy().load().key(Key.create(Profile.class, user.getUserId())).now();
        assertTrue("registerForConference should succeed.", result);
        assertEquals(CAP - 1, conference.getSeatsAvailable());
        assertTrue("Profile should have the conferenceId in conferenceIdsToAttend.",
                profile.getConferenceKeysToAttend().contains(conference.getWebsafeKey()));

        // Unregister
        result = conferenceApi.unregisterFromConference(
                user, conference.getWebsafeKey()).getResult();
        conference = conferenceApi.getConference(conference.getWebsafeKey());
        profile = ofy().load().key(Key.create(Profile.class, user.getUserId())).now();
        assertTrue("unregisterFromConference should succeed.", result);
        assertEquals(CAP, conference.getSeatsAvailable());
        assertFalse("Profile shouldn't have the conferenceId in conferenceIdsToAttend.",
                profile.getConferenceKeysToAttend().contains(conference.getWebsafeKey()));

}
View Full Code Here

        topics.add("Google");
        topics.add("Cloud");
        topics.add("Platform");
        ConferenceForm conferenceForm = new ConferenceForm(
                NAME, DESCRIPTION, topics, CITY, startDate, endDate, CAP);
        Conference conference = conferenceApi.createConference(user, conferenceForm);
        // Check the return value.
        assertEquals(NAME, conference.getName());
        assertEquals(DESCRIPTION, conference.getDescription());
        assertEquals(topics, conference.getTopics());
        assertEquals(USER_ID, conference.getOrganizerUserId());
        assertEquals(CITY, conference.getCity());
        assertEquals(startDate, conference.getStartDate());
        assertEquals(endDate, conference.getEndDate());
        assertEquals(CAP, conference.getMaxAttendees());
        assertEquals(CAP, conference.getSeatsAvailable());
        assertEquals(MONTH, conference.getMonth());
        // Check if a new Profile is created
        Profile profile = ofy().load().key(Key.create(Profile.class, user.getUserId())).now();
        assertEquals(USER_ID, profile.getUserId());
        assertEquals(EMAIL, profile.getMainEmail());
        assertEquals(TEE_SHIRT_SIZE, profile.getTeeShirtSize());
View Full Code Here

        topics.add("Google");
        topics.add("Cloud");
        topics.add("Platform");
        ConferenceForm conferenceForm = new ConferenceForm(
                NAME, DESCRIPTION, topics, CITY, startDate, endDate, CAP);
        Conference conference = conferenceApi.createConference(user, conferenceForm);

        List<Conference> conferencesCreated = conferenceApi.getConferencesCreated(user);
        assertEquals(1, conferencesCreated.size());
        assertTrue("The result should contain a conference",
                conferencesCreated.contains(conference));
View Full Code Here

        topics.add("Google");
        topics.add("Cloud");
        topics.add("Platform");
        ConferenceForm conferenceForm = new ConferenceForm(
                NAME, DESCRIPTION, topics, CITY, startDate, endDate, CAP);
        Conference conference = conferenceApi.createConference(user, conferenceForm);
        // Check the return value.
        assertEquals(NAME, conference.getName());
        assertEquals(DESCRIPTION, conference.getDescription());
        assertEquals(topics, conference.getTopics());
        assertEquals(USER_ID, conference.getOrganizerUserId());
        assertEquals(CITY, conference.getCity());
        assertEquals(startDate, conference.getStartDate());
        assertEquals(endDate, conference.getEndDate());
        assertEquals(CAP, conference.getMaxAttendees());
        assertEquals(CAP, conference.getSeatsAvailable());
        assertEquals(MONTH, conference.getMonth());

        // Update it with new values.
        String newName = "Google I/O";
        String newDescription = "Google's annual developer event.";
        String newCity = "San Francisco";
        startDate = dateFormat.parse("06/25/2014");
        endDate = dateFormat.parse("06/26/2014");
        topics = new ArrayList<>();
        topics.add("Google");
        topics.add("Developers");
        int newCap = 5000;
        conferenceForm = new ConferenceForm(newName, newDescription, topics, newCity, startDate,
                endDate, newCap);
        conference = conferenceApi.updateConference(
                user, conferenceForm, conference.getWebsafeKey());
        assertEquals(newName, conference.getName());
        assertEquals(newDescription, conference.getDescription());
        assertEquals(topics, conference.getTopics());
        assertEquals(USER_ID, conference.getOrganizerUserId());
        assertEquals(newCity, conference.getCity());
        assertEquals(startDate, conference.getStartDate());
        assertEquals(endDate, conference.getEndDate());
        assertEquals(newCap, conference.getMaxAttendees());
        assertEquals(newCap, conference.getSeatsAvailable());
        assertEquals(6, conference.getMonth());
    }
View Full Code Here

TOP

Related Classes of com.google.devrel.training.conference.domain.Conference

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.