Example #1
0
  /**
   * Add a Volunteer to an existing Job if the given data is valid.
   *
   * @param theVolunteerInfo the email of the Volunteer and their desired work grade.
   * @param theJobID the ID number for the Job to which the Volunteer will be added.
   * @return true if the Volunteer was added to the Job; false otherwise.
   * @throws IllegalArgumentException thrown for various input errors.
   */
  public boolean addVolunteerToJob(List<String> theVolunteerInfo, int theJobID)
      throws IllegalArgumentException {

    // Check that the Job ID is valid.
    boolean validID = checkJobValidity(theJobID);
    if (!validID) {
      throw new IllegalArgumentException("Sorry, but the Job ID you entered was invalid.");
    }

    // Check that the Job exists.
    Job thisJob = findJob(theJobID);
    if (thisJob == null) {
      throw new IllegalArgumentException(
          "Sorry, but the Job you are trying to sign up for does not exist.");
    }

    // Check that the Job has not already been completed.
    if (!(new BusinessRule6().test(thisJob))) {
      throw new IllegalArgumentException(
          "Sorry, but you cannot sign up for a job has already completed.");
    }

    // Check that the Volunteer is not signed up for a Job that occurs on the same date.
    if (new BusinessRule7().test(theVolunteerInfo.get(0), thisJob, myJobList)) {
      throw new IllegalArgumentException(
          "Sorry, but you are already signed up " + "for a job that occurs the same date!");
    }

    // Check that the grade of work that the Volunteer is signing up for is not already full.
    if (!(new BusinessRule3().test(thisJob, theVolunteerInfo.get(1)))) {
      throw new IllegalArgumentException("Sorry, but that grade in this job " + "is already full.");
    }

    // If all the checks pass, we add the Volunteer to the Job's Volunteer List.
    thisJob.getVolunteerList().add(theVolunteerInfo);
    return true;
  }
Example #2
0
  /**
   * Receive a job and add it to the master JobList if its data is valid.
   *
   * @param theJob the Job to potentially add to Schedule's List of Jobs.
   * @return true if theJob was added; false otherwise.
   */
  public boolean receiveJob(Job theJob) throws IllegalArgumentException {

    /*
     * We subject both the Job and JobList to a wide variety of tests.
     * If all of the tests are passed, then we add the Job to the JobList.
     */
    boolean addFlag = true;

    if (theJob == null) addFlag = false;

    // Check to ensure that the total number of pending jobs is less than 30.
    else if (!(new BusinessRule1().test(myJobList))) {
      throw new IllegalArgumentException(
          "Sorry, but the limit of 30 pending jobs has already been reached.");
    }

    /*
     * Check to ensure that the total number of Jobs for the week that this Job is to occur is
     * less than 5.
     * A week is defined as 3 days before a Job's Start Date and 3 days after its End Date.
     */
    else if (!(new BusinessRule2().test(theJob, myJobList))) {
      throw new IllegalArgumentException(
          "Sorry, but the limit of 5 jobs has already been reached for the week that "
              + "this job was scheduled.");
    }

    // Check that the Job is not scheduled to last longer than two days.
    else if (!(new BusinessRule4().test(theJob))) {
      throw new IllegalArgumentException("Sorry, but a job cannot last any longer than two days.");
    }

    // Check that a Job is scheduled to begin after the current date.
    else if (!(new BusinessRule5().pastTest(theJob))) {
      throw new IllegalArgumentException(
          "Sorry but the date you entered for this " + "job has already passed.");
    }

    // Check that a Job is scheduled to begin within the next three months.
    else if (!(new BusinessRule5().futureTest(theJob))) {
      throw new IllegalArgumentException(
          "Sorry but the date you entered is too far "
              + "into the future. \nAll jobs must be scheduled within the next 3 months.");
    }

    // Check that the Start Date and End Date are not swapped.
    else if (theJob.getStartDate().after(theJob.getEndDate())) {
      throw new IllegalArgumentException(
          "Sorry, but the Start Date must come before or on the same date as the End Date.");
    }

    // Check that the Job ID is valid.
    else if (theJob.getJobID() < 0 || theJob.getJobID() > Job.MAX_NUM_JOBS) {
      throw new IllegalArgumentException("Error: Invalid Job ID. Please logout and try again.");
    }

    // Check that the Volunteer List is not null.
    else if (theJob.getVolunteerList() == null) {
      throw new IllegalArgumentException(
          "Error: Null Volunteer List. Please logout and try again.");
    }

    // Check that the Volunteer List is empty.
    else if (!theJob.getVolunteerList().isEmpty()) {
      throw new IllegalArgumentException(
          "Error: Non-empty Volunteer List. Please logout and try again.");
    }

    // Check that there is at least one slot available for a Volunteer to sign up for.
    else if (!theJob.hasLightRoom() && !theJob.hasMediumRoom() && !theJob.hasHeavyRoom()) {
      throw new IllegalArgumentException(
          "Sorry, but a slot in at least one Volunteer Grade must be available.");
    }

    // Check that none of the slots are set to negative numbers.
    else if (theJob.getLightCurrent() > theJob.getLightMax()
        || theJob.getMediumCurrent() > theJob.getMediumMax()
        || theJob.getHeavyCurrent() > theJob.getHeavyMax()) {
      throw new IllegalArgumentException(
          "Sorry, but the number of slots for a Volunteer Grade cannot be negative.");
    }

    // Check that the Park for the Job is not null.
    else if (theJob.getPark() == null) {
      throw new IllegalArgumentException("Error: Null Park. Please logout and try again.");
    }

    // Check that the ParkManager for the Job is not null.
    else if (theJob.getManager() == null) {
      throw new IllegalArgumentException("Error: Null ParkManager. Please logout and try again.");
    }

    // If all tests passed, then we add the Job to the Schedule.
    if (addFlag) {
      // To get the master job list which is editable
      List<Job> editableJobList = myJobList.getJobList();
      editableJobList.add(theJob); // add valid job to list
    } else {
      // If we somehow got here without throwing an exception, and the Job is not valid, then we
      // throw a general exception.
      throw new IllegalArgumentException(
          "Error: Job data is invalid for unknown reasons. Please logout and try again.");
    }

    return addFlag;
  }