diff --git a/src/collections/ArrayList.java b/src/collections/ArrayList.java index 162ffdefa8dbc8d2b4b9ff3f769420334d4d3f62..fc7dcae90e7a14361691a137f5f9369031f9820c 100644 --- a/src/collections/ArrayList.java +++ b/src/collections/ArrayList.java @@ -106,4 +106,8 @@ public class ArrayList { throw new IllegalArgumentException("Такой элемент не существует в массиве"); } + + public int getSize() { + return size; + } } diff --git a/src/entities/Role.java b/src/entities/Role.java new file mode 100644 index 0000000000000000000000000000000000000000..6ca122e53510c7706767b5c5a27c16fa772740ab --- /dev/null +++ b/src/entities/Role.java @@ -0,0 +1,8 @@ +package entities; + +public enum Role { + Admin, + User, + Manager, + ; +} diff --git a/src/entities/User.java b/src/entities/User.java index 5204fa54893723d4264f19e57103de81d7c227e0..55abe44130082372414b6bffbba2415681f12dac 100644 --- a/src/entities/User.java +++ b/src/entities/User.java @@ -1,65 +1,94 @@ package entities; -public class User { - private int id; +import collections.ArrayList; +import fileManagement.entity.FileEntity; - private String fullName; - private String username; - private String password; +import java.io.FileNotFoundException; +import java.nio.file.Path; +import java.util.Objects; - private String position; +public class User { + private String userId; + private ArrayList files; + private String fullName; private int age; + private Role role; - public User(int id, String fullName, String username, String password, String position, int age) { - this.id = id; + public User(String userId, ArrayList files, String fullName, int age, Role role) { + this.userId = userId; + this.files = files; this.fullName = fullName; - this.username = username; - this.password = password; - this.position = position; this.age = age; + this.role = role; } - public int getId() { - return id; + void addFile(FileEntity file) { + files.add(file); } - public void setId(int id) { - if (id < 0) throw new IllegalArgumentException("Айди должно быть положительным"); + String viewFile(String fileName) throws FileNotFoundException { + FileEntity file = getFileByName(fileName); + return file.getContent(); + } - this.id = id; + void editFile(String fileName, String newContent) throws FileNotFoundException { + FileEntity file = getFileByName(fileName); + file.setContent(newContent); } - public String getFullName() { - return fullName; + void deleteFile(String fileName) throws FileNotFoundException { + FileEntity file = getFileByName(fileName); + files.remove(file); } - public void setFullName(String fullName) { - this.fullName = fullName; + + private FileEntity getFileByName(String fileName) throws FileNotFoundException { + for (int i = 0; i < files.getSize(); i++) { + FileEntity file = files.get(i); + Path filePath = file.getFileName(); + String fileToString = filePath.toString(); + if (fileToString.equals(fileName)) { + return file; + } + } + throw new FileNotFoundException("File not found"); } - public String getUsername() { - return username; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof User user)) return false; + return age == user.age && Objects.equals(userId, user.userId) && Objects.equals(files, user.files) && Objects.equals(fullName, user.fullName) && role == user.role; } - public void setUsername(String username) { - this.username = username; + @Override + public int hashCode() { + return Objects.hash(userId, files, fullName, age, role); } - public String getPassword() { - return password; + public String getUserId() { + return userId; } - public void setPassword(String password) { - this.password = password; + public void setUserId(String userId) { + this.userId = userId; } - public String getPosition() { - return position; + public ArrayList getFiles() { + return files; } - public void setPosition(String position) { - this.position = position; + public void setFiles(ArrayList files) { + this.files = files; + } + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; } public int getAge() { @@ -67,33 +96,14 @@ public class User { } public void setAge(int age) { - if (age < 18) throw new IllegalArgumentException("Малыш, иди подрасти, ты еще маленький"); - this.age = age; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; // if (o == null || ! (o instanceof User))) - User user = (User) o; - return id == user.id && - age == user.age && - fullName.equals(user.fullName) && - username.equals(user.username) && - password.equals(user.password) && - position.equals(user.position); + public Role getRole() { + return role; } - @Override - public String toString() { - return "User{" + - "id=" + id + - ", fullName='" + fullName + '\'' + - ", username='" + username + '\'' + - ", password='" + password + '\'' + - ", position='" + position + '\'' + - ", age=" + age + - '}'; + public void setRole(Role role) { + this.role = role; } } diff --git a/src/fileManagement/entity/FileEntity.java b/src/fileManagement/entity/FileEntity.java index a6443643aafa94031284e811e71a5f1355730796..90e09e1d7fc1e0918d1cb4df494c10216c2a2a18 100644 --- a/src/fileManagement/entity/FileEntity.java +++ b/src/fileManagement/entity/FileEntity.java @@ -19,10 +19,6 @@ public class FileEntity { this.passwordHash = passwordHash; } - public String getContent() { - return content; - } - public Path getFileName() { return fileName; } @@ -39,10 +35,22 @@ public class FileEntity { this.owner = owner; } + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + public String getPasswordHash() { return passwordHash; } + public void setPasswordHash(String passwordHash) { + this.passwordHash = passwordHash; + } + @Override public boolean equals(Object o) { if (!(o instanceof FileEntity that)) return false;