@Test public void testUpdateConference() throws Exception { DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); Date startDate = dateFormat.parse("03/25/2014"); Date endDate = dateFormat.parse("03/26/2014"); List<String> topics = new ArrayList<>(); 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); 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()); 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()); }
@ApiMethod( name = "updateConference", path = "conference/{websafeConferenceKey}", httpMethod = HttpMethod.PUT ) public Conference updateConference(final User user, final ConferenceForm conferenceForm, @Named("websafeConferenceKey") final String websafeConferenceKey) throws UnauthorizedException, NotFoundException, ForbiddenException, ConflictException { if (user == null) { throw new UnauthorizedException("Authorization required"); } final String userId = getUserId(user); TxResult<Conference> result = ofy().transact(new Work<TxResult<Conference>>() { @Override public TxResult<Conference> run() { Key<Conference> conferenceKey = Key.create(websafeConferenceKey); Conference conference = ofy().load().key(conferenceKey).now(); if (conference == null) { return new TxResult<>( new NotFoundException("No Conference found with the key: " + websafeConferenceKey)); } Profile profile = ofy().load().key(Key.create(Profile.class, userId)).now(); if (profile == null || !conference.getOrganizerUserId().equals(userId)) { return new TxResult<>( new ForbiddenException("Only the owner can update the conference.")); } conference.updateWithConferenceForm(conferenceForm); ofy().save().entity(conference).now(); return new TxResult<>(conference); } }); return result.getResult(); }
ConferenceApi { @ApiMethod( name = "updateConference", path = "conference/{websafeConferenceKey}", httpMethod = HttpMethod.PUT ) public Conference updateConference(final User user, final ConferenceForm conferenceForm, @Named("websafeConferenceKey") final String websafeConferenceKey) throws UnauthorizedException, NotFoundException, ForbiddenException, ConflictException { if (user == null) { throw new UnauthorizedException("Authorization required"); } final String userId = getUserId(user); TxResult<Conference> result = ofy().transact(new Work<TxResult<Conference>>() { @Override public TxResult<Conference> run() { Key<Conference> conferenceKey = Key.create(websafeConferenceKey); Conference conference = ofy().load().key(conferenceKey).now(); if (conference == null) { return new TxResult<>( new NotFoundException("No Conference found with the key: " + websafeConferenceKey)); } Profile profile = ofy().load().key(Key.create(Profile.class, userId)).now(); if (profile == null || !conference.getOrganizerUserId().equals(userId)) { return new TxResult<>( new ForbiddenException("Only the owner can update the conference.")); } conference.updateWithConferenceForm(conferenceForm); ofy().save().entity(conference).now(); return new TxResult<>(conference); } }); return result.getResult(); } }
ConferenceApi { @ApiMethod( name = "updateConference", path = "conference/{websafeConferenceKey}", httpMethod = HttpMethod.PUT ) public Conference updateConference(final User user, final ConferenceForm conferenceForm, @Named("websafeConferenceKey") final String websafeConferenceKey) throws UnauthorizedException, NotFoundException, ForbiddenException, ConflictException { if (user == null) { throw new UnauthorizedException("Authorization required"); } final String userId = getUserId(user); TxResult<Conference> result = ofy().transact(new Work<TxResult<Conference>>() { @Override public TxResult<Conference> run() { Key<Conference> conferenceKey = Key.create(websafeConferenceKey); Conference conference = ofy().load().key(conferenceKey).now(); if (conference == null) { return new TxResult<>( new NotFoundException("No Conference found with the key: " + websafeConferenceKey)); } Profile profile = ofy().load().key(Key.create(Profile.class, userId)).now(); if (profile == null || !conference.getOrganizerUserId().equals(userId)) { return new TxResult<>( new ForbiddenException("Only the owner can update the conference.")); } conference.updateWithConferenceForm(conferenceForm); ofy().save().entity(conference).now(); return new TxResult<>(conference); } }); return result.getResult(); }  }
ConferenceApi { @ApiMethod( name = "updateConference", path = "conference/{websafeConferenceKey}", httpMethod = HttpMethod.PUT ) public Conference updateConference(final User user, final ConferenceForm conferenceForm, @Named("websafeConferenceKey") final String websafeConferenceKey) throws UnauthorizedException, NotFoundException, ForbiddenException, ConflictException { if (user == null) { throw new UnauthorizedException("Authorization required"); } final String userId = getUserId(user); TxResult<Conference> result = ofy().transact(new Work<TxResult<Conference>>() { @Override public TxResult<Conference> run() { Key<Conference> conferenceKey = Key.create(websafeConferenceKey); Conference conference = ofy().load().key(conferenceKey).now(); if (conference == null) { return new TxResult<>( new NotFoundException("No Conference found with the key: " + websafeConferenceKey)); } Profile profile = ofy().load().key(Key.create(Profile.class, userId)).now(); if (profile == null || !conference.getOrganizerUserId().equals(userId)) { return new TxResult<>( new ForbiddenException("Only the owner can update the conference.")); } conference.updateWithConferenceForm(conferenceForm); ofy().save().entity(conference).now(); return new TxResult<>(conference); } }); return result.getResult(); }  @ApiMethod(name = "getProfile", path = "profile", httpMethod = HttpMethod.GET) Profile getProfile(final User user); @ApiMethod(name = "saveProfile", path = "profile", httpMethod = HttpMethod.POST) Profile saveProfile(final User user, final ProfileForm profileForm); @ApiMethod(name = "createConference", path = "conference", httpMethod = HttpMethod.POST) Conference createConference(final User user, final ConferenceForm conferenceForm); @ApiMethod( name = "updateConference", path = "conference/{websafeConferenceKey}", httpMethod = HttpMethod.PUT ) Conference updateConference(final User user, final ConferenceForm conferenceForm,
                                       @Named("websafeConferenceKey")
                                       final String websafeConferenceKey); @ApiMethod( name = "getAnnouncement", path = "announcement", httpMethod = HttpMethod.GET ) Announcement getAnnouncement(); @ApiMethod( name = "getConference", path = "conference/{websafeConferenceKey}", httpMethod = HttpMethod.GET ) Conference getConference(
            @Named("websafeConferenceKey") final String websafeConferenceKey); @ApiMethod( name = "getConferencesToAttend", path = "getConferencesToAttend", httpMethod = HttpMethod.GET ) Collection<Conference> getConferencesToAttend(final User user); @ApiMethod( name = "queryConferences", path = "queryConferences", httpMethod = HttpMethod.POST ) List<Conference> queryConferences(ConferenceQueryForm conferenceQueryForm); @ApiMethod( name = "getConferencesCreated", path = "getConferencesCreated", httpMethod = HttpMethod.POST ) List<Conference> getConferencesCreated(final User user); @ApiMethod( name = "registerForConference", path = "conference/{websafeConferenceKey}/registration", httpMethod = HttpMethod.POST ) WrappedBoolean registerForConference(final User user,
                                         @Named("websafeConferenceKey")
                                         final String websafeConferenceKey); @ApiMethod( name = "unregisterFromConference", path = "conference/{websafeConferenceKey}/registration", httpMethod = HttpMethod.DELETE ) WrappedBoolean unregisterFromConference(final User user,
                                            @Named("websafeConferenceKey")
                                            final String websafeConferenceKey); }
