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.vnd.businessobject; 018 019 import java.util.Collection; 020 import java.util.Collections; 021 import java.util.LinkedHashMap; 022 023 import org.kuali.kfs.sys.context.SpringContext; 024 import org.kuali.kfs.sys.identity.KfsKimAttributes; 025 import org.kuali.kfs.sys.service.impl.KfsParameterConstants; 026 import org.kuali.kfs.vnd.identity.ContractManagerRoleTypeServiceImpl; 027 import org.kuali.rice.kim.bo.Person; 028 import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo; 029 import org.kuali.rice.kim.bo.types.dto.AttributeSet; 030 import org.kuali.rice.kim.service.PersonService; 031 import org.kuali.rice.kim.service.RoleManagementService; 032 import org.kuali.rice.kns.bo.Inactivateable; 033 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; 034 import org.kuali.rice.kns.util.KualiDecimal; 035 import org.kuali.rice.kns.util.ObjectUtils; 036 037 /** 038 * Individuals who are assigned to manage a particular set of Contracts with Vendors, who must therefore look at associated Purchase 039 * Orders. 040 * 041 * @see org.kuali.kfs.vnd.businessobject.VendorContract 042 */ 043 public class ContractManager extends PersistableBusinessObjectBase implements Inactivateable{ 044 045 private Integer contractManagerCode; 046 private String contractManagerName; 047 private String contractManagerPhoneNumber; 048 private String contractManagerFaxNumber; 049 private KualiDecimal contractManagerDelegationDollarLimit; 050 private boolean active; 051 052 053 /** 054 * Default constructor. 055 */ 056 public ContractManager() { 057 } 058 059 public Integer getContractManagerCode() { 060 return contractManagerCode; 061 } 062 063 public void setContractManagerCode(Integer contractManagerCode) { 064 this.contractManagerCode = contractManagerCode; 065 } 066 067 public String getContractManagerName() { 068 return contractManagerName; 069 } 070 071 public void setContractManagerName(String contractManagerName) { 072 this.contractManagerName = contractManagerName; 073 } 074 075 public String getContractManagerPhoneNumber() { 076 return contractManagerPhoneNumber; 077 } 078 079 public void setContractManagerPhoneNumber(String contractManagerPhoneNumber) { 080 this.contractManagerPhoneNumber = contractManagerPhoneNumber; 081 } 082 083 public String getContractManagerFaxNumber() { 084 return contractManagerFaxNumber; 085 } 086 087 public void setContractManagerFaxNumber(String contractManagerFaxNumber) { 088 this.contractManagerFaxNumber = contractManagerFaxNumber; 089 } 090 091 public KualiDecimal getContractManagerDelegationDollarLimit() { 092 return contractManagerDelegationDollarLimit; 093 } 094 095 public void setContractManagerDelegationDollarLimit(KualiDecimal contractManagerDelegationDollarLimit) { 096 this.contractManagerDelegationDollarLimit = contractManagerDelegationDollarLimit; 097 } 098 099 /** 100 * This method gets the contract manager user identifier. 101 * @return contractManagerId 102 */ 103 public String getContractManagerUserIdentifier() { 104 String contractManagerId = null; 105 AttributeSet qualification = new AttributeSet(); 106 107 RoleManagementService roleService = SpringContext.getBean(RoleManagementService.class); 108 String roleId = roleService.getRoleIdByName(KfsParameterConstants.PURCHASING_NAMESPACE, ContractManagerRoleTypeServiceImpl.CONTRACT_MANAGER_ROLE_NAME); 109 // String roleId = roleService.getRoleIdByName(KFSConstants.ParameterNamespaces.PURCHASING, ContractManagerRoleTypeServiceImpl.CONTRACT_MANAGER_ROLE_NAME); 110 111 qualification.put(KfsKimAttributes.CONTRACT_MANAGER_CODE, String.valueOf(contractManagerCode)); 112 Collection<RoleMembershipInfo> roleMemberships = roleService.getRoleMembers(Collections.singletonList(roleId), qualification); 113 114 for (RoleMembershipInfo membership : roleMemberships) { 115 contractManagerId = membership.getMemberId(); 116 break; 117 } 118 119 return contractManagerId; 120 } 121 122 public Person getContractManagerPerson() { 123 Person contractManager = SpringContext.getBean(PersonService.class).getPerson(getContractManagerUserIdentifier()); 124 if (ObjectUtils.isNotNull(contractManager)) { 125 return contractManager; 126 } 127 return null; 128 } 129 130 /** 131 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper() 132 */ 133 @SuppressWarnings({ "unchecked", "rawtypes" }) 134 protected LinkedHashMap toStringMapper() { 135 LinkedHashMap m = new LinkedHashMap(); 136 if (this.contractManagerCode != null) { 137 m.put("contractManagerCode", this.contractManagerCode.toString()); 138 } 139 140 return m; 141 } 142 143 public boolean isActive() { 144 return active; 145 } 146 147 public void setActive(boolean active) { 148 this.active = active; 149 } 150 }