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