| 1 | package org.nakedobjects.application.accounts.fixture; |
|---|
| 2 | |
|---|
| 3 | import org.nakedobjects.applib.fixtures.AbstractFixture; |
|---|
| 4 | import org.nakedobjects.applib.value.Date; |
|---|
| 5 | import org.nakedobjects.applib.value.Money; |
|---|
| 6 | |
|---|
| 7 | import org.nakedobjects.application.accounts.dom.claim.Claim; |
|---|
| 8 | import org.nakedobjects.application.accounts.dom.claim.ClaimItem; |
|---|
| 9 | import org.nakedobjects.application.accounts.dom.employee.Employee; |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | public class ClaimsFixture extends AbstractFixture { |
|---|
| 13 | |
|---|
| 14 | @Override |
|---|
| 15 | public void install() { |
|---|
| 16 | Employee fred = createCustomer("Fred Smith", null); |
|---|
| 17 | Employee tom = createCustomer("Tom Brown", fred); |
|---|
| 18 | createCustomer("Sam Jones", fred); |
|---|
| 19 | |
|---|
| 20 | Claim claim = createClaim(tom, -16, "Meeting with client"); |
|---|
| 21 | addItem(claim, -16, 38.50, "Lunch with client"); |
|---|
| 22 | addItem(claim, -16, 16.50, "Euston - Mayfair (return)"); |
|---|
| 23 | |
|---|
| 24 | claim = createClaim(tom, -18, "Meeting in city office"); |
|---|
| 25 | addItem(claim, -16, 18.00, "Car parking"); |
|---|
| 26 | addItem(claim, -16, 26.50, "Reading - London (return)"); |
|---|
| 27 | |
|---|
| 28 | claim = createClaim(fred, -14, "Meeting at clients"); |
|---|
| 29 | addItem(claim, -14, 18.00, "Car parking"); |
|---|
| 30 | addItem(claim, -14, 26.50, "Reading - London (return)"); |
|---|
| 31 | |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | private Employee createCustomer(String name, Employee approver) { |
|---|
| 35 | Employee claimant; |
|---|
| 36 | claimant = newTransientInstance(Employee.class); |
|---|
| 37 | claimant.setName(name); |
|---|
| 38 | claimant.setApprover(approver); |
|---|
| 39 | persist(claimant); |
|---|
| 40 | return claimant; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | private Claim createClaim(Employee claimant, int days, String description) { |
|---|
| 44 | Claim claim = newTransientInstance(Claim.class); |
|---|
| 45 | claim.setClaimant(claimant); |
|---|
| 46 | claim.setDescription(description); |
|---|
| 47 | Date date = new Date(); |
|---|
| 48 | date = date.add(0,0, days); |
|---|
| 49 | claim.setDate(date); |
|---|
| 50 | persist(claim); |
|---|
| 51 | return claim; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | private void addItem(Claim claim, int days, double amount, String description) { |
|---|
| 55 | ClaimItem claimItem = newTransientInstance(ClaimItem.class); |
|---|
| 56 | Date date = new Date(); |
|---|
| 57 | date = date.add(0,0, days); |
|---|
| 58 | claimItem.setDateIncurred(date); |
|---|
| 59 | claimItem.setDescription(description); |
|---|
| 60 | claimItem.setAmount(new Money(amount, "USD")); |
|---|
| 61 | persist(claimItem); |
|---|
| 62 | claim.addToItems(claimItem); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | } |
|---|