001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kew.actionitem; 017 018import org.kuali.rice.kew.api.KewApiConstants; 019import org.kuali.rice.kew.api.actionlist.DisplayParameters; 020import org.kuali.rice.kew.api.document.DocumentStatus; 021import org.kuali.rice.kew.api.preferences.Preferences; 022import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValueActionListExtension; 023import org.kuali.rice.kew.service.KEWServiceLocator; 024import org.kuali.rice.kew.web.RowStyleable; 025import org.kuali.rice.kim.api.group.Group; 026import org.kuali.rice.kim.api.identity.Person; 027import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName; 028import org.kuali.rice.kim.api.services.KimApiServiceLocator; 029import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 030import org.kuali.rice.krad.util.KRADConstants; 031import org.kuali.rice.kew.api.WorkflowDocument; 032 033import javax.persistence.MappedSuperclass; 034import javax.persistence.Transient; 035import java.sql.Timestamp; 036import java.util.Date; 037import java.util.HashMap; 038import java.util.Map; 039 040/** 041 * Alternate model object for action list fetches that do not automatically use 042 * ojb collections. This is here to make action list faster. 043 * 044 * @author Kuali Rice Team (rice.collab@kuali.org) 045 * 046 */ 047@MappedSuperclass 048public class ActionItemActionListExtension extends ActionItem implements RowStyleable { 049 050 private static final long serialVersionUID = -8801104028828059623L; 051 052 @Transient 053 private Timestamp lastApprovedDate; 054 @Transient 055 private Map<String, String> customActions = new HashMap<String, String>(); 056 @Transient 057 private String rowStyleClass; 058 @Transient 059 private Integer actionListIndex; 060 061 @Transient 062 private String delegatorName = ""; 063 @Transient 064 private String groupName = ""; 065 @Transient 066 private DisplayParameters displayParameters; 067 @Transient 068 private boolean isInitialized = false; 069 @Transient 070 private DocumentRouteHeaderValueActionListExtension routeHeader; 071 072 @Transient 073 private boolean lastApprovedDateInitialized = false; 074 @Transient 075 private boolean delegatorNameInitialized = false; 076 @Transient 077 private boolean groupNameInitialized = false; 078 079 080 081 //KRAD ActionList Stuff TODO 082 private String routeHeaderRouteStatus; 083 private Timestamp routeHeaderCreateDate; 084 private String routeHeaderInitiatorName; 085 private Timestamp routeHeaderApprovedDate; 086 private String routeHeaderCurrentRouteLevelName; 087 private String routeHeaderInitiatorWorkflowId; 088 private String actionSelected; 089 090 public String getActionSelected() { 091 return "NONE"; 092 } 093 094 public void setActionSelected(String actionSelected) { 095 this.actionSelected = actionSelected; 096 } 097 098 public String getRouteHeaderRouteStatus() { 099 return routeHeader.getDocRouteStatus(); 100 } 101 102 public Timestamp getRouteHeaderCreateDate() { 103 return routeHeader.getCreateDate(); 104 } 105 106 public String getRouteHeaderInitiatorName() { 107 return routeHeader.getInitiatorName(); 108 } 109 110 public Timestamp getRouteHeaderApprovedDate() { 111 return routeHeader.getApprovedDate(); 112 } 113 114 public String getRouteHeaderCurrentRouteLevelName() { 115 return routeHeader.getCurrentRouteLevelName(); 116 } 117 118 public String getRouteHeaderInitiatorWorkflowId() { 119 return routeHeader.getInitiatorWorkflowId(); 120 } 121 122 public Integer getActionListIndex() { 123 return actionListIndex; 124 } 125 126 public void setActionListIndex(Integer actionListIndex) { 127 this.actionListIndex = actionListIndex; 128 } 129 130 public Timestamp getLastApprovedDate() { 131 initializeLastApprovedDate(); 132 return this.lastApprovedDate; 133 } 134 135 public Map<String, String> getCustomActions() { 136 return customActions; 137 } 138 139 public void setCustomActions(Map<String, String> customActions) { 140 this.customActions = customActions; 141 } 142 143 public String getRowStyleClass() { 144 return rowStyleClass; 145 } 146 147 public void setRowStyleClass(String rowStyleClass) { 148 this.rowStyleClass = rowStyleClass; 149 } 150 151 public String getDelegatorName() { 152 initializeDelegatorName(); 153 return delegatorName; 154 } 155 156 public String getGroupName() { 157 initializeGroupName(); 158 return groupName; 159 } 160 161 public void initialize(Preferences preferences) { 162 // always re-initialize row style class, just in case they changed a preference! 163 initializeRowStyleClass(preferences); 164 if (isInitialized) { 165 return; 166 } 167 if (KewApiConstants.PREFERENCES_YES_VAL.equals(preferences.getShowWorkgroupRequest())) { 168 initializeGroupName(); 169 } 170 if (KewApiConstants.PREFERENCES_YES_VAL.equals(preferences.getShowDelegator())) { 171 initializeDelegatorName(); 172 } 173 if (KewApiConstants.PREFERENCES_YES_VAL.equals(preferences.getShowDateApproved())) { 174 initializeLastApprovedDate(); 175 } 176 this.routeHeader.initialize(preferences); 177 isInitialized = true; 178 } 179 180 private void initializeRowStyleClass(Preferences preferences) { 181 //set background colors for document statuses 182 if (KewApiConstants.ROUTE_HEADER_CANCEL_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) { 183 setRowStyleClass(KewApiConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorCanceled())); 184 } else if (KewApiConstants.ROUTE_HEADER_DISAPPROVED_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) { 185 setRowStyleClass(KewApiConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorDisapproved())); 186 } else if (KewApiConstants.ROUTE_HEADER_ENROUTE_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) { 187 setRowStyleClass(KewApiConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorEnroute())); 188 } else if (KewApiConstants.ROUTE_HEADER_EXCEPTION_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) { 189 setRowStyleClass(KewApiConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorException())); 190 } else if (KewApiConstants.ROUTE_HEADER_FINAL_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) { 191 setRowStyleClass(KewApiConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorFinal())); 192 } else if (KewApiConstants.ROUTE_HEADER_INITIATED_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) { 193 setRowStyleClass(KewApiConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorInitiated())); 194 } else if (KewApiConstants.ROUTE_HEADER_PROCESSED_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) { 195 setRowStyleClass(KewApiConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorProcessed())); 196 } else if (KewApiConstants.ROUTE_HEADER_SAVED_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) { 197 setRowStyleClass(KewApiConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorSaved())); 198 } 199 } 200 201 private void initializeGroupName() { 202 if (!groupNameInitialized) { 203 if (getGroupId() != null) { 204 Group group = super.getGroup(); 205 this.groupName = group.getName(); 206 } 207 groupNameInitialized = true; 208 } 209 } 210 211 private void initializeDelegatorName() { 212 if (!delegatorNameInitialized) { 213 if (getDelegatorPrincipalId() != null) { 214 EntityNamePrincipalName name = KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(getDelegatorPrincipalId()); 215 if (name != null) { 216 this.delegatorName = name.getDefaultName().getCompositeName(); 217 } 218 } 219 if (getDelegatorGroupId() != null) { 220 Group delegatorGroup = KimApiServiceLocator.getGroupService().getGroup(getDelegatorGroupId()); 221 if (delegatorGroup !=null) 222 delegatorName = delegatorGroup.getName(); 223 } 224 delegatorNameInitialized = true; 225 } 226 } 227 228 private void initializeLastApprovedDate() { 229 if (!lastApprovedDateInitialized) { 230 this.lastApprovedDate = KEWServiceLocator.getActionTakenService().getLastApprovedDate(getDocumentId()); 231 lastApprovedDateInitialized = true; 232 } 233 } 234 235 public DisplayParameters getDisplayParameters() { 236 return displayParameters; 237 } 238 239 public void setDisplayParameters(DisplayParameters displayParameters) { 240 this.displayParameters = displayParameters; 241 } 242 243 public DocumentRouteHeaderValueActionListExtension getRouteHeader() { 244 return this.routeHeader; 245 } 246 247 public void setRouteHeader(DocumentRouteHeaderValueActionListExtension routeHeader) { 248 this.routeHeader = routeHeader; 249 } 250 251} 252