View Javadoc

1   /**
2    * Copyright 2005-2013 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.kns.service.KNSServiceLocator;
23  import org.kuali.rice.krad.service.KRADServiceLocator;
24  import edu.sampleu.bookstore.bo.Account;
25  import edu.sampleu.bookstore.bo.Address;
26  import edu.sampleu.bookstore.bo.Author;
27  
28  /**
29   * maintainableClass for Author document.
30   * Action to be taken before saving the BO
31   */
32  
33  public class AuthorMaintainable extends KualiMaintainableImpl {
34  	
35  	
36  	private static final long serialVersionUID = 1L;
37  
38  	@Override
39  	public void saveBusinessObject() {
40  		// TODO Auto-generated method stub
41  		Author author = (Author) this.getBusinessObject();
42  		 
43  		Account account = (Account)author.getExtension();
44  		if(account != null && account.getAuthorId() == null) {			
45  			author.setExtension(null);
46  		}
47  		
48  		List<Address> addresses = new ArrayList<Address>();
49  		addresses = author.getAddresses();
50  		for(Address address : addresses){
51  			if(address != null && address.getAuthorId() == null) {			
52  				address.setAuthorId(null);
53  			}
54  		}
55  
56          KNSServiceLocator.getBusinessObjectService().save(author);
57  		
58  		if(account != null && account.getAuthorId() == null) {			
59  			account.setAuthorId(author.getAuthorId());
60              KNSServiceLocator.getBusinessObjectService().save(account);
61  		}
62  		for(Address address : addresses){
63  			if(address != null && address.getAuthorId() == null) {			
64  				address.setAuthorId(author.getAuthorId());
65                  KNSServiceLocator.getBusinessObjectService().save(address);
66  			}
67  		}
68  	}
69  
70  }