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.List;
19  import java.util.Map;
20  
21  import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
22  import org.kuali.rice.krad.document.MaintenanceDocument;
23  import org.kuali.rice.krad.service.KRADServiceLocator;
24  import edu.sampleu.bookstore.bo.Account;
25  import edu.sampleu.bookstore.bo.Author;
26  import edu.sampleu.bookstore.bo.Book;
27  
28  /**
29   * maintainableClass for Book document. 
30   * Action to be taken before saving the BO
31   */
32  
33  public class BookMaintainable 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  		Book book = (Book) this.getBusinessObject();
42  	
43  
44  		// /-----------------------------------------------------///
45  		// /-----------------------------------------------------///
46  		// /---IF author has to be edited from Book Document-----///
47  		// /---follow the below mentioned code else comment out--///
48  		// /-----------------------------------------------------///
49  		// /-----------------------------------------------------///
50  		List<Author> authors = book.getAuthors();
51  		for (Author author : authors) {
52  			Account account = (Account) author.getExtension();
53  			if (account != null && account.getAuthorId() == null) {
54  				author.setExtension(null);
55  			}
56  
57  			KRADServiceLocator.getBusinessObjectService().save(author);
58  
59  			if (account != null && account.getAuthorId() == null) {
60  				account.setAuthorId(author.getAuthorId());
61  				KRADServiceLocator.getBusinessObjectService().save(account);
62  			}
63  		}
64  
65  		book.setAuthors(authors);
66  		KRADServiceLocator.getBusinessObjectService().save(book);
67  
68  	}
69  
70  	@Override
71  	public void processAfterCopy(MaintenanceDocument document,
72  			Map<String, String[]> parameters) {
73  		super.processAfterCopy(document, parameters);
74  		Book book = ((Book) document.getNewMaintainableObject()
75  				.getDataObject());
76  		book.setIsbn(null);
77  	}
78  
79  }