Advertisement
hsianghui

IS3106 Lab2 CustomerManager.java

Aug 27th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. package manager;
  2.  
  3. import entity.Contact;
  4. import entity.Customer;
  5. import entity.Field;
  6. import error.NoResultException;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9. import java.util.List;
  10. import java.util.Set;
  11. import session.CustomerSessionLocal;
  12.  
  13. /**
  14.  *
  15.  * @author lekhsian
  16.  */
  17. public class CustomerManager {
  18.  
  19.     private CustomerSessionLocal customerSessionLocal;
  20.  
  21.     public CustomerManager() { }
  22.  
  23.     public CustomerManager(CustomerSessionLocal customerSessionLocal) {
  24.         this.customerSessionLocal = customerSessionLocal;
  25.     }
  26.    
  27.     public Customer getCustomer(Long cId) throws Exception {
  28.         return customerSessionLocal.getCustomer(cId);
  29.     }
  30.    
  31.     public void updateCustomer(Long cId, String name, byte gender, String dob) throws Exception {
  32.         SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
  33.  
  34.         Date dob1 = df.parse(dob);
  35.  
  36.         Customer c = new Customer();
  37.         c.setId(cId);
  38.         c.setName(name);
  39.         c.setGender(gender);
  40.         c.setDob(dob1);
  41.         c.setCreated(new Date());
  42.  
  43.         customerSessionLocal.updateCustomer(c);
  44.     }
  45.  
  46.     public void createCustomer(String name, byte gender, String dob) throws Exception {
  47.         SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
  48.  
  49.         Date dob1 = df.parse(dob);
  50.  
  51.         Customer c = new Customer();
  52.         c.setName(name);
  53.         c.setGender(gender);
  54.         c.setDob(dob1);
  55.         c.setCreated(new Date());
  56.  
  57.         customerSessionLocal.createCustomer(c);
  58.     }
  59.  
  60.     public List<Customer> searchCustomer(String name) {
  61.         return customerSessionLocal.searchCustomers(name);
  62.     }
  63.  
  64.     public List<Customer> searchCustomersByField(String name, String value) {
  65.         Field f = new Field();
  66.         f.setName(name);
  67.         f.setValue(value);
  68.         return customerSessionLocal.searchCustomersByField(f);
  69.     }
  70.  
  71.     public List<Customer> searchCustomersByPhone(String phone) {
  72.         Contact c = new Contact();
  73.         c.setPhone(phone);
  74.         return customerSessionLocal.searchCustomersByContact(c);
  75.     }
  76.  
  77.     public List<Customer> searchCustomersByEmail(String email) {
  78.         Contact c = new Contact();
  79.         c.setEmail(email);
  80.         return customerSessionLocal.searchCustomersByContact(c);
  81.     }
  82.  
  83.     public Set<String> getAllFieldNames() {
  84.         return customerSessionLocal.getAllFieldNames();
  85.     }
  86.  
  87.     public void addField(Long cId, String name, String value) throws NoResultException {
  88.         Field f = new Field();
  89.         f.setName(name);
  90.         f.setValue(value);
  91.  
  92.         customerSessionLocal.addField(cId, f);
  93.     }
  94.  
  95.     public void addPhone(Long cId, String value) throws NoResultException {
  96.         Contact c = new Contact();
  97.         c.setPhone(value);
  98.  
  99.         customerSessionLocal.addContact(cId, c);
  100.     }
  101.  
  102.     public void addEmail(Long cId, String value) throws NoResultException {
  103.         Contact c = new Contact();
  104.         c.setEmail(value);
  105.  
  106.         customerSessionLocal.addContact(cId, c);
  107.     }
  108.  
  109.     public void deleteField(Long cId, Long fId) throws NoResultException {
  110.         customerSessionLocal.deleteField(cId, fId);
  111.     }
  112.    
  113.     public void deleteContact(Long cId) throws NoResultException {
  114.         customerSessionLocal.deleteContact(cId);
  115.     }
  116.  
  117.     public void deleteCustomer(Long cId) throws NoResultException {
  118.         customerSessionLocal.deleteCustomer(cId);
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement