| 1 | |
package edu.sampleu.bookstore.maintenance; |
| 2 | |
|
| 3 | |
import java.util.List; |
| 4 | |
import java.util.Map; |
| 5 | |
|
| 6 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
| 7 | |
import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; |
| 8 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 9 | |
import edu.sampleu.bookstore.bo.Account; |
| 10 | |
import edu.sampleu.bookstore.bo.Author; |
| 11 | |
import edu.sampleu.bookstore.bo.Book; |
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | 0 | public class BookMaintainable extends KualiMaintainableImpl { |
| 19 | |
|
| 20 | |
|
| 21 | |
private static final long serialVersionUID = 1L; |
| 22 | |
|
| 23 | |
@Override |
| 24 | |
public void saveBusinessObject() { |
| 25 | |
|
| 26 | 0 | Book book = (Book) this.getBusinessObject(); |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | 0 | List<Author> authors = book.getAuthors(); |
| 36 | 0 | for (Author author : authors) { |
| 37 | 0 | Account account = (Account) author.getExtension(); |
| 38 | 0 | if (account != null && account.getAuthorId() == null) { |
| 39 | 0 | author.setExtension(null); |
| 40 | |
} |
| 41 | |
|
| 42 | 0 | KNSServiceLocator.getBusinessObjectService().save(author); |
| 43 | |
|
| 44 | 0 | if (account != null && account.getAuthorId() == null) { |
| 45 | 0 | account.setAuthorId(author.getAuthorId()); |
| 46 | 0 | KNSServiceLocator.getBusinessObjectService().save(account); |
| 47 | |
} |
| 48 | 0 | } |
| 49 | |
|
| 50 | 0 | book.setAuthors(authors); |
| 51 | 0 | KNSServiceLocator.getBusinessObjectService().save(book); |
| 52 | |
|
| 53 | 0 | } |
| 54 | |
|
| 55 | |
@Override |
| 56 | |
public void processAfterCopy(MaintenanceDocument document, |
| 57 | |
Map<String, String[]> parameters) { |
| 58 | 0 | super.processAfterCopy(document, parameters); |
| 59 | 0 | Book book = ((Book) document.getNewMaintainableObject() |
| 60 | |
.getBusinessObject()); |
| 61 | 0 | book.setIsbn(null); |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
} |