Package healthwatcher.business.complaint

Source Code of healthwatcher.business.complaint.ComplaintRecord

package healthwatcher.business.complaint;

import lib.exceptions.ObjectAlreadyInsertedException;
import lib.exceptions.ObjectNotFoundException;
import lib.exceptions.ObjectNotValidException;
import lib.exceptions.RepositoryException;
import lib.util.Functions;
import lib.util.IteratorDsk;
import healthwatcher.data.IComplaintRepository;
import healthwatcher.model.complaint.AnimalComplaint;
import healthwatcher.model.complaint.Complaint;
import healthwatcher.model.complaint.FoodComplaint;


public class ComplaintRecord {

  private IComplaintRepository complaintRep;

  public ComplaintRecord(IComplaintRepository rep) {
    this.complaintRep = rep;
  }

  public Complaint search(Long code) throws RepositoryException, ObjectNotFoundException {
    return complaintRep.search(code);
  }

  public Long insert(Complaint complaint) throws ObjectNotValidException,//change return int to Long
  ObjectAlreadyInsertedException, ObjectNotValidException, RepositoryException {
    this.validate(complaint);
    if (complaintRep.exists(complaint.getCodigo())) {
      throw new ObjectAlreadyInsertedException("Complaint code already registered");
    }
    return complaintRep.insert(complaint);
  }

  public void validate(Complaint complaint) {
    Functions f = new Functions();

    if (complaint == null) {
      throw new IllegalArgumentException();
    }

    f.campoPreenchido(complaint.getDescricao());

    if (complaint instanceof AnimalComplaint) {
      f.campoPreenchido(((AnimalComplaint) complaint).getOccurenceLocalAddress());
      f.campoPreenchido(((AnimalComplaint) complaint).getAnimal());
    }

    if (complaint instanceof FoodComplaint) {
      f.campoPreenchido(((FoodComplaint) complaint).getQtdeComensais());
      f.campoPreenchido(((FoodComplaint) complaint).getQtdeDoentes());
    }
  }

  public void update(Complaint q) throws RepositoryException, ObjectNotFoundException,
      ObjectNotValidException {
    complaintRep.update(q);
  }

  public IteratorDsk getComplaintList() throws RepositoryException, ObjectNotFoundException {
    return complaintRep.getComplaintList();

  }
}
TOP

Related Classes of healthwatcher.business.complaint.ComplaintRecord

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.