ConferenceApi { @ApiMethod( name = "updateConference", path = "conference/{websafeConferenceKey}", httpMethod = HttpMethod.PUT ) public Conference updateConference(final User user, final ConferenceForm conferenceForm, @Named("websafeConferenceKey") final String websafeConferenceKey) throws UnauthorizedException, NotFoundException, ForbiddenException, ConflictException { if (user == null) { throw new UnauthorizedException("Authorization required"); } final String userId = getUserId(user); TxResult<Conference> result = ofy().transact(new Work<TxResult<Conference>>() { @Override public TxResult<Conference> run() { Key<Conference> conferenceKey = Key.create(websafeConferenceKey); Conference conference = ofy().load().key(conferenceKey).now(); if (conference == null) { return new TxResult<>( new NotFoundException("No Conference found with the key: " + websafeConferenceKey)); } Profile profile = ofy().load().key(Key.create(Profile.class, userId)).now(); if (profile == null || !conference.getOrganizerUserId().equals(userId)) { return new TxResult<>( new ForbiddenException("Only the owner can update the conference.")); } conference.updateWithConferenceForm(conferenceForm); ofy().save().entity(conference).now(); return new TxResult<>(conference); } }); return result.getResult(); }  @ApiMethod(name = "getProfile", path = "profile", httpMethod = HttpMethod.GET) Profile getProfile(final User user); @ApiMethod(name = "saveProfile", path = "profile", httpMethod = HttpMethod.POST) Profile saveProfile(final User user, final ProfileForm profileForm); @ApiMethod(name = "createConference", path = "conference", httpMethod = HttpMethod.POST) Conference createConference(final User user, final ConferenceForm conferenceForm); @ApiMethod( name = "updateConference", path = "conference/{websafeConferenceKey}", httpMethod = HttpMethod.PUT ) Conference updateConference(final User user, final ConferenceForm conferenceForm,
                                       @Named("websafeConferenceKey")
                                       final String websafeConferenceKey); @ApiMethod( name = "getAnnouncement", path = "announcement", httpMethod = HttpMethod.GET ) Announcement getAnnouncement(); @ApiMethod( name = "getConference", path = "conference/{websafeConferenceKey}", httpMethod = HttpMethod.GET ) Conference getConference(
            @Named("websafeConferenceKey") final String websafeConferenceKey); @ApiMethod( name = "getConferencesToAttend", path = "getConferencesToAttend", httpMethod = HttpMethod.GET ) Collection<Conference> getConferencesToAttend(final User user); @ApiMethod( name = "queryConferences", path = "queryConferences", httpMethod = HttpMethod.POST ) List<Conference> queryConferences(ConferenceQueryForm conferenceQueryForm); @ApiMethod( name = "getConferencesCreated", path = "getConferencesCreated", httpMethod = HttpMethod.POST ) List<Conference> getConferencesCreated(final User user); @ApiMethod( name = "registerForConference", path = "conference/{websafeConferenceKey}/registration", httpMethod = HttpMethod.POST ) WrappedBoolean registerForConference(final User user,
                                         @Named("websafeConferenceKey")
                                         final String websafeConferenceKey); @ApiMethod( name = "unregisterFromConference", path = "conference/{websafeConferenceKey}/registration", httpMethod = HttpMethod.DELETE ) WrappedBoolean unregisterFromConference(final User user,
                                            @Named("websafeConferenceKey")
                                            final String websafeConferenceKey);  }