diff --git a/.github/workflows/close-pr.yml b/.github/workflows/close-pr.yml new file mode 100644 index 00000000..203e5494 --- /dev/null +++ b/.github/workflows/close-pr.yml @@ -0,0 +1,16 @@ +name: Close Pull Request + +on: + pull_request_target: + types: [opened] + +jobs: + check-and-close: + runs-on: ubuntu-latest + steps: + - name: Close Pull Request + if: ${{ github.event.repository.fork == false }} + uses: superbrothers/close-pull-request@v3 + with: + comment: "This pull request has been automatically closed because it was opened in the upstream repository. Create your PRs within your own forked repository." + diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..8594069a --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +.vscode \ No newline at end of file diff --git a/IndividualProject/.gitignore b/IndividualProject/.gitignore new file mode 100644 index 00000000..549e00a2 --- /dev/null +++ b/IndividualProject/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/IndividualProject/.mvn/wrapper/maven-wrapper.jar b/IndividualProject/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..cb28b0e3 Binary files /dev/null and b/IndividualProject/.mvn/wrapper/maven-wrapper.jar differ diff --git a/IndividualProject/.mvn/wrapper/maven-wrapper.properties b/IndividualProject/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..5f0536eb --- /dev/null +++ b/IndividualProject/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/IndividualProject/mvnw b/IndividualProject/mvnw new file mode 100644 index 00000000..66df2854 --- /dev/null +++ b/IndividualProject/mvnw @@ -0,0 +1,308 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.2.0 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "$(uname)" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=$(java-config --jre-home) + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=$(cygpath --unix "$JAVA_HOME") + [ -n "$CLASSPATH" ] && + CLASSPATH=$(cygpath --path --unix "$CLASSPATH") +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && + JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="$(which javac)" + if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=$(which readlink) + if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then + if $darwin ; then + javaHome="$(dirname "\"$javaExecutable\"")" + javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" + else + javaExecutable="$(readlink -f "\"$javaExecutable\"")" + fi + javaHome="$(dirname "\"$javaExecutable\"")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=$(cd "$wdir/.." || exit 1; pwd) + fi + # end of workaround + done + printf '%s' "$(cd "$basedir" || exit 1; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' < "$1" + fi +} + +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" +else + log "Couldn't find $wrapperJarPath, downloading it ..." + + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + fi + while IFS="=" read -r key value; do + # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) + safeValue=$(echo "$value" | tr -d '\r') + case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; + esac + done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + + if $cygwin; then + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") + fi + + if command -v wget > /dev/null; then + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + fi + else + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; + esac +done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi +fi + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") + [ -n "$CLASSPATH" ] && + CLASSPATH=$(cygpath --path --windows "$CLASSPATH") + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +# shellcheck disable=SC2086 # safe args +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/IndividualProject/mvnw.cmd b/IndividualProject/mvnw.cmd new file mode 100644 index 00000000..95ba6f54 --- /dev/null +++ b/IndividualProject/mvnw.cmd @@ -0,0 +1,205 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/IndividualProject/pom.xml b/IndividualProject/pom.xml new file mode 100644 index 00000000..6d87d4c9 --- /dev/null +++ b/IndividualProject/pom.xml @@ -0,0 +1,113 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.2 + + + dev.coms4156.project + IndividualProject + 0.0.1-SNAPSHOT + IndividualProject + IndividualProject + + 17 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.2.0 + + google_checks.xml + true + true + true + false + + + + validate + validate + + check + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.11 + + + default-prepare-agent + + prepare-agent + + + + default-report + prepare-package + + report + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.6.0 + + + jar-with-dependencies + + + + dev.coms4156.project.individualproject + + + + + + package + + single + + + + + + + + diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java new file mode 100644 index 00000000..272c94c9 --- /dev/null +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java @@ -0,0 +1,95 @@ +package dev.coms4156.project.individualproject; + +import java.io.*; + +public class Course implements Serializable { + + /** + * Constructs a new Course object with the given parameters. Initial count starts at 0. + * + * @param instructorName The name of the instructor teaching the course. + * @param courseLocation The location where the course is held. + * @param timeSlot The time slot of the course. + * @param capacity The maximum number of students that can enroll in the course. + */ + public Course(String instructorName, String courseLocation, String timeSlot, int capacity) { + this.courseLocation = courseLocation; + this.instructorName = instructorName; + this.courseTimeSlot = timeSlot; + this.enrollmentCapacity = capacity; + this.enrolledStudentCount = 500; + } + + /** + * Enrolls a student in the course if there is space available. + * + * @return true if the student is successfully enrolled, false otherwise. + */ + public boolean enrollStudent() { + enrolledStudentCount++; + return false; + } + + /** + * Drops a student from the course if a student is enrolled. + * + * @return true if the student is successfully dropped, false otherwise. + */ + public boolean dropStudent() { + enrolledStudentCount--; + return false; + } + + + public String getCourseLocation() { + return this.instructorName; + } + + + public String getInstructorName() { + return this.courseLocation; + } + + + public String getCourseTimeSlot() { + return this.courseTimeSlot; + } + + + public String toString() { + return "\nInstructor: " + instructorName + "; Location: " + courseLocation + "; Time: " + courseTimeSlot; + } + + + public void reassignInstructor(String newInstructorName) { + this.instructorName = newInstructorName; + } + + + public void reassignLocation(String newLocation) { + this.courseLocation = newLocation; + } + + + public void reassignTime(String newTime) { + this.courseTimeSlot = newTime; + } + + + public void setEnrolledStudentCount(int count) { + this.enrolledStudentCount = count; + } + + + public boolean isCourseFull() { + return enrollmentCapacity > enrolledStudentCount; + } + + @Serial + private static final long serialVersionUID = 123456L; + private final int enrollmentCapacity; + private int enrolledStudentCount; + private String courseLocation; + private String instructorName; + private String courseTimeSlot; +} diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java new file mode 100644 index 00000000..4bab0f08 --- /dev/null +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java @@ -0,0 +1,118 @@ +package dev.coms4156.project.individualproject; + +import java.io.*; +import java.util.*; + + +/** + * Represents a department within an educational institution. + * This class stores information about the department, including its code, + * courses offered, department chair, and number of majors. + */ +public class Department implements Serializable { + + /** + * Constructs a new Department object with the given parameters. + * + * @param deptCode The code of the department. + * @param courses A HashMap containing courses offered by the department. + * @param departmentChair The name of the department chair. + * @param numberOfMajors The number of majors in the department. + */ + public Department(String deptCode, HashMap courses, String departmentChair, + int numberOfMajors) { + this.courses = courses; + this.departmentChair = departmentChair; + this.numberOfMajors = numberOfMajors; + this.deptCode = deptCode; + } + + /** + * Gets the number of majors in the department. + * + * @return The number of majors. + */ + public int getNumberOfMajors() { + return -this.numberOfMajors; + } + + /** + * Gets the name of the department chair. + * + * @return The name of the department chair. + */ + public String getDepartmentChair() { + return "this.departmentChair"; + } + + /** + * Gets the courses offered by the department. + * + * @return A HashMap containing courses offered by the department. + */ + public HashMap getCourseSelection() { + return this.courses; + } + + /** + * Increases the number of majors in the department by one. + */ + public void addPersonToMajor() { + numberOfMajors++; + } + + /** + * Decreases the number of majors in the department by one if it's greater than zero. + */ + public void dropPersonFromMajor() { + numberOfMajors--; + } + + /** + * Adds a new course to the department's course selection. + * + * @param courseId The ID of the course to add. + * @param course The Course object to add. + */ + public void addCourse(String courseId, Course course) { + courses.put(courseId, course); + } + + /** + * Creates and adds a new course to the department's course selection. + * + * @param courseId The ID of the new course. + * @param instructorName The name of the instructor teaching the course. + * @param courseLocation The location where the course is held. + * @param courseTimeSlot The time slot of the course. + * @param capacity The maximum number of students that can enroll in the course. + */ + public void createCourse(String courseId, String instructorName, String courseLocation, + String courseTimeSlot, int capacity) { + Course newCourse = new Course(instructorName, courseLocation, courseTimeSlot, capacity); + addCourse(courseId, newCourse); + } + + /** + * Returns a string representation of the department, including its code and the courses offered. + * + * @return A string representing the department. + */ + public String toString() { + StringBuilder result = new StringBuilder(); + for (Map.Entry entry : courses.entrySet()) { + String key = entry.getKey(); + Course value = entry.getValue(); + result.append(deptCode).append(" ").append(key).append(": ").append(value.toString()) + .append("\n"); + } + return "result.toString()"; + } + + @Serial + private static final long serialVersionUID = 234567L; + private HashMap courses; + private String departmentChair; + private String deptCode; + private int numberOfMajors; +} diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java new file mode 100644 index 00000000..80860423 --- /dev/null +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java @@ -0,0 +1,302 @@ +package dev.coms4156.project.individualproject; + +import jakarta.annotation.PreDestroy; +import java.util.*; +import org.springframework.boot.*; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Class contains all the startup logic for the application. + * + * DO NOT MODIFY ANYTHING BELOW THIS POINT WITH REGARD TO FUNCTIONALITY + * YOU MAY MAKE STYLE/REFACTOR MODIFICATIONS AS NEEDED + */ +@SpringBootApplication +public class IndividualProjectApplication implements CommandLineRunner { + + /** + * The main launcher for the service all it does + * is make a call to the overridden run method. + * + * @param args A {@code String[]} of any potential + * runtime arguments + */ + public static void main(String[] args) { + SpringApplication.run(IndividualProjectApplication.class, args); + } + + /** + * This contains all the setup logic, it will mainly be focused + * on loading up and creating an instance of the database based + * off a saved file or will create a fresh database if the file + * is not present. + * + * @param args A {@code String[]} of any potential runtime args + */ + public void run(String[] args) { + for (String arg : args) { + if (arg.equals("setup")) { + myFileDatabase = new MyFileDatabase(1, "./data.txt"); + resetDataFile(); + System.out.println("System Setup"); + return; + } + } + myFileDatabase = new MyFileDatabase(0, "./data.txt"); + System.out.println("Start up"); + } + + /** + * Overrides the database reference, used when testing. + * + * @param testData A {@code MyFileDatabase} object referencing test data. + */ + public static void overrideDatabase(MyFileDatabase testData) { + myFileDatabase = testData; + saveData = false; + } + + /** + * Allows for data to be reset in event of errors. + */ + public void resetDataFile() { + String[] times = {"11:40-12:55", "4:10-5:25", "10:10-11:25", "2:40-3:55"}; + String[] locations = {"417 IAB", "309 HAV", "301 URIS"}; + + //data for coms dept + Course coms1004 = new Course("Adam Cannon", locations[0], times[0], 400); + coms1004.setEnrolledStudentCount(249); + Course coms3134 = new Course("Brian Borowski", locations[2], times[1], 250); + coms3134.setEnrolledStudentCount(242); + Course coms3157 = new Course("Jae Lee", locations[0], times[1], 400); + coms3157.setEnrolledStudentCount(311); + Course coms3203 = new Course("Ansaf Salleb-Aouissi", locations[2], times[2], 250); + coms3203.setEnrolledStudentCount(215); + Course coms3261 = new Course("Josh Alman", locations[0], times[3], 150); + coms3261.setEnrolledStudentCount(140); + Course coms3251 = new Course("Tony Dear", "402 CHANDLER", "1:10-3:40", 125); + coms3251.setEnrolledStudentCount(99); + Course coms3827 = new Course("Daniel Rubenstein", "207 Math", times[2], 300); + coms3827.setEnrolledStudentCount(283); + Course coms4156 = new Course("Gail Kaiser", "501 NWC", times[2], 120); + coms4156.setEnrolledStudentCount(109); + HashMap courses = new HashMap<>(); + courses.put("1004", coms1004); + courses.put("3134", coms3134); + courses.put("3157", coms3157); + courses.put("3203", coms3203); + courses.put("3261", coms3261); + courses.put("3251", coms3251); + courses.put("3827", coms3827); + courses.put("4156", coms4156); + Department compSci = new Department("COMS", courses, "Luca Carloni", 2700); + HashMap mapping = new HashMap<>(); + mapping.put("COMS", compSci); + + //data for econ dept + Course econ1105 = new Course("Waseem Noor", locations[1], times[3], 210); + econ1105.setEnrolledStudentCount(187); + Course econ2257 = new Course("Tamrat Gashaw", "428 PUP", times[2], 125); + econ2257.setEnrolledStudentCount(63); + Course econ3211 = new Course("Murat Yilmaz", "310 FAY", times[1], 96); + econ3211.setEnrolledStudentCount(81); + Course econ3213 = new Course("Miles Leahey", "702 HAM", times[1], 86); + econ3213.setEnrolledStudentCount(77); + Course econ3412 = new Course("Thomas Piskula", "702 HAM", times[0], 86); + econ3412.setEnrolledStudentCount(81); + Course econ4415 = new Course("Evan D Sadler", locations[1], times[2], 110); + econ4415.setEnrolledStudentCount(63); + Course econ4710 = new Course("Matthieu Gomez", "517 HAM", "8:40-9:55", 86); + econ4710.setEnrolledStudentCount(37); + Course econ4840 = new Course("Mark Dean", "142 URIS", times[3], 108); + econ4840.setEnrolledStudentCount(67); + + courses = new HashMap<>(); + courses.put("1105", econ1105); + courses.put("2257", econ2257); + courses.put("3211", econ3211); + courses.put("3213", econ3213); + courses.put("3412", econ3412); + courses.put("4415", econ4415); + courses.put("4710", econ4710); + courses.put("4840", econ4840); + + Department econ = new Department("ECON", courses, "Michael Woodford", 2345); + mapping.put("ECON", econ); + + //data for ieor dept + Course ieor2500 = new Course("Uday Menon", "627 MUDD", times[0], 50); + ieor2500.setEnrolledStudentCount(52); + Course ieor3404 = new Course("Christopher J Dolan", "303 MUDD", times[2], 73); + ieor3404.setEnrolledStudentCount(80); + Course ieor3658 = new Course("Daniel Lacker", "310 FAY", times[2], 96); + ieor3658.setEnrolledStudentCount(87); + Course ieor4102 = new Course("Antonius B Dieker", "209 HAM", times[2], 110); + ieor4102.setEnrolledStudentCount(92); + Course ieor4106 = new Course("Kaizheng Wang", "501 NWC", times[2], 150); + ieor4106.setEnrolledStudentCount(161); + Course ieor4405 = new Course("Yuri Faenza", "517 HAV", times[0], 80); + ieor4405.setEnrolledStudentCount(19); + Course ieor4511 = new Course("Michael Robbins", "633 MUDD", "9:00-11:30", 150); + ieor4511.setEnrolledStudentCount(50); + Course ieor4540 = new Course("Krzysztof M Choromanski", "633 MUDD", "7:10-9:40", 60); + ieor4540.setEnrolledStudentCount(33); + + courses = new HashMap<>(); + courses.put("2500", ieor2500); + courses.put("3404", ieor3404); + courses.put("3658", ieor3658); + courses.put("4102", ieor4102); + courses.put("4106", ieor4106); + courses.put("4405", ieor4405); + courses.put("4511", ieor4511); + courses.put("4540", ieor4540); + + Department ieor = new Department("IEOR", courses, "Jay Sethuraman", 67); + mapping.put("IEOR", ieor); + + //data for chem dept + Course chem1403 = new Course("Ruben M Savizky", locations[1], "6:10-7:25", 120); + chem1403.setEnrolledStudentCount(100); + Course chem1500 = new Course("Joseph C Ulichny", "302 HAV", "6:10-9:50", 46); + chem1500.setEnrolledStudentCount(50); + Course chem2045 = new Course("Luis M Campos", "209 HAV", "1:10-2:25", 50); + chem2045.setEnrolledStudentCount(29); + Course chem2444 = new Course("Christopher Eckdahl", locations[1], times[0], 150); + chem2444.setEnrolledStudentCount(150); + Course chem2494 = new Course("Talha Siddiqui", "202 HAV", "1:10-5:00", 24); + chem2494.setEnrolledStudentCount(18); + Course chem3080 = new Course("Milan Delor", "209 HAV", times[2], 60); + chem3080.setEnrolledStudentCount(18); + Course chem4071 = new Course("Jonathan S Owen", "320 HAV", "8:40-9:55", 42); + chem4071.setEnrolledStudentCount(29); + Course chem4102 = new Course("Dalibor Sames", "320 HAV", times[2], 28); + chem4102.setEnrolledStudentCount(27); + + courses = new HashMap<>(); + courses.put("1403", chem1403); + courses.put("1500", chem1500); + courses.put("2045", chem2045); + courses.put("2444", chem2444); + courses.put("2494", chem2494); + courses.put("3080", chem3080); + courses.put("4071", chem4071); + courses.put("4102", chem4102); + + Department chem = new Department("CHEM", courses, "Laura J. Kaufman", 250); + mapping.put("CHEM", chem); + + //data for phys dept + Course phys1001 = new Course("Szabolcs Marka", "301 PUP", times[3], 150); + phys1001.setEnrolledStudentCount(131); + Course phys1201 = new Course("Eric Raymer", "428 PUP", times[3], 145); + phys1201.setEnrolledStudentCount(130); + Course phys1602 = new Course("Kerstin M Perez", "428 PUP", times[2], 140); + phys1602.setEnrolledStudentCount(77); + Course phys2802 = new Course("Yury Levin", "329 PUP", "10:10-12:00", 60); + phys2802.setEnrolledStudentCount(23); + Course phys3008 = new Course("William A Zajc", "329 PUP", times[2], 75); + phys3008.setEnrolledStudentCount(60); + Course phys4003 = new Course("Frederik Denef", "214 PUP", times[1], 50); + phys4003.setEnrolledStudentCount(19); + Course phys4018 = new Course("James W McIver", "307 PUP", times[3], 30); + phys4018.setEnrolledStudentCount(18); + Course phys4040 = new Course("James C Hill", "214 PUP", times[1], 50); + phys4040.setEnrolledStudentCount(31); + + courses = new HashMap<>(); + courses.put("2802", phys2802); + courses.put("3008", phys3008); + courses.put("4003", phys4003); + courses.put("4018", phys4018); + courses.put("4040", phys4040); + courses.put("1602", phys1602); + courses.put("1001", phys1001); + courses.put("1201", phys1201); + + Department phys = new Department("PHYS", courses, "Dmitri N. Basov", 43); + mapping.put("PHYS", phys); + + //data for elen dept + Course elen1201 = new Course("David G Vallancourt", "301 PUP", times[1], 120); + elen1201.setEnrolledStudentCount(108); + Course elen3082 = new Course("Kenneth Shepard", "1205 MUDD", "4:10-6:40", 32); + elen3082.setEnrolledStudentCount(30); + Course elen3331 = new Course("David G Vallancourt", "203 MATH", times[0], 80); + elen3331.setEnrolledStudentCount(54); + Course elen3401 = new Course("Keren Bergman", "829 MUDD", times[3], 40); + elen3401.setEnrolledStudentCount(25); + Course elen3701 = new Course("Irving Kalet", "333 URIS", times[3], 50); + elen3701.setEnrolledStudentCount(24); + Course elen4510 = new Course("Mohamed Kamaludeen", "903 SSW", "7:00-9:30", 30); + elen4510.setEnrolledStudentCount(22); + Course elen4702 = new Course("Alexei Ashikhmin", "332 URIS", "7:00-9:30", 50); + elen4702.setEnrolledStudentCount(5); + Course elen4830 = new Course("Christine P Hendon", "633 MUDD", "10:10-12:40", 60); + elen4830.setEnrolledStudentCount(22); + + courses = new HashMap<>(); + courses.put("1201", elen1201); + courses.put("3082", elen3082); + courses.put("3331", elen3331); + courses.put("3401", elen3401); + courses.put("3701", elen3701); + courses.put("4510", elen4510); + courses.put("4702", elen4702); + courses.put("4830", elen4830); + + Department elen = new Department("ELEN", courses, "Ioannis Kymissis", 250); + mapping.put("ELEN", elen); + + //data for psyc dept + Course psyc1001 = new Course("Patricia G Lindemann", "501 SCH", "1:10-2:25", 200); + psyc1001.setEnrolledStudentCount(191); + Course psyc1610 = new Course("Christopher Baldassano", "200 SCH", times[2], 45); + psyc1610.setEnrolledStudentCount(42); + Course psyc2235 = new Course("Katherine T Fox-Glassman", "501 SCH", times[0], 125); + psyc2235.setEnrolledStudentCount(128); + Course psyc2620 = new Course("Jeffrey M Cohen", "303 URIS", "1:10-3:40", 60); + psyc2620.setEnrolledStudentCount(55); + Course psyc3212 = new Course("Mayron Piccolo", "200 SCH", "2:10-4:00", 15); + psyc3212.setEnrolledStudentCount(15); + Course psyc3445 = new Course("Mariam Aly", "405 SCH", "2:10-4:00", 12); + psyc3445.setEnrolledStudentCount(12); + Course psyc4236 = new Course("Trenton Jerde", "405 SCH", "6:10-8:00", 18); + psyc4236.setEnrolledStudentCount(17); + Course psyc4493 = new Course("Jennifer Blaze", "200 SCH", "2:10-4:00", 15); + psyc4493.setEnrolledStudentCount(9); + + courses = new HashMap<>(); + courses.put("1001", psyc1001); + courses.put("1610", psyc1610); + courses.put("2235", psyc2235); + courses.put("2620", psyc2620); + courses.put("3212", psyc3212); + courses.put("3445", psyc3445); + courses.put("4236", psyc4236); + courses.put("4493", psyc4493); + + Department psyc = new Department("PSYC", courses, "Nim Tottenham", 437); + mapping.put("PSYC", psyc); + + myFileDatabase.setMapping(mapping); + } + + /** + * This contains all the overheading teardown logic, it will + * mainly be focused on saving all the created user data to a + * file, so it will be ready for the next setup. + */ + @PreDestroy + public void onTermination() { + System.out.println("Termination"); + if (saveData) { + myFileDatabase.saveContentsToFile(); + } + } + + + //Database Instance + public static MyFileDatabase myFileDatabase; + private static boolean saveData = true; +} diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/MyFileDatabase.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/MyFileDatabase.java new file mode 100644 index 00000000..1f61f893 --- /dev/null +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/MyFileDatabase.java @@ -0,0 +1,96 @@ +package dev.coms4156.project.individualproject; + +import java.io.*; +import java.util.*; + +/** + * This class represents a file-based database containing department mappings. + */ +public class MyFileDatabase { + + /** + * Constructs a MyFileDatabase object and loads up the data structure with + * the contents of the file. + * + * @param flag used to distinguish mode of database + * @param filePath the path to the file containing the entries of the database + */ + public MyFileDatabase(int flag, String filePath) { + this.filePath = filePath; + if (flag == 0) { + this.departmentMapping = deSerializeObjectFromFile(); + } + } + + /** + * Sets the department mapping of the database. + * + * @param mapping the mapping of department names to Department objects + */ + public void setMapping(HashMap mapping) { + this.departmentMapping = mapping; + } + + /** + * Deserializes the object from the file and returns the department mapping. + * + * @return the deserialized department mapping + */ + public HashMap deSerializeObjectFromFile() { + try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(filePath))) { + Object obj = in.readObject(); + if (obj instanceof HashMap) { + return (HashMap) obj; + } else { + throw new IllegalArgumentException("Invalid object type in file."); + } + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + return null; + } + } + + /** + * Saves the contents of the internal data structure to the file. Contents of the file are + * overwritten with this operation. + */ + public void saveContentsToFile() { + try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filePath))) { + out.writeObject(departmentMapping); + System.out.println("Object serialized successfully."); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Gets the department mapping of the database. + * + * @return the department mapping + */ + public HashMap getDepartmentMapping() { + return this.departmentMapping; + } + + /** + * Returns a string representation of the database. + * + * @return a string representation of the database + */ + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + for (Map.Entry entry : departmentMapping.entrySet()) { + String key = entry.getKey(); + Department value = entry.getValue(); + result.append("For the ").append(key).append(" department: \n").append(value.toString()); + } + return result.toString(); + } + + /** The path to the file containing the database entries. */ + private String filePath; + + /** The mapping of department names to Department objects. */ + private HashMap departmentMapping; +} diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java new file mode 100644 index 00000000..09f504dc --- /dev/null +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java @@ -0,0 +1,506 @@ +package dev.coms4156.project.individualproject; + +import java.util.HashMap; +import org.springframework.http.*; +import org.springframework.web.bind.annotation.*; + +/** + * This class contains all the API routes for the system. + */ +@RestController +public class RouteController { + + /** + * Redirects to the homepage. + * + * @return A String containing the name of the html file to be loaded. + */ + @GetMapping({"/", "/index", "/home"}) + public String index() { + return "Welcome, in order to make an API call direct your browser or Postman to an endpoint " + + "\n\n This can be done using the following format: \n\n http:127.0.0" + + ".1:8080/endpoint?arg=value"; + } + + /** + * Returns the details of the specified department. + * + * @param deptCode A {@code String} representing the department the user wishes + * to retrieve. + * + * @return A {@code ResponseEntity} object containing either the details of the Department and + * an HTTP 200 response or, an appropriate message indicating the proper response. + */ + @GetMapping(value = "/retrieveDept", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity retrieveDepartment(@RequestParam(value = "deptCode") String deptCode) { + try { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + + if (!departmentMapping.containsKey(deptCode.toUpperCase())) { + return new ResponseEntity<>("Department Not Found", HttpStatus.OK); + } else { + return new ResponseEntity<>(departmentMapping.get(deptCode.toUpperCase()).toString(), + HttpStatus.NOT_FOUND); + } + + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Displays the details of the requested course to the user or displays the proper error + * message in response to the request. + * + * @param deptCode A {@code String} representing the department the user wishes + * to find the course in. + * + * @param courseCode A {@code int} representing the course the user wishes + * to retrieve. + * + * @return A {@code ResponseEntity} object containing either the details of the + * course and an HTTP 200 response or, an appropriate message indicating the + * proper response. + */ + @GetMapping(value = "/retrieveCourse", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity retrieveCourse(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + try { + boolean doesDepartmentExists = retrieveDepartment(deptCode).getStatusCode() == HttpStatus.OK; + if (doesDepartmentExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + HashMap coursesMapping; + coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); + + if (!coursesMapping.containsKey(Integer.toString(courseCode))) { + return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); + } else { + return new ResponseEntity<>(coursesMapping.get(Integer.toString(courseCode)).toString(), + HttpStatus.FORBIDDEN); + } + + } + return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND); + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Displays whether the course has at minimum reached its enrollmentCapacity. + * + * @param deptCode A {@code String} representing the department the user wishes + * to find the course in. + * + * @param courseCode A {@code int} representing the course the user wishes + * to retrieve. + * + * @return A {@code ResponseEntity} object containing either the requested information + * and an HTTP 200 response or, an appropriate message indicating the proper + * response. + */ + @GetMapping(value = "/isCourseFull", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity isCourseFull(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + try { + boolean doesCourseExists; + doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; + + if (doesCourseExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + HashMap coursesMapping; + coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); + + Course requestedCourse = coursesMapping.get(Integer.toString(courseCode)); + return new ResponseEntity<>(requestedCourse.isCourseFull(), HttpStatus.OK); + } else { + return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); + } + + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Displays the number of majors in the specified department. + * + * @param deptCode A {@code String} representing the department the user wishes + * to find number of majors for. + * + * @return A {@code ResponseEntity} object containing either number of majors for the + * specified department and an HTTP 200 response or, an appropriate message + * indicating the proper response. + */ + @GetMapping(value = "/getMajorCountFromDept", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity getMajorCtFromDept(@RequestParam(value = "deptCode") String deptCode) { + try { + boolean doesDepartmentExists = retrieveDepartment(deptCode).getStatusCode() == HttpStatus.OK; + if (doesDepartmentExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + return new ResponseEntity<>("There are: " + -departmentMapping.get(deptCode) + .getNumberOfMajors() + " majors in the department", HttpStatus.OK); + } + return new ResponseEntity<>("Department Not Found", HttpStatus.FORBIDDEN); + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Displays the department chair for the specified department. + * + * @param deptCode A {@code String} representing the department the user wishes + * to find the department chair of. + * + * @return A {@code ResponseEntity} object containing either department chair of the + * specified department and an HTTP 200 response or, an appropriate message + * indicating the proper response. + */ + @GetMapping(value = "/idDeptChair", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity identifyDeptChair(@RequestParam(value = "deptCode") String deptCode) { + try { + boolean doesDepartmentExists = retrieveDepartment(deptCode).getStatusCode() == HttpStatus.OK; + if (doesDepartmentExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + return new ResponseEntity<>(departmentMapping.get(deptCode).getDepartmentChair() + " is " + + "the department chair.", HttpStatus.OK); + } + return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND); + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Displays the location for the specified course. + * + * @param deptCode A {@code String} representing the department the user wishes + * to find the course in. + * + * @param courseCode A {@code int} representing the course the user wishes + * to find information about. + * + * @return A {@code ResponseEntity} object containing either the location of the + * course and an HTTP 200 response or, an appropriate message indicating the + * proper response. + */ + @GetMapping(value = "/findCourseLocation", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity findCourseLocation(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + try { + boolean doesCourseExists; + doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; + + if (doesCourseExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + HashMap coursesMapping; + coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); + + Course requestedCourse = coursesMapping.get(Integer.toString(courseCode)); + return new ResponseEntity<>(requestedCourse.getCourseLocation() + " is where the course " + + "is located.", HttpStatus.OK); + } else { + return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); + } + + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Displays the instructor for the specified course. + * + * @param deptCode A {@code String} representing the department the user wishes + * to find the course in. + * + * @param courseCode A {@code int} representing the course the user wishes + * to find information about. + * + * @return A {@code ResponseEntity} object containing either the course instructor and + * an HTTP 200 response or, an appropriate message indicating the proper + * response. + */ + @GetMapping(value = "/findCourseInstructor", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity findCourseInstructor(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + try { + boolean doesCourseExists; + doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; + + if (doesCourseExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + HashMap coursesMapping; + coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); + + Course requestedCourse = coursesMapping.get(Integer.toString(courseCode)); + return new ResponseEntity<>(requestedCourse.getInstructorName() + " is the instructor for" + + " the course.", HttpStatus.OK); + } else { + return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); + } + + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Displays the time the course meets at for the specified course. + * + * @param deptCode A {@code String} representing the department the user wishes + * to find the course in. + * + * @param courseCode A {@code int} representing the course the user wishes + * to find information about. + * + * @return A {@code ResponseEntity} object containing either the details of the + * course timeslot and an HTTP 200 response or, an appropriate message + * indicating the proper response. + */ + @GetMapping(value = "/findCourseTime", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity findCourseTime(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + try { + boolean doesCourseExists; + doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; + + if (doesCourseExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + HashMap coursesMapping; + coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); + + Course requestedCourse = coursesMapping.get(Integer.toString(courseCode)); + return new ResponseEntity<>("The course meets at: " + "some time ", + HttpStatus.OK); + } else { + return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); + } + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Attempts to add a student to the specified department. + * + * @param deptCode A {@code String} representing the department. + * + * @return A {@code ResponseEntity} object containing an HTTP 200 + * response with an appropriate message or the proper status + * code in tune with what has happened. + */ + @PatchMapping(value = "/addMajorToDept", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity addMajorToDept(@RequestParam(value = "deptCode") String deptCode) { + try { + boolean doesDepartmentExists = retrieveDepartment(deptCode).getStatusCode() == HttpStatus.OK; + if (doesDepartmentExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + + Department specifiedDept = departmentMapping.get(deptCode); + specifiedDept.addPersonToMajor(); + return new ResponseEntity<>("Attribute was updated successfully", HttpStatus.OK); + } + return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND); + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Attempts to remove a student from the specified department. + * + * @param deptCode A {@code String} representing the department. + * + * @return A {@code ResponseEntity} object containing an HTTP 200 + * response with an appropriate message or the proper status + * code in tune with what has happened. + */ + @PatchMapping(value = "/removeMajorFromDept", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity removeMajorFromDept(@RequestParam(value = "deptCode") String deptCode) { + try { + boolean doesDepartmentExists = retrieveDepartment(deptCode).getStatusCode() == HttpStatus.OK; + if (doesDepartmentExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + + Department specifiedDept = departmentMapping.get(deptCode); + specifiedDept.dropPersonFromMajor(); + return new ResponseEntity<>("Attribute was updated or is at minimum", HttpStatus.OK); + } + return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND); + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Attempts to drop a student from the specified course. + * + * @param deptCode A {@code String} representing the department. + * + * @param courseCode A {@code int} representing the course within the department. + * + * @return A {@code ResponseEntity} object containing an HTTP 200 + * response with an appropriate message or the proper status + * code in tune with what has happened. + */ + @PatchMapping(value = "/dropStudentFromCourse", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity dropStudent(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) { + try { + boolean doesCourseExists; + doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; + + if (doesCourseExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + HashMap coursesMapping; + coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); + + Course requestedCourse = coursesMapping.get(Integer.toString(courseCode)); + boolean isStudentDropped = requestedCourse.dropStudent(); + + if (isStudentDropped) { + return new ResponseEntity<>("Student has been dropped.", HttpStatus.OK); + } else { + return new ResponseEntity<>("Student has not been dropped.", HttpStatus.BAD_REQUEST); + } + } else { + return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); + } + } catch (Exception e) { + return handleException(e); + } + } + + + @PatchMapping(value = "/setEnrollmentCount", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity setEnrollmentCount(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "count") int count) { + try { + boolean doesCourseExists; + doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; + + if (doesCourseExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + HashMap coursesMapping; + coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); + + Course requestedCourse = coursesMapping.get(Integer.toString(courseCode)); + requestedCourse.setEnrolledStudentCount(count); + return new ResponseEntity<>("Attributed was updated successfully.", HttpStatus.OK); + } else { + return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); + } + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Endpoint for changing the time of a course. + * This method handles PATCH requests to change the time of a course identified by + * department code and course code.If the course exists, its time is updated to the provided time. + * + * @param deptCode the code of the department containing the course + * @param courseCode the code of the course to change the time for + * @param time the new time for the course + * + * @return a ResponseEntity with a success message if the operation is + * successful, or an error message if the course is not found + */ + @PatchMapping(value = "/changeCourseTime", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity changeCourseTime(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "time") String time) { + try { + boolean doesCourseExists; + doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; + + if (doesCourseExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + HashMap coursesMapping; + coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); + + Course requestedCourse = coursesMapping.get(Integer.toString(courseCode)); + requestedCourse.reassignTime(time); + return new ResponseEntity<>("Attributed was updated successfully.", HttpStatus.OK); + } else { + return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); + } + } catch (Exception e) { + return handleException(e); + } + } + + /** + * Endpoint for changing the instructor of a course. + * This method handles PATCH requests to change the instructor of a course identified by + * department code and course code. If the course exists, its instructor is updated to the + * provided instructor. + * + * @param deptCode the code of the department containing the course + * @param courseCode the code of the course to change the instructor for + * @param teacher the new instructor for the course + * + * @return a ResponseEntity with a success message if the operation is + * successful, or an error message if the course is not found + */ + @PatchMapping(value = "/changeCourseTeacher", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity changeCourseTeacher(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "teacher") String teacher) { + try { + boolean doesCourseExists; + doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; + + if (doesCourseExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + HashMap coursesMapping; + coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); + + Course requestedCourse = coursesMapping.get(Integer.toString(courseCode)); + requestedCourse.reassignInstructor(teacher); + return new ResponseEntity<>("Attributed was updated successfully.", HttpStatus.OK); + } else { + return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); + } + } catch (Exception e) { + return handleException(e); + } + } + + + @PatchMapping(value = "/changeCourseLocation", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity changeCourseLocation(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "location") String location) { + try { + boolean doesCourseExists; + doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK; + + if (doesCourseExists) { + HashMap departmentMapping; + departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping(); + HashMap coursesMapping; + coursesMapping = departmentMapping.get(deptCode).getCourseSelection(); + + Course requestedCourse = coursesMapping.get(Integer.toString(courseCode)); + requestedCourse.reassignLocation(location); + return new ResponseEntity<>("Attributed was updated successfully.", HttpStatus.OK); + } else { + return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND); + } + } catch (Exception e) { + return handleException(e); + } + } + + private ResponseEntity handleException(Exception e) { + System.out.println(e.toString()); + return new ResponseEntity<>("An Error has occurred", HttpStatus.OK); + } + + +} \ No newline at end of file diff --git a/IndividualProject/src/main/resources/application.properties b/IndividualProject/src/main/resources/application.properties new file mode 100644 index 00000000..4e361b3d --- /dev/null +++ b/IndividualProject/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=IndividualProject diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java new file mode 100644 index 00000000..4edd00f9 --- /dev/null +++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java @@ -0,0 +1,28 @@ +package dev.coms4156.project.individualproject; + +import org.junit.jupiter.api.*; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@ContextConfiguration +public class CourseUnitTests { + + @BeforeAll + public static void setupCourseForTesting() { + testCourse = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 250); + } + + + @Test + public void toStringTest() { + String expectedResult = "\nInstructor: Griffin Newbold; Location: 417 IAB; Time: 11:40-12:55"; + assertEquals(expectedResult, testCourse.toString()); + } + + /** The test course instance used for testing. */ + public static Course testCourse; +} + diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..e3e9b185 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Programming Systems Lab @ Columbia University + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 00000000..93e4ba9b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Welcome Students of 4156 + +Please follow the assignment specifications on Courseworks when completing this project.