Task.java

package hhn.temp.project;

import hhn.temp.project.expections.TaskHasNoWorkerException;
import hhn.temp.project.provider.MySql;

public class Task {

  private String name;
  private String description;
  private TaskStatus taskStatus;
  private int taskID;
  private String workername;
  private MySql mySql;

  public Task(int id, String name, String description, String workername, TaskStatus status, MySql mySql) {

    this.taskID = id;
    this.name = name;
    this.description = description;
    this.taskStatus = status;
    this.workername = workername;
    this.mySql = mySql;
  }

  public int getTaskID() {
    return this.taskID;
  }

  public String getName() {
    return this.name;
  }

  public String getDescription() {
    return description;
  }

  public TaskStatus getStatus() {
    return taskStatus;
  }

  public void setDescription(String description) {
    if (description == null ) {

      throw new IllegalArgumentException("Description is null!");
    }

    this.mySql.updateDescription(taskID, description);
    this.description = description;
  }

  public void setStatus(TaskStatus taskStatus) {
    if (taskStatus == null ) {

      throw new IllegalArgumentException("TaskStatus is null!");
    }

    this.mySql.updateStatus(taskID, taskStatus);
    this.taskStatus = taskStatus;
  }

  public void setWorker(String workerName) {
    if(workerName == null || workerName.isEmpty()) {
      throw new IllegalArgumentException("There is nothing in this variable.");
    }
    if(!checkOnlyLetter(workerName)){
      throw new IllegalArgumentException("Only Lettery as Worker Name!");
    }

    this.mySql.updateStatus(taskID, TaskStatus.INPROCESS);
    this.mySql.updateWorker(taskID, workerName);
    this.workername = workerName;
    this.setStatus(TaskStatus.INPROCESS);
  }

  public String getWorker() {
    if(this.workername == null) {
      throw new TaskHasNoWorkerException("Please set first a Worker");
    }
    return this.workername;
  }

  private boolean checkOnlyLetter(String text) {
    boolean result = true;

    for(int i = 0; i < text.length(); i++) {
      char c = text.charAt(i);
      if(!Character.isLetter(c)) {
        result = false;
        break;
      }
    }
    return result;
  }
}