001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package edu.sampleu.bookstore.maintenance; 017 018import java.util.List; 019import java.util.Map; 020 021import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; 022import org.kuali.rice.kns.service.KNSServiceLocator; 023import org.kuali.rice.krad.maintenance.MaintenanceDocument; 024import org.kuali.rice.krad.service.KRADServiceLocator; 025import edu.sampleu.bookstore.bo.Account; 026import edu.sampleu.bookstore.bo.Author; 027import edu.sampleu.bookstore.bo.Book; 028 029/** 030 * maintainableClass for Book document. 031 * Action to be taken before saving the BO 032 */ 033 034public class BookMaintainable extends KualiMaintainableImpl { 035 036 037 private static final long serialVersionUID = 1L; 038 039 @Override 040 public void saveBusinessObject() { 041 // TODO Auto-generated method stub 042 Book book = (Book) this.getBusinessObject(); 043 044 045 // /-----------------------------------------------------/// 046 // /-----------------------------------------------------/// 047 // /---IF author has to be edited from Book Document-----/// 048 // /---follow the below mentioned code else comment out--/// 049 // /-----------------------------------------------------/// 050 // /-----------------------------------------------------/// 051 List<Author> authors = book.getAuthors(); 052 for (Author author : authors) { 053 Account account = (Account) author.getExtension(); 054 if (account != null && account.getAuthorId() == null) { 055 author.setExtension(null); 056 } 057 058 KNSServiceLocator.getBusinessObjectService().save(author); 059 060 if (account != null && account.getAuthorId() == null) { 061 account.setAuthorId(author.getAuthorId()); 062 KNSServiceLocator.getBusinessObjectService().save(account); 063 } 064 } 065 066 book.setAuthors(authors); 067 KNSServiceLocator.getBusinessObjectService().save(book); 068 069 } 070 071 @Override 072 public void processAfterCopy(MaintenanceDocument document, 073 Map<String, String[]> parameters) { 074 super.processAfterCopy(document, parameters); 075 Book book = ((Book) document.getNewMaintainableObject() 076 .getDataObject()); 077 book.setIsbn(null); 078 } 079 080}