Open Source & Free

10. Server Entities

Module 14: Creating a WhatsApp Clone Transcript we are finally back to the spring boot server we set up initially the code here is pretty simple as well the whatsapp application is the boilerplate main class of the spring boot project there isn’t much here and i’m only mentioning it for completeness security configuration is a bit more interesting although again it’s similar to what we saw in previous projects first we need to permit all requests to remove some http security limits we don’t need them here since this isn’t a web app similarly we need to disable csrf protection as it isn’t applicable for native apps finally we need to provide password encoder implementation we use this to encrypt the tokens in the database next let’s go into the entity objects i won’t go into what entities are as i discussed them a lot in the previous modules they are effectively an abstraction of the underlying data store the user entity represents the data we save for a chat contact i use a string unique id with a universal unique identifier which is more secure as i mentioned before it might make sense to use the phone as the id value though the username and tagline are also stored similarly to the client side code phone is listed as unique which makes sure the value is unique in the database when we send a verification code we store it in a database i could use a distributed caching system like redis or memcached but they’re an overkill for something as simple as this the date in which the user end entry was created is a standard database date this isn’t used at this time but it’s very similar to the code we have in the facebook clone to store media in fact it’s copied from there and we can refer to that for media storage slash upload the auth token is effectively a combination of username and password as such it’s hashed and as such only the user device knows that value i believe that’s how whatsapp works that’s why only one device can connect to a whatsapp account since the token is hashed when you need to retrieve an access token you need to effectively delete the last token and create a new one in order to set up a hash for the uninitiated a hash is an encrypted value that can only be generated but not retrieved so if my password is password and the hash is x y z j k l then i can get the value of the password from the hash but i can check that and i can check that password matches x y z jko but not vice versa hashes are also salted so they have 60 characters and length and the strong hashes are impossible to crack with standard tools the push key is the key used to send push messages to the client device this flag indicates whether a user is verified when we create a new user we initialize the id and creation date sensibly if this entity is loaded from the database these values will be overridden the dow methods create data access objects that we can send to the client we will make use of them later in the service code the user repository maps to the user object and exposes three finder methods we use find by phone during sign up and sending to detect the user with the given phone this method should be removed as it’s part of the copy and pasted media entity code we need to find the put the push by push key in order to remove or update expired push keys if the server returns an error we need to update that user dao is pretty much the content of the user class there isn’t much to discuss here with one major exception and that’s the json format annotation here we explicitly declare how we want the date object to translate to json when it’s sent to the client this is the standard json pattern and codename one in the client side knows how to parse this you

Codename One

11. Server DAO and Entities

Module 14: Creating a WhatsApp Clone Transcript let’s continue with the other entities i’ll skip media as it’s just a copy and paste of the facebook media class and partially implemented to boot chat group is an entity that traps the concept of a group in a sense it’s similar to the user entity but has no phone all of these properties the id name tagline creation date and even avatar are a part of a group however unlike a regular user a group is effectively created by a user a group also has two lists of group administrators and group members the chat group repository is empty as this is a feature we didn’t finish a chat message must be stored on servers for a while if your device isn’t connected at this moment for instance flight the server would need to keep the message until you are available again it can then be purged if we wish to be very secure we can encrypt the message based on client public key that way no one in the middle could peek into that message this should be easy enough to implement but i didn’t get around to to it it would mostly be client-side work here we store message messages so they can be fetched by the app like everything else we have a unique string id per message every message naturally has an author of that message but most importantly a destination which can be either a different user or group not both every message has a date timestamp for when it was sent the message has a text body always it can be now though if we have a media attachment to the message the ack flag indicates whether the client acknowledges acknowledged receiving the message this works great for one-to-one messages but the message sent to a group would probably need a more elaborate ack implementation the dao is again practically copied from the facebook app we can include the ids for the attachments as part of the message the chat message repository includes one fine method which helps us find messages that we didn’t acknowledge yet if a specific user has pending messages this finder is used to locate such messages and send them again the message dao entry represents the current message it maps pretty accurately to the entity object with that effectively done with the entity and dow layers there is still an error dial but it’s effectively identical to what we had in the facebook app and it’s totally trivial so i’ll skip that

