001/** 002 * Copyright 2005-2016 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.ArrayList; 019import java.util.List; 020 021import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; 022import org.kuali.rice.krad.service.KRADServiceLocator; 023import edu.sampleu.bookstore.bo.Account; 024import edu.sampleu.bookstore.bo.Address; 025import edu.sampleu.bookstore.bo.Author; 026 027/** 028 * maintainableClass for Author document. 029 * Action to be taken before saving the BO 030 */ 031 032public class AuthorMaintainable extends KualiMaintainableImpl { 033 034 035 private static final long serialVersionUID = 1L; 036 037 @Override 038 public void saveBusinessObject() { 039 // TODO Auto-generated method stub 040 Author author = (Author) this.getBusinessObject(); 041 042 Account account = (Account)author.getExtension(); 043 if(account != null && account.getAuthorId() == null) { 044 author.setExtension(null); 045 } 046 047 List<Address> addresses = new ArrayList<Address>(); 048 addresses = author.getAddresses(); 049 for(Address address : addresses){ 050 if(address != null && address.getAuthorId() == null) { 051 address.setAuthorId(null); 052 } 053 } 054 055 KRADServiceLocator.getBusinessObjectService().save(author); 056 057 if(account != null && account.getAuthorId() == null) { 058 account.setAuthorId(author.getAuthorId()); 059 KRADServiceLocator.getBusinessObjectService().save(account); 060 } 061 for(Address address : addresses){ 062 if(address != null && address.getAuthorId() == null) { 063 address.setAuthorId(author.getAuthorId()); 064 KRADServiceLocator.getBusinessObjectService().save(address); 065 } 066 } 067 } 068 069}