001 /* 002 * Copyright 2011 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 */ 016 package org.kuali.kfs.module.cam.document.validation.impl; 017 018 import org.kuali.kfs.coa.document.validation.impl.MaintenancePreRulesBase; 019 import org.kuali.kfs.module.cam.businessobject.Asset; 020 import org.kuali.rice.kns.document.MaintenanceDocument; 021 import org.kuali.rice.kns.util.GlobalVariables; 022 import org.kuali.rice.kns.util.ObjectUtils; 023 024 /** 025 * Business Prerules applicable to Asset documents. These PreRules checks for the Asset that needs to occur while 026 * still in the Struts processing. This includes setting the .... field using the values from .... and 027 * ..., and could be used for many other purposes.<br> 028 * This class (unlike AssetRule) does not delegate responsibility due to limited number of PreRules. 029 */ 030 public class AssetPreRule extends MaintenancePreRulesBase { 031 032 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AssetPreRule.class); 033 034 protected Asset newAsset; 035 protected Asset copyAsset; 036 protected String personId; 037 038 public AssetPreRule() { 039 } 040 041 /** 042 * Returns the Universal User Id of the current logged-in user 043 * 044 * @return String the PersonId 045 */ 046 047 public String getPersonId() { 048 if (ObjectUtils.isNull(personId)) { 049 this.personId = GlobalVariables.getUserSession().getPerson().getPrincipalId(); 050 } 051 return this.personId; 052 } 053 054 /** 055 * Sets up a convenience object and few other Asset attributes 056 * 057 * @see org.kuali.kfs.coa.document.validation.impl.MaintenancePreRulesBase#doCustomPreRules(org.kuali.rice.kns.document.MaintenanceDocument) 058 */ 059 @Override 060 061 protected boolean doCustomPreRules(MaintenanceDocument document) { 062 setupConvenienceObjects(document); 063 setFederalContribution(document); 064 return true; 065 } 066 067 /** 068 * Sets the convenience objects like newAsset and oldAsset, so you have short and easy handles to the new and old 069 * objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load all 070 * sub-objects from the DB by their primary keys, if available. 071 * 072 * @param document - the maintenanceDocument being evaluated 073 */ 074 protected void setupConvenienceObjects(MaintenanceDocument document) { 075 // setup newAccount convenience objects, make sure all possible sub-objects are populated 076 newAsset = (Asset) document.getNewMaintainableObject().getBusinessObject(); 077 copyAsset = (Asset) ObjectUtils.deepCopy(newAsset); 078 copyAsset.refresh(); 079 } 080 081 protected void setFederalContribution(MaintenanceDocument document) { 082 } 083 084 085 } 086