-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVendorService.java
More file actions
58 lines (47 loc) · 1.62 KB
/
VendorService.java
File metadata and controls
58 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package Service;
import DAO.VendorDAO;
import Exceptions.VendorException;
import Model.Vendor;
import java.util.ArrayList;
import java.util.List;
public class VendorService {
VendorDAO vendorDAO;
public VendorService(VendorDAO vendorDAO){
this.vendorDAO = vendorDAO;
}
List<Vendor> vendors;
public VendorService() {
vendors = new ArrayList<>();
}
//add new vendor
public void saveVendor(Vendor v) throws VendorException {
if (v.getVendorName().isEmpty()) {
throw new VendorException("Vendor Name cannot be null");
// More efficient to not pull the whole database and instead pull a small subset as needed.
} else if (!vendorDAO.getVendorsByName(v.getVendorName()).isEmpty()){ //update to be only name and not both params
throw new VendorException("Vendor already exists");
}
vendorDAO.insertVendor(v);
}
//get all vendors
public List<Vendor> getVendors() {
return vendorDAO.getVendors();
}
//get vendor by vendorID
public Vendor getVendorById(int vendorId) throws VendorException {
Vendor v = vendorDAO.getVendorById(vendorId);
if (v == null) {
throw new VendorException("No such vendor ID found");
} else {
return v;
}
}
//update/put vendor by vendorID
public void updateVendor (Vendor v, int id) throws VendorException {
if (v.getVendorName().isEmpty()) {
throw new VendorException("Vendor Name cannot by blank");
}
vendorDAO.updateVendor(v, id);
}
//delete vendor (see DAO notes)
}