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.kns.service.KNSServiceLocator;
23 import org.kuali.rice.krad.service.KRADServiceLocator;
24 import edu.sampleu.bookstore.bo.Account;
25 import edu.sampleu.bookstore.bo.Address;
26 import edu.sampleu.bookstore.bo.Author;
27
28
29
30
31
32
33 public class AuthorMaintainable extends KualiMaintainableImpl {
34
35
36 private static final long serialVersionUID = 1L;
37
38 @Override
39 public void saveBusinessObject() {
40
41 Author author = (Author) this.getBusinessObject();
42
43 Account account = (Account)author.getExtension();
44 if(account != null && account.getAuthorId() == null) {
45 author.setExtension(null);
46 }
47
48 List<Address> addresses = new ArrayList<Address>();
49 addresses = author.getAddresses();
50 for(Address address : addresses){
51 if(address != null && address.getAuthorId() == null) {
52 address.setAuthorId(null);
53 }
54 }
55
56 KNSServiceLocator.getBusinessObjectService().save(author);
57
58 if(account != null && account.getAuthorId() == null) {
59 account.setAuthorId(author.getAuthorId());
60 KNSServiceLocator.getBusinessObjectService().save(account);
61 }
62 for(Address address : addresses){
63 if(address != null && address.getAuthorId() == null) {
64 address.setAuthorId(author.getAuthorId());
65 KNSServiceLocator.getBusinessObjectService().save(address);
66 }
67 }
68 }
69
70 }