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 017 package org.kuali.kfs.module.cg.businessobject; 018 019 import java.util.LinkedHashMap; 020 021 import org.kuali.kfs.sys.KFSConstants; 022 import org.kuali.kfs.sys.context.SpringContext; 023 import org.kuali.rice.kim.bo.Person; 024 import org.kuali.rice.kim.bo.impl.PersonImpl; 025 import org.kuali.rice.kns.bo.Inactivateable; 026 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; 027 import org.kuali.rice.kns.util.ObjectUtils; 028 029 /** 030 * Represents a relationship between a {@link Proposal} and a {@link ProjectDirector}. 031 */ 032 public class ProposalProjectDirector extends PersistableBusinessObjectBase implements Primaryable, CGProjectDirector, Inactivateable { 033 034 private String principalId; 035 private Long proposalNumber; 036 private boolean proposalPrimaryProjectDirectorIndicator; 037 private String proposalProjectDirectorProjectTitle; 038 private boolean active = true; 039 040 private Person projectDirector; 041 042 043 private final String userLookupRoleNamespaceCode = KFSConstants.ParameterNamespaces.KFS; 044 private final String userLookupRoleName = KFSConstants.SysKimConstants.CONTRACTS_AND_GRANTS_PROJECT_DIRECTOR; 045 046 /** 047 * Default constructor. 048 */ 049 public ProposalProjectDirector() { 050 } 051 052 /** 053 * @see org.kuali.kfs.module.cg.businessobject.CGProjectDirector#getPrincipalId() 054 */ 055 public String getPrincipalId() { 056 return principalId; 057 } 058 059 /** 060 * @see org.kuali.kfs.module.cg.businessobject.CGProjectDirector#setPrincipalId(java.lang.String) 061 */ 062 public void setPrincipalId(String principalId) { 063 this.principalId = principalId; 064 } 065 066 /** 067 * @see org.kuali.kfs.module.cg.businessobject.CGProjectDirector#getProposalNumber() 068 */ 069 public Long getProposalNumber() { 070 return proposalNumber; 071 } 072 073 /** 074 * @see org.kuali.kfs.module.cg.businessobject.CGProjectDirector#setProposalNumber(java.lang.Long) 075 */ 076 public void setProposalNumber(Long proposalNumber) { 077 this.proposalNumber = proposalNumber; 078 } 079 080 081 /** 082 * Gets the proposalPrimaryProjectDirectorIndicator attribute. 083 * 084 * @return Returns the proposalPrimaryProjectDirectorIndicator 085 */ 086 public boolean isProposalPrimaryProjectDirectorIndicator() { 087 return proposalPrimaryProjectDirectorIndicator; 088 } 089 090 /** 091 * @see Primaryable#isPrimary() 092 */ 093 public boolean isPrimary() { 094 return isProposalPrimaryProjectDirectorIndicator(); 095 } 096 097 /** 098 * Sets the proposalPrimaryProjectDirectorIndicator attribute. 099 * 100 * @param proposalPrimaryProjectDirectorIndicator The proposalPrimaryProjectDirectorIndicator to set. 101 */ 102 public void setProposalPrimaryProjectDirectorIndicator(boolean proposalPrimaryProjectDirectorIndicator) { 103 this.proposalPrimaryProjectDirectorIndicator = proposalPrimaryProjectDirectorIndicator; 104 } 105 106 107 /** 108 * Gets the proposalProjectDirectorProjectTitle attribute. 109 * 110 * @return Returns the proposalProjectDirectorProjectTitle 111 */ 112 public String getProposalProjectDirectorProjectTitle() { 113 return proposalProjectDirectorProjectTitle; 114 } 115 116 /** 117 * Sets the proposalProjectDirectorProjectTitle attribute. 118 * 119 * @param proposalProjectDirectorProjectTitle The proposalProjectDirectorProjectTitle to set. 120 */ 121 public void setProposalProjectDirectorProjectTitle(String proposalProjectDirectorProjectTitle) { 122 this.proposalProjectDirectorProjectTitle = proposalProjectDirectorProjectTitle; 123 } 124 125 /** 126 * Gets the active attribute. 127 * 128 * @return Returns the active. 129 */ 130 public boolean isActive() { 131 return active; 132 } 133 134 /** 135 * Sets the active attribute value. 136 * 137 * @param active The active to set. 138 */ 139 public void setActive(boolean active) { 140 this.active = active; 141 } 142 143 /** 144 * @see org.kuali.kfs.module.cg.businessobject.CGProjectDirector#getProjectDirector() 145 */ 146 public Person getProjectDirector() { 147 if (principalId != null) { 148 projectDirector = SpringContext.getBean(org.kuali.rice.kim.service.PersonService.class).updatePersonIfNecessary(principalId, projectDirector); 149 } 150 return projectDirector; 151 } 152 153 /** 154 * @see org.kuali.kfs.module.cg.businessobject.CGProjectDirector#setProjectDirector(org.kuali.kfs.module.cg.businessobject.ProjectDirector) 155 */ 156 public void setProjectDirector(Person projectDirector) { 157 this.projectDirector = projectDirector; 158 } 159 160 /** 161 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper() 162 */ 163 protected LinkedHashMap toStringMapper() { 164 LinkedHashMap m = new LinkedHashMap(); 165 m.put("principalId", this.principalId); 166 if (this.proposalNumber != null) { 167 m.put("proposalNumber", this.proposalNumber.toString()); 168 } 169 return m; 170 } 171 172 /** 173 * This can be displayed by Proposal.xml lookup results. 174 * 175 * @see Object#toString() 176 */ 177 @Override 178 public String toString() { 179 // todo: get "nonexistent", "primary", and "secondary" from ApplicationResources.properties via KFSKeyConstants? 180 String name = ObjectUtils.isNull(getProjectDirector()) ? "nonexistent" : getProjectDirector().getName(); 181 String title = getProposalProjectDirectorProjectTitle() == null ? "" : " " + getProposalProjectDirectorProjectTitle(); 182 return name + " " + (isProposalPrimaryProjectDirectorIndicator() ? "primary" : "secondary") + title; 183 } 184 185 /** 186 * Gets the userLookupRoleNamespaceCode attribute. 187 * @return Returns the userLookupRoleNamespaceCode. 188 */ 189 public String getUserLookupRoleNamespaceCode() { 190 return userLookupRoleNamespaceCode; 191 } 192 193 /** 194 * Gets the userLookupRoleName attribute. 195 * @return Returns the userLookupRoleName. 196 */ 197 public String getUserLookupRoleName() { 198 return userLookupRoleName; 199 } 200 } 201