Coverage Report - org.kuali.rice.kim.bo.entity.impl.KimEntityDefaultInfoCacheImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KimEntityDefaultInfoCacheImpl
0%
0/98
0%
0/16
1.276
 
 1  
 /*
 2  
  * Copyright 2008-2009 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.kim.bo.entity.impl;
 17  
 
 18  
 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
 19  
 import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
 20  
 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
 21  
 import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier;
 22  
 import org.kuali.rice.kim.api.identity.name.EntityName;
 23  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 24  
 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoDefault;
 25  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
 26  
 
 27  
 import javax.persistence.Column;
 28  
 import javax.persistence.Entity;
 29  
 import javax.persistence.Id;
 30  
 import javax.persistence.Table;
 31  
 import javax.persistence.Transient;
 32  
 import java.sql.Timestamp;
 33  
 import java.util.Collections;
 34  
 
 35  
 /**
 36  
  * Used to store a cache of person information to be used if the user's information disappears from KIM. 
 37  
  * 
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  *
 40  
  */
 41  
 @Entity
 42  
 @Table(name="KRIM_ENTITY_CACHE_T")
 43  
 public class KimEntityDefaultInfoCacheImpl extends PersistableBusinessObjectBase {
 44  
 
 45  
         private static final long serialVersionUID = 1L;
 46  
 
 47  
         @Transient
 48  
         protected Long versionNumber; // prevent JPA from attempting to persist the version number attribute
 49  
         
 50  
         // principal data
 51  
         @Id
 52  
         @Column(name="PRNCPL_ID")
 53  
         protected String principalId;
 54  
         @Column(name="PRNCPL_NM")
 55  
         protected String principalName;
 56  
         @Column(name="ENTITY_ID")
 57  
         protected String entityId;
 58  
         @Column(name="ENTITY_TYP_CD")
 59  
         protected String entityTypeCode;
 60  
 
 61  
         // name data
 62  0
         @Column(name="FIRST_NM")
 63  
         protected String firstName = "";
 64  0
         @Column(name="MIDDLE_NM")
 65  
         protected String middleName = "";
 66  0
         @Column(name="LAST_NM")
 67  
         protected String lastName = "";
 68  0
         @Column(name="PRSN_NM")
 69  
         protected String name = "";
 70  
         
 71  0
         @Column(name="CAMPUS_CD")
 72  
         protected String campusCode = "";
 73  
 
 74  
         // employment data
 75  0
         @Column(name="PRMRY_DEPT_CD")
 76  
         protected String primaryDepartmentCode = "";
 77  0
         @Column(name="EMP_ID")
 78  
         protected String employeeId = "";
 79  
         
 80  
         @Column(name="LAST_UPDT_TS")
 81  
         protected Timestamp lastUpdateTimestamp;
 82  
 
 83  
         /**
 84  
          * 
 85  
          */
 86  0
         public KimEntityDefaultInfoCacheImpl() {
 87  0
         }
 88  
         
 89  0
         public KimEntityDefaultInfoCacheImpl( EntityDefault entity ) {
 90  0
                 if ( entity != null ) {
 91  0
                         entityId = entity.getEntityId();
 92  0
                         if ( entity.getPrincipals() != null && !entity.getPrincipals().isEmpty() ) {
 93  0
                                 principalId = entity.getPrincipals().get(0).getPrincipalId();
 94  0
                                 principalName = entity.getPrincipals().get(0).getPrincipalName();
 95  
                         }
 96  0
                         if ( entity.getEntityTypeContactInfos() != null && !entity.getEntityTypeContactInfos().isEmpty() ) {
 97  0
                                 entityTypeCode = entity.getEntityTypeContactInfos().get(0).getEntityTypeCode();
 98  
                         }
 99  0
                         if ( entity.getName() != null ) {
 100  0
                                 firstName = entity.getName().getFirstNameUnmasked();
 101  0
                                 middleName = entity.getName().getMiddleNameUnmasked();
 102  0
                                 lastName = entity.getName().getLastNameUnmasked();
 103  0
                                 name = entity.getName().getFormattedNameUnmasked();
 104  
                         }
 105  0
                         if ( entity.getDefaultAffiliation() != null ) {
 106  0
                                 campusCode = entity.getDefaultAffiliation().getCampusCode();
 107  
                         }
 108  0
                         if ( entity.getEmployment() != null ) {
 109  0
                                 primaryDepartmentCode = entity.getEmployment().getPrimaryDepartmentCode();
 110  0
                                 employeeId = entity.getEmployment().getEmployeeId();
 111  
                         }
 112  
                 }
 113  0
         }
 114  
 
 115  
     @SuppressWarnings("unchecked")
 116  
         public EntityDefault convertCacheToEntityDefaultInfo() {
 117  0
                 EntityDefault.Builder info = EntityDefault.Builder.create(this.entityId);
 118  
                 
 119  
                 // identity info
 120  0
                 info.setActive( this.isActive() );
 121  
 
 122  
                 // principal info
 123  0
                 Principal.Builder principalInfo = Principal.Builder.create(this.getPrincipalName());
 124  0
                 principalInfo.setEntityId(this.getEntityId());
 125  0
                 principalInfo.setPrincipalId(this.getPrincipalId());
 126  0
                 principalInfo.setActive(this.isActive());
 127  0
                 info.setPrincipals(Collections.singletonList(principalInfo));
 128  
 
 129  
                 // name info
 130  0
                 EntityName.Builder nameInfo = EntityName.Builder.create();
 131  0
         nameInfo.setEntityId( this.getEntityId());
 132  0
                 nameInfo.setFirstName( this.getFirstName() );
 133  0
                 nameInfo.setLastName( this.getLastName() );
 134  0
                 nameInfo.setMiddleName( this.getMiddleName() );
 135  0
                 info.setName(nameInfo);
 136  
 
 137  
                 // identity type information
 138  0
                 EntityTypeContactInfoDefault.Builder entityTypeInfo = EntityTypeContactInfoDefault.Builder.create();
 139  0
         entityTypeInfo.setEntityTypeCode(this.getEntityTypeCode());
 140  0
                 info.setEntityTypeContactInfos(Collections.singletonList(entityTypeInfo));
 141  
 
 142  
                 // affiliations
 143  0
                 EntityAffiliation.Builder aff = EntityAffiliation.Builder.create();
 144  0
                 aff.setCampusCode(this.getCampusCode());
 145  0
                 aff.setDefaultValue(true);
 146  0
         aff.setEntityId(info.getEntityId());
 147  0
                 info.setDefaultAffiliation(aff);
 148  0
                 info.setAffiliations(Collections.singletonList(aff));
 149  
 
 150  
                 // employment information
 151  0
                 EntityEmployment.Builder empInfo = EntityEmployment.Builder.create();
 152  0
                 empInfo.setEmployeeId( this.getEmployeeId() );
 153  0
                 empInfo.setPrimary(true);
 154  0
                 empInfo.setPrimaryDepartmentCode(this.getPrimaryDepartmentCode());
 155  0
                 info.setEmployment(empInfo);
 156  
                 
 157  
                 // external identifiers
 158  0
                 info.setExternalIdentifiers( Collections.singletonList(EntityExternalIdentifier.Builder.create()) );
 159  0
                 return info.build();
 160  
             
 161  
     }
 162  
 
 163  
         public String getPrincipalId() {
 164  0
                 return this.principalId;
 165  
         }
 166  
 
 167  
 
 168  
         public void setPrincipalId(String principalId) {
 169  0
                 this.principalId = principalId;
 170  0
         }
 171  
 
 172  
 
 173  
         public String getPrincipalName() {
 174  0
                 return this.principalName;
 175  
         }
 176  
 
 177  
 
 178  
         public void setPrincipalName(String principalName) {
 179  0
                 this.principalName = principalName;
 180  0
         }
 181  
 
 182  
 
 183  
         public String getEntityId() {
 184  0
                 return this.entityId;
 185  
         }
 186  
 
 187  
 
 188  
         public void setEntityId(String entityId) {
 189  0
                 this.entityId = entityId;
 190  0
         }
 191  
 
 192  
 
 193  
         public String getEntityTypeCode() {
 194  0
                 return this.entityTypeCode;
 195  
         }
 196  
 
 197  
 
 198  
         public void setEntityTypeCode(String entityTypeCode) {
 199  0
                 this.entityTypeCode = entityTypeCode;
 200  0
         }
 201  
 
 202  
 
 203  
         public String getFirstName() {
 204  0
                 return this.firstName;
 205  
         }
 206  
 
 207  
 
 208  
         public void setFirstName(String firstName) {
 209  0
                 this.firstName = firstName;
 210  0
         }
 211  
 
 212  
 
 213  
         public String getMiddleName() {
 214  0
                 return this.middleName;
 215  
         }
 216  
 
 217  
 
 218  
         public void setMiddleName(String middleName) {
 219  0
                 this.middleName = middleName;
 220  0
         }
 221  
 
 222  
 
 223  
         public String getLastName() {
 224  0
                 return this.lastName;
 225  
         }
 226  
 
 227  
 
 228  
         public void setLastName(String lastName) {
 229  0
                 this.lastName = lastName;
 230  0
         }
 231  
 
 232  
 
 233  
         public String getName() {
 234  0
                 return this.name;
 235  
         }
 236  
 
 237  
 
 238  
         public void setName(String name) {
 239  0
                 this.name = name;
 240  0
         }
 241  
 
 242  
 
 243  
         public String getCampusCode() {
 244  0
                 return this.campusCode;
 245  
         }
 246  
 
 247  
 
 248  
         public void setCampusCode(String campusCode) {
 249  0
                 this.campusCode = campusCode;
 250  0
         }
 251  
 
 252  
 
 253  
         public String getPrimaryDepartmentCode() {
 254  0
                 return this.primaryDepartmentCode;
 255  
         }
 256  
 
 257  
 
 258  
         public void setPrimaryDepartmentCode(String primaryDepartmentCode) {
 259  0
                 this.primaryDepartmentCode = primaryDepartmentCode;
 260  0
         }
 261  
 
 262  
 
 263  
         public String getEmployeeId() {
 264  0
                 return this.employeeId;
 265  
         }
 266  
 
 267  
 
 268  
         public void setEmployeeId(String employeeId) {
 269  0
                 this.employeeId = employeeId;
 270  0
         }
 271  
 
 272  
 
 273  
         public boolean isActive() {
 274  0
                 return false;
 275  
         }
 276  
 
 277  
         public Timestamp getLastUpdateTimestamp() {
 278  0
                 return this.lastUpdateTimestamp;
 279  
         }
 280  
 
 281  
         // handle automatic updating of the timestamp
 282  
         
 283  
         @Override
 284  
     protected void prePersist() {
 285  0
             super.prePersist();
 286  0
         lastUpdateTimestamp = new Timestamp(System.currentTimeMillis());
 287  0
     }
 288  
 
 289  
         @Override
 290  
     protected void preUpdate() {
 291  0
             super.preUpdate();
 292  0
         lastUpdateTimestamp = new Timestamp(System.currentTimeMillis());
 293  0
     }
 294  
         
 295  
 }