Fakultas Ilmu Komputer UI

Commit 1e66f488 authored by hazlazuardi's avatar hazlazuardi
Browse files

Resolve validateAssignment

parents 5ddd2dca a6238ecc
Pipeline #81931 passed with stages
in 2 minutes and 58 seconds
ga3,st,rpl,2021-06-07,false,st
it1,st,rpl,2020-01-01,true,st,ta
ga3,st,rpl,2021-06-07,true,st,ta
......@@ -4,7 +4,6 @@ import Softeng.Group3.SiJadwal.actor.Role;
import Softeng.Group3.SiJadwal.actor.RoleType;
import Softeng.Group3.SiJadwal.actor.User;
import Softeng.Group3.SiJadwal.model.Assignment;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.repository.*;
import Softeng.Group3.SiJadwal.utility.InputReader;
......@@ -23,7 +22,6 @@ public class Main {
private static TimetableList timetableList = new TimetableList();
private static AssignmentList assignmentList = new AssignmentList();
public static Boolean isRunning = true;
public static Boolean isLoggedIn = false;
......@@ -66,7 +64,6 @@ public class Main {
}
private static void action() {
System.out.println();
System.out.println();
System.out.println("AVAILABLE ACTIONS for " + currentUser.getRole().getRoleName());
......@@ -97,11 +94,8 @@ public class Main {
public static void main(String[] args) {
CSVOperator.InitUsersCourses(userList, courseList, timetableList);
Course dummyCourse = courseList.getCourse("rpl");
Assignment dummyAssignment = new Assignment();
dummyAssignment.setAssignmentName("ga3");
assignmentList.addAssignment("ga3", dummyAssignment);
CSVOperator.InitUsersCourses(userList, courseList, timetableList, assignmentList);
while (isRunning) {
System.out.println("ON-BOARDING");
System.out.println("===============================");
......
......@@ -300,12 +300,12 @@ public class Student extends Role {
Assignment picked = assignmentList.getAssignmentList().get(Integer.parseInt(assignmentPicked) - 1);
System.out.println("Picked: " + picked.getAssignmentName());
System.out.println("Picked: " + picked.getAssignmentName() + " valid: (" + picked.getValidated() + ")");
String courseAssignment = picked.getAssignmentCourse().getCourseName();
String assignmentName = picked.getAssignmentName();
Assignment validated = validateAssignment(courseAssignment, assignmentName);
validateAssignment(picked);
CSVAssignment.verifyAssignmentCsv(validated);
CSVAssignment.verifyAssignmentCsv(picked);
break;
......@@ -314,41 +314,48 @@ public class Student extends Role {
System.out.println("===============================");
System.out.println("Pick an assignment to update: ");
assignmentList.listToString(assignmentList.getAssignmentList());
String[] assignmentsPicked = in.next().split("");
int cnt2 = 1;
for(Assignment s : assignmentList.getAssignmentList()){
System.out.println(cnt2 + ". " + s.getAssignmentName());
cnt2++;
}
String updateAssg = in.next();
System.out.println("Picked: ");
for (String s: assignmentsPicked) {
System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
assignment = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1);
System.out.println("Enter new due date: yyyy-MM-dd");
String updateDate = in.nextLine();
dueDate = LocalDate.parse(updateDate);
assignment.setDueDate(dueDate);
Assignment picked2 = assignmentList.getAssignmentList().get(Integer.parseInt(updateAssg) - 1);
System.out.println("Picked: " + picked2.getAssignmentName());
String courseAssignment2 = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().getCourseName();
String assignmentName2 = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName();
validateAssignment(courseAssignment2, assignmentName2);
System.out.println("Enter new due date: yyyy-MM-dd");
String updateDate = in.nextLine();
dueDate = LocalDate.parse(updateDate);
picked2.setDueDate(dueDate);
CSVAssignment.updateAssignment(picked2);
}
break;
case 16:
System.out.println("Pick an assignment to delete: ");
assignmentsPicked = in.next().split("");
int cnt3 = 1;
for(Assignment s : assignmentList.getAssignmentList()){
System.out.println(cnt3 + ". " + s.getAssignmentName());
cnt3++;
}
String delAssg = in.next();
System.out.println("Picked: ");
for (String s: assignmentsPicked) {
System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().
deleteAssignment(assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1));
assignmentList.deleteAssignment(assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1));
Assignment picked3 = assignmentList.getAssignmentList().get(Integer.parseInt(delAssg) - 1);
System.out.println("Assignment deleted.");
break;
}
System.out.println("Picked: " + picked3.getAssignmentName());
assignmentList.deleteAssignment(picked3);
CSVAssignment.deleteAssignment(picked3.getAssignmentName());
case 17:
System.out.println("Choose which assignment you want to see:");
......@@ -357,10 +364,11 @@ public class Student extends Role {
}
}
private Assignment validateAssignment(String courseName, String assignmentName) {
Assignment toValidate = courseList.getCourse(courseName).getAssignment(assignmentName);
toValidate.addValidatedBy(Main.currentUser);
return toValidate;
private Assignment validateAssignment(Assignment assignment) {
assignment.addValidatedBy(Main.currentUser);
validated = assignment.getValidated();
assignment.setValidated((validated));
return assignment;
}
public HashMap<String, Course> listToHashmap(List<Course> list){
......
......@@ -44,12 +44,11 @@ public class TeachingAssistant extends Role {
}
}
private Assignment validateAssignment(String courseName, String assignmentName) {
Assignment toValidate = courseList.getCourse(courseName).getAssignment(assignmentName);
toValidate.addValidatedBy(Main.currentUser);
validated = toValidate.getValidated();
toValidate.setValidated((validated));
return toValidate;
private Assignment validateAssignment(Assignment assignment) {
assignment.addValidatedBy(Main.currentUser);
validated = assignment.getValidated();
assignment.setValidated((validated));
return assignment;
}
@Override
......@@ -100,7 +99,7 @@ public class TeachingAssistant extends Role {
courseList.getCourseList().get(Integer.parseInt(s) - 1).addAssignment(assignment);
}
validateAssignment(assignment.getAssignmentCourse().getCourseName(), assignmentName);
validateAssignment(assignment);
break;
case 7:
......@@ -126,58 +125,61 @@ public class TeachingAssistant extends Role {
System.out.println("Picked: " + picked.getAssignmentName());
String courseAssignment = picked.getAssignmentCourse().getCourseName();
String assignmentName = picked.getAssignmentName();
validateAssignment(courseAssignment, assignmentName);
validateAssignment(picked);
CSVAssignment.verifyAssignmentCsv(picked);
break;
case 9:
// System.out.println("Update an assignment: ");
// System.out.println("===============================");
//
// System.out.println("Pick an assignment to update: ");
// retrieveAllAssignment();
//
// assignmentsPicked = in.next().split("");
// System.out.println("Picked: ");
// for (String s: assignmentsPicked) {
// System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
// assignment = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1);
//
//
// System.out.println("Enter new due date: yyyy-MM-dd");
// String updateDate = in.nextLine();
// dueDate = LocalDate.parse(updateDate);
// assignment.setDueDate(dueDate);
//
//
// String courseAssignment = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().getCourseName();
// String assignmentName = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName();
// validateAssignment(courseAssignment, assignmentName);
//
// }
System.out.println("Update an assignment: ");
System.out.println("===============================");
System.out.println("Pick an assignment to update: ");
int cnt2 = 1;
for(Assignment s : assignmentList.getAssignmentList()){
System.out.println(cnt2 + ". " + s.getAssignmentName());
cnt2++;
}
String updateAssg = in.next();
System.out.println("Picked: ");
Assignment picked2 = assignmentList.getAssignmentList().get(Integer.parseInt(updateAssg) - 1);
System.out.println("Picked: " + picked2.getAssignmentName());
System.out.println("Enter new due date: yyyy-MM-dd");
String updateDate = in.nextLine();
dueDate = LocalDate.parse(updateDate);
picked2.setDueDate(dueDate);
CSVAssignment.updateAssignment(picked2);
break;
case 10:
// System.out.println("Pick an assignment to delete: ");
// retrieveAllAssignment();
//
// assignmentsPicked = in.next().split("");
// System.out.println("Picked: ");
// for (String s: assignmentsPicked) {
// System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
// assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().
// deleteAssignment(assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1));
//
// assignmentList.deleteAssignment(assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1));
//
// System.out.println("Assignment deleted.");
break;
System.out.println("Pick an assignment to delete: ");
int cnt3 = 1;
for(Assignment s : assignmentList.getAssignmentList()){
System.out.println(cnt3 + ". " + s.getAssignmentName());
cnt3++;
}
// default:
String delAssg = in.next();
System.out.println("Picked: ");
Assignment picked3 = assignmentList.getAssignmentList().get(Integer.parseInt(delAssg) - 1);
System.out.println("Picked: " + picked3.getAssignmentName());
assignmentList.deleteAssignment(picked3);
CSVAssignment.deleteAssignment(picked3.getAssignmentName());
}
}
public HashMap<String, Course> listToHashmap(List<Course> list){
HashMap<String, Course> hashMap = new HashMap<>();
......
......@@ -37,7 +37,8 @@ public class AssignmentList {
public void listToString(List<Assignment> assignmentList){
int i = 1;
for (Assignment assignment: assignmentList) {
System.out.println(i + ". " + assignment.getAssignmentName());
System.out.println(i + ". " + assignment.getAssignmentName() +"\n" +
"\s valid: " + assignment.getValidated());
i++;
}
}
......
......@@ -76,6 +76,35 @@ public class CSVAssignment {
}
}
public static void updateAssignment(Assignment assg){
try{
BufferedReader check = new BufferedReader(new FileReader("Assignments.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] assgWritten = row.split(",");
if((assgWritten[0].equalsIgnoreCase(assg.getAssignmentName()) && assgWritten[2].equalsIgnoreCase(assg.getAssignmentCourse().getCourseName()))){
assgWritten[3] = assg.getDueDate().toString();
}
newList.add(assgWritten[0]);
for(int i = 1; i < assgWritten.length; i++) {
newList.add(",");
newList.add(assgWritten[i]);
}
newList.add("\n");
} check.close();
FileWriter reader = new FileWriter("Assignments.csv");
for (String s : newList) {
reader.append(s);
}reader.flush();
reader.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
public static void deleteAssignment(String name){
try{
BufferedReader check = new BufferedReader(new FileReader("Assignments.csv"));
......
......@@ -2,12 +2,15 @@ package Softeng.Group3.SiJadwal.repository;
import java.io.*;
import java.sql.Time;
import java.time.LocalDate;
import Softeng.Group3.SiJadwal.actor.RoleType;
import Softeng.Group3.SiJadwal.model.Assignment;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.model.Timetable;
public class CSVOperator {
public static void InitUsersCourses(UserList userlist, CourseList courselist, TimetableList timetableList){
public static void InitUsersCourses(UserList userlist, CourseList courselist, TimetableList timetableList, AssignmentList assignmentList){
try{
BufferedReader check = new BufferedReader(new FileReader("Users.csv"));
String row;
......@@ -39,6 +42,25 @@ public class CSVOperator {
timetableList.addTimetable(tables[0], newTable);
}
check.close();
check = new BufferedReader(new FileReader("Assignments.csv"));
while((row = check.readLine()) != null){
String[] assgs;
assgs = row.split(",");
Assignment newAssg = new Assignment();
newAssg.setAssignmentName(assgs[0]);
newAssg.setCreatedBy(userlist.getUser(assgs[1]));
newAssg.setAssignmentCourse(courselist.getCourse(assgs[2]));
String[] date = assgs[3].split("-");
newAssg.setDueDate(LocalDate.of(Integer.parseInt(date[0]), Integer.parseInt(date[1]), Integer.parseInt(date[2])));
newAssg.setValidated(Boolean.valueOf(assgs[4]));
for(int i = 5; i < assgs.length; i++){
newAssg.addValidatedBy(userlist.getUser(assgs[i]));
}
assignmentList.addAssignment(newAssg.getAssignmentName(), newAssg);
}
check.close();
}
catch (IOException e) {
System.out.println("File not found.");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment