Skip to content

Commit

Permalink
Merge pull request #84 from Ftywan/testing
Browse files Browse the repository at this point in the history
added testing codes for the job model
  • Loading branch information
Ftywan committed Nov 4, 2018
2 parents dfd775d + 29bfc84 commit 9370074
Show file tree
Hide file tree
Showing 22 changed files with 743 additions and 48 deletions.
Empty file added data\addressbook.xml
Empty file.
7 changes: 7 additions & 0 deletions data\makerManagerAdmins.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<makermanager_admins>
<admins>
<username>admin</username>
<password>$2a$10$A8xPZ9ip9i9kHPTl8EZq7emu8FTyOW.HG9PTG1il1iQoIh1JwR0hG</password>
</admins>
</makermanager_admins>
2 changes: 2 additions & 0 deletions data\makerManagerJobs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MakerManagerJobs/>
Empty file added data\makerManagerMachines.xml
Empty file.
47 changes: 30 additions & 17 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ Give the user guidance as to what (s)he can do with makerManager +
.. *Adding a print Job:*
Adds a print job to the machine's queue. +

Format: addJob n/JOB NAME m/MACHINE NAME on/JOB OWNER NAME pr/JOB PRIORITY d/JOB DURATION jn/JOB NOTE [t/TAG]
Format: addJob n/JOBNAME m/MACHINENAME on/JOBOWNERNAME pr/JOBPRIORITY d/JOBDURATION jn/JOBNOTE [t/TAG]...

Examples:
addJob n/iDCP m/TYPrinter on/TIAN YUAN pr/HIGH d/1.5 jn/This is for the iDCP project t/iDCP

.. *Finding a print Job:*
Finds all jobs whose names contain any of the specified keywords (case-insensitive) and displays them as a list with index numbers. +

Format: findJob JOBNAME [JOBNAME]...

Examples:
findJob alice bob charlie

.. *Starting a print Job:*
Starts an existing print job in the queue. +

Expand Down Expand Up @@ -101,15 +109,15 @@ deletes an existing print in the queue. +
.. *Requests a print job to be deleted by admin:*
Tags a print job with a "requestDeletion" tag that is to be removed by admin

Format: requestDeletion n/JOB NAME
Format: requestDeletion n/JOBNAME

Examples:
requestDeletion n/iDCP

.. *`[WIP][DISABLED]` Listing Prints:*
Lists prints with optional filters. Currently lists persons. +

Format: list [n/PRINT_NAME] [m/MACHINE_NAME] [s/SPECIAL_NOTES] [p/PRIORITY]
Format: listJob [n/PRINT_NAME] [m/MACHINE_NAME] [s/SPECIAL_NOTES] [p/PRIORITY]

Examples:
list n/myprint m/printer_1 s/red filament only p/1 +
Expand All @@ -128,7 +136,7 @@ Lists all completed prints with optional filters. +
.. *`[WIP][DISABLED]` Editing a Print:*
Edits an existing print in the queue. +

Format: edit INDEX [n/PRINT_NAME] [m/MACHINE_NAME] [s/SPECIAL_NOTES] <p/PRIORITY>
Format: editJob INDEX [n/PRINT_NAME] [m/MACHINE_NAME] [s/SPECIAL_NOTES] <p/PRIORITY>

Examples:
edit 1 n/myprint m/printer_1 s/red filament only p/1 +
Expand Down Expand Up @@ -191,8 +199,7 @@ Updating your own account's password. Note that NEW_PW has to match some specifi
... *Add Machine:*
Adds a new machine. All machine names must be unique. Status can only be either “ENABLED” or “DISABLED”. +

Format:
addMachine n/MACHINE_NAME ms/STATUS
Format: addMachine n/MACHINE_NAME ms/STATUS

Example:
addMachine n/my_machine ms/ENABLED
Expand All @@ -219,21 +226,27 @@ Edits an existing machine. All machine names must be unique. Status can only be
*A: *Install the app in the other computer and overwrite the empty data file it creates with the file that contains the data of your previous makerManagerfolder.

