Skip to content
Closed
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
327066e
Update pom.xml
Siyuan106 Feb 9, 2025
ebc8637
Update DatabaseController.java
Siyuan106 Feb 9, 2025
4b23807
Update Login.vue
Liuwf4319 Feb 11, 2025
2d7b756
Update MainContent.vue
Liuwf4319 Feb 11, 2025
fb6f194
Update SpringController.java
Liuwf4319 Feb 11, 2025
6e5ff36
Update DatabaseController.java
Liuwf4319 Feb 11, 2025
3156d33
Update SpringController.java
Liuwf4319 Feb 11, 2025
22ddcbc
Update User.java
Liuwf4319 Feb 11, 2025
5f73074
Update MainContent.vue
Liuwf4319 Feb 11, 2025
e0a552a
Update MainContent.vue
Liuwf4319 Feb 12, 2025
b414a90
feature: update pom.xml
Siyuan106 Feb 17, 2025
03c65e4
Create ChatEntity.java
Siyuan106 Feb 17, 2025
cc3ae54
Update ChatEntity.java
Siyuan106 Feb 17, 2025
f6bbf85
Add files via upload
Siyuan106 Feb 17, 2025
b8fe668
Create UserRepository.java
Siyuan106 Feb 17, 2025
f2a39df
Create ChatRepository.java
Siyuan106 Feb 17, 2025
f62f40a
feature: update AiLearningToolApplication.java
Siyuan106 Feb 17, 2025
f93bee0
feature: update application.properties
Siyuan106 Feb 17, 2025
a9f6bdb
feature: update SpringController.java
Siyuan106 Feb 17, 2025
5286ce3
feature: update DatabaseController.java
Siyuan106 Feb 17, 2025
2bb11ee
Update DatabaseController.java
Siyuan106 Feb 22, 2025
7a7f3db
Update SpringController.java
Siyuan106 Feb 22, 2025
b317c97
Update application.properties
Siyuan106 Feb 22, 2025
f11d14c
Update UserEntity.java
Liuwf4319 Feb 22, 2025
6d658b0
Update UserEntity.java
Liuwf4319 Feb 22, 2025
202599f
Update UserTest.java
Liuwf4319 Feb 22, 2025
8d6cde8
Update ChatTest.java
Liuwf4319 Feb 22, 2025
9104f67
Update SpringControllerTest.java
Liuwf4319 Feb 22, 2025
3cd5471
Update DatabaseControllerTest.java
Liuwf4319 Feb 22, 2025
722e959
chore: Update the architecture diagram.
vladislav-k1 Feb 24, 2025
c660fef
Update Login.vue
Liuwf4319 Feb 24, 2025
7c8cb12
Update App.vue
Liuwf4319 Feb 24, 2025
0c7ea2e
Update App.vue
Liuwf4319 Feb 24, 2025
70edb07
Update MainContent.vue
Liuwf4319 Feb 24, 2025
1bf9b8f
Update DatabaseControllerTest.java
Liuwf4319 Feb 24, 2025
5952501
Update SpringControllerTest.java
Liuwf4319 Feb 24, 2025
bb28896
Update SpringControllerTest.java
Liuwf4319 Feb 24, 2025
c08b49f
Update ChatEntity.java
Liuwf4319 Feb 24, 2025
5ce3f20
Update UserEntity.java
Liuwf4319 Feb 24, 2025
6a82fae
Update ChatEntity.java
Liuwf4319 Feb 24, 2025
832292c
Update SpringController.java
Liuwf4319 Feb 24, 2025
ddfa48c
Update UserRepository.java
Liuwf4319 Feb 24, 2025
57b4348
Update ChatRepository.java
Liuwf4319 Feb 24, 2025
b115261
Update SpringController.java
Siyuan106 Feb 27, 2025
1249afd
Update MainContent.vue
Siyuan106 Feb 27, 2025
4d57285
Update MainView.vue
Siyuan106 Mar 2, 2025
cd2af63
Update Login.vue
Siyuan106 Mar 2, 2025
c5c8cf9
Update MainContent.vue
Siyuan106 Mar 2, 2025
8167aba
Update SpringController.java
Siyuan106 Mar 2, 2025
3082ed8
Create language.js
Liuwf4319 Mar 3, 2025
790fefa
Update UserEntity.java
Liuwf4319 Mar 3, 2025
6a4d84e
Update HistorySidebar.vue
Siyuan106 Mar 3, 2025
b9e967c
Update User.java
Liuwf4319 Mar 3, 2025
b4bd47f
Update Login.vue
Siyuan106 Mar 3, 2025
4467a18
Update DatabaseController.java
Liuwf4319 Mar 3, 2025
a4e2437
Update main.js
Liuwf4319 Mar 3, 2025
ac4fe7d
Update App.vue
Liuwf4319 Mar 3, 2025
d2c243b
Update HistorySidebar.vue
Siyuan106 Mar 3, 2025
ebd12f6
Update HistorySidebar.vue
Siyuan106 Mar 3, 2025
71639a7
Update DatabaseController.java
Siyuan106 Mar 3, 2025
621d63b
Update ChatEntity.java
Liuwf4319 Mar 3, 2025
df534d1
Update ChatEntity.java
Siyuan106 Mar 3, 2025
4763392
Merge branch 'dev' into feature/issue-184/create-sqlite-database-to-s…
Siyuan106 Mar 3, 2025
55c2b8d
Update SpringControllerTest.java
Liuwf4319 Mar 3, 2025
fa84395
Update DatabaseControllerTest.java
Liuwf4319 Mar 3, 2025
8018fa3
Update ChatTest.java
Liuwf4319 Mar 3, 2025
3d186a2
Update Chat.java
Liuwf4319 Mar 3, 2025
7f762cf
Update SpringControllerTest.java
Liuwf4319 Mar 3, 2025
c8a9b3c
Update DatabaseControllerTest.java
Liuwf4319 Mar 3, 2025
ceb336d
Update ChatTest.java
Liuwf4319 Mar 3, 2025
4faf030
Update MainView.vue
RainBOY-ZZX Mar 5, 2025
0c3fb66
Update ChatEntity.java
Liuwf4319 Mar 11, 2025
4c3adaa
Update UserEntity.java
Liuwf4319 Mar 11, 2025
d4afb9d
Update ChatRepository.java
Liuwf4319 Mar 11, 2025
e3e3c63
Update UserRepository.java
Liuwf4319 Mar 11, 2025
3bdb047
Update DatabaseController.java
Liuwf4319 Mar 11, 2025
f1681f5
Update SpringController.java
Liuwf4319 Mar 11, 2025
75519a8
Update DatabaseControllerTest.java
Liuwf4319 Mar 11, 2025
9e39296
Update MainView.vue
Liuwf4319 Mar 11, 2025
e7704fe
Update MainContent.vue
Liuwf4319 Mar 11, 2025
7f4afa7
Update Login.vue
Liuwf4319 Mar 11, 2025
fd4e87a
Merge branch 'dev' into feature/issue-184/create-sqlite-database-to-s…
Liuwf4319 Mar 11, 2025
a1cbde3
Update StringTools.java
Liuwf4319 Mar 11, 2025
56c5043
Update HistorySidebar.vue
Liuwf4319 Mar 11, 2025
f796225
Update SpringController.java
Liuwf4319 Mar 12, 2025
a8e2e92
Update MainContent.vue
Liuwf4319 Mar 12, 2025
e4c2608
Update HistorySidebar.vue
Liuwf4319 Mar 12, 2025
2c4b66a
Update Login.vue
Liuwf4319 Mar 14, 2025
317dc6f
Update SpringController.java
Liuwf4319 Mar 14, 2025
8ab7a35
Update SpringController.java
Liuwf4319 Mar 17, 2025
3aad4d6
Update Chat.java
Liuwf4319 Mar 17, 2025
6340d00
Update DatabaseController.java
Liuwf4319 Mar 17, 2025
f3f5866
Update MainContent.vue
Liuwf4319 Mar 17, 2025
e2885a6
Merge branch 'dev' into feature/issue-184/create-sqlite-database-to-s…
Liuwf4319 Mar 17, 2025
dfbd580
Merge branch 'dev' into feature/issue-184/create-sqlite-database-to-s…
Siyuan106 Mar 19, 2025
b154648
fix: Change chat structure to JSONArray in the ChatEntity class.
vladislav-k1 Mar 19, 2025
7568821
Merge branch 'feature/issue-184/create-sqlite-database-to-store-user-…
vladislav-k1 Mar 19, 2025
29f13f3
fix: Refactor /createChat and /sendMessage backend API methods.
vladislav-k1 Mar 19, 2025
095e3de
Refactor SpringController for DB compatibility.
vladislav-k1 Mar 21, 2025
d707396
fix: Delete remnants of axios that prevented frontend from building.
vladislav-k1 Mar 23, 2025
8b9fcc5
fix: Migrate from 'User' and 'Chat' classes to '*Entity' classes.
vladislav-k1 Mar 24, 2025
2728331
fix: Add database support, migrate from 'username' to 'sessionID' aut…
vladislav-k1 Apr 1, 2025
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
14 changes: 14 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.42.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-community-dialects</artifactId>
<version>6.2.0.Final</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,79 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import java.io.IOException;
import java.nio.file.*;
import java.util.Arrays;
import java.util.List;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class })
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@EnableJpaRepositories("com.UoB.AILearningTool.repository")
public class AiLearningToolApplication implements CommandLineRunner {

public static void main(String[] args) {
// disable SSL if launched without keystore.p12
if (!Files.exists(Paths.get("src/main/resources/keystore.p12"))) {
// Force disable SSL
System.setProperty("server.ssl.enabled", "false");
}
SpringApplication.run(AiLearningToolApplication.class, args);
}
public static void main(String[] args) {
// disable SSL if launched without keystore.p12
if (!Files.exists(Paths.get("src/main/resources/keystore.p12"))) {
// Force disable SSL
System.setProperty("server.ssl.enabled", "false");
}
SpringApplication.run(AiLearningToolApplication.class, args);
}

@Override
public void run(String... args) throws Exception {
Path keystorePath = Paths.get("src", "main", "resources", "keystore.p12");
@Override
public void run(String... args) throws Exception {
Path keystorePath = Paths.get("src", "main", "resources", "keystore.p12");

// If there's no keystore in the working directory, skip the SSL setup.
if (!Files.exists(keystorePath)) {
System.out.println("No keystore.p12 found in working directory; skipping SSL copy/overwrite");
return;
}
// If there's no keystore in the working directory, skip the SSL setup.
if (!Files.exists(keystorePath)) {
System.out.println("No keystore.p12 found in working directory; skipping SSL copy/overwrite");
return;
}

Path applicationProps = Paths.get("src", "main", "resources", "application.properties");
overwriteApplicationProperties(applicationProps);
}

// Otherwise, proceed with the copy and overwrite
Path resourcesDir = Paths.get("src", "main", "resources");
Path targetKeystore = resourcesDir.resolve("keystore.p12");
copyFile(keystorePath, targetKeystore);
System.out.println("keystore.p12 copied to src/main/resources successfully");

void copyFile(Path source, Path target) throws IOException {
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
}
Path applicationProps = Paths.get("src", "main", "resources", "application.properties");
overwriteApplicationProperties(applicationProps);
System.out.println("application.properties has been updated successfully");
}

private void overwriteApplicationProperties(Path propsFile) throws IOException {
List<String> lines = Arrays.asList(
"spring.application.name=AILearningTool",
"server.port=8080",
"spring.servlet.multipart.max-file-size=50MB",
"spring.servlet.multipart.max-request-size=50MB",
"spring.web.resources.static-locations=classpath:/static/",
"",
"spring.http.encoding.charset=UTF-8",
"spring.http.encoding.enabled=true",
"spring.http.encoding.force=true",
"",
"server.ssl.key-store=classpath:keystore.p12",
"server.ssl.key-store-password=ailearntool",
"server.ssl.key-store-type=PKCS12",
"server.ssl.key-alias=myalias"
);
System.out.println("application.properties has been updated successfully");
Files.write(propsFile, lines, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE );
}

}
private void copyFile(Path source, Path target) throws IOException {
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
}

