Coverage Report - org.kuali.rice.kew.actiontaken.ActionTakenValue
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionTakenValue
0%
0/83
0%
0/22
1.341
 
 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.joda.time.DateTime;
 25  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 26  
 import org.kuali.rice.core.util.RiceConstants;
 27  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 28  
 import org.kuali.rice.kew.actionrequest.KimGroupRecipient;
 29  
 import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient;
 30  
 import org.kuali.rice.kew.actionrequest.Recipient;
 31  
 import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
 32  
 import org.kuali.rice.kew.api.action.ActionTaken;
 33  
 import org.kuali.rice.kew.api.action.ActionType;
 34  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 35  
 import org.kuali.rice.kew.util.CodeTranslator;
 36  
 import org.kuali.rice.kew.util.KEWConstants;
 37  
 import org.kuali.rice.kim.api.group.Group;
 38  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 39  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 40  
 
 41  
 import javax.persistence.Column;
 42  
 import javax.persistence.Entity;
 43  
 import javax.persistence.FetchType;
 44  
 import javax.persistence.GeneratedValue;
 45  
 import javax.persistence.Id;
 46  
 import javax.persistence.OneToMany;
 47  
 import javax.persistence.Table;
 48  
 import javax.persistence.Transient;
 49  
 import javax.persistence.Version;
 50  
 import java.io.Serializable;
 51  
 import java.sql.Timestamp;
 52  
 import java.util.ArrayList;
 53  
 import java.util.Collection;
 54  
 
 55  
 
 56  
 /**
 57  
  * Model object mapped to ojb for representing actions taken on documents by
 58  
  * users.
 59  
  *
 60  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 61  
  */
 62  
 @Entity
 63  
 //@Sequence(name="KREW_ACTN_TKN_S", property="actionTakenId")
 64  
 @Table(name="KREW_ACTN_TKN_T")
 65  0
 public class ActionTakenValue implements Serializable {
 66  
 
 67  
     /**
 68  
          *
 69  
          */
 70  
         private static final long serialVersionUID = -81505450567067594L;
 71  
         @Id
 72  
         @GeneratedValue(generator="KREW_ACTN_TKN_S")
 73  
         @GenericGenerator(name="KREW_ACTN_TKN_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
 74  
                         @Parameter(name="sequence_name",value="KREW_ACTN_TKN_S"),
 75  
                         @Parameter(name="value_column",value="id")
 76  
         })
 77  
         @Column(name="ACTN_TKN_ID")
 78  
     private String actionTakenId;
 79  
     @Column(name="DOC_HDR_ID")//,insertable=false, updatable=false)
 80  
         private String documentId;
 81  
     @Column(name="ACTN_CD")
 82  
         private String actionTaken;
 83  
         @Column(name="ACTN_DT")
 84  
         private Timestamp actionDate;
 85  0
     @Column(name="ANNOTN")
 86  
     private String annotation = "";
 87  
     @Column(name="DOC_VER_NBR")
 88  
         private Integer docVersion;
 89  
     @Version
 90  
         @Column(name="VER_NBR")
 91  
         private Integer lockVerNbr;
 92  
     @Column(name="PRNCPL_ID")
 93  
         private String principalId;
 94  
     @Column(name="DLGTR_PRNCPL_ID")
 95  
         private String delegatorPrincipalId;
 96  
     @Column(name="DLGTR_GRP_ID")
 97  
         private String delegatorGroupId;
 98  
     //@ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
 99  
     //@JoinColumn(name="DOC_HDR_ID")
 100  
     //private DocumentRouteHeaderValue routeHeader;
 101  
     @OneToMany(fetch=FetchType.EAGER, mappedBy="actionTaken")
 102  
     @Fetch(value = FetchMode.SELECT)
 103  
         private Collection<ActionRequestValue> actionRequests;
 104  0
     @Column(name="CUR_IND")
 105  
     private Boolean currentIndicator = Boolean.TRUE;
 106  
     @Transient
 107  
     private String actionDateString;
 108  
 
 109  
     public Principal getPrincipal() {
 110  0
             return getPrincipalForId( principalId );
 111  
     }
 112  
     
 113  
         //@PrePersist
 114  
         public void beforeInsert(){
 115  0
                 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());                
 116  0
         }
 117  
 
 118  
     public String getPrincipalDisplayName() {
 119  
             // TODO this stinks to have to have a dependency on UserSession here
 120  0
             return KEWServiceLocator.getIdentityHelperService().getPerson(getPrincipalId()).getName();
 121  
     }
 122  
 
 123  
     public Principal getDelegatorPrincipal() {
 124  0
             return getPrincipalForId(delegatorPrincipalId);
 125  
     }
 126  
 
 127  
     public Group getDelegatorGroup()
 128  
     {
 129  0
             return KimApiServiceLocator.getGroupService()
 130  
                     .getGroup(String.valueOf(delegatorGroupId));
 131  
     }
 132  
 
 133  
     public void setDelegator(Recipient recipient) {
 134  0
         if (recipient instanceof KimPrincipalRecipient) {
 135  0
             setDelegatorPrincipalId(((KimPrincipalRecipient)recipient).getPrincipalId());
 136  0
         } else if (recipient instanceof KimGroupRecipient) {
 137  0
             setDelegatorGroupId(((KimGroupRecipient)recipient).getGroup().getId());
 138  
         } else {
 139  0
             setDelegatorPrincipalId(null);
 140  0
             setDelegatorGroupId(null);
 141  
         }
 142  0
     }
 143  
 
 144  
     public boolean isForDelegator() {
 145  0
         return getDelegatorPrincipalId() != null || getDelegatorGroupId() != null;
 146  
     }
 147  
 
 148  
     public String getDelegatorDisplayName() {
 149  0
         if (! isForDelegator()) {
 150  0
             return "";
 151  
         }
 152  0
         if (getDelegatorPrincipalId() != null) {
 153  
                 // TODO this stinks to have to have a dependency on UserSession here
 154  0
                 return KEWServiceLocator.getIdentityHelperService().getPerson(this.getDelegatorPrincipalId()).getName();
 155  
         } else {
 156  0
             return getDelegatorGroup().getName();
 157  
       }
 158  
     }
 159  
     
 160  
     private Principal getPrincipalForId(String principalId) {
 161  0
             Principal principal = null;
 162  
             
 163  0
             if (!StringUtils.isBlank(principalId)) {
 164  0
                     principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId);
 165  
             }
 166  
             
 167  0
             return principal;
 168  
     }
 169  
 
 170  
     public String getActionTakenLabel() {
 171  0
         return CodeTranslator.getActionTakenLabel(actionTaken);
 172  
     }
 173  
 
 174  
     public Collection<ActionRequestValue> getActionRequests() {
 175  0
         if (actionRequests == null) {
 176  0
             setActionRequests(new ArrayList<ActionRequestValue>());
 177  
         }
 178  0
         return actionRequests;
 179  
     }
 180  
 
 181  
     public void setActionRequests(Collection<ActionRequestValue> actionRequests) {
 182  0
         this.actionRequests = actionRequests;
 183  0
     }
 184  
 
 185  
     //public DocumentRouteHeaderValue getRouteHeader() {
 186  
     //    return routeHeader;
 187  
     //}
 188  
 
 189  
     //public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
 190  
     //    this.routeHeader = routeHeader;
 191  
     //}
 192  
 
 193  
     public Timestamp getActionDate() {
 194  0
         return actionDate;
 195  
     }
 196  
 
 197  
 
 198  
     public void setActionDate(Timestamp actionDate) {
 199  0
         this.actionDate = actionDate;
 200  0
     }
 201  
 
 202  
 
 203  
     public String getActionTaken() {
 204  0
         return actionTaken;
 205  
     }
 206  
 
 207  
 
 208  
     public void setActionTaken(String actionTaken) {
 209  0
         this.actionTaken = actionTaken;
 210  0
     }
 211  
 
 212  
 
 213  
     public String getActionTakenId() {
 214  0
         return actionTakenId;
 215  
     }
 216  
 
 217  
     public void setActionTakenId(String actionTakenId) {
 218  0
         this.actionTakenId = actionTakenId;
 219  0
     }
 220  
 
 221  
     public String getAnnotation() {
 222  0
         return annotation;
 223  
     }
 224  
 
 225  
     public void setAnnotation(String annotation) {
 226  0
         this.annotation = annotation;
 227  0
     }
 228  
 
 229  
     public String getDelegatorPrincipalId() {
 230  0
         return delegatorPrincipalId;
 231  
     }
 232  
 
 233  
     public void setDelegatorPrincipalId(String delegatorPrincipalId) {
 234  0
         this.delegatorPrincipalId = delegatorPrincipalId;
 235  0
     }
 236  
 
 237  
     public String getDelegatorGroupId() {
 238  0
         return delegatorGroupId;
 239  
     }
 240  
     public void setDelegatorGroupId(String delegatorGroupId) {
 241  0
         this.delegatorGroupId = delegatorGroupId;
 242  0
     }
 243  
     public Integer getDocVersion() {
 244  0
         return docVersion;
 245  
     }
 246  
 
 247  
     public void setDocVersion(Integer docVersion) {
 248  0
         this.docVersion = docVersion;
 249  0
     }
 250  
 
 251  
     public Integer getLockVerNbr() {
 252  0
         return lockVerNbr;
 253  
     }
 254  
 
 255  
     public void setLockVerNbr(Integer lockVerNbr) {
 256  0
         this.lockVerNbr = lockVerNbr;
 257  0
     }
 258  
 
 259  
     public String getDocumentId() {
 260  0
             return documentId;
 261  
     }
 262  
 
 263  
     public void setDocumentId(String documentId) {
 264  0
         this.documentId = documentId;
 265  0
     }
 266  
 
 267  
     public String getPrincipalId() {
 268  0
             return principalId;
 269  
     }
 270  
     
 271  
     public void setPrincipalId(String principalId) {
 272  0
             this.principalId = principalId;
 273  0
     }
 274  
 
 275  
     public Boolean getCurrentIndicator() {
 276  0
         return currentIndicator;
 277  
     }
 278  
 
 279  
     public void setCurrentIndicator(Boolean currentIndicator) {
 280  0
         this.currentIndicator = currentIndicator;
 281  0
     }
 282  
 
 283  
     public Collection getRootActionRequests() {
 284  0
         return getActionRequestService().getRootRequests(getActionRequests());
 285  
     }
 286  
 
 287  
     private ActionRequestService getActionRequestService() {
 288  0
         return (ActionRequestService) KEWServiceLocator.getService(KEWServiceLocator.ACTION_REQUEST_SRV);
 289  
     }
 290  
 
 291  
     public String getActionDateString() {
 292  0
         if(actionDateString == null || actionDateString.trim().equals("")){
 293  0
             return RiceConstants.getDefaultDateFormat().format(getActionDate());
 294  
         } else {
 295  0
             return actionDateString;
 296  
         }
 297  
     }
 298  
     public void setActionDateString(String actionDateString) {
 299  0
         this.actionDateString = actionDateString;
 300  0
     }
 301  
 
 302  
     public boolean isApproval() {
 303  0
             return KEWConstants.ACTION_TAKEN_APPROVED_CD.equals(getActionTaken());
 304  
     }
 305  
 
 306  
     public boolean isCompletion() {
 307  0
             return KEWConstants.ACTION_TAKEN_COMPLETED_CD.equals(getActionTaken());
 308  
     }
 309  
     
 310  
     public static ActionTaken to(ActionTakenValue actionTakenBo) {
 311  0
             if (actionTakenBo == null) {
 312  0
                     return null;
 313  
             }
 314  0
             ActionTaken.Builder builder = ActionTaken.Builder.create(actionTakenBo.getActionTakenId().toString(),
 315  
                             actionTakenBo.getDocumentId(),
 316  
                             actionTakenBo.getPrincipalId(),
 317  
                             ActionType.fromCode(actionTakenBo.getActionTaken()));
 318  0
             builder.setActionDate(new DateTime(actionTakenBo.getActionDate().getTime()));
 319  0
             builder.setAnnotation(actionTakenBo.getAnnotation());
 320  0
             builder.setCurrent(actionTakenBo.getCurrentIndicator().booleanValue());
 321  0
             builder.setDelegatorGroupId(actionTakenBo.getDelegatorGroupId());
 322  0
             builder.setDelegatorPrincipalId(actionTakenBo.getDelegatorPrincipalId());
 323  0
             return builder.build();
 324  
     }
 325  
     
 326  
 }