1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package edu.sampleu.bookstore.maintenance; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; |
22 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
23 | |
import edu.sampleu.bookstore.bo.Account; |
24 | |
import edu.sampleu.bookstore.bo.Address; |
25 | |
import edu.sampleu.bookstore.bo.Author; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class AuthorMaintainable extends KualiMaintainableImpl { |
33 | |
|
34 | |
|
35 | |
private static final long serialVersionUID = 1L; |
36 | |
|
37 | |
@Override |
38 | |
public void saveBusinessObject() { |
39 | |
|
40 | 0 | Author author = (Author) this.getBusinessObject(); |
41 | |
|
42 | 0 | Account account = (Account)author.getExtension(); |
43 | 0 | if(account != null && account.getAuthorId() == null) { |
44 | 0 | author.setExtension(null); |
45 | |
} |
46 | |
|
47 | 0 | List<Address> addresses = new ArrayList<Address>(); |
48 | 0 | addresses = author.getAddresses(); |
49 | 0 | for(Address address : addresses){ |
50 | 0 | if(address != null && address.getAuthorId() == null) { |
51 | 0 | address.setAuthorId(null); |
52 | |
} |
53 | |
} |
54 | |
|
55 | 0 | KRADServiceLocator.getBusinessObjectService().save(author); |
56 | |
|
57 | 0 | if(account != null && account.getAuthorId() == null) { |
58 | 0 | account.setAuthorId(author.getAuthorId()); |
59 | 0 | KRADServiceLocator.getBusinessObjectService().save(account); |
60 | |
} |
61 | 0 | for(Address address : addresses){ |
62 | 0 | if(address != null && address.getAuthorId() == null) { |
63 | 0 | address.setAuthorId(author.getAuthorId()); |
64 | 0 | KRADServiceLocator.getBusinessObjectService().save(address); |
65 | |
} |
66 | |
} |
67 | 0 | } |
68 | |
|
69 | |
} |