Skip to content

Commit

Permalink
Merge pull request #146 from Psyf/psyf1.4.2Dev
Browse files Browse the repository at this point in the history
Psyf1.4.2 dev
  • Loading branch information
teojunjie committed Nov 6, 2018
2 parents ef1dc62 + f26ff20 commit b55da69
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class ManageJobCommand extends Command {
private static final String MESSAGE_NO_SUCH_JOB = "No such print found";
private static final String MESSAGE_NO_SUCH_OPTION = "No such options. Only use: start, restart, cancel.";
private static final String MESSAGE_ACCESS_DENIED = "Non admin user is not allowed to delete jobs in maker manager";
private static final String MESSAGE_ONLY_TOP_JOB_STARTABLE = "You can only start/restart the first job in queue."
+ " If you have to start another job, please ask the manager to help change the queue.";

private JobName name;
private String option;
Expand All @@ -45,17 +47,22 @@ public ManageJobCommand(JobName name, String option) {
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);

//TODO: Currently findJob is happening twice. Fix.
if (model.findJob(this.name) == null) {
throw new CommandException(MESSAGE_NO_SUCH_JOB);
}

if (option.equals(OPTION_START)) {
if (!model.isTopJob(name)) {
throw new CommandException(MESSAGE_ONLY_TOP_JOB_STARTABLE);
}
model.startJob(name);
model.commitAddressBook();
model.updateFilteredMachineList(PREDICATE_SHOW_ALL_MACHINES);
return new CommandResult(MESSAGE_STARTED_JOB);
} else if (option.equals(OPTION_RESTART)) {
if (!model.isTopJob(name)) {
throw new CommandException(MESSAGE_ONLY_TOP_JOB_STARTABLE);
}
model.restartJob(name);
model.commitAddressBook();
model.updateFilteredMachineList(PREDICATE_SHOW_ALL_MACHINES);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ public int getTotalNumberOfStoredJobs() {
return getMachineList().stream().mapToInt(machine -> machine.getJobs().size()).sum();
}

public boolean isTopJob(JobName job) {
return machines.isTopJob(job);
}

//======================== get lists methods ===========================//
@Override
public ObservableList<Person> getPersonList() {
Expand Down Expand Up @@ -472,6 +476,7 @@ public String toString() {
// TODO: refine later
}


/**
* list all the current's version data for addressbook
*/
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public interface Model {
void autoMoveJobs(Machine currentMachine, Machine targetMachine);

// ============================== Machine methods ======================================= //

boolean isTopJob(JobName job);

/**
* Adds the given machine
* Machine must not exists
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ public int getTotalNumberOfJobsDisplayed() {
}

@Override
public boolean isTopJob(JobName job) {
return versionedAddressBook.isTopJob(job);
}

/**
* used for moving Job to Machine
* @param job
* @param targetMachine
*/
public void moveJobToMachine(Job job, Machine targetMachine) {
job.setMachine(targetMachine.getName());
targetMachine.addJob(job);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/seedu/address/model/machine/UniqueMachineList.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,18 @@ public Machine getMostFreeMachine() {
return mostFreeMachine;
}

/**
* Returns true if any machine has job at the front of the queue
* @param job
*/
public boolean isTopJob(JobName job) {
for (Machine m : internalList) {
if (m.getJobs().get(0).getJobName().equals(job)) {
return true;
}
}

return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ public int getTotalNumberOfJobsDisplayed() {
}

@Override
public boolean isTopJob(JobName job) {
return false;
}

public void moveJobToMachine(Job job, Machine targetMachine) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ public int getTotalNumberOfJobsDisplayed() {
}

@Override
public boolean isTopJob(JobName job) {
return false;
}

public void moveJobToMachine(Job job, Machine targetMachine) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public int getTotalNumberOfJobsDisplayed() {
}

@Override
public boolean isTopJob(JobName job) {
return false;
}

public void moveJobToMachine(Job job, Machine targetMachine) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ public int getTotalNumberOfJobsDisplayed() {
}

@Override

public boolean isTopJob(JobName job) {
return false;
}

public void moveJobToMachine(Job job, Machine targetMachine) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ public int getTotalNumberOfJobsDisplayed() {
}

@Override
public boolean isTopJob(JobName job) {
return false;
}

public void moveJobToMachine(Job job, Machine targetMachine) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ public int getTotalNumberOfJobsDisplayed() {
}

@Override
public boolean isTopJob(JobName job) {
return false;
}

public void moveJobToMachine(Job job, Machine targetMachine) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ public int getTotalNumberOfJobsDisplayed() {
}

@Override
public boolean isTopJob(JobName job) {
return false;
}

public void moveJobToMachine(Job job, Machine targetMachine) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,4 @@ public void addJobToMachineList_returnsMachineNotFoundException() {
uniqueMachineList.addJobToMachineList(ValidJobs.IDCP);
}




}

0 comments on commit b55da69

Please sign in to comment.