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