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.ec.businessobject; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 021 import org.apache.commons.lang.StringUtils; 022 import org.kuali.kfs.module.ec.EffortPropertyConstants; 023 import org.kuali.kfs.module.ec.document.EffortCertificationDocument; 024 import org.kuali.kfs.sys.KFSPropertyConstants; 025 import org.kuali.kfs.sys.ObjectUtil; 026 import org.kuali.kfs.sys.context.SpringContext; 027 import org.kuali.rice.kew.exception.WorkflowException; 028 import org.kuali.rice.kim.bo.Person; 029 import org.kuali.rice.kns.service.ParameterConstants.COMPONENT; 030 import org.kuali.rice.kns.util.ObjectUtils; 031 import org.kuali.rice.kns.workflow.service.KualiWorkflowInfo; 032 033 /** 034 * Business object for the outstanding documents by organization report 035 */ 036 @COMPONENT(component="OutstandingCertificationsByOrganization") 037 public class OutstandingCertificationsByOrganization extends EffortCertificationDocument { 038 039 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OutstandingCertificationsByOrganization.class); 040 041 /** 042 * gets a string representation of the document's chart and organization. 043 * 044 * @return comma separated String 045 */ 046 public String getCertificationOrganizations() { 047 String certificationOrganizations = ""; 048 List<String> certificationOrganizationList = new ArrayList(); 049 List<EffortCertificationDetail> details = getEffortCertificationDetailLines(); 050 051 for (EffortCertificationDetail detailLine : details) { 052 String accountOrg = detailLine.getAccount().getChartOfAccountsCode() + "-" + detailLine.getAccount().getOrganizationCode(); 053 if (!certificationOrganizationList.contains(accountOrg)) { 054 certificationOrganizationList.add(accountOrg); 055 if (certificationOrganizations.equals("")) 056 certificationOrganizations = accountOrg; 057 else 058 certificationOrganizations = certificationOrganizations + ", " + accountOrg; 059 } 060 } 061 062 return certificationOrganizations; 063 } 064 065 /** 066 * Queries workflow to get users who have an approval request for this effort certification. 067 * 068 * @return String - names of users (seperated by comma) who have an approval request 069 */ 070 public String getNextApprovers() { 071 String nextApprovers = ""; 072 073 try { 074 List<String> approverUUIDs = SpringContext.getBean(KualiWorkflowInfo.class).getApprovalRequestedUsers(Long.valueOf(getDocumentHeader().getDocumentNumber())); 075 for (String approverUUID : approverUUIDs) { 076 Person approveUser = SpringContext.getBean(org.kuali.rice.kim.service.PersonService.class).getPerson(approverUUID); 077 if (approveUser == null) { 078 LOG.error("User information not found for UUID: " + approverUUID); 079 } 080 if (StringUtils.isBlank(nextApprovers)) { 081 nextApprovers = approveUser.getName(); 082 } 083 else { 084 nextApprovers += "; " + approveUser.getName(); 085 } 086 } 087 } 088 catch (WorkflowException e) { 089 LOG.error("Problem getting next approver", e); 090 } 091 092 return nextApprovers; 093 } 094 095 /** 096 * @see java.lang.Object#equals(java.lang.Object) 097 */ 098 @Override 099 public boolean equals(Object arg0) { 100 if(arg0 instanceof OutstandingCertificationsByOrganization) { 101 List<String> keyFields = new ArrayList<String>(); 102 keyFields.add(KFSPropertyConstants.DOCUMENT_NUMBER); 103 104 ObjectUtil.equals(this, arg0, keyFields ); 105 } 106 107 return false; 108 } 109 } 110