Fakultas Ilmu Komputer UI

Commit 5ddd2dca authored by hazlazuardi's avatar hazlazuardi
Browse files

Validate not working

parents 4cb87ef6 e25589ee
ga3,st,rpl,2021-06-07,false,st
admin,Admin
st,Student
ta,Teaching Assistant
\ No newline at end of file
ta,Teaching Assistant
......@@ -3,10 +3,9 @@ package Softeng.Group3.SiJadwal;
import Softeng.Group3.SiJadwal.actor.Role;
import Softeng.Group3.SiJadwal.actor.RoleType;
import Softeng.Group3.SiJadwal.actor.User;
import Softeng.Group3.SiJadwal.repository.CSVOperator;
import Softeng.Group3.SiJadwal.repository.CourseList;
import Softeng.Group3.SiJadwal.repository.TimetableList;
import Softeng.Group3.SiJadwal.repository.UserList;
import Softeng.Group3.SiJadwal.model.Assignment;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.repository.*;
import Softeng.Group3.SiJadwal.utility.InputReader;
import java.io.*;
......@@ -22,6 +21,7 @@ public class Main {
public static UserList userList = new UserList();
private static CourseList courseList = new CourseList();
private static TimetableList timetableList = new TimetableList();
private static AssignmentList assignmentList = new AssignmentList();
public static Boolean isRunning = true;
......@@ -66,6 +66,7 @@ public class Main {
}
private static void action() {
System.out.println();
System.out.println();
System.out.println("AVAILABLE ACTIONS for " + currentUser.getRole().getRoleName());
......@@ -97,7 +98,10 @@ 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);
while (isRunning) {
System.out.println("ON-BOARDING");
System.out.println("===============================");
......
......@@ -40,6 +40,7 @@ public class Student extends Role {
System.out.println("14. Validate assignments");
System.out.println("15. Update an assignments");
System.out.println("16. Delete an assignments");
System.out.println("17. See an assignment information");
}
@Override
......@@ -271,6 +272,8 @@ public class Student extends Role {
assignment.setCreatedBy(Main.currentUser);
assignmentList.addAssignment(assignmentName, assignment);
CSVAssignment.writeAssignment(assignment);
for (String s: coursesPicked) {
courseList.getCourseList().get(Integer.parseInt(s) - 1).addAssignment(assignment);
}
......@@ -288,15 +291,22 @@ public class Student extends Role {
case 14:
System.out.println("Pick the assignment that you want to validate:");
assignmentList.listToString(assignmentList.getAssignmentList());
String[] assignmentsPicked = in.next().split(" ");
System.out.println("Picked: ");
for (String s: assignmentsPicked) {
System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
String courseAssignment = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().getCourseName();
String assignmentName = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName();
validateAssignment(courseAssignment, assignmentName);
int cnt = 1;
for(Assignment s : assignmentList.getAssignmentList()){
System.out.println(cnt + ". " + s.getAssignmentName());
cnt++;
}
String assignmentPicked = in.next();
Assignment picked = assignmentList.getAssignmentList().get(Integer.parseInt(assignmentPicked) - 1);
System.out.println("Picked: " + picked.getAssignmentName());
String courseAssignment = picked.getAssignmentCourse().getCourseName();
String assignmentName = picked.getAssignmentName();
Assignment validated = validateAssignment(courseAssignment, assignmentName);
CSVAssignment.verifyAssignmentCsv(validated);
break;
case 15:
......@@ -305,7 +315,7 @@ public class Student extends Role {
System.out.println("Pick an assignment to update: ");
assignmentList.listToString(assignmentList.getAssignmentList());
assignmentsPicked = in.next().split("");
String[] assignmentsPicked = in.next().split("");
System.out.println("Picked: ");
for (String s: assignmentsPicked) {
System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
......@@ -317,9 +327,9 @@ public class Student extends Role {
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);
String courseAssignment2 = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().getCourseName();
String assignmentName2 = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName();
validateAssignment(courseAssignment2, assignmentName2);
}
break;
......@@ -340,13 +350,17 @@ public class Student extends Role {
break;
}
case 17:
System.out.println("Choose which assignment you want to see:");
assignmentList.listToString(assignmentList.getAssignmentList());
default:
}
}
private void validateAssignment(String courseName, String assignmentName) {
private Assignment validateAssignment(String courseName, String assignmentName) {
Assignment toValidate = courseList.getCourse(courseName).getAssignment(assignmentName);
toValidate.addValidatedBy(Main.currentUser);
return toValidate;
}
public HashMap<String, Course> listToHashmap(List<Course> list){
......
......@@ -5,6 +5,7 @@ import Softeng.Group3.SiJadwal.model.Assignment;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.model.Timetable;
import Softeng.Group3.SiJadwal.repository.AssignmentList;
import Softeng.Group3.SiJadwal.repository.CSVAssignment;
import Softeng.Group3.SiJadwal.repository.CourseList;
import Softeng.Group3.SiJadwal.repository.TimetableList;
......@@ -113,64 +114,70 @@ public class TeachingAssistant extends Role {
case 8:
System.out.println("Pick the assignment that you want to validate:");
retrieveAllAssignment();
String[] assignmentsPicked = in.next().split("");
System.out.println("Picked: ");
for (String s: assignmentsPicked) {
System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
String courseAssignment = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().getCourseName();
String assignmentName = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName();
validateAssignment(courseAssignment, assignmentName);
int cnt = 1;
for(Assignment s : assignmentList.getAssignmentList()){
System.out.println(cnt + ". " + s.getAssignmentName());
cnt++;
}
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);
String assignmentPicked = in.next();
Assignment picked = assignmentList.getAssignmentList().get(Integer.parseInt(assignmentPicked) - 1);
System.out.println("Enter new due date: yyyy-MM-dd");
String updateDate = in.nextLine();
dueDate = LocalDate.parse(updateDate);
assignment.setDueDate(dueDate);
System.out.println("Picked: " + picked.getAssignmentName());
String courseAssignment = picked.getAssignmentCourse().getCourseName();
String assignmentName = picked.getAssignmentName();
validateAssignment(courseAssignment, assignmentName);
CSVAssignment.verifyAssignmentCsv(picked);
String courseAssignment = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().getCourseName();
String assignmentName = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName();
validateAssignment(courseAssignment, assignmentName);
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);
//
// }
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.");
// 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;
}
default:
// default:
}
}
public HashMap<String, Course> listToHashmap(List<Course> list){
HashMap<String, Course> hashMap = new HashMap<>();
......
package Softeng.Group3.SiJadwal.repository;
import Softeng.Group3.SiJadwal.actor.User;
import Softeng.Group3.SiJadwal.model.Assignment;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Time;
import java.time.LocalDate;
import java.util.*;
public class CSVAssignment {
public static void writeAssignment(Assignment assg) {
try{
FileWriter reader = new FileWriter("Assignments.csv", true);
BufferedReader check = new BufferedReader(new FileReader("Assignments.csv"));
String row;
HashMap<String, String> coursesCSV = new HashMap<>();
while((row = check.readLine()) != null){
String[] usersWritten;
usersWritten = row.split(",");
coursesCSV.put(usersWritten[0], usersWritten[1]);
}
if(!coursesCSV.containsKey(assg.getAssignmentName())){
reader.append(assg.getAssignmentName()).append(",")
.append(assg.getCreatedBy().getUsername()).append(",")
.append(assg.getAssignmentCourse().getCourseName()).append(",")
.append(assg.getDueDate().toString()).append(",")
.append(assg.getValidated().toString());
for(User s : assg.getValidatedBy()){
reader.append(",").append(s.getUsername());
}reader.append("\n");
}
reader.flush();
reader.close();
check.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
public static void verifyAssignmentCsv(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[4] = assg.getValidated().toString();
}
newList.add(assgWritten[0]);
for(int i = 1; i < 5; i++) {
newList.add(",");
newList.add(assgWritten[i]);
}
for(User s : assg.getValidatedBy()){
newList.add(",");
newList.add(s.getUsername());
}
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"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] courseWritten = row.split(",");
if(!courseWritten[0].equalsIgnoreCase(name)){
newList.add(courseWritten[0]);
for(int i = 1; i < courseWritten.length; i++) {
newList.add(",");
newList.add(courseWritten[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();
}
}
}
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