Ejemplo n.º 1
0
  public void updatePastJobs() {
    GregorianCalendar currentDate = new GregorianCalendar();
    long currentTime = currentDate.getTimeInMillis() + 2670040009l;

    for (Job job : myJobList.getJobList()) {
      if (currentTime > job.getStartDate().getTimeInMillis()) {
        job.setInPast(true);
      }
    }
  }
Ejemplo n.º 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;
  }