Skip to content

Commit

Permalink
renamed screens package to match use case package, further debugging …
Browse files Browse the repository at this point in the history
…not qqc ne fonctionne pas
  • Loading branch information
jltng committed Dec 1, 2022
1 parent abbe8cf commit ce38791
Show file tree
Hide file tree
Showing 23 changed files with 205 additions and 116 deletions.
42 changes: 42 additions & 0 deletions src/main/java/CourseCreationMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import entities.CourseMap;
import screens.course_features.*;
import use_cases.course_features.course_creation_use_case.CourseCreationDsGateway;
import use_cases.course_features.course_creation_use_case.CourseCreationInputBoundary;
import use_cases.course_features.course_creation_use_case.CourseCreationInteractor;
import use_cases.course_features.course_creation_use_case.CourseCreationOutputBoundary;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

public class CourseCreationMain {
public static void main(String[] args) {

// Build the main program window
JFrame application = new JFrame("Course Creation Example!");
CardLayout cardLayout = new CardLayout();
JPanel screens = new JPanel(cardLayout);
application.add(screens);

// Create parts to plug into use case + entities engine
CourseCreationDsGateway course;
try {
course = new FileCourse("courses.ser");
// course = new InMemoryCourse();
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException("Could not create file.");
}

CourseCreationOutputBoundary presenter = new CourseCreationPresenter();
CourseMap courseMap = new CourseMap();
CourseCreationInputBoundary interactor = new CourseCreationInteractor(course, presenter, courseMap);
CourseCreationController controller = new CourseCreationController(interactor);

// Build the GUI, plugging in the parts
CourseCreationScreen createScreen = new CourseCreationScreen(controller, screens, cardLayout);
screens.add(createScreen, "Create a new course");
cardLayout.show(screens, "create a new course");
application.pack();
application.setVisible(true);
}
}
40 changes: 40 additions & 0 deletions src/main/java/CourseEnrolmentMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import entities.CourseMap;
import screens.course_features.*;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentDsGateway;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentInputBoundary;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentInteractor;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentOutputBoundary;

import javax.swing.*;
import java.awt.*;

public class CourseEnrolmentMain {
public static void main(String[] args) {

// Build the main program window
JFrame application = new JFrame("Course Enrolment Example!");
CardLayout cardLayout = new CardLayout();
JPanel screens = new JPanel(cardLayout);
application.add(screens);

// Create parts to plug into use case + entities engine
CourseEnrolmentDsGateway course = null;

CourseEnrolmentOutputBoundary presenter = new CourseEnrolmentPresenter();

// not to be initialized, for the sake of running only
CourseMap courseMap = new CourseMap();
// not to be initialized, for the sake of running only

CourseEnrolmentInputBoundary interactor = new CourseEnrolmentInteractor(
course, presenter, courseMap, "studentid");
CourseEnrolmentController controller = new CourseEnrolmentController(interactor);

// Build GUI, plug in parts
CourseEnrolmentScreen enrolmentScreen = new CourseEnrolmentScreen(controller);
screens.add(enrolmentScreen, "Enrol in a course");
cardLayout.show(screens, "enrol in course");
application.pack();
application.setVisible(true);
}
}
6 changes: 0 additions & 6 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@
import screens.*;
import screens.calendar_scheduler.*;
import screens.course_progress.*;
import screens.courses_features.*;
import screens.login_registration.*;
import screens.task_management.event_creation_screens.*;
import use_cases.course_features.course_creation_use_case.*;
import use_cases.course_tracker.progress_tracker_use_case.*;
import screens.collaborative_task_scheduling.*;
import use_cases.collaborative_task_scheduling.scheduling_ct_use_case.*;
import use_cases.calendar_scheduler.schedule_conflict_use_case.ScheduleConflictPresenter;
import use_cases.calendar_scheduler.scheduler_use_case.SchedulerPresenter;
import use_cases.login_registration.user_register_usecase.*;
import use_cases.task_management.event_creation_use_case.*;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.HashMap;

