修复errors
This commit is contained in:
parent
6cdec726ca
commit
8ff882cdd0
@ -29,7 +29,7 @@ public class DatabaseService {
|
|||||||
try (Connection conn = getConnection()) {
|
try (Connection conn = getConnection()) {
|
||||||
createTables(conn);
|
createTables(conn);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String sql = "SELECT * FROM users";
|
String sql = "SELECT * FROM users";
|
||||||
@ -60,7 +60,7 @@ public class DatabaseService {
|
|||||||
return dataSource.getConnection();
|
return dataSource.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTables(Connection conn) throws SQLException {
|
private void createTables(Connection conn){
|
||||||
String createUsersTable = "CREATE TABLE users (" +
|
String createUsersTable = "CREATE TABLE users (" +
|
||||||
"id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
|
"id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
|
||||||
"username VARCHAR(255) UNIQUE, " +
|
"username VARCHAR(255) UNIQUE, " +
|
||||||
@ -121,7 +121,7 @@ public class DatabaseService {
|
|||||||
projects.add(project);
|
projects.add(project);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
}
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ public class DatabaseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserInfo getUserInfo(String username) throws SQLException {
|
public UserInfo getUserInfo(String username){
|
||||||
String sql = "SELECT * FROM users WHERE username = ?";
|
String sql = "SELECT * FROM users WHERE username = ?";
|
||||||
try (Connection conn = getConnection();
|
try (Connection conn = getConnection();
|
||||||
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
@ -183,7 +183,7 @@ public class DatabaseService {
|
|||||||
rs.getString("careerGoals"));
|
rs.getString("careerGoals"));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ public class DatabaseService {
|
|||||||
users.add(rs.getString("username"));
|
users.add(rs.getString("username"));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
}
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,10 +33,6 @@ public class ProjectBean implements Serializable {
|
|||||||
|
|
||||||
public List<String> selectedKeywords; // List of selected keywords for the current project
|
public List<String> selectedKeywords; // List of selected keywords for the current project
|
||||||
|
|
||||||
private static String getJDBCurl() {
|
|
||||||
return "jdbc:derby:testDB;create=true";
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> users;
|
private List<String> users;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@ -44,9 +40,6 @@ public class ProjectBean implements Serializable {
|
|||||||
loadProjects(); // Load projects from the database
|
loadProjects(); // Load projects from the database
|
||||||
System.out.println("Projects loaded: " + projects.size());
|
System.out.println("Projects loaded: " + projects.size());
|
||||||
loadAllKeywords(); // Load all unique keywords from all projects
|
loadAllKeywords(); // Load all unique keywords from all projects
|
||||||
if (projects.isEmpty()) {
|
|
||||||
Project emptyProject = new Project("", "", "", new ArrayList<>(), "", new ArrayList<>(), "", "");
|
|
||||||
}
|
|
||||||
setProject(projects.get(0)); // Set the first project as the current project
|
setProject(projects.get(0)); // Set the first project as the current project
|
||||||
users = databaseService.getAllUsers();
|
users = databaseService.getAllUsers();
|
||||||
}
|
}
|
||||||
@ -57,21 +50,17 @@ public class ProjectBean implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadUserInfo() {
|
public void loadUserInfo() {
|
||||||
try {
|
|
||||||
UserInfo info = databaseService.getUserInfo(username);
|
UserInfo info = databaseService.getUserInfo(username);
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
userInfo = info;
|
userInfo = info;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateUserInfo() {
|
public void updateUserInfo() {
|
||||||
try {
|
try {
|
||||||
databaseService.updateUserInfo(username, userInfo);
|
databaseService.updateUserInfo(username, userInfo);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,11 +111,6 @@ public class ProjectBean implements Serializable {
|
|||||||
projects.add(project);
|
projects.add(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String loadProject(String title) {
|
|
||||||
project = projects.stream().filter(p -> p.getTitle().equals(title)).findFirst().orElse(null);
|
|
||||||
return "project.xhtml?faces-redirect=true";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String saveProject() {
|
public String saveProject() {
|
||||||
FacesContext context = FacesContext.getCurrentInstance();
|
FacesContext context = FacesContext.getCurrentInstance();
|
||||||
|
|
||||||
@ -152,7 +136,7 @@ public class ProjectBean implements Serializable {
|
|||||||
loadAllKeywords();
|
loadAllKeywords();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
context.addMessage("saveButton", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Submission Failed", null));
|
context.addMessage("saveButton", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Submission Failed", null));
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
}
|
||||||
return "project";
|
return "project";
|
||||||
}
|
}
|
||||||
@ -196,7 +180,7 @@ public class ProjectBean implements Serializable {
|
|||||||
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Login failed", null));
|
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Login failed", null));
|
||||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("username");
|
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("username");
|
||||||
isLoggedIn = false;
|
isLoggedIn = false;
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
return "login";
|
return "login";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,14 +227,6 @@ public class ProjectBean implements Serializable {
|
|||||||
return project != null ? String.join(", ", project.getCollaborators()) : "";
|
return project != null ? String.join(", ", project.getCollaborators()) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProjectKeywords() {
|
|
||||||
return projectKeywords;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProjectKeywords(String projectKeywords) {
|
|
||||||
this.projectKeywords = projectKeywords;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getProjectCollaborators() {
|
public String getProjectCollaborators() {
|
||||||
return projectCollaborators;
|
return projectCollaborators;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,8 +28,4 @@
|
|||||||
<welcome-file-list>
|
<welcome-file-list>
|
||||||
<welcome-file>index.jsf</welcome-file>
|
<welcome-file>index.jsf</welcome-file>
|
||||||
</welcome-file-list>
|
</welcome-file-list>
|
||||||
<!-- Weld listener -->
|
|
||||||
<listener>
|
|
||||||
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
|
|
||||||
</listener>
|
|
||||||
</web-app>
|
</web-app>
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
xmlns:h="http://xmlns.jcp.org/jsf/html"
|
xmlns:h="http://xmlns.jcp.org/jsf/html"
|
||||||
xmlns:f="http://xmlns.jcp.org/jsf/core">
|
>
|
||||||
<h:head>
|
<h:head>
|
||||||
<meta charset="UTF-8"/>
|
<meta charset="UTF-8"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user