Codename One

12. User Service

Module 14: Creating a WhatsApp Clone Transcript the next step is the services layer which implements the relatively simple business layer of this application we’ll start with the user service class it’s the main class in this package and handles pretty much the entire business logic of the app it’s a service bean this means it handles generic business logic for the application we need access to the repositories we just defined for users groups and messages the api keys service is the exact one i used in facebook with the exception of a different properties file name i’ll discuss that later it generally abstracts api keys and separates them from the source code the password encoder is used to encrypt and verify the token media repository and notification servers are identical to the stuff we had in the facebook clone app this method sends an sms message via the twillow web service if you recall we added the twillow sdk into the pom file in the first lesson this sdk makes sending an sms message very easy as you can see from the code the login api lets us validate a user and get the current data the server has for that user since there is no username slash password we need to use the token to authenticate first we need to find the user with the given phone assuming the user isn’t there will throw an exception since the auth is hashed as we discussed before we need to test the incoming auth via the matches method in encoder it verifies the hash matches the auth token this method creates a string of the given length which includes a random number for verification signup creates an entry for a specific user but doesn’t activate the account until it’s verified we first check if the phone number is already registered if so we need to fail otherwise we create the new user and initialize the value of the data and the verification code finally we send the activation code and return the user entity the verify method activates a user account if the verification mode is correct we mark the user as verified and return true we use set props both from the sign up and update methods there isn’t much here but if we add additional metadata this might become a bigger method like it is and the facebook clone update verifies the user’s token then updates the properties there isn’t much here these aren’t used at the moment but they are pretty much identical to what we have in the facebook clone and should be easy to integrate in a similar way this is part of the work to integrate support for the user typing feature right now the client app doesn’t send or render this event but it should be relatively simple to add when a user starts typing to a conversation we can invoke this method two user can be a user or a group is the user present it’s if the user is present it’s a user i’ll discuss the event code in the sockets when we reach the app socket class and this if this is a group we need to send the event to all the users within the group via the socket connection this method sends a message to its destination which can be a user or a group in order to send a message we first need to create a chat entity message entity so we can persist the message in case delivery failed this is the same code we saw in the typing event if the message is destined to a user the following block will occur otherwise we’ll go to the else block where the exact same code will execute in a loop over the members of the group we mark the destination of the message and convert it to json to adjacent string we invoke the send message api the send message uses the socket to send the message to the device if this failed and the device isn’t reachable we should send this message as text using push notification this method is identical to the other send message method but it uses a json string which is more convenient when a message comes in through the websocket the previous version is the one used when this is invoked from the web service which is what we use and this one works when a message is sent via the websocket this method converts a chat message entity to json so we can send it to the client object mapper can convert a pojo object to the equivalent json string this method sends json via the socket to the group or a user it allows us to propagate a message onward it works pretty much like the other methods in this class that send to a group or a user this method finds the user matching the given phone number this method is used by find registered user and find registered user by id it generalizes that translation of a user list to a single user dial value it implicitly fails for unverified users as well ack allows us to acknowledge that a message was received it just toggles the ack flag when a user connects via websocket this method is invoked it finds all the messages that weren’t act by the user and sends them to that user that way if a device lost connection it will get the content once it’s back online this method is invoked on launch to update the push key in the server so we can send push messages to the device with that user service is finished

Codename One

13. User Web Service

