View Javadoc

1   package edu.sampleu.bookstore.maintenance;
2   
3   import java.util.List;
4   import java.util.Map;
5   
6   import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
7   import org.kuali.rice.krad.document.MaintenanceDocument;
8   import org.kuali.rice.krad.service.KRADServiceLocator;
9   import edu.sampleu.bookstore.bo.Account;
10  import edu.sampleu.bookstore.bo.Author;
11  import edu.sampleu.bookstore.bo.Book;
12  
13  /**
14   * maintainableClass for Book document. 
15   * Action to be taken before saving the BO
16   */
17  
18  public class BookMaintainable extends KualiMaintainableImpl {
19  
20  	
21  	private static final long serialVersionUID = 1L;
22  
23  	@Override
24  	public void saveBusinessObject() {
25  		// TODO Auto-generated method stub
26  		Book book = (Book) this.getBusinessObject();
27  	
28  
29  		// /-----------------------------------------------------///
30  		// /-----------------------------------------------------///
31  		// /---IF author has to be edited from Book Document-----///
32  		// /---follow the below mentioned code else comment out--///
33  		// /-----------------------------------------------------///
34  		// /-----------------------------------------------------///
35  		List<Author> authors = book.getAuthors();
36  		for (Author author : authors) {
37  			Account account = (Account) author.getExtension();
38  			if (account != null && account.getAuthorId() == null) {
39  				author.setExtension(null);
40  			}
41  
42  			KRADServiceLocator.getBusinessObjectService().save(author);
43  
44  			if (account != null && account.getAuthorId() == null) {
45  				account.setAuthorId(author.getAuthorId());
46  				KRADServiceLocator.getBusinessObjectService().save(account);
47  			}
48  		}
49  
50  		book.setAuthors(authors);
51  		KRADServiceLocator.getBusinessObjectService().save(book);
52  
53  	}
54  
55  	@Override
56  	public void processAfterCopy(MaintenanceDocument document,
57  			Map<String, String[]> parameters) {
58  		super.processAfterCopy(document, parameters);
59  		Book book = ((Book) document.getNewMaintainableObject()
60  				.getDataObject());
61  		book.setIsbn(null);
62  	}
63  
64  }