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