001 package edu.sampleu.bookstore.maintenance; 002 003 import java.util.List; 004 import java.util.Map; 005 006 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; 007 import org.kuali.rice.krad.document.MaintenanceDocument; 008 import org.kuali.rice.krad.service.KRADServiceLocator; 009 import edu.sampleu.bookstore.bo.Account; 010 import edu.sampleu.bookstore.bo.Author; 011 import edu.sampleu.bookstore.bo.Book; 012 013 /** 014 * maintainableClass for Book document. 015 * Action to be taken before saving the BO 016 */ 017 018 public class BookMaintainable extends KualiMaintainableImpl { 019 020 021 private static final long serialVersionUID = 1L; 022 023 @Override 024 public void saveBusinessObject() { 025 // TODO Auto-generated method stub 026 Book book = (Book) this.getBusinessObject(); 027 028 029 // /-----------------------------------------------------/// 030 // /-----------------------------------------------------/// 031 // /---IF author has to be edited from Book Document-----/// 032 // /---follow the below mentioned code else comment out--/// 033 // /-----------------------------------------------------/// 034 // /-----------------------------------------------------/// 035 List<Author> authors = book.getAuthors(); 036 for (Author author : authors) { 037 Account account = (Account) author.getExtension(); 038 if (account != null && account.getAuthorId() == null) { 039 author.setExtension(null); 040 } 041 042 KRADServiceLocator.getBusinessObjectService().save(author); 043 044 if (account != null && account.getAuthorId() == null) { 045 account.setAuthorId(author.getAuthorId()); 046 KRADServiceLocator.getBusinessObjectService().save(account); 047 } 048 } 049 050 book.setAuthors(authors); 051 KRADServiceLocator.getBusinessObjectService().save(book); 052 053 } 054 055 @Override 056 public void processAfterCopy(MaintenanceDocument document, 057 Map<String, String[]> parameters) { 058 super.processAfterCopy(document, parameters); 059 Book book = ((Book) document.getNewMaintainableObject() 060 .getDataObject()); 061 book.setIsbn(null); 062 } 063 064 }