Module 14: Creating a WhatsApp Clone Transcript next we’ll jump to the web service package this is pretty much identical to the facebook clone app we create a web service mapping for the user services technically we could have broken this down to more web services but there is no real reason as we don’t have that much functionality here this is a thin wrapper around user service that contains no actual functionality it only translates the logic in that class to web calls if an exception is thrown in this class it’s implicitly translated to an error dao which is translated to an error json login and sign up are almost identical with the small exception that login expects an auth header value both are simple post methods that return the dao object as json body to the client verify and update return string values to indicate that they succeeded i added the implementation to get set avatar via url but this isn’t mapped to the client side this can probably be implemented in the same way as the facebook clone these methods return their result as an array of one element or as a zero length array since there is no way and json to return null like the business logic method does so we return a blank array list or a list with one element and that’s the end of the class the rest of the methods delegate directly to the user service bin

Codename One

14. Web Socket

Module 14: Creating a WhatsApp Clone Transcript next we’ll jump to the websocket package which is the last package first we need to configure the websocket we do this by implementing the websocket configurer and using the annotations on the class to indicate its purpose we define the socket so we can define the packet size to 8k we can set a larger size but generally keeping packets small is a good practice the app socket class is bound to the slash socket url in this line of code this is the thread used to process the websocket connections we can allocate more thread resources based on need let’s go to the app socket the app is an implementation of text websocket handler which handles text messages since all our messages are json this makes more sense i cache the currently active connections here this isn’t a good approach in the long term a better approach would be redis for this sort of caching but for an initial app this can work fine we need access to the user service so we can send message to a group or user the method sends this method sends json to a websocket based on the user token and returns true if it is successful we get the sessions for the given client if he has a web service session we create a text message with js the json we loop over all the websocket connections one by one if a connection is open we send the message there and return otherwise we add the socket to the remove queue we don’t want to remove in the middle of the loop to prevent an exception we remove all the defunct websockets from the queue in this line for all the classes we’re sending via socket in work we return force this method handles the incoming text packets we need to parse the json into a map if m has a type of pro it’s probably an init method if init messages allows us to add a websocket to our cache of connections so we can push a message back into the websocket when we need to send a server note notification otherwise we test if this is a user typing event in which case we need to send a typing message onward finally we send the message as json to the users in the group or to the specific user this invokes the code we saw in the user service class when combination when a connection is closed we loop over the existing list and purge it of the dead connection for simplicity we don’t support partial messages which shouldn’t be necessary for a small 8k messages with that the class is done

Codename One

Introduction

Module 15: Create a Netflix Clone Transcript welcome to the first lesson of creating a netflix clone with codename one there are a few things i’d like to talk about in this module but first i want to clarify that this module is relatively short as are trying to focus only on the new things so the netflix clone is less of a clone and more of a proof of concept the clone is much simpler in scope and functionality when compared to previous modules this is intentional i don’t want to repeat things that were better covered in the facebook or uber tutorials but i do want to cover new things i placed most of the focus on the nuances of the netflix ui but i also placed some focus on different approaches for working with spring boot i think these will prove valuable as we go back and look at the stuff we did in the previous modules but first let’s talk about the complexities of video platforms technically they aren’t very complex in fact they are remarkably simple for the most part the biggest problem faced by netflix is scale and that only matters when you reach netflix levels of scale videos and platforms like netflix are generally generated statically before the first request is made that effectively means that servers just serve ready-made files and don’t do complex runtime work there are great tools that pre-process video files such as ffmpeg these tools can be used as native libraries in the server or as command line tools most netflix clones just pre-generate all the video files in the various resolutions bitrate options then the work amounts to picking the right video url the video urls can be further scaled using pre-existing content delivery networks also known as cdns we specifically use cloudflare at codename one but any cdn would do we didn’t cover cdn hosting and literally all of the complexities in the server here we also don’t cover anything related to video processing that’s server logic that falls way outside the scope of a mobile tutorial furthermore a lot of this work can be done completely outside of the server as a separate tool that updates the url’s databases video hosting can be done as a separate microservice and mostly hidden from our main backend logic as a result the content of the application will be mostly hard coded this is important as there is an ip issue with distributing a clone of content which we don’t want to get into we also won’t implement the multi-user and authentication portions of the app we covered all of that rather well in the uber clone and there’s no point of going into this again once all this is removed the server is ridiculously trivial most of this applies to the client ui to we covered almost all of this before so the netflix clone is a rehash of many of those ideas with a new coat of paint the ui is trivial and includes only two forms both of which are only partially implemented there is no reason to go deeper as the their source application isn’t very complicated to begin with you can use the facebook clone as a reference to more elaborate ui once the css is in place implementing the missing functionality in a netflix clone becomes trivial but there’s one bigger mission i chose to use the native player native video playback is actually pretty great it handles everything we need in terms of ui for the video player the problem starts when that mode isn’t enough say we want more control over the behavior of playback code we can’t do much in that mode our control is very limited however native playback is pretty much a turnkey solution for video playback that’s why we picked it it’s a great tool for getting started lightweight is more error prone and powerful a good example is closed captions which we can implement manually in lightweight mode but literally placing by literally labeling and placing labels on top of the playing video that’s very powerful i will create a separate module that will cover lightweight video playback it should be easy to adapt the playback code to make use of that approach the final ui should include these two forms the latter will allow video playback notice that all the videos lead to a hard-coded video url of a spinning earth again due to ip issues thanks for watching i hope you’ll enjoy the rest of the course and will find it educational