private void overwriteApplicationProperties(Path propsFile) throws IOException {
List<String> lines = Arrays.asList(
"spring.application.name=AILearningTool",
"server.port=8080",
"spring.servlet.multipart.max-file-size=50MB",
"spring.servlet.multipart.max-request-size=50MB",
"spring.web.resources.static-locations=classpath:/static/",
"",
"spring.http.encoding.charset=UTF-8",
"spring.http.encoding.enabled=true",
"spring.http.encoding.force=true",
"",
"server.ssl.key-store=classpath:keystore.p12",
"server.ssl.key-store-password=ailearntool",
"server.ssl.key-store-type=PKCS12",
"server.ssl.key-alias=myalias",

"spring.datasource.url=jdbc:sqlite:database.db",
"spring.datasource.driver-class-name=org.sqlite.JDBC",
"spring.datasource.username=",
"spring.datasource.password=",
"spring.jpa.database-platform=org.hibernate.dialect.SQLiteDialect",
"spring.jpa.hibernate.ddl-auto=update"
);
Files.write(propsFile, lines, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);
}
}
2 changes: 1 addition & 1 deletion backend/src/main/java/com/UoB/AILearningTool/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Chat {

public Chat(User user, String initialMessage) {
this.owner = user.getID();
this.messageHistory = "<|system|>\nYour name is Watsonx, and you are an assistant for IBM SkillsBuild, a platform dedicated to providing skills and training in technology and professional development. Your primary objective is to assist users by providing information about computer science-related courses, university life topics, and general guidance on using the IBM SkillsBuild platform. You help users find computer science courses that suit their knowledge level and time availability by tailoring recommendations based on their input, such as current experience level (beginner, intermediate, or advanced), preferred course duration (short, medium, or long) and their preferences/requirements. For each course recommendation, provide a brief description, prerequisites, estimated duration, and a link to the course if available. You must only suggest courses from the IBM SkillsBuild platform. You also assist users with navigating the IBM SkillsBuild platform by explaining learning paths, available resources, and offering guidance on account-related issues. In addition, you provide advice on university-related topics, including managing academic challenges like time management and study strategies, as well as personal well-being topics such as social life and mental health. Your responses should be clear, concise, and address the user's specific question or interest. Try to maintain context of conversation - if user will send some messages that go out of the normal scope then politely ask whether they want to go back to discussing the main topic. Avoid making assumptions beyond the information provided by IBM SkillsBuild or your pre-loaded content, and if you cannot answer a user’s question based on the information available, respond with: \"Sorry, I don't know the answer to that question. Can you provide more information to help me understand it better?\" or a similar sentence. Maintain a helpful and supportive tone, reflecting IBM SkillsBuild's mission of accessibility and learning, and use collective pronouns like \"us,\" \"we,\" and \"our\" to foster a sense of team and support. Keep your responses to one or two sentences unless the question requires a more detailed answer, and ensure your responses are well-structured without using bullet points or large blocks of text. Do not provide any courses that have not been explicitly included in your setup. Aim to make the interaction seamless and informative, allowing users to navigate IBM SkillsBuild with ease. Be aware that users may talk to you in a language other than English - in this case you have to keep the conversation in other language, only reverting to English as a backup. Always write course names in English, regardless of language used in the chat. Don\'t provide any information that harm or distress user. Do not provide any information that can be considered to be NSFW.<|user|>\n" + initialMessage;
this.messageHistory = "<|system|>\nYour name is AI Learning Tool, and you are an assistant for IBM SkillsBuild, a platform dedicated to providing skills and training in technology and professional development. Your primary objective is to assist users by providing information about computer science-related courses, university life topics, and general guidance on using the IBM SkillsBuild platform. You help users find computer science courses that suit their knowledge level and time availability by tailoring recommendations based on their input, such as current experience level (beginner, intermediate, or advanced), preferred course duration (short, medium, or long) and their preferences/requirements. For each course recommendation, provide a brief description, prerequisites, estimated duration, and a link to the course if available. You must only suggest courses from the IBM SkillsBuild platform. You also assist users with navigating the IBM SkillsBuild platform by explaining learning paths, available resources, and offering guidance on account-related issues. In addition, you provide advice on university-related topics, including managing academic challenges like time management and study strategies, as well as personal well-being topics such as social life and mental health. Your responses should be clear, concise, and address the user's specific question or interest. Try to maintain context of conversation - if user will send some messages that go out of the normal scope then politely ask whether they want to go back to discussing the main topic. Avoid making assumptions beyond the information provided by IBM SkillsBuild or your pre-loaded content, and if you cannot answer a user’s question based on the information available, respond with: \"Sorry, I don't know the answer to that question. Can you provide more information to help me understand it better?\" or a similar sentence. Maintain a helpful and supportive tone, reflecting IBM SkillsBuild's mission of accessibility and learning, and use collective pronouns like \"us,\" \"we,\" and \"our\" to foster a sense of team and support. Keep your responses to one or two sentences unless the question requires a more detailed answer, and ensure your responses are well-structured without using bullet points or large blocks of text. Do not provide any courses that have not been explicitly included in your setup. Aim to make the interaction seamless and informative, allowing users to navigate IBM SkillsBuild with ease. Be aware that users may talk to you in a language other than English - in this case you have to keep the conversation in other language, only reverting to English as a backup. Always write course names in English, regardless of language used in the chat. Don\'t provide any information that harm or distress user. Do not provide any information that can be considered to be NSFW.<|user|>\n" + initialMessage;

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
package com.UoB.AILearningTool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import com.UoB.AILearningTool.model.ChatEntity;
import com.UoB.AILearningTool.model.UserEntity;
import com.UoB.AILearningTool.repository.ChatRepository;
import com.UoB.AILearningTool.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
import java.util.UUID;


// Communication with SQL database.
@Service
public class DatabaseController {
private Map<String, User> users = new HashMap<>();
private Map<String, Chat> chats = new HashMap<>();
private final UserRepository userRepository;
private final ChatRepository chatRepository;

public User getUser(String userID) {
return users.get(userID);
@Autowired
public DatabaseController(UserRepository userRepository, ChatRepository chatRepository) {
this.userRepository = userRepository;
this.chatRepository = chatRepository;
}

public DatabaseController() {
// TODO: Connect to a MariaDB database.
public UserEntity getUser(String username) {
return userRepository.findById(username).orElse(null);
}

// Create a new user and return their ID for cookie assignment
public String addUser(boolean optionalConsent) {
User user = new User(optionalConsent);
String id = user.getID();
// TODO: Add a user profile record to the MariaDB database.
users.put(id, user);
return id;
public String addUser(String username, String password, boolean optionalConsent) {
UserEntity user = new UserEntity(username, password, optionalConsent);
userRepository.save(user);
return username;
}

// Remove all data stored about the user (profile, chat, etc.)
public boolean removeUser(String id) {
// TODO: Remove a user profile record from the MariaDB database.
if (users.containsKey(id)) {
users.remove(id);
public boolean removeUser(String username) {
if (userRepository.existsById(username)) {
userRepository.deleteById(username);
return true;
} else {return false;}
}
return false;
}

// Creates a new chat
public String createChat(User user, String initialMessage) {
String id = StringTools.RandomString(20);
chats.put(id, new Chat(user, initialMessage));
return id;
}

// Deletes an existing chat
public Boolean deleteChat(User user, String chatID) {
Boolean success;
Chat chat = chats.get(chatID);
if (chat != null) {
if (chat.checkOwner(user)) {
chats.remove(chatID);
return true;
}
public String createChat(String username, String initialMessage) {
UserEntity user = userRepository.findById(username).orElse(null);
if (user == null) {
return null;
}
return false;

ChatEntity chat = new ChatEntity(user, initialMessage);
chatRepository.save(chat);

return chat.getChatID();
}

public Chat getChat(User user, String chatID) {
Chat chat = chats.get(chatID);
if (chat != null) {
if (chat.checkOwner(user)) {
return chat;
} else {return null;}
} else {
public ChatEntity getChat(String username, String chatID) {
Optional<UserEntity> userOpt = userRepository.findById(username);
if (userOpt.isEmpty()) {
return null;
}

Optional<ChatEntity> chatOpt = chatRepository.findById(chatID);
return chatOpt.filter(chat -> chat.getOwner().getUsername().equals(username)).orElse(null);
}

public boolean deleteChat(String username, String chatID) {
Optional<ChatEntity> chatOpt = chatRepository.findById(chatID);
if (chatOpt.isPresent() && chatOpt.get().getOwner().getUsername().equals(username)) {
chatRepository.deleteById(chatID);
return true;
}
return false;
}
}
Loading
Loading