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 | 0 | public class AuthorMaintainable extends KualiMaintainableImpl { |
18 | |
|
19 | |
|
20 | |
private static final long serialVersionUID = 1L; |
21 | |
|
22 | |
@Override |
23 | |
public void saveBusinessObject() { |
24 | |
|
25 | 0 | Author author = (Author) this.getBusinessObject(); |
26 | |
|
27 | 0 | Account account = (Account)author.getExtension(); |
28 | 0 | if(account != null && account.getAuthorId() == null) { |
29 | 0 | author.setExtension(null); |
30 | |
} |
31 | |
|
32 | 0 | List<Address> addresses = new ArrayList<Address>(); |
33 | 0 | addresses = author.getAddresses(); |
34 | 0 | for(Address address : addresses){ |
35 | 0 | if(address != null && address.getAuthorId() == null) { |
36 | 0 | address.setAuthorId(null); |
37 | |
} |
38 | |
} |
39 | |
|
40 | 0 | KRADServiceLocator.getBusinessObjectService().save(author); |
41 | |
|
42 | 0 | if(account != null && account.getAuthorId() == null) { |
43 | 0 | account.setAuthorId(author.getAuthorId()); |
44 | 0 | KRADServiceLocator.getBusinessObjectService().save(account); |
45 | |
} |
46 | 0 | for(Address address : addresses){ |
47 | 0 | if(address != null && address.getAuthorId() == null) { |
48 | 0 | address.setAuthorId(author.getAuthorId()); |
49 | 0 | KRADServiceLocator.getBusinessObjectService().save(address); |
50 | |
} |
51 | |
} |
52 | 0 | } |
53 | |
|
54 | |
} |