G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 5th, 2020 196 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Controller;
  2.  
  3. import Controller.wrappers.ApiAboutWrapper;
  4. import Controller.wrappers.ApiCourseOfferingWrapper;
  5. import Controller.wrappers.ApiCourseWrapper;
  6. import Controller.wrappers.ApiDepartmentWrapper;
  7. import Model.*;
  8. import org.springframework.http.HttpStatus;
  9. import org.springframework.web.bind.annotation.*;
  10.  
  11. import java.lang.reflect.Array;
  12. import java.util.ArrayList;
  13.  
  14. @RestController
  15. public class CourseCatalogueController {
  16.     private boolean isDataCollected = false;
  17.     private ArrayList<Department> departments;
  18.     private CSVReader reader = new CSVReader();
  19.  
  20.     private ApiAboutWrapper aboutWrapper;
  21.     private ArrayList<ApiDepartmentWrapper> departmentWrappers = new ArrayList<>();
  22.  
  23.     /******************************* 1. General *******************************/
  24.  
  25.     @ResponseStatus(value = HttpStatus.OK)
  26.     @GetMapping("/api/about")
  27.     public ApiAboutWrapper getAbout() {
  28.         if (!isDataCollected) {
  29.             collectData();
  30.             isDataCollected = true;
  31.         }
  32.  
  33.         String appName = "CMPT 213 - Course Catalogue";
  34.         String authorName = "Cole Stankov";
  35.  
  36.         ApiAboutWrapper aboutWrapper = new ApiAboutWrapper(appName, authorName);
  37.         this.aboutWrapper = aboutWrapper;
  38.  
  39.         return aboutWrapper;
  40.     }
  41.  
  42.     @ResponseStatus(value = HttpStatus.OK)
  43.     @GetMapping("/api/dump-model")
  44.     public void dumpModel() {
  45.         if (!isDataCollected) {
  46.             collectData();
  47.             isDataCollected = true;
  48.         }
  49.         ArrayList<CourseCatalogue> courses;
  50.         ArrayList<CourseOffering> courseOffering;
  51.         ArrayList<Section> sections;
  52.         ArrayList<String> componentCodes = new ArrayList<>();
  53.         String instructors;
  54.  
  55.         for (Department dep : departments) {
  56.             courses = dep.getCourseList();
  57.  
  58.             for (CourseCatalogue course : courses) {
  59.                 courseOffering = course.getCourseOfferings();
  60.                 System.out.print(dep.getDepartmentCode() + " " + course.getCatalogNumber() + "\n");
  61.  
  62.                 for (CourseOffering offering : courseOffering) {
  63.                     sections = offering.getSupplementarySections();
  64.                     instructors = offering.getInstructorsStringafied();
  65.  
  66.                     System.out.println("    " +
  67.                             offering.getSemesterCode() + " in " +
  68.                             offering.getLocation() + " by " +
  69.                             instructors);
  70.  
  71.                     for (Section section : sections) {
  72.                         if (!componentCodes.contains(section.getComponentCode())) {
  73.                             System.out.println("        Type=" +
  74.                                     section.getComponentCode() + ", Enrollment=" +
  75.                                     section.getEnrollmentTotalByCode() + "/" +
  76.                                     section.getEnrollmentCapacityByCode());
  77.  
  78.                             componentCodes.add(section.getComponentCode());
  79.                         }
  80.                     }
  81.                     componentCodes.clear();
  82.                 }
  83.             }
  84.         }
  85.  
  86.     }
  87.  
  88.     /******** 2. Access Departments, Courses, Offerings, and Sections *********/
  89.  
  90.     @ResponseStatus(value = HttpStatus.OK)
  91.     @GetMapping("/api/departments")
  92.     public ArrayList<ApiDepartmentWrapper> getDepartments() {
  93.         if (!isDataCollected) {
  94.             collectData();
  95.             isDataCollected = true;
  96.         }
  97.  
  98.         for(Department currentDepartment: departments){
  99.             ApiDepartmentWrapper department = new ApiDepartmentWrapper();
  100.             department.deptId = currentDepartment.getDepartmentID();
  101.             department.name = currentDepartment.getDepartmentCode();
  102.             this.departmentWrappers.add(department);
  103.         }
  104.  
  105.         return this.departmentWrappers;
  106.     }
  107.  
  108.     @ResponseStatus(value = HttpStatus.OK)
  109.     @GetMapping("/api/departments/{departmentID}/courses")
  110.     public ArrayList<ApiCourseWrapper> getDepartmentByID(@PathVariable("departmentID") int departmentID) {
  111.         if (!isDataCollected) {
  112.             collectData();
  113.             isDataCollected = true;
  114.         }
  115.  
  116.         ArrayList<ApiCourseWrapper> courseWrappers = new ArrayList<>();
  117.         ArrayList<CourseCatalogue> courseCatalogue = getCoursesByDepartID(departmentID);
  118.  
  119.         for(CourseCatalogue course: courseCatalogue){
  120.             ApiCourseWrapper courseWrapper = new ApiCourseWrapper();
  121.             courseWrapper.catalogNumber = course.getCatalogNumber();
  122.             courseWrapper.courseId = course.getCourseID();
  123.             courseWrappers.add(courseWrapper);
  124.         }
  125.  
  126.         return courseWrappers;
  127.     } // might have to change ID but it works
  128.  
  129.     @ResponseStatus(value = HttpStatus.OK)
  130.     @GetMapping("/api/departments/{departmentID}/courses/{courseID}/offerings")
  131.     public ArrayList<ApiCourseOfferingWrapper> getCourseAllOfferingsByCourseID(
  132.                                             @PathVariable("departmentID") int departmentID,
  133.                                             @PathVariable("courseID") int courseID) {
  134.         if (!isDataCollected) {
  135.             collectData();
  136.             isDataCollected = true;
  137.         }
  138.  
  139.         ArrayList<ApiCourseOfferingWrapper> courseOfferingWrappers = new ArrayList<>();
  140.         ArrayList<CourseCatalogue> courseCatalogue = getCoursesByDepartID(departmentID);
  141.         ArrayList<CourseOffering> courseOfferings = getCourseOfferingsByCourseID(courseCatalogue, courseID);
  142.  
  143.         for(CourseOffering currentCourseOffering: courseOfferings){
  144.             ApiCourseOfferingWrapper courseOfferingWrapper = new ApiCourseOfferingWrapper();
  145.             courseOfferingWrapper.courseOfferingId = currentCourseOffering.getCourseOfferingID();
  146.             courseOfferingWrapper.location = currentCourseOffering.getLocation();
  147.             courseOfferingWrapper.instructors = currentCourseOffering.getInstructorsStringafied();
  148.             courseOfferingWrapper.semesterCode = currentCourseOffering.getSemesterCode();
  149.             courseOfferingWrapper.term = currentCourseOffering.getSemester();
  150.             courseOfferingWrapper.year = currentCourseOffering.getYear();
  151.             courseOfferingWrappers.add(courseOfferingWrapper);
  152.         }
  153.  
  154.         return courseOfferingWrappers;
  155.     }
  156.  
  157.     @ResponseStatus(value = HttpStatus.OK)
  158.     @GetMapping("/api/departments/{departmentID}/courses/{courseID}/offerings{offeringID}")
  159.     public void getCourseOfferingByCourseID(@PathVariable("departmentID") int departmentID,
  160.                                             @PathVariable("courseID") int courseID,
  161.                                             @PathVariable("offeringID") int offeringID) {
  162.  
  163.     }
  164.  
  165.     /***************************** 3. Graph Data *******************************/
  166.  
  167.     @ResponseStatus(value = HttpStatus.OK)
  168.     @GetMapping("/api/stats/students-per-semester?deptId=5")
  169.     public void getDepartmentCourseStats() {
  170.  
  171.     }
  172.  
  173.     /********************** 4. Add New Offering / Section **********************/
  174.  
  175.     @ResponseStatus(value = HttpStatus.OK)
  176.     @PostMapping("/api/addoffering")
  177.     public void addOffering() {
  178.  
  179.     }
  180.  
  181.     /************************ 5. Course Change Watchers ***********************/
  182.  
  183.     @ResponseStatus(value = HttpStatus.OK)
  184.     @GetMapping("/api/watchers")
  185.     public void getChangeWatchers() {
  186.  
  187.     }
  188.  
  189.     @ResponseStatus(value = HttpStatus.OK)
  190.     @PostMapping("/api/watchers")
  191.     public void createWatcher() {
  192.  
  193.     }
  194.  
  195.     @ResponseStatus(value = HttpStatus.OK)
  196.     @GetMapping("/api/watchers/{watcherID}")
  197.     public void getWatcherByID(@PathVariable("watcherID") int watcherID) {
  198.  
  199.     }
  200.  
  201.     @ResponseStatus(value = HttpStatus.OK)
  202.     @DeleteMapping("/api/watchers/{watcherID}")
  203.     public void deleteWatcherByID(@PathVariable("watcherID") int watcherID) {
  204.  
  205.     }
  206.  
  207.     /************************** Helper Functions *************************/
  208.  
  209.     private void collectData() {
  210.         reader.readFile();
  211.         departments = reader.getDepartmentList();
  212.     }
  213.  
  214.     private ArrayList<CourseCatalogue> getCoursesByDepartID(int departmentID){
  215.         boolean departmentFound = false;
  216.         ArrayList<CourseCatalogue> courseCatalogue = new ArrayList<>();
  217.  
  218.         for(Department currentDepartment: departments){
  219.             if(currentDepartment.getDepartmentID() == departmentID){
  220.                 courseCatalogue = currentDepartment.getCourseList();
  221.                 departmentFound = true;
  222.                 break;
  223.             }
  224.         }
  225.  
  226.         if(!departmentFound){
  227.             throw new IndexOutOfBoundsException();
  228.         }
  229.  
  230.         return courseCatalogue;
  231.     }
  232.  
  233.     private ArrayList<CourseOffering> getCourseOfferingsByCourseID(ArrayList<CourseCatalogue> courseCatalogues, int courseID){
  234.         boolean departmentFound = false;
  235.         ArrayList<CourseOffering> courseOfferings = new ArrayList<>();
  236.  
  237.         for(CourseCatalogue currentCourse: courseCatalogues){
  238.             if(currentCourse.getCourseID() == courseID){
  239.                 courseOfferings = currentCourse.getCourseOfferings();
  240.                 departmentFound = true;
  241.                 break;
  242.             }
  243.         }
  244.  
  245.         if(!departmentFound){
  246.             throw new IndexOutOfBoundsException();
  247.         }
  248.  
  249.         return courseOfferings;
  250.     }
  251.  
  252.  
  253.     /************************** Exception Handlers *************************/
  254.  
  255.     @ResponseStatus(value = HttpStatus.NOT_FOUND) //404
  256.     @ExceptionHandler(IndexOutOfBoundsException.class)
  257.     public void IndexOutOfBoundsException() {
  258.         //nothing to do here
  259.     }
  260.  
  261.     @ResponseStatus(value = HttpStatus.BAD_REQUEST) //400
  262.     @ExceptionHandler(IllegalArgumentException.class)
  263.     public void IllegalArgumentException() {
  264.         //nothing to do here
  265.     }
  266. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top