Codename One

Server Part I

Module 15: Create a Netflix Clone Transcript in this lesson we’ll go over the basic server architecture and project lombok which we use in the server implementation we’ll start with some basic information about the server and then dive into quick lombok overview so first let’s talk about the database unlike previous modules where i chose to use mysql this time around i picked h2 for the database since it requires literally no setup i wouldn’t use it for production but since the whole complexity of mysql is covered in other modules this just isn’t necessary lombok is used to make the server code tiny and devoid of boilerplate this is pretty cool we don’t really need much in terms of web services if we had authentication and authorization there would have been more i could also implement paging support and more complex requests for various segments of the ui but those are pretty obvious if you’ve gone through gone over the feed section of the facebook loan the authentication aspect is the big missing piece here and i just didn’t want to get into it it’s usually one of the more painful aspects of building a server but since this is a mobile course i don’t think it’s very important to cover again as it was covered in previous modules let’s start with a palm file this is all pretty minimal first we have the standard declarations we use spring boot 2.2.2 which is the current version at this time this code is generated with the spring initializer which i described before this declares the h2 database instead of mysql and here we declare the use of lombok which i’ll get into shortly i also added a dependency on apache commons io which is pretty useful for small utility calls lombok is a set of tools that include ide plugins libraries and runtime tools they essentially try to modernize the java syntax using special annotations and it does a pretty great job at removing a lot of the common boilerplate from java 8 syntax their biggest claim to fame is removing the getter and setup boilerplate code from java in this module we’ll use lombok in the server it works for codename one app code but we won’t touch on that the main reason that is that the value of lombok diminishes thanks to properties so we don’t need it as much but if you need it you can see this tip about installing lombok for a codename one app let’s look at a few examples of using lombok notice that these examples are picked directly from the lombok developer guide here we have a class with three fields but only one of them is marked as non-null as such we can’t construct this object without the description field as we would have an invalid object so we have a private constructor that accepts this required field to create the actual instance of this class we use the of method which accepts the required description argument so you would be able to just write constructorexample.of description that’s pretty nice but it took five lines of code not including curly brace braces or spaces that’s a bit verbose that can be achieved with one annotation in lombok you just define the constructor and the method name that you wish to add as a static factory method and voila it works exactly like the code we saw before you can literally write constructed example.of description the other constructor is for subclasses it accepts all of the state members and also makes sure to fail if we try to violate the not null annotation notice it’s scoped as protected so it would be used only when deriving the class this can be implemented with a single line of code the all args constructor annotation does all of that implicitly it also has an optional access level property which defaults to public the inner class is pretty simple there isn’t too much to save here but still there’s a bit of vibrosity we can implement the blank constructor using the no args constructor notice that this example is a bit synthetic normally we would use this annotation in conjunction with other constructor options to indicate that we also want that option we already saw non-null being used before so this example should come as no surprise this annotation can also apply to method arguments etc the method can now assume the variable isn’t null notice that this usage is a bit stupid as the person.get name call will throw a null pointer exception anyway but if you invoke code that might propagate null it could be useful let’s move on to another cool feature of lombok notice that this code can be improved by using the java 8 try with resource syntax so this isn’t as beneficial but it’s still pretty cool this block can be written like this which is as terse as with the try with resources code and possibly even more terse lombok claims lombok’s claim to fame has always been getter and sitter elimination so this whole block of code can be replaced with this notice that this is still relatively verbose as we want a protected setter so let’s see something that’s even more terse first notice that the setter for age as package protected access while has package protected access while the getter is public also check out all the boilerplate code we have for equals and tostring this can be optimized with some of the newer objects class methods but not by much the boilerplate doesn’t end though we have a hashcode method too and a non-trivial inner class with a static creation method notice that this is the required arc constructor syntax we mentioned before that code that includes pages of data can be achieved using the at data annotation it includes getters setters tostring and hash code implicitly notice you can explicitly override the definition of a specific setter from data as we did for the case of age another common task is variable definition again there is a lot of boilerplate here so much that java defined a new val keyword keyword but this isn’t yet available for java 8 which is used by most of us lombok added two keywords vel and var va var var lets us define a variable that can change a mutable variable val defines an immutable variable effectively a final variable there are a lot of annotations we didn’t cover here at value is the immutable variant of at data all fields are made private and final by default and setters are not generated the class itself is also made final by default because immutability is not something that can be forced onto a subclass just like data the tostring equals and code methods are also generated each field gets a getter method and a constructor that covers every argument is also generated the builder annotation produces complex builder apis for your classes at builder lets you automatically produce the code required to have your class be instantiatable with code such as person.builder.name shy.build notice that this works nicely with the add value annotation to produce immutable classes with the builder pattern add sneaky throws can be used to sneakily throw checked exceptions without actually declaring this in your methods throws clause since checked exceptions are a feature of the java language and not of the java bytecode this is technically possible synchronized is a safer variant of the synchronized method modifier the synchronized keyword locks on this object which is problematic as it exposes the lock state externally this annotation implicitly creates a hidden dollar lock object and synchronizes on that object the next best alternative to a setter for an immutable property is to construct a clone of the object but with a new value for this one field a method to generate this clone is precisely what at with generates a with field name method which produces a clone except for the new value for the associated field you put at log in your clock in your class you you then will have a static final log field initialized as is the commonly described prescribed way for the logging framework you use which you can then use to write log statements notice that there are a lot of annotations you can use to describe explicit log system you want to use in the project you can let lombok generate a getter which will calculate a value once the first time the scatter is called and cached and cache it from then on this can be useful if calculating the value takes a lot of cpu or the value takes a lot of memory to use this feature create a private final variable initialize it with the expression that’s expensive to run and annotate your field with at getter lazy equals true the field will be hidden from the rest of your code and the expression will be evaluated no more than once when the getter is first called there are no magic marker values i.e even if the result of your expensive calculation is null the result is cached and your expensive calculation need not be thread safe as lombok takes care of locking most of this is taken directly from uh the projectlombok.org features slash all tutorial but there’s a lot more information there thanks for watching i hope you enjoy the rest of the course and find it educational

