001 package edu.sampleu.bookstore.maintenance; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 006 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; 007 import org.kuali.rice.krad.service.KRADServiceLocator; 008 import edu.sampleu.bookstore.bo.Account; 009 import edu.sampleu.bookstore.bo.Address; 010 import edu.sampleu.bookstore.bo.Author; 011 012 /** 013 * maintainableClass for Author document. 014 * Action to be taken before saving the BO 015 */ 016 017 public class AuthorMaintainable extends KualiMaintainableImpl { 018 019 020 private static final long serialVersionUID = 1L; 021 022 @Override 023 public void saveBusinessObject() { 024 // TODO Auto-generated method stub 025 Author author = (Author) this.getBusinessObject(); 026 027 Account account = (Account)author.getExtension(); 028 if(account != null && account.getAuthorId() == null) { 029 author.setExtension(null); 030 } 031 032 List<Address> addresses = new ArrayList<Address>(); 033 addresses = author.getAddresses(); 034 for(Address address : addresses){ 035 if(address != null && address.getAuthorId() == null) { 036 address.setAuthorId(null); 037 } 038 } 039 040 KRADServiceLocator.getBusinessObjectService().save(author); 041 042 if(account != null && account.getAuthorId() == null) { 043 account.setAuthorId(author.getAuthorId()); 044 KRADServiceLocator.getBusinessObjectService().save(account); 045 } 046 for(Address address : addresses){ 047 if(address != null && address.getAuthorId() == null) { 048 address.setAuthorId(author.getAuthorId()); 049 KRADServiceLocator.getBusinessObjectService().save(address); 050 } 051 } 052 } 053 054 }