Coverage Report - org.kuali.rice.kew.actiontaken.ActionTakenValue
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionTakenValue
0%
0/74
0%
0/20
1.3
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.actiontaken;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.hibernate.annotations.Fetch;
 21  
 import org.hibernate.annotations.FetchMode;
 22  
 import org.hibernate.annotations.GenericGenerator;
 23  
 import org.hibernate.annotations.Parameter;
 24  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 25  
 import org.kuali.rice.core.util.RiceConstants;
 26  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 27  
 import org.kuali.rice.kew.actionrequest.KimGroupRecipient;
 28  
 import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient;
 29  
 import org.kuali.rice.kew.actionrequest.Recipient;
 30  
 import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
 31  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 32  
 import org.kuali.rice.kew.util.CodeTranslator;
 33  
 import org.kuali.rice.kew.util.KEWConstants;
 34  
 import org.kuali.rice.kim.api.entity.principal.Principal;
 35  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 36  
 import org.kuali.rice.kim.api.group.Group;
 37  
 
 38  
 
 39  
 import javax.persistence.*;
 40  
 import java.io.Serializable;
 41  
 import java.sql.Timestamp;
 42  
 import java.util.ArrayList;
 43  
 import java.util.Collection;
 44  
 
 45  
 
 46  
 /**
 47  
  * Model object mapped to ojb for representing actions taken on documents by
 48  
  * users.
 49  
  *
 50  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 51  
  */
 52  
 @Entity
 53  
 //@Sequence(name="KREW_ACTN_TKN_S", property="actionTakenId")
 54  
 @Table(name="KREW_ACTN_TKN_T")
 55  0
 public class ActionTakenValue implements Serializable {
 56  
 
 57  
     /**
 58  
          *
 59  
          */
 60  
         private static final long serialVersionUID = -81505450567067594L;
 61  
         @Id
 62  
         @GeneratedValue(generator="KREW_ACTN_TKN_S")
 63  
         @GenericGenerator(name="KREW_ACTN_TKN_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
 64  
                         @Parameter(name="sequence_name",value="KREW_ACTN_TKN_S"),
 65  
                         @Parameter(name="value_column",value="id")
 66  
         })
 67  
         @Column(name="ACTN_TKN_ID")
 68  
     private Long actionTakenId;
 69  
     @Column(name="DOC_HDR_ID")//,insertable=false, updatable=false)
 70  
         private String documentId;
 71  
     @Column(name="ACTN_CD")
 72  
         private String actionTaken;
 73  
         @Column(name="ACTN_DT")
 74  
         private Timestamp actionDate;
 75  0
     @Column(name="ANNOTN")
 76  
     private String annotation = "";
 77  
     @Column(name="DOC_VER_NBR")
 78  
         private Integer docVersion;
 79  
     @Version
 80  
         @Column(name="VER_NBR")
 81  
         private Integer lockVerNbr;
 82  
     @Column(name="PRNCPL_ID")
 83  
         private String principalId;
 84  
     @Column(name="DLGTR_PRNCPL_ID")
 85  
         private String delegatorPrincipalId;
 86  
     @Column(name="DLGTR_GRP_ID")
 87  
         private String delegatorGroupId;
 88  
     //@ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
 89  
     //@JoinColumn(name="DOC_HDR_ID")
 90  
     //private DocumentRouteHeaderValue routeHeader;
 91  
     @OneToMany(fetch=FetchType.EAGER, mappedBy="actionTaken")
 92  
     @Fetch(value = FetchMode.SELECT)
 93  
         private Collection<ActionRequestValue> actionRequests;
 94  0
     @Column(name="CUR_IND")
 95  
     private Boolean currentIndicator = Boolean.TRUE;
 96  
     @Transient
 97  
     private String actionDateString;
 98  
 
 99  
     public Principal getPrincipal() {
 100  0
             return getPrincipalForId( principalId );
 101  
     }
 102  
     
 103  
         //@PrePersist
 104  
         public void beforeInsert(){
 105  0
                 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());                
 106  0
         }
 107  
 
 108  
     public String getPrincipalDisplayName() {
 109  
             // TODO this stinks to have to have a dependency on UserSession here
 110  0
             return KEWServiceLocator.getIdentityHelperService().getPerson(getPrincipalId()).getName();
 111  
     }
 112  
 
 113  
     public Principal getDelegatorPrincipal() {
 114  0
             return getPrincipalForId(delegatorPrincipalId);
 115  
     }
 116  
 
 117  
     public Group getDelegatorGroup()
 118  
     {
 119  0
             return KimApiServiceLocator.getIdentityManagementService()
 120  
                     .getGroup(String.valueOf(delegatorGroupId));
 121  
     }
 122  
 
 123  
     public void setDelegator(Recipient recipient) {
 124  0
         if (recipient instanceof KimPrincipalRecipient) {
 125  0
             setDelegatorPrincipalId(((KimPrincipalRecipient)recipient).getPrincipalId());
 126  0
         } else if (recipient instanceof KimGroupRecipient) {
 127  0
             setDelegatorGroupId(((KimGroupRecipient)recipient).getGroup().getId());
 128  
         } else {
 129  0
             setDelegatorPrincipalId(null);
 130  0
             setDelegatorGroupId(null);
 131  
         }
 132  0
     }
 133  
 
 134  
     public boolean isForDelegator() {
 135  0
         return getDelegatorPrincipalId() != null || getDelegatorGroupId() != null;
 136  
     }
 137  
 
 138  
     public String getDelegatorDisplayName() {
 139  0
         if (! isForDelegator()) {
 140  0
             return "";
 141  
         }
 142  0
         if (getDelegatorPrincipalId() != null) {
 143  
                 // TODO this stinks to have to have a dependency on UserSession here
 144  0
                 return KEWServiceLocator.getIdentityHelperService().getPerson(this.getDelegatorPrincipalId()).getName();
 145  
         } else {
 146  0
             return getDelegatorGroup().getName();
 147  
       }
 148  
     }
 149  
     
 150  
     private Principal getPrincipalForId(String principalId) {
 151  0
             Principal principal = null;
 152  
             
 153  0
             if (!StringUtils.isBlank(principalId)) {
 154  0
                     principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId);
 155  
             }
 156  
             
 157  0
             return principal;
 158  
     }
 159  
 
 160  
     public String getActionTakenLabel() {
 161  0
         return CodeTranslator.getActionTakenLabel(actionTaken);
 162  
     }
 163  
 
 164  
     public Collection<ActionRequestValue> getActionRequests() {
 165  0
         if (actionRequests == null) {
 166  0
             setActionRequests(new ArrayList<ActionRequestValue>());
 167  
         }
 168  0
         return actionRequests;
 169  
     }
 170  
 
 171  
     public void setActionRequests(Collection<ActionRequestValue> actionRequests) {
 172  0
         this.actionRequests = actionRequests;
 173  0
     }
 174  
 
 175  
     //public DocumentRouteHeaderValue getRouteHeader() {
 176  
     //    return routeHeader;
 177  
     //}
 178  
 
 179  
     //public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
 180  
     //    this.routeHeader = routeHeader;
 181  
     //}
 182  
 
 183  
     public Timestamp getActionDate() {
 184  0
         return actionDate;
 185  
     }
 186  
 
 187  
 
 188  
     public void setActionDate(Timestamp actionDate) {
 189  0
         this.actionDate = actionDate;
 190  0
     }
 191  
 
 192  
 
 193  
     public String getActionTaken() {
 194  0
         return actionTaken;
 195  
     }
 196  
 
 197  
 
 198  
     public void setActionTaken(String actionTaken) {
 199  0
         this.actionTaken = actionTaken;
 200  0
     }
 201  
 
 202  
 
 203  
     public Long getActionTakenId() {
 204  0
         return actionTakenId;
 205  
     }
 206  
 
 207  
     public void setActionTakenId(Long actionTakenId) {
 208  0
         this.actionTakenId = actionTakenId;
 209  0
     }
 210  
 
 211  
     public String getAnnotation() {
 212  0
         return annotation;
 213  
     }
 214  
 
 215  
     public void setAnnotation(String annotation) {
 216  0
         this.annotation = annotation;
 217  0
     }
 218  
 
 219  
     public String getDelegatorPrincipalId() {
 220  0
         return delegatorPrincipalId;
 221  
     }
 222  
 
 223  
     public void setDelegatorPrincipalId(String delegatorPrincipalId) {
 224  0
         this.delegatorPrincipalId = delegatorPrincipalId;
 225  0
     }
 226  
 
 227  
     public String getDelegatorGroupId() {
 228  0
         return delegatorGroupId;
 229  
     }
 230  
     public void setDelegatorGroupId(String delegatorGroupId) {
 231  0
         this.delegatorGroupId = delegatorGroupId;
 232  0
     }
 233  
     public Integer getDocVersion() {
 234  0
         return docVersion;
 235  
     }
 236  
 
 237  
     public void setDocVersion(Integer docVersion) {
 238  0
         this.docVersion = docVersion;
 239  0
     }
 240  
 
 241  
     public Integer getLockVerNbr() {
 242  0
         return lockVerNbr;
 243  
     }
 244  
 
 245  
     public void setLockVerNbr(Integer lockVerNbr) {
 246  0
         this.lockVerNbr = lockVerNbr;
 247  0
     }
 248  
 
 249  
     public String getDocumentId() {
 250  0
             return documentId;
 251  
     }
 252  
 
 253  
     public void setDocumentId(String documentId) {
 254  0
         this.documentId = documentId;
 255  0
     }
 256  
 
 257  
     public String getPrincipalId() {
 258  0
             return principalId;
 259  
     }
 260  
     
 261  
     public void setPrincipalId(String principalId) {
 262  0
             this.principalId = principalId;
 263  0
     }
 264  
 
 265  
     public Boolean getCurrentIndicator() {
 266  0
         return currentIndicator;
 267  
     }
 268  
 
 269  
     public void setCurrentIndicator(Boolean currentIndicator) {
 270  0
         this.currentIndicator = currentIndicator;
 271  0
     }
 272  
 
 273  
     public Collection getRootActionRequests() {
 274  0
         return getActionRequestService().getRootRequests(getActionRequests());
 275  
     }
 276  
 
 277  
     private ActionRequestService getActionRequestService() {
 278  0
         return (ActionRequestService) KEWServiceLocator.getService(KEWServiceLocator.ACTION_REQUEST_SRV);
 279  
     }
 280  
 
 281  
     public String getActionDateString() {
 282  0
         if(actionDateString == null || actionDateString.trim().equals("")){
 283  0
             return RiceConstants.getDefaultDateFormat().format(getActionDate());
 284  
         } else {
 285  0
             return actionDateString;
 286  
         }
 287  
     }
 288  
     public void setActionDateString(String actionDateString) {
 289  0
         this.actionDateString = actionDateString;
 290  0
     }
 291  
 
 292  
     public boolean isApproval() {
 293  0
             return KEWConstants.ACTION_TAKEN_APPROVED_CD.equals(getActionTaken());
 294  
     }
 295  
 
 296  
     public boolean isCompletion() {
 297  0
             return KEWConstants.ACTION_TAKEN_COMPLETED_CD.equals(getActionTaken());
 298  
     }
 299  
 }