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.List;
19 import java.util.Map;
20
21 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
22 import org.kuali.rice.krad.document.MaintenanceDocument;
23 import org.kuali.rice.krad.service.KRADServiceLocator;
24 import edu.sampleu.bookstore.bo.Account;
25 import edu.sampleu.bookstore.bo.Author;
26 import edu.sampleu.bookstore.bo.Book;
27
28
29
30
31
32
33 public class BookMaintainable extends KualiMaintainableImpl {
34
35
36 private static final long serialVersionUID = 1L;
37
38 @Override
39 public void saveBusinessObject() {
40
41 Book book = (Book) this.getBusinessObject();
42
43
44
45
46
47
48
49
50 List<Author> authors = book.getAuthors();
51 for (Author author : authors) {
52 Account account = (Account) author.getExtension();
53 if (account != null && account.getAuthorId() == null) {
54 author.setExtension(null);
55 }
56
57 KRADServiceLocator.getBusinessObjectService().save(author);
58
59 if (account != null && account.getAuthorId() == null) {
60 account.setAuthorId(author.getAuthorId());
61 KRADServiceLocator.getBusinessObjectService().save(account);
62 }
63 }
64
65 book.setAuthors(authors);
66 KRADServiceLocator.getBusinessObjectService().save(book);
67
68 }
69
70 @Override
71 public void processAfterCopy(MaintenanceDocument document,
72 Map<String, String[]> parameters) {
73 super.processAfterCopy(document, parameters);
74 Book book = ((Book) document.getNewMaintainableObject()
75 .getDataObject());
76 book.setIsbn(null);
77 }
78
79 }