View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.ole.vnd.businessobject;
18  
19  import java.util.Collection;
20  import java.util.Collections;
21  import java.util.HashMap;
22  import java.util.LinkedHashMap;
23  import java.util.Map;
24  
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.ole.sys.identity.OleKimAttributes;
27  import org.kuali.ole.sys.service.impl.OleParameterConstants;
28  import org.kuali.ole.vnd.identity.ContractManagerRoleTypeServiceImpl;
29  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
30  import org.kuali.rice.core.api.util.type.KualiDecimal;
31  import org.kuali.rice.kim.api.identity.Person;
32  import org.kuali.rice.kim.api.identity.PersonService;
33  import org.kuali.rice.kim.api.role.RoleMembership;
34  import org.kuali.rice.kim.api.role.RoleService;
35  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
36  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
37  import org.kuali.rice.krad.util.ObjectUtils;
38  
39  /**
40   * Individuals who are assigned to manage a particular set of Contracts with Vendors, who must therefore look at associated Purchase
41   * Orders.
42   *
43   * @see org.kuali.ole.vnd.businessobject.VendorContract
44   */
45  public class ContractManager extends PersistableBusinessObjectBase implements MutableInactivatable {
46  
47      private Integer contractManagerCode;
48      private String contractManagerName;
49      private String contractManagerPhoneNumber;
50      private String contractManagerFaxNumber;
51      private KualiDecimal contractManagerDelegationDollarLimit;
52      private boolean active;
53  
54  
55      /**
56       * Default constructor.
57       */
58      public ContractManager() {
59      }
60  
61      public Integer getContractManagerCode() {
62          return contractManagerCode;
63      }
64  
65      public void setContractManagerCode(Integer contractManagerCode) {
66          this.contractManagerCode = contractManagerCode;
67      }
68  
69      public String getContractManagerName() {
70          return contractManagerName;
71      }
72  
73      public void setContractManagerName(String contractManagerName) {
74          this.contractManagerName = contractManagerName;
75      }
76  
77      public String getContractManagerPhoneNumber() {
78          return contractManagerPhoneNumber;
79      }
80  
81      public void setContractManagerPhoneNumber(String contractManagerPhoneNumber) {
82          this.contractManagerPhoneNumber = contractManagerPhoneNumber;
83      }
84  
85      public String getContractManagerFaxNumber() {
86          return contractManagerFaxNumber;
87      }
88  
89      public void setContractManagerFaxNumber(String contractManagerFaxNumber) {
90          this.contractManagerFaxNumber = contractManagerFaxNumber;
91      }
92  
93      public KualiDecimal getContractManagerDelegationDollarLimit() {
94          return contractManagerDelegationDollarLimit;
95      }
96  
97      public void setContractManagerDelegationDollarLimit(KualiDecimal contractManagerDelegationDollarLimit) {
98          this.contractManagerDelegationDollarLimit = contractManagerDelegationDollarLimit;
99      }
100 
101     /**
102      * This method gets the contract manager user identifier.
103      * @return contractManagerId
104      */
105     public String getContractManagerUserIdentifier() {
106         String contractManagerId = null;
107         Map<String,String> qualification = new HashMap<String,String>();
108 
109         RoleService roleService = KimApiServiceLocator.getRoleService();
110         String roleId = roleService.getRoleIdByNamespaceCodeAndName(OleParameterConstants.PURCHASING_NAMESPACE, ContractManagerRoleTypeServiceImpl.CONTRACT_MANAGER_ROLE_NAME);
111 
112         qualification.put(OleKimAttributes.CONTRACT_MANAGER_CODE, String.valueOf(contractManagerCode));
113         Collection<RoleMembership> roleMemberships = roleService.getRoleMembers(Collections.singletonList(roleId), qualification);
114 
115         for (RoleMembership membership : roleMemberships) {
116             contractManagerId = membership.getMemberId();
117             break;
118         }
119 
120         return contractManagerId;
121     }
122 
123     public Person getContractManagerPerson() {
124         Person contractManager = SpringContext.getBean(PersonService.class).getPerson(getContractManagerUserIdentifier());
125         if (ObjectUtils.isNotNull(contractManager)) {
126             return contractManager;
127         }
128         return null;
129     }
130 
131     /**
132      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
133      */
134     @SuppressWarnings({ "unchecked", "rawtypes" })
135     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
136         LinkedHashMap m = new LinkedHashMap();
137         if (this.contractManagerCode != null) {
138             m.put("contractManagerCode", this.contractManagerCode.toString());
139         }
140 
141         return m;
142     }
143 
144     @Override
145     public boolean isActive() {
146         return active;
147     }
148 
149     @Override
150     public void setActive(boolean active) {
151         this.active = active;
152     }
153 }