public class Main {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

import use_cases.course_features.course_creation_use_case.CourseCreationInputBoundary;
import use_cases.course_features.course_creation_use_case.CourseCreationRequestModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

public class CourseCreationFailed extends RuntimeException {
public CourseCreationFailed(String error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

// Interface adapters layer

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

// Framework / Drivers layer

Expand Down Expand Up @@ -77,23 +77,24 @@ public CourseCreationScreen(CourseCreationController controller, JPanel screens,

/**
* React to a button click which triggers the corresponding use case
* NEED TO FIX THIS!!!
*/
@Override
public void actionPerformed(ActionEvent evt) {
// instructor decides to cancel the course creation process
if (evt.getActionCommand().equals("Cancel")) {
screenLayout.show(screens, "main");
} else if (evt.getActionCommand().equals("Save")) {
try {
// try {
// initialize new Arraylist and add task
ArrayList<String> tasks = new ArrayList<>();
tasks.add(taskName.getText());
courseCreationController.create(courseName.getText(), courseInstructor.getText(),
tasks);
JOptionPane.showMessageDialog(this, "Course successful created.");
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
// } catch (Exception e) {
// JOptionPane.showMessageDialog(this, e.getMessage());
// }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentInputBoundary;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentRequestModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

public class CourseEnrolmentFailed extends RuntimeException {
public CourseEnrolmentFailed(String error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

// Interfaces adapters layer

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

// Framework/Drivers layer

Expand All @@ -8,7 +8,6 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class CourseEnrolmentScreen extends JPanel implements ActionListener {
/** student enters course name */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

// Framework/Driver layer

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package screens.courses_features;
package screens.course_features;

import use_cases.course_features.course_creation_use_case.CourseCreationDsGateway;
import use_cases.course_features.course_creation_use_case.CourseCreationRequestModel;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentDsGateway;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentRequestModel;

import java.io.*;
import java.util.ArrayList;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

public class FileCourse implements CourseCreationDsGateway {
public class FileCourse implements CourseCreationDsGateway, CourseEnrolmentDsGateway {
/**
* is this supposed to be String to Request Model OR String to Course
*/
Expand All @@ -20,8 +23,17 @@ public class FileCourse implements CourseCreationDsGateway {
* @param path -
*/
public FileCourse(String path) throws IOException, ClassNotFoundException {
this.courses = readFromFile();
// this.courses = readFromFile();
this.filePath = path;

// check if path / file exists
// if so, read existing file, if not, create and write empty map to new file
if (Files.exists(Path.of(path))) {
this.courses = readFromFile();
} else {
this.courses = new HashMap<String, CourseCreationRequestModel>();
save();
}
}

/**
Expand All @@ -31,29 +43,37 @@ public FileCourse(String path) throws IOException, ClassNotFoundException {
public HashMap<String, CourseCreationRequestModel> readFromFile() throws IOException, ClassNotFoundException {
FileInputStream fileReader = new FileInputStream(this.filePath);
ObjectInputStream in = new ObjectInputStream(fileReader);
HashMap<String, CourseCreationRequestModel> courseMap = (HashMap<String, CourseCreationRequestModel>) in.readObject();
HashMap<String, CourseCreationRequestModel> f = (HashMap<String, CourseCreationRequestModel>) in.readObject();
in.close();
fileReader.close();
return courseMap;
return f;
}

/**
* adds the request model to database
* @param requestModel the course info that is being saved
*/
@Override
public void saveCourse(CourseCreationRequestModel requestModel) {
public void save(CourseCreationRequestModel requestModel) throws IOException {
courses.put(requestModel.getCourseID(), requestModel);
// this.saveCourse();
this.save();
}
private void saveCourse() throws IOException {

/**
* writes the map of course ids to CourseCreationRequestModel objects into the Course database file
*/
private void save() throws IOException {
FileOutputStream fileWriter = new FileOutputStream(filePath);
ObjectOutputStream out = new ObjectOutputStream(fileWriter);
out.writeObject(courses);
out.close();
fileWriter.close();
}

/**
* return whether a course exists with the course identifier
* @param courseIdentifier the course id to check
*/
@Override
public boolean existsByCourseID(String courseIdentifier) {
return courses.containsKey(courseIdentifier);
Expand All @@ -62,4 +82,13 @@ public boolean existsByCourseID(String courseIdentifier) {
public Map<String, CourseCreationRequestModel> getCourses() {
return this.courses;
}

@Override
public boolean existsByStudent(String studentIdentifier) {
return courses.containsKey(studentIdentifier);
}

public void save(CourseEnrolmentRequestModel requestModel) {
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package screens.courses_features;
package screens.course_features;

// not needed for functionality, only for testing

import use_cases.course_features.course_creation_use_case.CourseCreationDsGateway;
import use_cases.course_features.course_creation_use_case.CourseCreationRequestModel;
Expand All @@ -23,7 +25,7 @@ public boolean existsByCourseID(String identifier) {
* @param requestModel the data to save
*/
@Override
public void saveCourse(CourseCreationRequestModel requestModel) {
public void save(CourseCreationRequestModel requestModel) {
System.out.println("Save " + requestModel.getCourseID());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

// Use case layer

import java.io.IOException;

public interface CourseCreationDsGateway {
// checks if the course is already in the course map by its unique id
boolean existsByCourseID(String courseIdentifier);

void saveCourse(CourseCreationRequestModel requestModel);
void save(CourseCreationRequestModel requestModel) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
// Use case layer

import entities.*;
//import read_write.CourseReadWrite;
//import read_write.TaskReadWrite;

import java.io.IOException;
import java.util.ArrayList;

public class CourseCreationInteractor implements CourseCreationInputBoundary {
Expand Down Expand Up @@ -40,6 +39,14 @@ public CourseCreationResponseModel create(CourseCreationRequestModel requestMode
return courseCreationOutputBoundary.prepareFailView("Course already exists.");
}

// need to check that task ids entered exist in the Task database
// ArrayList<String> courseTasks = requestModel.getTasks();
// for (String task : courseTasks) {
// if (TaskMap.findTask(task) == null) {
// return courseCreationOutputBoundary.prepareFailView("one of the IDs does not correspond with a task.");
// }
// }

// checks passed; course can be created

// create a new course
Expand All @@ -48,14 +55,22 @@ public CourseCreationResponseModel create(CourseCreationRequestModel requestMode

// course successfully created and saved
CourseCreationRequestModel courseCreationModel = new CourseCreationRequestModel(course.getCourseName(), course.getCourseInstructor(), course.getTasks());
courseCreationDSGateway.saveCourse(courseCreationModel);
try {
courseCreationDSGateway.save(courseCreationModel);
} catch (IOException e) {
throw new RuntimeException(e);
}

// NEW:
// extract tasks array

// OLD
// tasks from course (task id will be course name + task number / index of task in arraylist)
ArrayList<String> courseTasks = course.getTasks();
for (String task : courseTasks) {
// ArrayList<String> courseTasks = course.getTasks();
// for (String task : courseTasks) {
// need to initialize new task to add course tasks to TaskMap, but unable to since Task is abstract
// TaskMap.addTask(course.getCourseName() + courseTasks.indexOf(task), task);
}
// }

// save course to file
// CourseReadWrite crw = new CourseReadWrite("src/data/CourseMap");
Expand Down
Loading

0 comments on commit ce38791

Please sign in to comment.