Codename One

Server Part II

Module 15: Create a Netflix Clone Transcript in the third part we’ll dive right into the model objects representing the server and ultimately the front end code if you’re unfamiliar with entities jpa uuid etc i suggest going back to the previous modules and refreshing your memory a bit as we’ll build a lot on top of that one way in which this will be different though is the usage of lombok which will make our code far more tears still the code here is mostly mock the real world netflix has a lot of code but most of it applies to algorithmic scheduling user management scaling etc all of these aren’t applicable here in this lesson our focus will be on entities and data transfer objects also known as dtos which are sometimes mixed with data access objects or dowels there is overlap between both of these concepts but what we have is generally dtos is they transfer data to the client they don’t just abstract the database layer writing an entity with lombok is much easier there are no getters setters constructors equals hash codes etc notice we still use jpa just like we used to so we have the jpa entity annotation and then the lombok annotations everything works as you would expect including the primary key definition etc notice i chose to go with uuid object as a primary key coupled with auto generation that’s a much simpler trick than the one i picked in previous modules we already talked about using strings for keys when we use a uuid object we get a long string that isn’t guessable in the database that means we can expose that primary key to the end user without worrying that he might use it to scan through details of other users as the string is pretty long and hard to guess as we saw we just need to use the uuid object type there are several other strategies for generating a uuid and jpa i chose the simplest one it might not be the best one but it is convenient so why doesn’t everyone use this approach turns out it’s much slower than using numeric auto increment values on a database column databases such as mysql are heavily optimized for auto increment fields and string based primary keys are just slower to insert some developers consider that a non-starter especially when looking at performance graphs which is scary performance really takes a dive for instant operations while it remains flat when using long auto increment fields personally i don’t think that’s a problem even for video app like this you wouldn’t insert too often and read operations are still pretty fast this might become an issue if you have a log or auditing table that might include multiple insert operations per second at that point you need to use a long for that for the primary key and make sure never to expose it externally the name and description fields correspond to these fields in the database this is the entire definition as the excesses are generated automatically we have three one-to-one media relations these include the three images for every content item specifically the hero image which is the big picture that appears on top of the application the show logo is displayed on top of the hero image it’s a separate image to support different device aspect ratio and layout and the icon is the image representing a show within the list finally we have the actual video files which we store in media objects as well we have multiple video files representing different quality levels of the video in real life we can have even more options such as different aspect ratios languages etc normally i would like this to be a map between quality and media but this is a bit challenging to represent correctly in jpa so i left this as a simple set for convenience we place the dto creation within the entity object this code is mostly just the construction but it’s uh it it’s there’s one block where we convert the media object if the dto in the dto it makes more sense to hold the media as a map instead of a list or set so we translate the video to a map i find the stream syntax a bit obtuse sometimes this is how it would look with a standard for loop essentially for each element we replace the content with a map where the key is the quality and the value as the media url once this is done we create a new dto object with the automatic constructor and return it and finally i also added a small helper method to make the code above a bit simpler so we won’t get a null pointer exception if the media is null this is the dto object we just created notice it’s super simple and mostly consistent consists of the lombok annotations the strings just map directly to the entity there’s nothing to say here for the media i chose to include the icons themselves i could have taken the approach of returning urls for the media which might have advantages in the future for now this is simpler but possibly not as efficient using a url would have had the advantage of caching the data locally for future refreshes using the actual icon means all the data is transferred with one request this is the map we created for the media items we already discussed this in the stream part before it maps between the video quality enum and the string url for the sake of completeness this is the video quality enum pretty simple but matches what we need right now the media entity is another standard lombok entity with the standard trimmings we use the same uuid primary key generation logic rest of the stuff is pretty standard notice that we store the modified time as an instant instead of date instant is a java 8 date time api class it represents a timestamp and is more convenient to use than date the media data is stored in blob storage in the database finally the url to the media and the video quality enum are stored as well that means we can have multiple instances of the same media object for various quality levels one thing i didn’t cover here is the repositories for the entity objects they’re all empty as we don’t need any finder methods for this specific demo so it’s all pretty trivial thanks for watching i hope you’ll enjoy the rest of the course and find it educational

