The first thing we'll do is add functionality to
create conferences. Here's the Create a Conference page in the
UI for the web app. Where you see enter the
name, the city, the description. If we were to go
ahead and enter these values now the conference wouldn't
get created because this page sends a call to the
Create Conference function. And it's going to be your job to
implement that function but it's not implemented yet. We're going
to create conference entities in such a way that each
one has a parent and that parent is a profile of
the user who created it. The reason for doing this is
it makes it very easy to quickly find all the conferences
that are particularly user created. For example, you'll be able to
very quickly find all the conferences that you created. Now let's
take a look at the code. So here I have the
class conference. And you'll see that it has this @Parent property.
Using objectify, the way you create an entity with a parent is that you use the
annotation @Parent to annotate one property as the
parent. So in this case, we've annotated profileKey
as the property that's going to hold the
parent, so profileKey is going to be the
key of the profile entity that's the parent
of this conference. Now when you created profile
entities, you specified user ID as a property
to use as the ID. For conference entities, we
don't have any specific thing that we can use
as the key that uniquely identifies the conference. So
we're going to let App Engine allocate the
key for off. However, using objectify, you still need
to identify one property as the property to hold
the ID. So in this case, we're going to use
the cunningly named property ID and mark it
as @ID. So this is the property that uses
the ID for the key. If you remember for
profile entities the ID property was a string and
here for conference it's a long. That's long with
an L, there's three kinds of types that your
property annotated by @Id can be. It can be
a long, capital L long, little L or string
capital S. So one more annotation that we didn't use
in the profile class is @Index. You'll notice that some
of the fields in the conference have this @index annotation
and what that means is we want to index property.
And the reason we do this is that later on
we're going to be searching on that property. We're going to be
searching on the name, for example, we won't be searching
on the description. So what I'm going to do is just
quickly scroll through this code and explain what
it does. We already talked about the @Parent. The
profile key is the key of the parent
of this entity, topics, every conference can optionally have
one or more topics that it's about. For
example, your conference might be about medical innovations or
web technologies or maybe it's about both web
technologies and programming languages. So, this is a multi-valued
property, it's a list of strings. We have the city,
we have the start date of the conference, the end
date. We're also going to keep track of the month
so that we can issue queries such as show me
all the conferences in December. So max attendees is the
maximum capacity of the conference. We're also going to have the
seats available, which keeps track of how many seats are
still available. Obviously at the very beginning, the seats available
is the same as the capacity but as
people sign up to attend the conference. The seats
available is going to go down. For entities in
general, the default constructor is private and here we
have the constructor for the conference and what this
constructor does is it sets the Id to then
pass to Id and it also figures out the
profile key by calling Key.create on Profile. It also
figures out the profileKey of the parent profile and sets it and then it
just sets the organizerUserId and then it
calls this updateWithConferenceForm to set the other
values in the conference. Here we've got
some getter method. We get the profileKey
here. This getWebsafeKey just basically returns a
string of the conference's key. So that
it can be passed around through forms and
through the browser, if necessary. And this one
here, the getOrganizerDisplayName. The display name's calculated on
the fly when we need it. Just in
case the organizer updates their display name. Okay.
Just some more getters, getTopics, we get a
defensive copy of the list, getCity, you need
to get the start date, the end date, getMonth
and so on. The updateWithConferenceForm method takes value
send in the conference form and update the conference
entity with those values. For example, here you
see how we calculate which month conference is occurring
in and set the value of the month
field. There's a couple more methods that we'll be
using later, there's bookSeats so that when the user
registers to attend the conference, we need to keep
track of how many seats are available. So we
decrease the number of seats available by the number booked.
And then give back seats if someone registers for
a conference and changes their mind and unregisters then we
need to reset the seats available. And then this
toString is just a function so that you can get
a string of the entire conference. Now, we actually
wrote all the code for conference.java for you. I want
you to make sure that you take a look and read it and understand it. Now let's
take a quick look at the ConferenceForm class. Again,
we've written this class for you. This class defines
the input parameters to the createConference function just like
ProfileForm defined the input parameters to the function saveProfile.
So basically contains the fields that are going to be
passed in the form or whatever input method to
the create conference function. And if you're
getting worried that we wrote too much
for you, don't worry, you're going to
be writing the create conference method yourself