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