Codename One

Server Part III

Module 15: Create a Netflix Clone Transcript in this final installment covering the server we’ll go over the service classes and the final entity representing the content creation the content collection is an oversimplification of the concept a site like netflix would probably generate this data dynamically based on user viewing preferences and complex heuristics i just hard coded an entity which was simpler the service class doesn’t do anything other than create the built-in data and implements the basic service call the content collection starts similarly to the other entities again it uses a uuid as an identifier at the moment will only have one content collection but in theory there can be as many as there are users the lead content represents the show that appears on the top of the ui in this case it’s the stranger things header these represents the rows of content below that they contain the popular recommended and personal list of shows next we have the method that returns the dto since all lists are effectively lots of content we use the same method to convert everything again we make use of java 8 streams to get all the dtos from the list by invoking the getdto method on every element now we’re getting to the web service code we’re using the request mapping attribute to specify that this is a web service on the video path the rest controller attribute designates this as a simple json api so a lot of common sense defaults follow for instance response in the body etc notice the all args constructor this means the class has a constructor that accepts all arguments no default constructor this is important notice the final field for the video service it’s passed via the constructor notice that the video service doesn’t have the autowad annotation we usually place for beans in spring boot this is called constructor injection and it has a few advantages normally it’s a bit too verbose as we need to maintain a constructor with all the injected beans but in this case lombok makes it seamless in other words lombok and spring boot inject the video service being pretty seamlessly for us we only have one api in the server it returns the content json a more real world api would also have authentication identity apis and maybe a state querying submitting api for instance view positions statistics etc but those are relatively simple and we were covered by other modules here so i’m skipping them for now the service class is similar to the rest api class i used the required rx constructor which is effectively the same as all arcs constructed in this case it creates a constructor for all the required args specifically all the final fields this again works for creating constructor based injection this class is also transactional as it accesses the database we need access to all the repositories to create the entities this is a simple utility method to read bytes from a stream in the class path notice the usage of the add cleanup annotation from lombok and apaches i o util api post construct is a feature of spring boot that lets us invoke a method after the container was constructed this is effectively a constructor for the entire application here we can initialize the app with default data if necessary notice i throw an exception here since i assume this method won’t fail it’s the first launch so it’s core that it succeeds it’s pretty easy to detect the first launch if the database is empty the count method on the repository will return 0 elements in that case we need to initialize the database in this large method i set up the initial data in the database i prefer doing it through code rather than manually populating the database and providing a pre-filled one as it’s easier to do when working in a fluid environment where you constantly wipe the database in this case i just take the hard-coded images and get their byte array data i then create media objects for all the thumbnail entities the rest is pretty self-explanatory eventually all the videos are created and all the media entities are added notice the urls are to an external video sample site i was able to find online this is consistent with the way a video site would work your actual content would be hosted on a cdn for performance also notice i didn’t get into the whole process of encryption encryption and complex drm streaming that’s a whole different level of complexity finally the last bit of content is added to the content repository and everything is saved to the database this is the entire server api this returns a json structure used in the client we could stream this in smaller blocks but that was already covered in the facebook demo so i skipped it here thanks for watching i hope you’ll enjoy the rest of this course and find it educational you

Codename One

Client Model

Module 15: Create a Netflix Clone Transcript we’re finally at the client side which is also pretty simple this time we’ll start with the model and move to the ui rather than the other direction which is what we normally cover since we did the server work first this fits pretty directly after that which makes it easier to start with that portion this model is pretty much proper property business objects to match the lombok objects in the server side while some of the terse aspects of lombok are missed properties make up for it by being far more powerful overall we start with the server class which abstracts our connection to the server since we have one method in the server web service this is continued here we fetch the content from the server synchronically using the rest api this api translates to the the response to json almost seamlessly we say that the response should be in the form of the content collection class this means the json will be parsed into that class which will will examine next the content collection is a standard property business object it maps almost directly to the class with the same name on the server side the main difference is that the properties use our object syntax these match their definition in the server side and include the exact same data the entire class is pretty standard property business object finally the last properties object we have is the content object which is the same as the one in the server the final piece is the enum that matches the one in the server with that our communication layer is complete and we can move on to the ui elements thanks for watching i hope you’ll enjoy the rest of the course and find it educational

Codename One