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