View Javadoc
1   package org.kuali.ole.deliver.service;
2   
3   import org.apache.commons.collections.CollectionUtils;
4   import org.kuali.ole.deliver.bo.OlePatronDocument;
5   import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
6   import org.kuali.rice.kim.impl.identity.entity.EntityBo;
7   import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
8   import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo;
9   import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
10  
11  import java.util.List;
12  
13  /**
14   * Created by sheiksalahudeenm on 17/4/15.
15   */
16  public class OLEDeliverService {
17  
18      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OLEDeliverService.class);
19  
20      public static OlePatronDocument populatePatronName(OlePatronDocument olePatronDocument){
21          if(olePatronDocument != null){
22              try {
23                  EntityBo entityBo =olePatronDocument.getEntity();
24                  List<EntityNameBo> entityNameBoList = entityBo.getNames();
25                  if(CollectionUtils.isNotEmpty(entityNameBoList)){
26                      for(EntityNameBo entityNameBo:entityNameBoList){
27                          if(entityNameBo.getDefaultValue()){
28                              olePatronDocument.setFirstName(entityNameBo.getFirstName());
29                              olePatronDocument.setMiddleName(entityNameBo.getMiddleName());
30                              olePatronDocument.setLastName(entityNameBo.getLastName());
31                              olePatronDocument.setPatronName(entityNameBo.getLastName() + ", " + entityNameBo.getFirstName());
32                              olePatronDocument.setNamePrefix(entityNameBo.getNamePrefix());
33                              olePatronDocument.setNameSuffix(entityNameBo.getNameSuffix());
34                          }
35                      }
36                  }
37              } catch (Exception e) {
38                  LOG.error("Error occurred while populating patron names (patron Id -"+olePatronDocument.getOlePatronId()+"):"+e);  //To change body of catch statement use File | Settings | File Templates.
39              }
40          }
41          return olePatronDocument;
42      }
43  
44      public static OlePatronDocument populatePatronEmailAndPhone(OlePatronDocument olePatronDocument){
45          if(olePatronDocument != null){
46              try {
47                  EntityBo entityBo =olePatronDocument.getEntity();
48                  if(CollectionUtils.isNotEmpty(entityBo.getEntityTypeContactInfos())){
49                      List<EntityTypeContactInfoBo> entityTypeContactInfoBoList = entityBo.getEntityTypeContactInfos();
50                      for(EntityTypeContactInfoBo entityTypeContactInfoBo : entityTypeContactInfoBoList){
51                          List<EntityEmailBo> entityEmailList = entityTypeContactInfoBo.getEmailAddresses();
52                          if(CollectionUtils.isNotEmpty(entityEmailList)){
53                              for(EntityEmailBo entityEmailBo: entityEmailList){
54                                  if(entityEmailBo.getDefaultValue()){
55                                      olePatronDocument.setEmailAddress(entityEmailBo.getEmailAddress());
56                                  }
57                              }
58                          }
59                          List<EntityPhoneBo> entityPhoneBos = entityTypeContactInfoBo.getPhoneNumbers();
60                          if(CollectionUtils.isNotEmpty(entityPhoneBos)){
61                              for(EntityPhoneBo entityPhoneBo: entityPhoneBos){
62                                  if(entityPhoneBo.getDefaultValue()){
63                                      olePatronDocument.setPhoneNumber(entityPhoneBo.getPhoneNumber());
64                                  }
65                              }
66                          }
67                      }
68                  }
69              } catch (Exception e) {
70                  LOG.error("Error occurred while populating patron names (patron Id -"+olePatronDocument.getOlePatronId()+"):"+e);  //To change body of catch statement use File | Settings | File Templates.
71              }
72          }
73          return olePatronDocument;
74      }
75  }