001/** 002 * Copyright 2005-2013 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 org.kuali.rice.krms.util; 017 018import org.kuali.rice.core.api.util.RiceKeyConstants; 019import org.kuali.rice.krad.bo.GlobalBusinessObject; 020import org.kuali.rice.krad.maintenance.MaintenanceDocument; 021import org.kuali.rice.krad.util.KRADConstants; 022import org.kuali.rice.krms.dto.RuleManagementWrapper; 023import org.kuali.student.common.uif.rule.KsMaintenanceDocumentRuleBase; 024 025/** 026 * This class contains the rules for the AgendaEditor. 027 * 028 * @author Kuali Student Team 029 */ 030public class RuleEditorBusRule extends KsMaintenanceDocumentRuleBase { 031 032 @Override 033 protected boolean primaryKeyCheck(MaintenanceDocument document) { 034 // default to success if no failures 035 boolean success = true; 036 Class<?> dataObjectClass = document.getNewMaintainableObject().getDataObjectClass(); 037 038 // Since the dataObject is a wrapper class we need to return the agendaBo instead. 039 Object oldBo = ((RuleManagementWrapper) document.getOldMaintainableObject().getDataObject()); 040 Object newDataObject = ((RuleManagementWrapper) document.getNewMaintainableObject().getDataObject()); 041 042 // We dont do primaryKeyChecks on Global Business Object maintenance documents. This is 043 // because it doesnt really make any sense to do so, given the behavior of Globals. When a 044 // Global Document completes, it will update or create a new record for each BO in the list. 045 // As a result, there's no problem with having existing BO records in the system, they will 046 // simply get updated. 047 if (newDataObject instanceof GlobalBusinessObject) { 048 return success; 049 } 050 051 // fail and complain if the person has changed the primary keys on 052 // an EDIT maintenance document. 053 if (document.isEdit()) { 054 if (!getDataObjectMetaDataService().equalsByPrimaryKeys(oldBo, newDataObject)) { 055 // add a complaint to the errors 056 putDocumentError(KRADConstants.DOCUMENT_ERRORS, 057 RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_PRIMARY_KEYS_CHANGED_ON_EDIT, 058 getHumanReadablePrimaryKeyFieldNames(dataObjectClass)); 059 success &= false; 060 } 061 } 062 063 return success; 064 } 065 066 @Override 067 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { 068 return true; 069 } 070 071} 072