View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package edu.sampleu.bookstore.maintenance;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
22  import org.kuali.rice.krad.service.KRADServiceLocator;
23  import edu.sampleu.bookstore.bo.Account;
24  import edu.sampleu.bookstore.bo.Address;
25  import edu.sampleu.bookstore.bo.Author;
26  
27  /**
28   * maintainableClass for Author document.
29   * Action to be taken before saving the BO
30   */
31  
32  public class AuthorMaintainable extends KualiMaintainableImpl {
33  	
34  	
35  	private static final long serialVersionUID = 1L;
36  
37  	@Override
38  	public void saveBusinessObject() {
39  		// TODO Auto-generated method stub
40  		Author author = (Author) this.getBusinessObject();
41  		 
42  		Account account = (Account)author.getExtension();
43  		if(account != null && account.getAuthorId() == null) {			
44  			author.setExtension(null);
45  		}
46  		
47  		List<Address> addresses = new ArrayList<Address>();
48  		addresses = author.getAddresses();
49  		for(Address address : addresses){
50  			if(address != null && address.getAuthorId() == null) {			
51  				address.setAuthorId(null);
52  			}
53  		}
54  		
55  		KRADServiceLocator.getBusinessObjectService().save(author);
56  		
57  		if(account != null && account.getAuthorId() == null) {			
58  			account.setAuthorId(author.getAuthorId());			
59  			KRADServiceLocator.getBusinessObjectService().save(account);
60  		}
61  		for(Address address : addresses){
62  			if(address != null && address.getAuthorId() == null) {			
63  				address.setAuthorId(author.getAuthorId());			
64  				KRADServiceLocator.getBusinessObjectService().save(address);
65  			}
66  		}
67  	}
68  
69  }