Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added doc/Note App Class Diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/NoteAppPrjReview.smproj
Binary file not shown.
Binary file added doc/Project Review.pdf
Binary file not shown.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<maven.compiler.target>21</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.3</version>
</dependency>
<dependency>
<groupId>com.mailjet</groupId>
<artifactId>mailjet-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.noteapp.common.service;

/**
* Đại diện cho các ngoại lệ gây ra bởi hệ thống NoteApp
* @author Nhóm 17
*/
public class CausedBySystemException extends NoteAppServiceException {
protected static final String DEFAULT_NOTIFY = "Caused by NoteApp System";

public CausedBySystemException(String message) {
super(DEFAULT_NOTIFY + message);
}

public CausedBySystemException(String message, Throwable cause) {
super(DEFAULT_NOTIFY + message, cause);
}

public CausedBySystemException(Throwable cause) {
super(DEFAULT_NOTIFY, cause);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.noteapp.common.service;

/**
* Đại diện cho các ngoại lệ gây ra bởi người dùng khi sử dụng hệ thống NoteApp
* @author Nhóm 17
*/
public class CausedByUserException extends NoteAppServiceException {

public CausedByUserException(String message) {
super(message);
}

public CausedByUserException(String message, Throwable cause) {
super(message, cause);
}

public CausedByUserException(Throwable cause) {
super(cause);
}

}
102 changes: 102 additions & 0 deletions src/main/java/com/noteapp/common/service/NoteAppService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.noteapp.common.service;

import com.noteapp.note.service.INoteService;
import com.noteapp.note.service.IShareNoteService;
import com.noteapp.note.service.io.FileIOService;
import com.noteapp.user.service.IAdminService;
import com.noteapp.user.service.IUserService;
import com.noteapp.user.service.security.VerificationMailService;

/**
* Cung cấp các service ở mức tổng quan của NoteApp System
* @author Nhóm 17
* @see IUserService
* @see IAdminService
* @see INoteService
* @see IShareNoteService
* @see VerificationMailService
* @see FileIOService
*/
public class NoteAppService {
private IUserService userService;
private IAdminService adminService;
private INoteService noteService;
private IShareNoteService shareNoteService;
private VerificationMailService verificationMailService;
private FileIOService fileIOService;

public NoteAppService() {
userService = null;
adminService = null;
noteService = null;
shareNoteService = null;
verificationMailService = null;
fileIOService = null;
}

public IUserService getUserService() throws NoteAppServiceException {
if (userService == null) {
throw new CausedBySystemException("Service has not inited!");
}
return userService;
}

public void setUserService(IUserService userService) {
this.userService = userService;
}

public IAdminService getAdminService() throws NoteAppServiceException {
if (adminService == null) {
throw new CausedBySystemException("Service has not inited!");
}
return adminService;
}

public void setAdminService(IAdminService adminService) {
this.adminService = adminService;
}

public INoteService getNoteService() throws NoteAppServiceException {
if (noteService == null) {
throw new CausedBySystemException("Service has not inited!");
}
return noteService;
}

public void setNoteService(INoteService noteService) {
this.noteService = noteService;
}

public IShareNoteService getShareNoteService() throws NoteAppServiceException {
if (shareNoteService == null) {
throw new CausedBySystemException("Service has not inited!");
}
return shareNoteService;
}

public void setShareNoteService(IShareNoteService shareNoteService) {
this.shareNoteService = shareNoteService;
}

public VerificationMailService getVerificationMailService() throws NoteAppServiceException {
if (verificationMailService == null) {
throw new CausedBySystemException("Service has not inited!");
}
return verificationMailService;
}

public void setVerificationMailService(VerificationMailService verificationMailService) {
this.verificationMailService = verificationMailService;
}

public FileIOService getFileIOService() throws NoteAppServiceException {
if (fileIOService == null) {
throw new CausedBySystemException("Service has not inited!");
}
return fileIOService;
}

public void setFileIOService(FileIOService fileIOService) {
this.fileIOService = fileIOService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.noteapp.common.service;

/**
* Đại diện cho tất cả các ngoại lệ có thể xảy ra khi sử dụng dịch vụ
* của hệ thống NoteApp
* @author Nhóm 17
*/
public class NoteAppServiceException extends Exception {

public NoteAppServiceException(String message) {
super(message);
}

public NoteAppServiceException(String message, Throwable cause) {
super(message, cause);
}

public NoteAppServiceException(Throwable cause) {
super(cause);
}

}
144 changes: 144 additions & 0 deletions src/main/java/com/noteapp/controller/AdminDashboardController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package com.noteapp.controller;

import com.noteapp.common.service.NoteAppService;
import com.noteapp.common.service.NoteAppServiceException;
import com.noteapp.user.dao.AdminDAO;
import com.noteapp.user.dao.UserDAO;
import com.noteapp.user.service.AdminService;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
* Controller cho view Dashboard của Admin
* @author admin
*/
public class AdminDashboardController extends RequestServiceController implements Initable {
@FXML
private Button viewUsersButton;
@FXML
private TextField searchUserField;
@FXML
private VBox userCardLayout;
@FXML
private Button closeButton;
@FXML
private Button logoutButton;

private Map<String, Boolean> lockedStatusOfUsers;

@Override
public void init() {
noteAppService = new NoteAppService();
noteAppService.setAdminService(new AdminService(UserDAO.getInstance(), AdminDAO.getInstance()));
initView();
closeButton.setOnAction((ActionEvent event) -> {
close();
});
logoutButton.setOnAction((ActionEvent event) -> {
LoginController.open(stage);
});
viewUsersButton.setOnAction((ActionEvent event) -> {
initView();
});
searchUserField.setOnAction((ActionEvent event) -> {
searchUser();
});
}

protected void initView() {
try {
lockedStatusOfUsers = noteAppService.getAdminService().getAllLockedStatus();
loadUsers(lockedStatusOfUsers);
} catch (NoteAppServiceException ex) {
showAlert(Alert.AlertType.ERROR, ex.getMessage());
}
}

private void saveLockedStatus(String username, boolean lockedStatus) {
try {
noteAppService.getAdminService().updateLockedStatus(username, lockedStatus);
} catch (NoteAppServiceException ex) {
showAlert(Alert.AlertType.ERROR, ex.getMessage());
}
}

/**
* Tải thông tin về các User và trạng thái Locked của họ vào
* một danh sách có thể hiển thị trên màn hình
* @param lockedStatusOfUsers Một Map lưu giữ trạng thái Locked của mỗi User
* @see userCardLayout
* @see UserItemController
*/
protected void loadUsers(Map<String, Boolean> lockedStatusOfUsers) {
userCardLayout.getChildren().clear();
if (lockedStatusOfUsers.isEmpty()) {
return;
}
String filePath = Controller.DEFAULT_FXML_RESOURCE + "UserItemView.fxml";
//Load từng user vào UserItemController
for (Map.Entry<String, Boolean> entry: lockedStatusOfUsers.entrySet()) {
String username = entry.getKey();
boolean isLocked = entry.getValue();
try {
UserItemController controller = new UserItemController();
HBox box = controller.loadFXML(filePath);
controller.setData(username, isLocked);
//Thêm action cho nút đổi trạng thái lock
controller.getChangeLockStatusButton().setOnAction((ActionEvent event) -> {
controller.changeLockedStatus();
String thisUsername = controller.getUsername();
boolean thisLockedStatus = controller.isLocked();
this.lockedStatusOfUsers.put(thisUsername, thisLockedStatus);
saveLockedStatus(thisUsername, thisLockedStatus);
});
userCardLayout.getChildren().add(box);
} catch (IOException ex) {
showAlert(Alert.AlertType.ERROR, "Can load user items");
}
}
}

/**
* Thực hiện tìm kiếm user có username chứa chuỗi được nhập vào
* {@link searchUserField} và load lại danh sách hiển thị những
* user khớp với yêu cầu
*/
protected void searchUser() {
String searchText = searchUserField.getText();
Map<String, Boolean> searchUsers = new HashMap<>();
for (Map.Entry<String, Boolean> entry: lockedStatusOfUsers.entrySet()) {
String username = entry.getKey();
boolean isLocked = entry.getValue();
if (username.contains(searchText)) {
searchUsers.put(username, isLocked);
}
}
loadUsers(searchUsers);
}

/**
* Mở một giao diện Dashboard cho Admin
* @param stage Stage được truyền vào để chứa giao diện này
*/
public static void open(Stage stage) {
try {
String filePath = Controller.DEFAULT_FXML_RESOURCE + "AdminDashboardView.fxml";
AdminDashboardController controller = new AdminDashboardController();
controller.setStage(stage);
controller.loadFXMLAndSetScene(filePath);
controller.init();
controller.showFXML();
} catch (IOException ex) {
showAlert(Alert.AlertType.ERROR, "Can't open admin dashboard");
}
}
}
Loading