SlideShare a Scribd company logo
Creating a Facebook Clone - Part XXXVIII
Media
✦One media file per post
✦Most of the work is already done
✦Important: mySQL doesn’t support large blobs by
default. Had to add:

--max_allowed_packet=256M
© Codename One 2017 all rights reserved
@ManyToOne
private User user;
private long date;
@Field
private String title;
@Field
private String content;
private String visibility;
private String styling;
@OneToMany
@OrderBy("date ASC")
private Set<Comment> comments;
@ManyToMany
private Set<Media> attachments;
@ManyToMany
private Set<User> likes;
public Post() {
Post (Entity)
public Post() {
id = UUID.randomUUID().toString();
}
public PostDAO getDAO() {
List<CommentDAO> commentsDAO = null;
if(comments != null && comments.size() > 0) {
commentsDAO = new ArrayList<>();
for(Comment c : comments) {
commentsDAO.add(c.getDAO());
}
}
Map<String, String> mediaIds = null;
if(attachments != null && attachments.size() > 0) {
mediaIds = new LinkedHashMap<>();
for(Media c : attachments) {
mediaIds.put(c.getId(), c.getMimeType());
}
}
return new PostDAO(id, user.getDAO(), date, title, content,
visibility, styling,
commentsDAO, User.toUserDAOList(likes), mediaIds);
}
Post (Entity)
public Post() {
id = UUID.randomUUID().toString();
}
public PostDAO getDAO() {
List<CommentDAO> commentsDAO = null;
if(comments != null && comments.size() > 0) {
commentsDAO = new ArrayList<>();
for(Comment c : comments) {
commentsDAO.add(c.getDAO());
}
}
Map<String, String> mediaIds = null;
if(attachments != null && attachments.size() > 0) {
mediaIds = new LinkedHashMap<>();
for(Media c : attachments) {
mediaIds.put(c.getId(), c.getMimeType());
}
}
return new PostDAO(id, user.getDAO(), date, title, content,
visibility, styling,
commentsDAO, User.toUserDAOList(likes), mediaIds);
}
Post (Entity)
public Post() {
id = UUID.randomUUID().toString();
}
public PostDAO getDAO() {
List<CommentDAO> commentsDAO = null;
if(comments != null && comments.size() > 0) {
commentsDAO = new ArrayList<>();
for(Comment c : comments) {
commentsDAO.add(c.getDAO());
}
}
Map<String, String> mediaIds = null;
if(attachments != null && attachments.size() > 0) {
mediaIds = new LinkedHashMap<>();
for(Media c : attachments) {
mediaIds.put(c.getId(), c.getMimeType());
}
}
return new PostDAO(id, user.getDAO(), date, title, content,
visibility, styling,
commentsDAO, User.toUserDAOList(likes), mediaIds);
}
Post (Entity)
public class PostDAO {
private String id;
private UserDAO user;
private long date;
private String title;
private String content;
private String visibility;
private String styling;
private List<CommentDAO> comments;
private List<UserDAO> likes;
private Map<String, String> attachments;
public PostDAO() {
}
public PostDAO(String id, UserDAO user, long date, String title,
String content, String visibility, String styling,
PostDAO
private List<UserDAO> likes;
private Map<String, String> attachments;
public PostDAO() {
}
public PostDAO(String id, UserDAO user, long date, String title,
String content, String visibility, String styling,
List<CommentDAO> comments, List<UserDAO> likes,
Map<String, String> attachments) {
this.id = id;
this.user = user;
this.date = date;
this.title = title;
this.content = content;
this.visibility = visibility;
this.styling = styling;
this.comments = comments;
this.likes = likes;
this.attachments = attachments;
}
PostDAO
@Service
public class PostService {
private static final int DAY = 24 * 60 * 60000;
@Autowired
private UserRepository users;
@Autowired
private PostRepository posts;
@Autowired
private NewsfeedRepository news;
@Autowired
private CommentRepository comments;
@Autowired
private MediaRepository medias;
@Autowired
PostService
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
p.setDate(System.currentTimeMillis());
p.setStyling(pd.getStyling());
p.setTitle(pd.getTitle());
p.setUser(u);
p.setVisibility(pd.getVisibility());
if(pd.getAttachments() != null && !pd.getAttachments().isEmpty()) {
Set<Media> s = new HashSet<>();
for(String id : pd.getAttachments().keySet()) {
s.add(medias.findById(id).get());
}
p.setAttachments(s);
}
posts.save(p);
addPostToNewsfeed(u, p);
if(u.getFriends() != null) {
for(User c : u.getFriends()) {
PostService
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
p.setDate(System.currentTimeMillis());
p.setStyling(pd.getStyling());
p.setTitle(pd.getTitle());
p.setUser(u);
p.setVisibility(pd.getVisibility());
if(pd.getAttachments() != null && !pd.getAttachments().isEmpty()) {
Set<Media> s = new HashSet<>();
for(String id : pd.getAttachments().keySet()) {
s.add(medias.findById(id).get());
}
p.setAttachments(s);
}
posts.save(p);
addPostToNewsfeed(u, p);
if(u.getFriends() != null) {
for(User c : u.getFriends()) {
PostService
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
p.setDate(System.currentTimeMillis());
p.setStyling(pd.getStyling());
p.setTitle(pd.getTitle());
p.setUser(u);
p.setVisibility(pd.getVisibility());
if(pd.getAttachments() != null && !pd.getAttachments().isEmpty()) {
Set<Media> s = new HashSet<>();
for(String id : pd.getAttachments().keySet()) {
s.add(medias.findById(id).get());
}
p.setAttachments(s);
}
posts.save(p);
addPostToNewsfeed(u, p);
if(u.getFriends() != null) {
for(User c : u.getFriends()) {
PostService
@RequestMapping(value="/public/{id:.+}", method=RequestMethod.GET)
public ResponseEntity<byte[]> getPublic(@PathVariable("id") String id)
throws PermissionException {
MediaDAO av = medias.getPublicMedia(id);
if(av != null) {
return ResponseEntity.ok().
contentType(MediaType.valueOf(av.getMimeType())).
contentLength(av.getData().length).
body(av.getData());
}
return ResponseEntity.notFound().build();
}
@RequestMapping(value="/all/{id:.+}", method=RequestMethod.GET)
public ResponseEntity<byte[]> getAll(
@RequestParam(name="auth", required=true) String auth,
@PathVariable("id") String id)
throws PermissionException {
MediaDAO av = medias.getMedia(auth, id);
if(av != null) {
return ResponseEntity.ok().
contentType(MediaType.valueOf(av.getMimeType())).
contentLength(av.getData().length).
body(av.getData());
MediaService
@RequestMapping(value="/public/{id:.+}", method=RequestMethod.GET)
public ResponseEntity<byte[]> getPublic(@PathVariable("id") String id)
throws PermissionException {
MediaDAO av = medias.getPublicMedia(id);
if(av != null) {
return ResponseEntity.ok().
contentType(MediaType.valueOf(av.getMimeType())).
contentLength(av.getData().length).
body(av.getData());
}
return ResponseEntity.notFound().build();
}
@RequestMapping(value="/all/{id:.+}", method=RequestMethod.GET)
public ResponseEntity<byte[]> getAll(
@RequestParam(name="auth", required=true) String auth,
@PathVariable("id") String id)
throws PermissionException {
MediaDAO av = medias.getMedia(auth, id);
if(av != null) {
return ResponseEntity.ok().
contentType(MediaType.valueOf(av.getMimeType())).
contentLength(av.getData().length).
body(av.getData());
MediaService
@RequestMapping(value="/public/{id:.+}", method=RequestMethod.GET)
public ResponseEntity<byte[]> getPublic(@PathVariable("id") String id)
throws PermissionException {
MediaDAO av = medias.getPublicMedia(id);
if(av != null) {
return ResponseEntity.ok().
contentType(MediaType.valueOf(av.getMimeType())).
contentLength(av.getData().length).
body(av.getData());
}
return ResponseEntity.notFound().build();
}
@RequestMapping(value="/all/{id:.+}", method=RequestMethod.GET)
public ResponseEntity<byte[]> getAll(
@RequestParam(name="auth", required=true) String auth,
@PathVariable("id") String id)
throws PermissionException {
MediaDAO av = medias.getMedia(auth, id);
if(av != null) {
return ResponseEntity.ok().
contentType(MediaType.valueOf(av.getMimeType())).
contentLength(av.getData().length).
body(av.getData());
MediaService

More Related Content

Similar to Creating a Facebook Clone - Part XXXVIII.pdf

Creating a Facebook Clone - Part XXVI - Transcript.pdf
Creating a Facebook Clone - Part XXVI - Transcript.pdfCreating a Facebook Clone - Part XXVI - Transcript.pdf
Creating a Facebook Clone - Part XXVI - Transcript.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XL.pdf
Creating a Facebook Clone - Part XL.pdfCreating a Facebook Clone - Part XL.pdf
Creating a Facebook Clone - Part XL.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XX - Transcript.pdf
Creating a Facebook Clone - Part XX - Transcript.pdfCreating a Facebook Clone - Part XX - Transcript.pdf
Creating a Facebook Clone - Part XX - Transcript.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdf
ShaiAlmog1
 
Di web tech mail (no subject)
Di web tech mail   (no subject)Di web tech mail   (no subject)
Di web tech mail (no subject)
shubhamvcs
 
PDFDemo
PDFDemoPDFDemo
PDFDemo
shubraj1987
 
greenDAO
greenDAOgreenDAO
greenDAO
Mu Chun Wang
 
Creating a Facebook Clone - Part XI.pdf
Creating a Facebook Clone - Part XI.pdfCreating a Facebook Clone - Part XI.pdf
Creating a Facebook Clone - Part XI.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XVIII - Transcript.pdf
Creating a Facebook Clone - Part XVIII - Transcript.pdfCreating a Facebook Clone - Part XVIII - Transcript.pdf
Creating a Facebook Clone - Part XVIII - Transcript.pdf
ShaiAlmog1
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
Oliver Gierke
 
Creating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdfCreating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdf
ShaiAlmog1
 
Presentation Android Architecture Components
Presentation Android Architecture ComponentsPresentation Android Architecture Components
Presentation Android Architecture Components
Attract Group
 
Better Bullshit Driven Development [SeleniumCamp 2017]
Better Bullshit Driven Development [SeleniumCamp 2017]Better Bullshit Driven Development [SeleniumCamp 2017]
Better Bullshit Driven Development [SeleniumCamp 2017]
automician
 
Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
Audrey Lim
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
ShaiAlmog1
 
Dev Day Andreas Roth.pdf
Dev Day Andreas Roth.pdfDev Day Andreas Roth.pdf
Dev Day Andreas Roth.pdf
CarolinaMatthies
 
Android dev toolbox
Android dev toolboxAndroid dev toolbox
Android dev toolbox
Shem Magnezi
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
ShaiAlmog1
 

Similar to Creating a Facebook Clone - Part XXXVIII.pdf (20)

Creating a Facebook Clone - Part XXVI - Transcript.pdf
Creating a Facebook Clone - Part XXVI - Transcript.pdfCreating a Facebook Clone - Part XXVI - Transcript.pdf
Creating a Facebook Clone - Part XXVI - Transcript.pdf
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
 
Creating a Facebook Clone - Part XL.pdf
Creating a Facebook Clone - Part XL.pdfCreating a Facebook Clone - Part XL.pdf
Creating a Facebook Clone - Part XL.pdf
 
Creating a Facebook Clone - Part XX - Transcript.pdf
Creating a Facebook Clone - Part XX - Transcript.pdfCreating a Facebook Clone - Part XX - Transcript.pdf
Creating a Facebook Clone - Part XX - Transcript.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdf
 
Di web tech mail (no subject)
Di web tech mail   (no subject)Di web tech mail   (no subject)
Di web tech mail (no subject)
 
PDFDemo
PDFDemoPDFDemo
PDFDemo
 
greenDAO
greenDAOgreenDAO
greenDAO
 
Creating a Facebook Clone - Part XI.pdf
Creating a Facebook Clone - Part XI.pdfCreating a Facebook Clone - Part XI.pdf
Creating a Facebook Clone - Part XI.pdf
 
Creating a Facebook Clone - Part XVIII - Transcript.pdf
Creating a Facebook Clone - Part XVIII - Transcript.pdfCreating a Facebook Clone - Part XVIII - Transcript.pdf
Creating a Facebook Clone - Part XVIII - Transcript.pdf
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
Creating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdfCreating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdf
 
Presentation Android Architecture Components
Presentation Android Architecture ComponentsPresentation Android Architecture Components
Presentation Android Architecture Components
 
Better Bullshit Driven Development [SeleniumCamp 2017]
Better Bullshit Driven Development [SeleniumCamp 2017]Better Bullshit Driven Development [SeleniumCamp 2017]
Better Bullshit Driven Development [SeleniumCamp 2017]
 
Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Dev Day Andreas Roth.pdf
Dev Day Andreas Roth.pdfDev Day Andreas Roth.pdf
Dev Day Andreas Roth.pdf
 
Android dev toolbox
Android dev toolboxAndroid dev toolbox
Android dev toolbox
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
ShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdfCreating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part III - Transcript.pdf
Creating a Whatsapp Clone - Part III - Transcript.pdfCreating a Whatsapp Clone - Part III - Transcript.pdf
Creating a Whatsapp Clone - Part III - Transcript.pdf
ShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 
Creating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdf
 
Creating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdfCreating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdf
 
Creating a Whatsapp Clone - Part III - Transcript.pdf
Creating a Whatsapp Clone - Part III - Transcript.pdfCreating a Whatsapp Clone - Part III - Transcript.pdf
Creating a Whatsapp Clone - Part III - Transcript.pdf
 

Recently uploaded

"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 

Recently uploaded (20)

"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
 

Creating a Facebook Clone - Part XXXVIII.pdf

  • 1. Creating a Facebook Clone - Part XXXVIII
  • 2. Media ✦One media file per post ✦Most of the work is already done ✦Important: mySQL doesn’t support large blobs by default. Had to add:
 --max_allowed_packet=256M © Codename One 2017 all rights reserved
  • 3. @ManyToOne private User user; private long date; @Field private String title; @Field private String content; private String visibility; private String styling; @OneToMany @OrderBy("date ASC") private Set<Comment> comments; @ManyToMany private Set<Media> attachments; @ManyToMany private Set<User> likes; public Post() { Post (Entity)
  • 4. public Post() { id = UUID.randomUUID().toString(); } public PostDAO getDAO() { List<CommentDAO> commentsDAO = null; if(comments != null && comments.size() > 0) { commentsDAO = new ArrayList<>(); for(Comment c : comments) { commentsDAO.add(c.getDAO()); } } Map<String, String> mediaIds = null; if(attachments != null && attachments.size() > 0) { mediaIds = new LinkedHashMap<>(); for(Media c : attachments) { mediaIds.put(c.getId(), c.getMimeType()); } } return new PostDAO(id, user.getDAO(), date, title, content, visibility, styling, commentsDAO, User.toUserDAOList(likes), mediaIds); } Post (Entity)
  • 5. public Post() { id = UUID.randomUUID().toString(); } public PostDAO getDAO() { List<CommentDAO> commentsDAO = null; if(comments != null && comments.size() > 0) { commentsDAO = new ArrayList<>(); for(Comment c : comments) { commentsDAO.add(c.getDAO()); } } Map<String, String> mediaIds = null; if(attachments != null && attachments.size() > 0) { mediaIds = new LinkedHashMap<>(); for(Media c : attachments) { mediaIds.put(c.getId(), c.getMimeType()); } } return new PostDAO(id, user.getDAO(), date, title, content, visibility, styling, commentsDAO, User.toUserDAOList(likes), mediaIds); } Post (Entity)
  • 6. public Post() { id = UUID.randomUUID().toString(); } public PostDAO getDAO() { List<CommentDAO> commentsDAO = null; if(comments != null && comments.size() > 0) { commentsDAO = new ArrayList<>(); for(Comment c : comments) { commentsDAO.add(c.getDAO()); } } Map<String, String> mediaIds = null; if(attachments != null && attachments.size() > 0) { mediaIds = new LinkedHashMap<>(); for(Media c : attachments) { mediaIds.put(c.getId(), c.getMimeType()); } } return new PostDAO(id, user.getDAO(), date, title, content, visibility, styling, commentsDAO, User.toUserDAOList(likes), mediaIds); } Post (Entity)
  • 7. public class PostDAO { private String id; private UserDAO user; private long date; private String title; private String content; private String visibility; private String styling; private List<CommentDAO> comments; private List<UserDAO> likes; private Map<String, String> attachments; public PostDAO() { } public PostDAO(String id, UserDAO user, long date, String title, String content, String visibility, String styling, PostDAO
  • 8. private List<UserDAO> likes; private Map<String, String> attachments; public PostDAO() { } public PostDAO(String id, UserDAO user, long date, String title, String content, String visibility, String styling, List<CommentDAO> comments, List<UserDAO> likes, Map<String, String> attachments) { this.id = id; this.user = user; this.date = date; this.title = title; this.content = content; this.visibility = visibility; this.styling = styling; this.comments = comments; this.likes = likes; this.attachments = attachments; } PostDAO
  • 9. @Service public class PostService { private static final int DAY = 24 * 60 * 60000; @Autowired private UserRepository users; @Autowired private PostRepository posts; @Autowired private NewsfeedRepository news; @Autowired private CommentRepository comments; @Autowired private MediaRepository medias; @Autowired PostService
  • 10. } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); p.setDate(System.currentTimeMillis()); p.setStyling(pd.getStyling()); p.setTitle(pd.getTitle()); p.setUser(u); p.setVisibility(pd.getVisibility()); if(pd.getAttachments() != null && !pd.getAttachments().isEmpty()) { Set<Media> s = new HashSet<>(); for(String id : pd.getAttachments().keySet()) { s.add(medias.findById(id).get()); } p.setAttachments(s); } posts.save(p); addPostToNewsfeed(u, p); if(u.getFriends() != null) { for(User c : u.getFriends()) { PostService
  • 11. } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); p.setDate(System.currentTimeMillis()); p.setStyling(pd.getStyling()); p.setTitle(pd.getTitle()); p.setUser(u); p.setVisibility(pd.getVisibility()); if(pd.getAttachments() != null && !pd.getAttachments().isEmpty()) { Set<Media> s = new HashSet<>(); for(String id : pd.getAttachments().keySet()) { s.add(medias.findById(id).get()); } p.setAttachments(s); } posts.save(p); addPostToNewsfeed(u, p); if(u.getFriends() != null) { for(User c : u.getFriends()) { PostService
  • 12. } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); p.setDate(System.currentTimeMillis()); p.setStyling(pd.getStyling()); p.setTitle(pd.getTitle()); p.setUser(u); p.setVisibility(pd.getVisibility()); if(pd.getAttachments() != null && !pd.getAttachments().isEmpty()) { Set<Media> s = new HashSet<>(); for(String id : pd.getAttachments().keySet()) { s.add(medias.findById(id).get()); } p.setAttachments(s); } posts.save(p); addPostToNewsfeed(u, p); if(u.getFriends() != null) { for(User c : u.getFriends()) { PostService
  • 13. @RequestMapping(value="/public/{id:.+}", method=RequestMethod.GET) public ResponseEntity<byte[]> getPublic(@PathVariable("id") String id) throws PermissionException { MediaDAO av = medias.getPublicMedia(id); if(av != null) { return ResponseEntity.ok(). contentType(MediaType.valueOf(av.getMimeType())). contentLength(av.getData().length). body(av.getData()); } return ResponseEntity.notFound().build(); } @RequestMapping(value="/all/{id:.+}", method=RequestMethod.GET) public ResponseEntity<byte[]> getAll( @RequestParam(name="auth", required=true) String auth, @PathVariable("id") String id) throws PermissionException { MediaDAO av = medias.getMedia(auth, id); if(av != null) { return ResponseEntity.ok(). contentType(MediaType.valueOf(av.getMimeType())). contentLength(av.getData().length). body(av.getData()); MediaService
  • 14. @RequestMapping(value="/public/{id:.+}", method=RequestMethod.GET) public ResponseEntity<byte[]> getPublic(@PathVariable("id") String id) throws PermissionException { MediaDAO av = medias.getPublicMedia(id); if(av != null) { return ResponseEntity.ok(). contentType(MediaType.valueOf(av.getMimeType())). contentLength(av.getData().length). body(av.getData()); } return ResponseEntity.notFound().build(); } @RequestMapping(value="/all/{id:.+}", method=RequestMethod.GET) public ResponseEntity<byte[]> getAll( @RequestParam(name="auth", required=true) String auth, @PathVariable("id") String id) throws PermissionException { MediaDAO av = medias.getMedia(auth, id); if(av != null) { return ResponseEntity.ok(). contentType(MediaType.valueOf(av.getMimeType())). contentLength(av.getData().length). body(av.getData()); MediaService
  • 15. @RequestMapping(value="/public/{id:.+}", method=RequestMethod.GET) public ResponseEntity<byte[]> getPublic(@PathVariable("id") String id) throws PermissionException { MediaDAO av = medias.getPublicMedia(id); if(av != null) { return ResponseEntity.ok(). contentType(MediaType.valueOf(av.getMimeType())). contentLength(av.getData().length). body(av.getData()); } return ResponseEntity.notFound().build(); } @RequestMapping(value="/all/{id:.+}", method=RequestMethod.GET) public ResponseEntity<byte[]> getAll( @RequestParam(name="auth", required=true) String auth, @PathVariable("id") String id) throws PermissionException { MediaDAO av = medias.getMedia(auth, id); if(av != null) { return ResponseEntity.ok(). contentType(MediaType.valueOf(av.getMimeType())). contentLength(av.getData().length). body(av.getData()); MediaService