== Command Summary
... *Normal Commands:*
. help
. addJob n/PRINT_NAME m/MACHINE_NAME d/PRINT_DURATION [s/SPECIAL_NOTES] <p/PRIORITY>
. `[WIP][DISABLED]` list [n/PRINT_NAME] [m/MACHINE_NAME] [s/SPECIAL_NOTES] [p/PRIORITY]
. `[WIP][DISABLED]` list_history [n/PRINT_NAME] [m/MACHINE_NAME] [s/SPECIAL_NOTES] [p/PRIORITY]
. findJob JOBNAME [JOBNAME]...
. manageJob JOBNAME start
. manageJob JOBNAME cancel
. manageJob JOBNAME restart
. manageJob JOBNAME delete
. requestDeletion n/JOBNAME
. listJob [n/PRINT_NAME] [m/MACHINE_NAME] [s/SPECIAL_NOTES] [p/PRIORITY]
. list_history [n/PRINT_NAME] [m/MACHINE_NAME] [s/SPECIAL_NOTES] [p/PRIORITY]
. editJob INDEX [n/PRINT_NAME] [m/MACHINE_NAME] [s/SPECIAL_NOTES] <p/PRIORITY>
. listMachines
. findMachines [machine name] [machine name 2]
. exit

... *Admin Commands:"*
. login ADMIN_ID PASSWORD
. logout
. addAdmin USERNAME PASSWORD VERIFY_PASSWORD
. removeAdmin USERNAME
. updatePassword USERNAME OLD_PW NEW_PW NEW_PW_VERIFY
. add_machine n/MACHINE_NAME s/STATUS
. `[WIP][DISABLED]` remove_machine MACHINE_NAME
. edit_machine MACHINE_NAME [n/MACHINE_NAME] [s/STATUS]
. manageJob JOB_NAME start
. manageJob JOB_NAME cancel
. manageJob JOB_NAME restart
. `[WIP][DISABLED]` manageJob JOB_NAME delete
. requestDeletion n/iDCP
. addMachine n/MACHINE_NAME ms/STATUS
. removeMachine MACHINE_NAME
. editMachine MACHINE_NAME [n/MACHINE_NAME] [s/STATUS]
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public static Long parseDuration(String duration) throws ParseException {
public static JobNote parseJobNote(String jobNote) throws ParseException {
requireNonNull(jobNote);
String trimJobNote = jobNote.trim();
if (!JobNote.isValidNote(jobNote)) {
if (!JobNote.isValidJobNote(jobNote)) {
throw new ParseException(Job.MESSAGE_NOTE_CONSTRAINTS);
}

Expand Down
97 changes: 89 additions & 8 deletions src/main/java/seedu/address/model/job/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Job(JobName name, MachineName machine, Person owner, TimeStamp addedTime,


/**
* checks if a job has been finished
* returns the job note
*/
public boolean isFinished() throws JobNotStartedException {

Expand Down Expand Up @@ -117,7 +117,7 @@ public void setDuration(long duration) {
}

/**
* Used to start a job
* starts a job
*/
public void startJob() {
if (this.status == PAUSED) {
Expand All @@ -129,12 +129,16 @@ public void startJob() {
}

/**
* Used in case of failed prints
* restarts a job once the job is cancelled
*/
public void restartJob() {
this.startJob();
}


/**
* cancel the printing of the job
*/
public void pauseJob() {
this.status = PAUSED;
}
Expand All @@ -143,30 +147,58 @@ public void cancelJob() {
this.status = Status.CANCELLED;
}

/**
* finishes a job
*/
public void finishJob() {
this.status = Status.FINISHED;
}

/**
* sets the note of the job by a new job
* @param jobNote
*/
public void setJobNote(String jobNote) {
this.jobNote.changeNote(jobNote);
}

/**
* returns the priority of the job
* @return
*/
public Priority getPriority() {
return priority;
}

/**
* sets the priority of the job
* @param priority
*/
public void setPriority(Priority priority) {
this.priority = priority;
}

/**
* returns the status of the job
* @return
*/
public Status getStatus() {
return this.status;
}

/**
* sets the status of the job
* @param status
*/
public void setStatus(Status status) {
this.status = status;
}


/**
* returns the name of the job
* @return
*/
public JobName getJobName() {
return name;
}
Expand All @@ -179,10 +211,16 @@ public TimeStamp getAddedTime() {
return addedTime;
}

/**
* returns the timestamp of the job being executed
*/
public TimeStamp getStartTime() {
return startTime;
}

/**
* returns the owner object of the job
*/
public Person getOwner() {
return owner;
}
Expand All @@ -195,11 +233,17 @@ public Set<Tag> getTags() {
return Collections.unmodifiableSet(tags);
}

/**
* Adds an extra note to the job
*/
public void addNote(String addition) {
this.jobNote.addNote(addition);
}


/**
* changes the name of the job to a new name
* @param newName
*/
public void setName(String newName) {
name = new JobName(newName);
}
Expand All @@ -208,11 +252,41 @@ public void setMachine(MachineName newMachine) {
machineName = newMachine;
}

/**
* changes the owner of the job to a new one
* @param newOwner
*/
public void setOwner(Person newOwner) {
owner = newOwner;
}


/**
* checks if a job has been finished
*/
/*
public boolean isFinished() throws JobNotStartedException {
if (this.status == ONGOING) {
Integer[] current = new TimeStamp().getTime();
Integer[] start = startTime.getTime();
Integer[] deviation = new Integer[start.length];
for (int i = 0; i < start.length; i++) {
deviation[i] = current[i] - start[i];
}
double runningTime = 30.0 * 24.0 * deviation[0] + 24.0 * deviation[1] + deviation[2]
+ 1 / 60 * deviation[3] + 1 / 3600 * deviation[4];
return runningTime > this.duration;
} else {
throw new JobNotStartedException();
}
}
*/


/**
* Returns true if both jobs of the same name have at least one other identity field that is the same.
* This defines a weaker notion of equality between two jobs.
Expand Down Expand Up @@ -258,19 +332,26 @@ public int hasHigherPriority(Job comparedJob) {
*/
@Override
public boolean equals(Object other) {
if (!(other instanceof Job)) {
return false;
}

Job otherJob = (Job) other;

if (other == this) {
/*
if (otherJob == this) {
return true;
}
*/

if (other == null) {
if (otherJob == null) {
return false;
}


return otherJob.getJobName().equals(getJobName()) && otherJob.getMachineName().equals(getMachineName())
&& otherJob.getOwner().equals(getOwner()) && otherJob.getAddedTime().equals(getAddedTime()) && otherJob
.getTags().equals(getTags());
&& otherJob.getOwner().equals(getOwner())
&& otherJob.getAddedTime().showTime().equals(getAddedTime().showTime());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/job/JobName.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class JobName {
"Job names should only contain alphanumeric characters and without spaces, and it should not be blank";

/*
* The first character of the address must not be a whitespace,
* The first character of the name must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String JOBNAME_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum}]*";
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/seedu/address/model/job/JobNote.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package seedu.address.model.job;

import static seedu.address.model.person.Name.NAME_VALIDATION_REGEX;

/**
* Represents a Note Object for Job.
*/
Expand All @@ -11,14 +9,20 @@ public class JobNote {
"Job notes should only contain alphanumeric characters and spaces, "
+ "and it should not be blank";

/*
* The first character of the note must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String JOBNOTE_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";

private String note;

public JobNote(String note) {
this.note = note;
}

public static boolean isValidNote(String test) {
return test.matches(NAME_VALIDATION_REGEX);
public static boolean isValidJobNote(String test) {
return test.matches(JOBNOTE_VALIDATION_REGEX);
}

public String toString() {
Expand Down
Loading

0 comments on commit 9370074

Please sign in to comment.