1. SOCIAL NETWORKING SITE
22102D020145 1 OF 101
Project – 2: Design a social website with the following features.
Build Profile - Members allow to build their profiles.
Upload content - The Social Networking Sites allow members to upload text messages,
photographs, audio and video files. All posts are arranged in descending order with the last post
coming first.
Build conversations - Content posted by members can be browsed and commented upon by all
members who form part of the community. Content can also be tagged from third party sites on
subjects that interest the group.
INTRODUCTION:
Designing a Dynamic Social Website
In the digital age, social networking sites have become an integral part of our lives, connecting
people across the globe and facilitating the exchange of ideas, interests, and experiences. In this
project, we aim to design a cutting-edge social website that brings people together, empowers them
to build meaningful connections, and fosters engaging conversations within a vibrant community.
Our social website will provide a user-friendly platform where members can create and personalize
their profiles, showcasing their interests, achievements, and personality. By allowing members to
build their profiles, we aim to create a space that reflects their individuality and enables them to
connect with like-minded individuals.
One of the key features of our social website is the ability for members to upload various forms of
content, including text messages, photographs, audio files, and videos. By providing a diverse range
of content formats, we seek to cater to different preferences and enable members to express
themselves creatively. All uploaded content will be organized in a chronological order, with the
most recent posts appearing at the top, allowing users to stay updated and engaged with the latest
contributions from the community.
Building conversations lies at the heart of our social website. Members will have the opportunity to
browse through the content posted by others and participate in dynamic discussions by leaving
comments and feedback. This interactive approach encourages active engagement and facilitates the
exchange of diverse perspectives within the community. Furthermore, we also facilitate the tagging
of content from third-party sites, allowing members to explore and share topics of interest beyond
the platform, enhancing the richness of discussions and broadening the horizons of the community.
Our team of experienced designers and developers are dedicated to creating an intuitive and visually
appealing interface, ensuring seamless navigation and an enjoyable user experience. We prioritize
user privacy and data security, implementing robust measures to protect personal information and
guarantee a safe and trusted online environment.
2. SOCIAL NETWORKING SITE
22102D020145 2 OF 101
Through this project, we strive to cultivate a vibrant online community where members can
connect, express themselves, and build meaningful relationships. By combining the features of
profile building, content uploading, and interactive conversations, our social website aims to
provide a platform that fosters creativity, collaboration, and a sense of belonging. Join us on this
exciting journey as we shape the future of social networking together.
Features:
Build Profile– Members will be able to create their own profiles, which will include their
name, age, location, interests, and other personal information.
Upload Content– Members will be able to upload text messages, photographs, audio and
video files. All posts will be arranged in descending order with the last post coming first.
Build Conversations–Content posted by members can be browsed and commented upon by
all members who form part of the community. Content can also be tagged from third party
sites on subjects that interest the group.
This project will focus on the design of a social website that allows users to build their profiles,
upload content, and build conversations with other users. The website will be designed to be user-
friendly and easy to navigate. It will also be designed to be secure and private, so that users can feel
comfortable sharing their personal information and content.
The following are some of the specific features that will be included in the social website:
Profile Builder– Users will be able to create their own profiles, which will include their
name, age, location, interests, and other personal information.
Content Uploader– Users will be able to upload text messages, photographs, audio and
video files. All posts will be arranged in descending order with the last post coming first.
Conversation Builder–Content posted by members can be browsed and commented upon
by all members who form part of the community. Content can also be tagged from third
party sites on subjects that interest the group.
The social website will be designed to be user-friendly and easy to navigate. It will also be designed
to be secure and private, so that users can feel comfortable sharing their personal information and
content.
The following are some of the design considerations that will be taken into account:
User-friendliness– The website will be designed to be easy to use and navigate. Users
should be able to find the information and features they need quickly and easily.
Security– The website will be designed to be secure and private. Users should feel
comfortable sharing their personal information and content on the website.
Privacy– The website will be designed to protect user privacy. Users should be able to
control who can see their personal information and content.
3. SOCIAL NETWORKING SITE
22102D020145 3 OF 101
The social website will be a valuable resource for users who want to connect with other people who
share their interests. It will also be a great way for users to share their thoughts, ideas, and
experiences with the world.
SYSTEM ARCHITECTURE:
The system architecture of a social networking site is complex and involves many different
components. The following is a high-level overview of the system architecture:
User interface: The user interface is the part of the system that users interact with. It allows
users to create profiles, upload content, and build conversations. The user interface is
typically implemented using a web browser.
Content management system: The content management system (CMS) is responsible for
storing and managing the content of the social networking site. The CMS allows users to
create, edit, and delete content. It also allows users to control who can access and view their
content.
Application server: The application server is responsible for running the code that powers
the social networking site. The application server provides a platform for the CMS and other
components to run on.
Database: The database stores all of the data for the social networking site. This includes
user profiles, content, and other information.
Web server: The web server is responsible for delivering the content of the social
networking site to users. The web server receives requests from users' web browsers and
delivers the requested content.
Network: The network is responsible for connecting the different components of the social
networking site. The network allows users to access the social networking site from
anywhere in the world.
The system architecture of a social networking site is complex and involves many different
components. The specific components that are used will depend on the size and complexity of the
social networking site.
Here are some additional considerations for the system architecture of a social networking site:
Security: The social networking site must be secure to protect the privacy of its users. This
means that the system must be designed to prevent unauthorized access to user data.
Scalability: The social networking site must be scalable to handle a large number of users.
This means that the system must be designed to be able to add more resources as needed.
Performance: The social networking site must be performant to provide a good user
experience. This means that the system must be designed to be able to handle a large number
of requests without slowing down.
4. SOCIAL NETWORKING SITE
22102D020145 4 OF 101
The system architecture of a social networking site is a critical part of the development process. By
carefully considering the different components and considerations, you can create a social
networking site that is secure, scalable, and performant.
The system architecture of the social website consists of several key components that work together
to provide a seamless user experience. These components include:
1. User Interface (UI): The user interface component is responsible for presenting the website's
visual elements to users and facilitating their interactions. It encompasses the design of the
website, including layout, color scheme, and navigation menus, ensuring an intuitive and
visually appealing experience for members.
2. User Profiles: The user profile component allows members to create and customize their
profiles. It includes features such as profile pictures, personal information, interests, and
achievements. The profiles serve as a representation of each member's identity within the
community.
3. Content Management: The content management component handles the storage, retrieval,
and organization of various types of content uploaded by members. This includes text
messages, photographs, audio files, and videos. All posts are arranged in descending order,
with the latest content displayed first for easy access.
4. Community Interaction: The community interaction component enables members to engage
with each other's content. It includes features like commenting, liking, and sharing, which
foster conversations and encourage collaboration. Members can leave comments on posts,
providing feedback, initiating discussions, and forming connections with other community
members.
5. Third-Party Integration: The third-party integration component allows members to tag and
share content from external sources that align with the interests of the community. This
feature enhances the diversity of topics and resources available for discussion, enabling
members to explore a wide range of subjects beyond the platform.
6. Privacy and Security: The privacy and security component ensures the protection of user
data and maintains a safe online environment. It includes measures such as user
authentication, secure data transmission, and data encryption to safeguard personal
information and prevent unauthorized access.
7. Backend and Database: The backend and database component consists of server-side
technologies and databases that power the website's functionality. It handles requests from
the user interface, processes data, and stores it securely. This component also manages user
authentication, content storage, and retrieval.
8. Scalability and Performance: The scalability and performance component focuses on
ensuring the website can handle a growing number of users and content without
5. SOCIAL NETWORKING SITE
22102D020145 5 OF 101
compromising performance. It involves optimizing code, utilizing caching mechanisms, and
employing scalable infrastructure to maintain a responsive and efficient user experience.
Overall, the system architecture of the social website is designed to provide a user-friendly
interface, robust content management, interactive community engagement, and a secure
environment. By integrating these components effectively, the website can deliver an engaging and
seamless social networking experience for its members.
UML DIAGRAM:
10. SOCIAL NETWORKING SITE
22102D020145 10 OF 101
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="linkedin-clone" options="-parameters" />
</option>
</component>
</project>
wrapper
WrapperDownloader
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
11. SOCIAL NETWORKING SITE
22102D020145 11 OF 101
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the
wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory,
MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new
FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH +
"'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
21. SOCIAL NETWORKING SITE
22102D020145 21 OF 101
private final UserRepository userRepository;
private final PostRepository postRepository;
private final PictureRepository pictureRepository;
private final CommentRepository commentRepository;
private final NotificationRepository notificationRepository;
private final InterestReactionRepository interestReactionRepository;
@CrossOrigin(origins = "*")
@GetMapping("/in/{id}/feed-posts")
public Set<Post> getFeedPosts(@PathVariable Long id) {
System.out.println("nnn ------------------- Get feed posts");
User user = userRepository.findById(id).orElseThrow(()->new UserNotFoundException("User
with "+id+" not found"));
Set<Post> feedPosts = new HashSet<>();
feedPosts.addAll(user.getPosts());
Set<Connection> connections = user.getUsersFollowing();
for(Connection con: connections) {
if(con.getIsAccepted()){
User userFollowing = con.getUserFollowed();
feedPosts.addAll(userFollowing.getPosts());
Set<InterestReaction> interestReactions = userFollowing.getInterestReactions();
for(InterestReaction ir: interestReactions){
feedPosts.add(ir.getPost());
}
}
}
connections = user.getUserFollowedBy();
for(Connection con: connections) {
if(con.getIsAccepted()){
User userFollowing = con.getUserFollowing();
feedPosts.addAll(userFollowing.getPosts());
Set<InterestReaction> interestReactions = userFollowing.getInterestReactions();
for(InterestReaction ir: interestReactions){
feedPosts.add(ir.getPost());
}
}
}
for(Post p: feedPosts) {
User owner = p.getOwner();
22. SOCIAL NETWORKING SITE
22102D020145 22 OF 101
Picture pic = owner.getProfilePicture();
if(pic != null){
if(pic.isCompressed()){
Picture dbPic = pictureRepository.findById(pic.getId()).orElseThrow(()->new
UserNotFoundException("Pic with "+pic.getId()+" not found"));;
Picture tempPicture = new
Picture(dbPic.getId(),dbPic.getName(),dbPic.getType(),decompressBytes(dbPic.getBytes()));
tempPicture.setCompressed(false);
owner.setProfilePicture(tempPicture);
}
}
Set<Comment> comments = p.getComments();
for(Comment c: comments){
User commentOwner = c.getUserMadeBy();
Picture cpic = commentOwner.getProfilePicture();
if(cpic != null){
if(cpic.isCompressed()){
Picture tempPicture = new
Picture(cpic.getId(),cpic.getName(),cpic.getType(),decompressBytes(cpic.getBytes()));
tempPicture.setCompressed(false);
commentOwner.setProfilePicture(tempPicture);
}
}
}
Set<Picture> newPicts = new HashSet<>();
for(Picture pict : p.getPictures()){
if(pict != null){
if(pict.isCompressed()){
Picture tempPicture = new
Picture(pict.getId(),pict.getName(),pict.getType(),decompressBytes(pict.getBytes()));
tempPicture.setCompressed(false);
newPicts.add(tempPicture);
System.out.println("> Picture compressed and saved saved ");
}else
newPicts.add(pict);
}
}
p.setPictures(newPicts);
/* System.out.println(owner);
System.out.println(p);*/
}
return feedPosts;
}
23. SOCIAL NETWORKING SITE
22102D020145 23 OF 101
@CrossOrigin(origins = "*")
@PostMapping(value="/in/{id}/feed/new-post", consumes =
{MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity newPost(@PathVariable Long id,@RequestPart("object") Post
post,@RequestPart(value = "imageFile", required=false) MultipartFile[] files) throws IOException
{
System.out.println("nnn> newPost: "+id);
User currentUser = userRepository.findById(id).orElseThrow(()->new
UserNotFoundException("User with "+id+" not found"));
System.out.println("n> findByIdn");
post.setOwner(currentUser);
System.out.println("n> setOwnern");
if(files!=null){
for(MultipartFile file: files){
Picture pic = new
Picture(file.getOriginalFilename() ,file.getContentType() ,compressBytes(file.getBytes()));
pic.setCompressed(true);
pic.setPost(post);
pictureRepository.save(pic);
System.out.println("> Picture compressed and saved saved ");
}
}
System.out.println("n> to saven");
postRepository.save(post);
System.out.println("nnn> New post made with success");
System.out.println(post);
System.out.println(post.getOwner());
return ResponseEntity.ok(""Post created with success!"");
}
@CrossOrigin(origins = "*")
@PutMapping("/in/{id}/feed/post-interested/{postdId}")
public ResponseEntity newInterestedPost(@PathVariable Long id,@PathVariable Long postdId)
{
System.out.println("> /in/{id}/feed/post-interested/{postdId}");
User currentUser = userRepository.findById(id).orElseThrow(()->new
UserNotFoundException("User with "+id+" not found"));
Post post = postRepository.findById(postdId).orElseThrow(()->new
PostNotFoundException("Post with "+id+" not found"));
// IF reaction exists delete it
for(InterestReaction ir: post.getInterestReactions()) {
if(ir.getUserMadeBy()==currentUser) {
currentUser.getInterestReactions().remove(ir);
currentUser.setInterestReactions(currentUser.getInterestReactions());
24. SOCIAL NETWORKING SITE
22102D020145 24 OF 101
post.getInterestReactions().remove(ir);
post.setInterestReactions(post.getInterestReactions());
ir.setUserMadeBy(null);
ir.setPost(null);
userRepository.save(currentUser);
postRepository.save(post);
interestReactionRepository.delete(ir);
System.out.println("> Reaction deleted");
System.out.println(post);
return ResponseEntity.ok(""Reaction deleted with success!"");
}
}
InterestReaction newReaction = new InterestReaction(currentUser,post);
User postOwner = post.getOwner();
if(postOwner!=currentUser){
Notification notification = new Notification(INTEREST,postOwner,newReaction);
notificationRepository.save(notification);
}
interestReactionRepository.save(newReaction);
System.out.println("> New reaction made with success");
System.out.println(post);
return ResponseEntity.ok(""Interested in post created with success!"");
}
@CrossOrigin(origins = "*")
@GetMapping("/in/{id}/feed/is-interested/{postdId}")
public ResponseEntity<?> isInterestedPost(@PathVariable Long id, @PathVariable Long
postdId) {
System.out.println("n> ----- Reaction searchn");
InterestReaction isInterested = null;
Post post = postRepository.findById(postdId).orElseThrow(()->new
PostNotFoundException("Post with "+id+" not found"));
User currentUser = userRepository.findById(id).orElseThrow(()->new
UserNotFoundException("User with "+id+" not found"));
for(InterestReaction ir: post.getInterestReactions()) {
if(ir.getUserMadeBy()==currentUser) {
System.out.println("> Reaction found");
return ResponseEntity.ok(ir);
}
}
System.out.println("> "+isInterested);
System.out.println(post);
return ResponseEntity.ok(null);
}
25. SOCIAL NETWORKING SITE
22102D020145 25 OF 101
@CrossOrigin(origins = "*")
@PutMapping("/in/{id}/feed/new-comment/{postdId}")
public ResponseEntity newComment(@PathVariable Long id,@PathVariable Long
postdId,@RequestBody Comment comment) {
User currentUser = userRepository.findById(id).orElseThrow(()->new
UserNotFoundException("User with "+id+" not found"));
Post post = postRepository.findById(postdId).orElseThrow(()->new
PostNotFoundException("Post with "+id+" not found"));
userService.newPostComment(currentUser,post,comment);
System.out.println("> New comment made with success");
System.out.println(comment);
System.out.println(post);
return ResponseEntity.ok(""Comment in post created with success!"");
}
@CrossOrigin(origins = "*")
@GetMapping("/in/{id}/recommended-posts")
public List<Post> getRecommendedPosts(@PathVariable Long id) {
RecommendationAlgos recAlgos = new RecommendationAlgos();
recAlgos.recommendedPosts(userRepository, postRepository, userService);
List<Post> recommendedPosts = new ArrayList<>();
User currentUser = userRepository.findById(id).orElseThrow(() -> new
UserNotFoundException("User with " + id + " not found"));
System.out.println("nnn 1 ===================================nnn");
if (currentUser.getRecommendedPosts().size() != 0) {
for (Post p : currentUser.getRecommendedPosts()) {
for(Post fp: getFeedPosts(id)){
Long id1 = fp.getId();
Long id2 = p.getId();
if (id1 == id2)
recommendedPosts.add(p);
}
}
}else {
return new ArrayList<>(getFeedPosts(id));
}
System.out.println("nnn 2 ===================================nnn");
Collections.reverse(recommendedPosts);
System.out.println("nnn 3 ===================================nnn");
for(Post p: recommendedPosts) {
User owner = p.getOwner();
Picture pic = owner.getProfilePicture();
if(pic != null){
26. SOCIAL NETWORKING SITE
22102D020145 26 OF 101
if(pic.isCompressed()){
Picture dbPic = pictureRepository.findById(pic.getId()).orElseThrow(()->new
UserNotFoundException("Pic with "+pic.getId()+" not found"));;
Picture tempPicture = new
Picture(dbPic.getId(),dbPic.getName(),dbPic.getType(),decompressBytes(dbPic.getBytes()));
tempPicture.setCompressed(false);
owner.setProfilePicture(tempPicture);
}
}
Set<Comment> comments = p.getComments();
for(Comment c: comments){
User commentOwner = c.getUserMadeBy();
Picture cpic = commentOwner.getProfilePicture();
if(cpic != null){
if(cpic.isCompressed()){
Picture tempPicture = new
Picture(cpic.getId(),cpic.getName(),cpic.getType(),decompressBytes(cpic.getBytes()));
tempPicture.setCompressed(false);
commentOwner.setProfilePicture(tempPicture);
}
}
}
Set<Picture> newPicts = new HashSet<>();
for(Picture pict : p.getPictures()){
if(pict != null){
if(pict.isCompressed()){
Picture tempPicture = new
Picture(pict.getId(),pict.getName(),pict.getType(),decompressBytes(pict.getBytes()));
tempPicture.setCompressed(false);
newPicts.add(tempPicture);
System.out.println("> Picture compressed and saved saved ");
}else
newPicts.add(pict);
}
}
p.setPictures(newPicts);
/* System.out.println(owner);
System.out.println(p);*/
}
return recommendedPosts;
}
}
JobsController
27. SOCIAL NETWORKING SITE
22102D020145 27 OF 101
package com.linkedin.linkedinclone.controllers;
import com.linkedin.linkedinclone.exceptions.ObjectExistsException;
import com.linkedin.linkedinclone.exceptions.PostNotFoundException;
import com.linkedin.linkedinclone.exceptions.UserNotFoundException;
import com.linkedin.linkedinclone.model.*;
import com.linkedin.linkedinclone.recommendation.RecommendationAlgos;
import com.linkedin.linkedinclone.repositories.CommentRepository;
import com.linkedin.linkedinclone.repositories.JobsRepository;
import com.linkedin.linkedinclone.repositories.PostRepository;
import com.linkedin.linkedinclone.repositories.UserRepository;
import com.linkedin.linkedinclone.services.UserService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import static com.linkedin.linkedinclone.utils.PictureSave.decompressBytes;
import static jdk.nashorn.internal.objects.Global.println;
@RestController
@AllArgsConstructor
public class JobsController {
@Autowired
UserService userService;
private final UserRepository userRepository;
private final JobsRepository jobRepository ;
private final CommentRepository commentRepository;
@CrossOrigin(origins = "*")
@PostMapping("/in/{id}/new-job")
public ResponseEntity newJob(@PathVariable Long id, @RequestBody Job job) {
System.out.println(job);
User currentUser = userRepository.findById(id).orElseThrow(()->new
UserNotFoundException("User with "+id+" not found"));
job.setUserMadeBy(currentUser);
jobRepository.save(job);
return ResponseEntity.ok(""Job created with success!"");
}
@CrossOrigin(origins = "*")
@GetMapping("/in/{id}/jobs")
public Set<Job> getJobs(@PathVariable Long id) {
28. SOCIAL NETWORKING SITE
22102D020145 28 OF 101
System.out.println("nngetJobsn");
User currentUser = userRepository.findById(id).orElseThrow(()->new
UserNotFoundException("User with "+id+" not found"));
Set<Job> jobs = new HashSet<>();
/* jobs.addAll(currentUser.getJobsCreated());
Set<User> network = userService.getUserNetwork(currentUser);
for(User u: network){
jobs.addAll(u.getJobsCreated());
}*/
Set<Job> allJobs = new HashSet<>(jobRepository.findAll());
jobs.addAll(allJobs);
System.out.println("n");
for(Job j: jobs) {
System.out.println(j);
User owner = j.getUserMadeBy();
Picture pic = owner.getProfilePicture();
if(pic != null){
if(pic.isCompressed()){
Picture tempPicture = new
Picture(pic.getId(),pic.getName(),pic.getType(),decompressBytes(pic.getBytes()));
pic.setCompressed(false);
owner.setProfilePicture(tempPicture);
}
}
Set<User> usersApplied = j.getUsersApplied();
for(User u: usersApplied) {
Picture cpic = u.getProfilePicture();
if(cpic != null){
if(cpic.isCompressed()){
Picture tempPicture = new
Picture(cpic.getId(),cpic.getName(),cpic.getType(),decompressBytes(cpic.getBytes()));
cpic.setCompressed(false);
u.setProfilePicture(tempPicture);
}
}
}
}
return jobs;
}
29. SOCIAL NETWORKING SITE
22102D020145 29 OF 101
@CrossOrigin(origins = "*")
@PutMapping("/in/{id}/jobs/make-application/{jobId}")
public ResponseEntity newApplication(@PathVariable Long id, @PathVariable Long jobId) {
System.out.println("nnnewApplicationn");
User currentUser = userRepository.findById(id).orElseThrow(()->new
UserNotFoundException("User with "+id+" not found"));
Job job = jobRepository.findById(jobId).orElseThrow(()->new UserNotFoundException("Job
not found"));
Set<User> usersApplied = job.getUsersApplied();
if(!usersApplied.contains(currentUser)){
usersApplied.add(currentUser);
job.setUsersApplied(usersApplied);
jobRepository.save(job);
}else
return ResponseEntity
.badRequest()
.body("{"timestamp": " + """ + new Date().toString() + "","
+ ""status": 400, "
+ ""error": "Bad Request", "
+ ""message": "Application has already been made!", "
);
return ResponseEntity.ok(""Interested in post created with success!"");
}
@CrossOrigin(origins = "*")
@GetMapping("/in/{id}/jobs/{jobId}/applicants")
public Set<User> getJobApplicants(@PathVariable Long id, @PathVariable Long jobId) {
User currentUser = userRepository.findById(id).orElseThrow(()->new
UserNotFoundException("User with "+id+" not found"));
Job job = jobRepository.findById(jobId).orElseThrow(()->new UserNotFoundException("Job
not found"));
return job.getUsersApplied();
}
@CrossOrigin(origins = "*")
@GetMapping("/in/{id}/recommended-jobs")
public List<Job> getRecommendedJobs(@PathVariable Long id){
RecommendationAlgos recAlgos = new RecommendationAlgos();
recAlgos.recommendedJobs(userRepository, jobRepository, userService);
User currentUser = userRepository.findById(id).orElseThrow(()->new
UserNotFoundException("User with "+id+" not found"));
List<Job> recommendedJobs = new ArrayList<>();
if (currentUser.getRecommendedJobs().size() != 0){
System.out.println("list is null");
recommendedJobs = currentUser.getRecommendedJobs();
} else {
31. SOCIAL NETWORKING SITE
22102D020145 31 OF 101
import com.linkedin.linkedinclone.model.*;
import com.linkedin.linkedinclone.repositories.*;
import com.linkedin.linkedinclone.services.UserService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.google.common.collect.Lists.reverse;
import static com.linkedin.linkedinclone.utils.PictureSave.decompressBytes;
import static com.linkedin.linkedinclone.utils.Utils.minDistance;
@RestController
@AllArgsConstructor
public class NetworkController {
@Autowired
UserService userService;
private final UserRepository userRepository;
private final RoleRepository roleRepository;
private final ConnectionRepository connectionRepository;
private final NotificationRepository notificationRepository;
private final ChatRepository chatRepository;
@CrossOrigin(origins = "*")
//@PreAuthorize("hasRole('PROFESSIONAL')")
@GetMapping("/in/{id}/search/{searchQuery}")
public List<User> search(@PathVariable Long id,@PathVariable String searchQuery) {
User user = userRepository.findById(id).orElseThrow(() -> new
UserNotFoundException("User with id "+id+"doesn't exist"));
List<User> searchResults = new ArrayList<User>();
List<User> allUsers = userService.getAllUsers();
String[] searchQueries = searchQuery.split("W+");
MultiValueMap<Integer,User> map = new LinkedMultiValueMap<>();
for(String s: searchQueries) {
String w = s.toLowerCase();
System.out.println(">>> Lemma: " + s);
for(User u: allUsers){
if((u.getId() != id) && (!u.getName().equals("admin"))){
32. SOCIAL NETWORKING SITE
22102D020145 32 OF 101
int dist;
System.out.println(u.getName());
if ( (dist = minDistance(w, u.getName().toLowerCase(Locale.ROOT))) < 10){
System.out.println("- "+u.getName()+" "+dist);
map.add(dist, u);
} else if ((dist = minDistance(w,u.getSurname().toLowerCase(Locale.ROOT))) < 10) {
System.out.println("- "+u.getSurname()+" "+dist);
map.add(dist,u);
}else if( (u.getCurrentCompany()!=null &&
u.getCurrentCompany().toLowerCase(Locale.ROOT) == w) || (u.getCurrentJob()!=null &&
u.getCurrentJob().toLowerCase(Locale.ROOT) == w)) {
map.add(1,u);
}
}
}
}
for(Map.Entry m: map.entrySet()){
System.out.println("-- "+m.getValue());
searchResults.addAll((List<User>) m.getValue());
}
for(User u: searchResults){
System.out.println(u.getName());
Picture uPic = u.getProfilePicture();
if(uPic!=null && uPic.isCompressed()) {
Picture temp = new Picture(uPic.getName(), uPic.getType(),
decompressBytes(uPic.getBytes()));
u.setProfilePicture(temp);
}
}
return reverse(searchResults);
}
@CrossOrigin(origins = "*")
//@PreAuthorize("hasRole('PROFESSIONAL')")
@GetMapping("/in/{id}/network")
public Set<User> getNetwork(@PathVariable Long id) {
User currentUser = userRepository.findById(id).orElseThrow(() -> new
UserNotFoundException("User with id "+id+"doesn't exist"));
Set<User> network = new HashSet<>();
Set<Connection> connectionsFollowing = currentUser.getUsersFollowing();
System.out.println("connectionsFollowing");
for(Connection con: connectionsFollowing) {
if(con.getIsAccepted()){
33. SOCIAL NETWORKING SITE
22102D020145 33 OF 101
User userinNetwork = con.getUserFollowed();
System.out.println(userinNetwork.getName());
network.add(userinNetwork);
}
}
Set<Connection> connectionsFollowedBy = currentUser.getUserFollowedBy();
System.out.println("connectionsFollowedBy");
for(Connection con: connectionsFollowedBy) {
if(con.getIsAccepted()){
User userinNetwork = con.getUserFollowing();
System.out.println(userinNetwork.getName());
network.add(userinNetwork);
}
}
for(User u: network){
System.out.println(u.getName());
Picture uPic = u.getProfilePicture();
if(uPic!=null && uPic.isCompressed()) {
Picture temp = new Picture(uPic.getName(), uPic.getType(),
decompressBytes(uPic.getBytes()));
temp.setCompressed(false);
u.setProfilePicture(temp);
}
}
return network;
}
@CrossOrigin(origins = "*")
//@PreAuthorize("hasRole('PROFESSIONAL')")
@GetMapping("/in/{id}/request/{otherUserId}")
public ResponseEntity<String> hasSendRequest(@PathVariable Long id, @PathVariable Long
otherUserId) {
System.out.println("nn>Check request");
User currentUser = userRepository.findById(id).orElseThrow(() -> new
UserNotFoundException("User with id "+id+"doesn't exist"));
User otherUser = userRepository.findById(otherUserId).orElseThrow(() -> new
UserNotFoundException("User with id "+id+"doesn't exist"));
System.out.println(otherUser.getName());
Set<Connection> connectionsFollowing = currentUser.getUsersFollowing();
System.out.println("connectionsFollowing");
for(Connection con: connectionsFollowing) {
if(!con.getIsAccepted() && con.getUserFollowed()==otherUser){
User userinNetwork = con.getUserFollowed();
34. SOCIAL NETWORKING SITE
22102D020145 34 OF 101
System.out.println(userinNetwork.getName());
return ResponseEntity.ok("true");
}
}
connectionsFollowing = currentUser.getUserFollowedBy();
System.out.println("----");
for(Connection con: connectionsFollowing) {
if(!con.getIsAccepted() && con.getUserFollowing()==otherUser){
User userinNetwork = con.getUserFollowing();
System.out.println(userinNetwork.getName());
return ResponseEntity.ok("true");
}
}
return ResponseEntity.ok("false");
}
@CrossOrigin(origins = "*")
//@PreAuthorize("hasRole('PROFESSIONAL')")
@PutMapping("/in/{id}/new-connection/{newUserId}")
public ResponseEntity addToConnections(@PathVariable Long id,@PathVariable Long
newUserId) {
System.out.println("New connection request:");
User user = userRepository.findById(id).orElseThrow(() -> new
UserNotFoundException("User with id "+id+"doesn't exist"));
userService.newConnection(user,newUserId);
System.out.println("New connection added with success!");
return ResponseEntity.ok(""New connection added with success!"");
}
@CrossOrigin(origins = "*")
//@PreAuthorize("hasRole('PROFESSIONAL')")
@PutMapping("/in/{id}/notifications/{connectionId}/accept-connection")
public ResponseEntity acceptConnection(@PathVariable Long id,@PathVariable Long
connectionId) {
System.out.println("nnn---------");
User user = userRepository.findById(id).orElseThrow(() -> new
UserNotFoundException("User with id "+id+"doesn't exist"));
System.out.println(user.getName() + " will accept connection id"+ connectionId);
35. SOCIAL NETWORKING SITE
22102D020145 35 OF 101
Connection conn = connectionRepository.findById(connectionId).orElseThrow(() -> new
UserNotFoundException("Notification with id "+id+"doesn't exist"));
conn.setIsAccepted(true);
connectionRepository.save(conn);
Notification not = notificationRepository.findByConnectionId(connectionId).orElseThrow(()
-> new UserNotFoundException("Notification with id "+id+"doesn't exist"));
not.setIsShown(true);
notificationRepository.save(not);
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
SimpleDateFormat sdf1 = new SimpleDateFormat("dd.MM.yyyy:HH.mm.ss");
Chat chat = new Chat();
chat.setTimestamp(new Timestamp(System.currentTimeMillis()));
Set<User> users = new HashSet<>();
users.add(user);
if(conn.getUserFollowed()!=user)
users.add(conn.getUserFollowed());
else if(conn.getUserFollowing()!=user)
users.add(conn.getUserFollowing());
chat.setUsers(users);
chatRepository.save(chat);
System.out.println("nnn");
System.out.println(chat);
for(User u: users) {
System.out.println(u);
System.out.println(u.getChats());}
return ResponseEntity.ok(""Connection accepted with success!"");
}
/* @CrossOrigin(origins = "*")
//@PreAuthorize("hasRole('PROFESSIONAL')")
@GetMapping("/in/{id}/network/users/{userShownId}")
public UserProfileDTO getNetwork(@PathVariable Long id) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
User currentUser =
userRepository.findUserByUsername(((org.springframework.security.core.userdetails.User)
auth.getPrincipal()).getUsername());
return network;
}*/
}
36. SOCIAL NETWORKING SITE
22102D020145 36 OF 101
VSWorkSpaceState
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
admin-nav.component
#mylogo{
padding-right: 8px;
}
.btn:focus,.btn:active {
outline: none !important;
box-shadow: none;
}
.navbar{
background-color: rgb(255, 255, 255);
}
.navbar-nav .nav-link{
font-size: 18px;
}
#set-btn{
color: #262626;
text-decoration: none;
}
/* Color of the links BEFORE scroll */
.navbar-scroll .nav-link,
.navbar-scroll .navbar-toggler-icon,
.navbar-scroll .navbar-brand {
color: #262626;
}
/* Color of the navbar BEFORE scroll */
.navbar-scroll {
background-color: #FFC017;
}
/* Color of the links AFTER scroll */
37. SOCIAL NETWORKING SITE
22102D020145 37 OF 101
.navbar-scrolled .nav-link,
.navbar-scrolled .navbar-toggler-icon,
.navbar-scroll .navbar-brand {
color: #262626;
}
/* Color of the navbar AFTER scroll */
.navbar-scrolled {
background-color: #fff;
}
/* An optional height of the navbar AFTER scroll */
.navbar.navbar-scroll.navbar-scrolled {
padding-top: auto;
padding-bottom: auto;
}
.search-area input {
background-color:#e4f2fd;
color:white;
border: 0;
}
.logout-btn{
background-color: #158eff;
color:white;
border: 0;
}
.logout-btn:hover{
background-color: #0078e9;
}
.users-btn{
background-color: #004b91;
color:white;
border: 0;
}
.users-btn:hover{
background-color: #01417e;
}
admin.component
.more-btn:focus,.more-btn:active {
outline: none !important;
45. SOCIAL NETWORKING SITE
22102D020145 45 OF 101
.navbar{
background-color: rgb(255, 255, 255);
}
.navbar-nav .nav-link{
font-size: 18px;
}
#set-btn{
color: #262626;
text-decoration: none;
}
/* Color of the links BEFORE scroll */
.navbar-scroll .nav-link,
.navbar-scroll .navbar-toggler-icon,
.navbar-scroll .navbar-brand {
color: #262626;
}
/* Color of the navbar BEFORE scroll */
.navbar-scroll {
background-color: #FFC017;
}
/* Color of the links AFTER scroll */
.navbar-scrolled .nav-link,
.navbar-scrolled .navbar-toggler-icon,
.navbar-scroll .navbar-brand {
color: #262626;
}
/* Color of the navbar AFTER scroll */
.navbar-scrolled {
background-color: #fff;
}
/* An optional height of the navbar AFTER scroll */
.navbar.navbar-scroll.navbar-scrolled {
padding-top: auto;
padding-bottom: auto;
}
.search-area input {
background-color:#e4f2fd;
color:white;
border: 0;
}