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