Fakultas Ilmu Komputer UI

Commit 245e1117 authored by saddamonpc's avatar saddamonpc
Browse files

Add the ability for User to register, Admin to set coordinator role and see...

Add the ability for User to register, Admin to set coordinator role and see TA's calendar with permission
parent 0e6d715a
Pipeline #81643 passed with stage
in 3 minutes and 22 seconds
......@@ -160,6 +160,57 @@ public class Main {
// If we reach here, that means we found the user, and we are now logged in.
AdminCLI.main(new String[]{searchUsername});
break;
case "REGISTER":
System.out.println("(S)tudent / (T)eaching Assistant / (A)dmin?");
String newUsername;
String newFullname;
Long newNPM;
switch (sc.nextLine()) {
case "S":
System.out.println("Enter your username:");
newUsername = sc.nextLine();
System.out.println("Enter your full name:");
newFullname = sc.nextLine();
System.out.println("Enter your NPM:");
newNPM = Long.parseLong(sc.nextLine());
new Student(newUsername, newFullname, newNPM, userList);
System.out.println("Successfully registered " + newUsername + " as a Student!");
// Save the new user
ListIO.saveList(courseList, userList);
break;
case "T":
System.out.println("Enter your username:");
newUsername = sc.nextLine();
System.out.println("Enter your full name:");
newFullname = sc.nextLine();
System.out.println("Enter your NPM:");
newNPM = Long.parseLong(sc.nextLine());
new TeachingAssistant(newUsername, newFullname, newNPM, userList);
System.out.println("Successfully registered " + newUsername + " as a Teaching Assistant!");
// Save the new user
ListIO.saveList(courseList, userList);
break;
case "A":
System.out.println("Enter your username:");
newUsername = sc.nextLine();
System.out.println("Enter your full name:");
newFullname = sc.nextLine();
new Admin(newUsername, newFullname, userList);
System.out.println("Successfully registered " + newUsername + " as an Admin!");
// Save the new user
ListIO.saveList(courseList, userList);
break;
default:
System.out.println("Wrong input!");
break;
}
}
}
}
......@@ -168,6 +219,7 @@ public class Main {
public static void intro() {
System.out.println("Welcome to Teaching Assistant Student Connector (TASC) program by Group G4");
System.out.println("Type 'EXIT' to exit.");
System.out.println("Type REGISTER to register as a Student / Teaching Assistant / Admin.");
System.out.println("Login as (S)tudent <username> / (T)eaching Assistant <username> / (A)dmin <username> ?");
System.out.println();
}
......
......@@ -14,11 +14,6 @@ public class Appointment implements Serializable {
private String startTime;
private String endTime;
private String description;
public String getStatus() {
return status;
}
private String status;
public Appointment(String date, Student student, TeachingAssistant ta, String startTime, String endTime, String description) {
......@@ -32,18 +27,6 @@ public class Appointment implements Serializable {
this.status = "Pending";
}
public String getId (){
return id;
}
public void setStatus (String newstatus){
this.status = newstatus;
}
public Student getStudent() {
return student;
}
public String generateId(){
int leftLimit = 65; // letter 'A'
int rightLimit = 90; // letter 'Z'
......@@ -58,15 +41,26 @@ public class Appointment implements Serializable {
String generatedString = buffer.toString();
return generatedString;
}
// public Schedule(String startTime, String endTime) {
// this.name = "Free";
// this.startTime = startTime;
// this.endTime = endTime;
// }
public String toString() {
return "ID: " + id + "\nDate: " + date + "\nStudent: " + student.getUsername() + "\nTA: " + ta.getUsername() + "\nStart Time : " + startTime + "\nEnd Time: " + endTime + "\nDescription: " + description + "\nStatus: " + status;
//return date + student + " " + ta + " " + startTime + " - " + endTime + " " + description + status;
}
public String getId (){
return id;
}
public Student getStudent() {
return student;
}
public String getStatus() {
return status;
}
public void setStatus (String newstatus){
this.status = newstatus;
}
}
......@@ -13,6 +13,7 @@ public class Calendar implements Serializable {
private ArrayList<Schedule> friday = new ArrayList<Schedule>();
private ArrayList<Schedule> saturday = new ArrayList<Schedule>();
private ArrayList<Schedule> sunday = new ArrayList<Schedule>();
private boolean adminPermission = false;
public void showCalendar() {
System.out.println("Monday:");
......@@ -111,4 +112,17 @@ public class Calendar implements Serializable {
return sunday;
}
public boolean isAdminPermission() {
return adminPermission;
}
// Switches to allow / deny Admin to see Calendar
public void switchPermission() {
if (this.adminPermission) {
this.adminPermission = false;
} else {
this.adminPermission = true;
}
}
}
......@@ -46,7 +46,7 @@ public class AdminCLI extends CLI {
System.out.println("Choose SKS: ");
int sks = Integer.valueOf(sc.nextLine());
new Course(name, courseId, professor, sks, courseList);
System.out.println("Sucessfully added a new course!");
System.out.println("Successfully added a new course!");
break;
case "COURSE DETAILS":
......@@ -60,13 +60,30 @@ public class AdminCLI extends CLI {
break;
case "ASSIGN TA":
System.out.println("Input TA's username: ");
String qTA = sc.nextLine();
System.out.println("Input courseId: ");
String qCourse = sc.nextLine();
System.out.println("Input TA's username: ");
String qTA = sc.nextLine();
currentAdmin.setCourseTA(userList.searchTA(qTA), courseList.searchCourse(qCourse));
break;
case "SET COORDINATOR":
System.out.println("Input courseId:");
Course theCourse = courseList.searchCourse(sc.nextLine());
System.out.println("Input TA's username you want to set as the coordinator role:");
theCourse.setCoordinatorRole(sc.nextLine());
break;
case "CALENDAR":
System.out.println("Enter TA's Username: ");
currentAdmin.seeCalendar(sc.nextLine(), userList);
break;
case "ASK PERMISSION":
System.out.println("Input TA's username:");
currentAdmin.askPermission(sc.nextLine(), userList);
break;
case "LOG OUT":
break;
......@@ -87,6 +104,9 @@ public class AdminCLI extends CLI {
System.out.println("ADD COURSE \t\t\t Add new course.");
System.out.println("COURSE DETAILS \t\t See course details with the right courseId.");
System.out.println("ASSIGN TA \t\t\t Assign TA to a course.");
System.out.println("SET COORDINATOR \t Assign a current TA responsible for a course as a coordinator role.");
System.out.println("CALENDAR \t\t\t See a TA's calendar.");
System.out.println("ASK PERMISSION \t\t Ask a TA to see their calendar.");
System.out.println();
}
......
......@@ -44,14 +44,13 @@ public class StudentCLI extends CLI {
break;
case "APPOINTMENTS":
for (Appointment appointment : currentStudent.appointmentlist) {
for (Appointment appointment : currentStudent.appointmentList) {
System.out.println(appointment);
System.out.println();
}
break;
case "CALENDAR":
// TODO: Make this such that users can see TA's calendar by inputting their username
System.out.println("Enter TA's Username: ");
currentStudent.seeCalendar(sc.nextLine(), userList);
break;
......
......@@ -18,6 +18,9 @@ public class TACLI extends CLI {
intro(currentTA);
// Prints notification for an admin asking permission to see calendar, if there's one.
currentTA.getAskPermissionAdmin();
while (!q.equals("LOG OUT")) {
// Saves the list everytime the user is in the "Main menu"
ListIO.saveList(courseList, userList);
......@@ -50,7 +53,7 @@ public class TACLI extends CLI {
System.out.println("Sucessfully added a new schedule!");
case "APPOINTMENTS":
for (Appointment appointment : currentTA.appointmentlist) {
for (Appointment appointment : currentTA.appointmentList) {
System.out.println(appointment);
System.out.println();
}
......@@ -66,6 +69,15 @@ public class TACLI extends CLI {
currentTA.rejectAppointment(sc.nextLine(), userList);
break;
case "SET PERMISSION":
currentTA.switchPermission();
if (currentTA.getCalendar().isAdminPermission()) {
System.out.println("Your calendar is now viewable to all Admins!");
} else {
System.out.println("Your calendar is now private.");
}
break;
case "LOG OUT":
break;
......@@ -86,8 +98,9 @@ public class TACLI extends CLI {
System.out.println("COURSELIST \t\t\t See all courses.");
System.out.println("ADD SCHEDULE \t\t Add new schedule.");
System.out.println("APPOINTMENTS \t\t See all your appointments.");
System.out.println("ACCEPT APPOINTMENT \t\t Appointment you want to accept.");
System.out.println("REJECT APPOINTMENT \t\t Appointment you want to reject.");
System.out.println("ACCEPT APPOINTMENT \t Appointment you want to accept.");
System.out.println("REJECT APPOINTMENT \t Appointment you want to reject.");
System.out.println("SET PERMISSION \t\t Allow / deny Admins to see your schedule.");
System.out.println();
}
......
......@@ -13,6 +13,7 @@ public class Course implements Serializable {
private ArrayList<TeachingAssistant> teachingAssistants = new ArrayList<TeachingAssistant>();
private String professor;
private int sks;
private int coordinatorRoleIndex;
private boolean adminPermission;
// Constructor
......@@ -37,10 +38,30 @@ public class Course implements Serializable {
System.out.println("Professor: " + professor);
System.out.println("SKS: " + sks);
System.out.println("Responsible TA(s):");
for (TeachingAssistant ta : teachingAssistants) System.out.println(ta);
for (int i = 0; i < teachingAssistants.size(); i++) {
TeachingAssistant currentTA = teachingAssistants.get(i);
if (i == coordinatorRoleIndex) {
System.out.println(currentTA + " (Coordinator)");
} else {
System.out.println(currentTA);
}
}
System.out.println();
}
public void setCoordinatorRole(String username) {
boolean found = false;
for (int i = 0; i < teachingAssistants.size(); i++) {
if (teachingAssistants.get(i).getUsername().equals(username)) {
this.coordinatorRoleIndex = i;
found = true;
System.out.println("Successfully set Teaching Assistant " + username + " role as a coordinator.");
break;
}
}
if (found == false) System.out.println("Wrong username!");
}
public String getCourseId() {
return courseId;
}
......
......@@ -18,9 +18,6 @@ public class Admin extends User {
userList.userList.add(this);
}
// TODO: Change the role of the teaching assistant to something else? (needs to be discussed)
public void assignRole(TeachingAssistant ta) {}
// Assign TA to the course
public void setCourseTA(TeachingAssistant ta, Course course) {
if (ta.getUsername().equals("falseTA") || course.getCourseId().equals("FALSECOURSE")) {
......@@ -32,11 +29,6 @@ public class Admin extends User {
System.out.println();
}
// Create course
public void createCourse(String name, String courseId, String professor, int sks, CourseList courseList) {
new Course(name, courseId, professor, sks, courseList);
}
// See all courses
public void seeCourseList(CourseList courseList) {
courseList.showCourseList();
......@@ -57,10 +49,24 @@ public class Admin extends User {
}
// TODO: Iteration 3 - Admin can see the appointment, if appointment has the permission true
public void seeAppointment(Appointment ap) {}
public void seeAppointment(Appointment ap) {
}
public void askPermission(String username, UserList userList) {
TeachingAssistant searchedTA = userList.searchTA(username);
searchedTA.setAskPermissionAdmin(this);
System.out.println("You have successfully asked " + searchedTA.getUsername() + " to see their calendar!");
}
// TODO: Iteration 3 - Admin can see the TA's calendar, if calendar has the permission true
public void seeCalendar(TeachingAssistant ta) {}
public void seeCalendar(String username, UserList userList) {
TeachingAssistant searchedTA = userList.searchTA(username);
if (searchedTA.getCalendar().isAdminPermission()) {
searchedTA.getCalendar().showCalendar();
} else {
System.out.println("You don't have permission to see " + username + "'s calendar!");
}
}
public String toString() {
return username + " - " + fullname;
......
......@@ -11,7 +11,7 @@ public class Student extends UserStudent {
private String fullname;
private String role;
private long npm;
public ArrayList<Appointment> appointmentlist = new ArrayList<Appointment>();
public ArrayList<Appointment> appointmentList = new ArrayList<Appointment>();
// Constructor
......@@ -33,8 +33,8 @@ public class Student extends UserStudent {
} else {
Appointment newAppointment = new Appointment(date, this, ta, startTime, endTime, description);
//this.calendar.addAppointment(day, newAppointment);
this.appointmentlist.add(newAppointment);
ta.appointmentlist.add(newAppointment);
this.appointmentList.add(newAppointment);
ta.appointmentList.add(newAppointment);
}
}
......
......@@ -12,8 +12,9 @@ public class TeachingAssistant extends UserStudent {
private String fullname;
private String role;
private long npm;
private Admin askPermissionAdmin = null;
private Calendar calendar = new Calendar();
public ArrayList<Appointment> appointmentlist = new ArrayList<Appointment>();
public ArrayList<Appointment> appointmentList = new ArrayList<Appointment>();
// Constructor
public TeachingAssistant(String username, String fullname, long npm, UserList userList) {
......@@ -45,45 +46,66 @@ public class TeachingAssistant extends UserStudent {
// TODO: Implement these 2 methods such that they can change the status of the appointment to accepted or rejected
public void acceptAppointment(String id, UserList userList) {
boolean found = false;
for(Appointment appointment : appointmentlist){
if (appointment.getId().equals(id)){
for (Appointment appointment : appointmentList) {
if (appointment.getId().equals(id)) {
found = true;
appointment.setStatus("Accepted");
Student student = userList.searchStudent(appointment.getStudent().getUsername());
for(Appointment studentappointment: student.appointmentlist){
if (studentappointment.getId().equals(id)){
for (Appointment studentappointment : student.appointmentList) {
if (studentappointment.getId().equals(id)) {
studentappointment.setStatus("Accepted");
}
}
}
}
if(found == false){
if (found == false) {
System.out.println("Appointment not found");
}else{
} else {
System.out.println("Appointment with ID " + id + " has been accepted");
}
}
public void rejectAppointment(String id, UserList userList) {
boolean found = false;
for(Appointment appointment : appointmentlist){
if (appointment.getId().equals(id)){
for (Appointment appointment : appointmentList) {
if (appointment.getId().equals(id)) {
found = true;
appointment.setStatus("Rejected");
Student student = userList.searchStudent(appointment.getStudent().getUsername());
for(Appointment studentappointment: student.appointmentlist){
if (studentappointment.getId().equals(id)){
for (Appointment studentappointment : student.appointmentList) {
if (studentappointment.getId().equals(id)) {
studentappointment.setStatus("Rejected");
}
}
}
}
if(found == false){
if (found == false) {
System.out.println("Appointment not found.");
}else{
} else {
System.out.println("Appointment with ID " + id + " has been rejected.");
}
}
// Everytime this method is invoked, askPermissionAdmin will be updated to null
public void getAskPermissionAdmin() {
if (this.askPermissionAdmin != null) {
System.out.println();
System.out.println("ALERT!");
System.out.println(
"Admin " + this.askPermissionAdmin.getUsername() + " wants permission to see your calendar!");
System.out.println();
this.askPermissionAdmin = null;
}
}
public void setAskPermissionAdmin(Admin askPermissionAdmin) {
this.askPermissionAdmin = askPermissionAdmin;
}
public void switchPermission() {
this.calendar.switchPermission();
}
public String toString() {
return username + " - " + fullname;
}
......
package softeng.g4.user;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import softeng.g4.course.CourseList;
import static org.junit.jupiter.api.Assertions.*;
class AdminTest {
private UserList userList;
private CourseList courseList;
private Admin testAdmin;
private TeachingAssistant testTa;
private Student testStudent;
@BeforeEach
void setUpTearDown() {
userList = new UserList();
courseList = new CourseList();
testAdmin = new Admin("falseAdmin", "False Admin", userList);
testTa = new TeachingAssistant("testTa",
"Test Teacher", Long.parseLong("123456789"), userList);
testStudent = new Student("testStudent",
"Test Student", Long.valueOf("123456789"), userList);
}
@Test
void assignRole() {
}
@Test
void setCourseTA() {
}
@Test
void createCourse() {
}
@Test
void seeCourseList() {
}
@Test
void getUserList() {
}
@Test
void seeAppointment() {
}
@Test
void seeCalendar() {
}
@Test
void testToString() {
}
@Test
void getRole() {
}
@Test
void getUsername() {
}
}
\ No newline at end of file
......@@ -54,6 +54,12 @@ class TeachingAssistantTest {
// After this all System.out.println() statements will come to outContent stream.
testTa.setSchedule("monday", "Busy", "07:00", "21:00");
testTa.setSchedule("tuesday", "Busy", "07:00", "21:00");
testTa.setSchedule("wednesday", "Busy", "07:00", "21:00");
testTa.setSchedule("thursday", "Busy", "07:00", "21:00");
testTa.setSchedule("friday", "Busy", "07:00", "21:00");
testTa.setSchedule("saturday", "Busy", "07:00", "21:00");
testTa.setSchedule("sunday", "Busy", "07:00", "21:00");
testTa.seeCalendar();
......@@ -64,11 +70,17 @@ class TeachingAssistantTest {
"Monday:" +
"Busy 07:00 - 21:00" +
"Tuesday:" +
"Busy 07:00 - 21:00" +
"Wednesday:" +
"Busy 07:00 - 21:00" +
"Thursday:" +
"Busy 07:00 - 21:00" +
"Friday:" +
"Busy 07:00 - 21:00" +
"Saturday:" +
"Sunday:";
"Busy 07:00 - 21:00" +
"Sunday:" +
"Busy 07:00 - 21:00";
assertEquals(expectedOutput, outContentEdit);
}
......@@ -77,18 +89,18 @@ class TeachingAssistantTest {
void acceptAppointment() {
testStudent.setAppointment(
"31/12", "testTa", "08:00", "09:40", "testDesc", userList);
testTa.acceptAppointment(testTa.appointmentlist.get(0).getId(), userList);
assertEquals(testTa.appointmentlist.get(0).getStatus(), "Accepted");
assertEquals(testStudent.appointmentlist.get(0).getStatus(),"Accepted");
testTa.acceptAppointment(testTa.appointmentList.get(0).getId(), userList);
assertEquals(testTa.appointmentList.get(0).getStatus(), "Accepted");
assertEquals(testStudent.appointmentList.get(0).getStatus(),"Accepted");
}
@Test
void rejectAppointment() {
testStudent.setAppointment(
"31/12", "testTa", "08:00", "09:40", "testDesc", userList);
testTa.rejectAppointment(testTa.appointmentlist.get(0).getId(), userList);
assertEquals(testTa.appointmentlist.get(0).getStatus(), "Rejected");
assertEquals(testStudent.appointmentlist.get(0).getStatus(),"Rejected");
testTa.rejectAppointment(testTa.appointmentList.get(0).getId(), userList);
assertEquals(testTa.appointmentList.get(0).getStatus(), "Rejected");
assertEquals(testStudent.appointmentList.get(0).getStatus(),"Rejected");
}