Commit b2fc1663 authored by Oskars's avatar Oskars
Browse files

Change: more changes and main class

parent e9e67428
......@@ -4,43 +4,64 @@ import model.users.BusinessUser;
import model.users.PrivateUser;
import model.users.User;
import model.Post;
import model.Encryption;
import model.Page;
import model.PostType;
public class main {
public class main {
public static void main(String[] args) {
//PRIVATE USER
PrivateUser privateUser1 = new PrivateUser("Oskars Birgelis", "Oskars", "Birgelis", null, null);
System.out.println(Encryption.encryptMD5("RightPassword"));
// CREATE PRIVATE USER, POST
PrivateUser privateUser1 = new PrivateUser("Oskars Birgelis", "Oskars", "RightPassword", null, null);
PrivateUser privateUser2 = new PrivateUser("Peteris Petersons", "Peteris", "Petersons", null, null);
privateUser1.createPost(PostType.PUBLIC, "this is public PrivateUser Post number 1");
privateUser1.createPost(PostType.PUBLIC, "this is public PrivateUser Post number 2");
privateUser1.createPost(PostType.PRIVATE, "this is private PrivateUser Post number 3");
privateUser2.createPost(PostType.PRIVATE, "this is private PrivateUser Post number 1");
privateUser2.createPost(PostType.PRIVATE, "this is private PrivateUser Post number 2");
//printPrivateUserInfo(privateUser1);
//printPrivateUserInfo(privateUser2);
//BUSINESS USER
// CREATE BUSINESS USER, PAGE, POST
BusinessUser businessUser1 = new BusinessUser("Armands Armandsons", "Armands", "Armandsons", null);
BusinessUser businessUser2 = new BusinessUser("Pavels Pavelsons", "Pavels", "Pavelsons", null);
businessUser1.createPage("Physics","This page is about physics", null, null);
businessUser2.createPage("Mathematics","This page is about mathematics", null, null);
businessUser1.createPostInPage(PostType.PUBLIC, "this is public BusinessUser Post number 1", businessUser1.findPage("Physics") );
businessUser1.createPostInPage(PostType.PUBLIC, "this is public BusinessUser Post number 2", businessUser1.findPage("Physics") );
businessUser2.createPostInPage(PostType.PRIVATE, "this is private BusinessUser Post number 1", businessUser1.findPage("Mathematics") );
businessUser1.createPostInPage(PostType.PRIVATE, "this is private BusinessUser Post number 1", businessUser1.findPage("Physics") );
businessUser2.createPostInPage(PostType.PUBLIC, "this is public BusinessUser Post number 2", businessUser1.findPage("Mathematics") );
businessUser2.createPostInPage(PostType.PRIVATE, "this is private BusinessUser Post number 2", businessUser1.findPage("Mathematics") );
//printBusinessUserInfo(businessUser1);
//printBusinessUserInfo(businessUser2);
// FOLLOWING PRIVATE USER, PAGE
privateUser1.followPrivateUser(privateUser2); //privateUser2 will follow purivateUser1
privateUser1.followPage(businessUser1.findPage("Physics") );
//printPrivateUserInfo(privateUser1);
//printBusinessUserInfo(businessUser1);
// FIND USER, PAGE, PUBLICPOSTSINPRIVATEUSER, PUBLICPOSTSINPAGE
//System.out.println("Search user: " + ( (User.findUser("Oskars") != null)? User.findUser("Oskars") : "User not found") );
//System.out.println("Search page: " + ( (User.findPage("Mathematics") != null)? User.findPage("Mathematics") : "Page not found") );
if(privateUser1.findPublicPostsInPrivateUser().size() == 0) System.out.println("There is no posts from this user");
else {
//System.out.println("Search public posts for private user: " + privateUser1);
for(Post post: privateUser1.findPublicPostsInPrivateUser()){
//System.out.println(post);
}
}
//System.out.println(privateUser1.findPublicPostInPage("Mathematics"));
//REGISTER, LOGIN (register is User object creation - skipping it)
System.out.println((privateUser1.login("WrongPassword"))? "Logged in" : "Wrong password");
System.out.println((privateUser1.login("RightPassword"))? "Logged in" : "Wrong password");
System.out.println(Encryption.encryptMD5("RightPassword"));
System.out.println(Encryption.encryptMD5("RightPassword"));
printBusinessUserInfo(businessUser1);
printBusinessUserInfo(businessUser2);
}
......@@ -66,6 +87,6 @@ public class main {
}
}
}
}
......@@ -23,9 +23,9 @@ public abstract class GuestUser {
return generatedId;
}
//OTHER METHODS
public abstract User findUser(String username);
public abstract Page findPage(String title);
public abstract ArrayList<Post> findPublicPostsInPrivateUser();
public abstract ArrayList<Post> findPublicPostInPage(Page page);
//public abstract User findUser(String username); // commented this line - to make findUser() method static in User class
//public abstract Page findPage(String title); // same
public abstract ArrayList<Post> findPublicPostsInPrivateUser(); //left this as it is - so only user object can call this
public abstract ArrayList<Post> findPublicPostInPage(String pageTitle); //left this as it is - so only user object can call this
}
......@@ -46,11 +46,12 @@ public class PrivateUser extends User{
return super.toString() + ", Posts: " + posts.size() + ", Followers: " + followers.size();
}
public void followPrivateUser(PrivateUser privateUser) {
public void followPrivateUser(PrivateUser privateUser) {
if(privateUser != null) {
ArrayList<User> uf = privateUser.getFollowers();
uf.add(this);
privateUser.setFollowers(uf);
followers.add(privateUser);
//ArrayList<User> uf = privateUser.getFollowers();
//uf.add(this);
//privateUser.setFollowers(uf);
}
}
......
......@@ -31,16 +31,14 @@ public abstract class User extends GuestUser implements IPost{
public User(String nameAndSurname, String username, String password) {
super();
this.nameAndSurname = (Verification.verificateNameAndSurname(nameAndSurname))
? nameAndSurname : "Empty";
this.username = (Verification.verificateUsername(username))
? username : "Empty";
this.nameAndSurname = (Verification.verificateNameAndSurname(nameAndSurname))? nameAndSurname : "Empty";
this.username = (Verification.verificateUsername(username))? username : "Empty";
if(Verification.verificatePassword(password)) {
this.password = password;
generatedPassword = Encryption.encryptMD5(password);
}else {
this.password = "Empty";
generatedPassword = null;
generatedPassword = Encryption.encryptMD5("Empty");
}
allUsers.add(this);
......@@ -63,7 +61,7 @@ public abstract class User extends GuestUser implements IPost{
generatedPassword = Encryption.encryptMD5(password);
}else {
this.password = "Empty";
generatedPassword = null;
generatedPassword = Encryption.encryptMD5("Empty");
}
}
......@@ -100,8 +98,7 @@ public abstract class User extends GuestUser implements IPost{
}
public boolean login(String inputPassword) {
return (generatedPassword == Encryption.encryptMD5(inputPassword))?
true : false;
return (generatedPassword == Encryption.encryptMD5(inputPassword))? true : false;
}
public boolean followPage(Page page) {
......@@ -114,28 +111,27 @@ public abstract class User extends GuestUser implements IPost{
return false;
}
//DERRIVED METHODS
@Override
public User findUser(String username) {
public static User findUser(String username) {
for(User usr: allUsers) {
if(usr.getUsername() == username) return usr;
}
return null;
}
@Override
public Page findPage(String title) {
public static Page findPage(String title) {
for(Page pag: Page.allPages) {
if(pag.getTitle() == title) return pag;
}
return null;
}
//DERRIVED METHODS
@Override
public ArrayList<Post> findPublicPostInPage(Page page){
public ArrayList<Post> findPublicPostInPage(String pageTitle){
ArrayList<Post> publicPosts = new ArrayList<Post>();
for(Page pag : Page.allPages) {
if(pag.getTitle() == page.getTitle()) {
if(pag.getTitle() == pageTitle) {
for(Post post: pag.getPostsInPage()) {
if(post.getPostType() == PostType.PUBLIC) publicPosts.add(post);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment