1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.mobility.emergencyinfo.dao;
16
17 import java.io.IOException;
18 import java.net.MalformedURLException;
19 import java.net.URL;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import javax.persistence.EntityManager;
24 import javax.persistence.PersistenceContext;
25 import org.apache.commons.collections.CollectionUtils;
26 import org.apache.log4j.Logger;
27 import org.kuali.mobility.emergencyinfo.entity.EmergencyInfo;
28 import org.kuali.mobility.emergencyinfo.entity.EmergencyInfoImpl;
29
30 import org.kuali.mobility.emergencyinfo.entity.EmergencyInfoJPAImpl;
31 import org.kuali.mobility.emergencyinfo.util.CampusPredicate;
32 import org.kuali.mobility.util.mapper.DataMapper;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Repository;
35
36 @Repository
37 public class EmergencyInfoWSDaoImpl implements EmergencyInfoDao {
38
39 private static final Logger LOG = Logger.getLogger( EmergencyInfoWSDaoImpl.class );
40
41 @PersistenceContext
42 private EntityManager entityManager;
43
44 @Autowired
45 private DataMapper dataMapper;
46
47 private String sourceUrl;
48 private List<EmergencyInfoImpl> contacts = null;
49
50 private void initData() {
51 contacts = new ArrayList<EmergencyInfoImpl>();
52 try {
53 URL url = new URL( getSourceUrl() );
54 contacts.addAll(getDataMapper().mapData(contacts, url, "emergencyinfoMapping.xml"));
55 } catch( MalformedURLException mue ) {
56 LOG.error( "URL supplied for sourceUrl is malformed.", mue );
57 } catch( ClassNotFoundException cnfe ) {
58 LOG.error( "Data mapper unable to load class defined in mapping.", cnfe );
59 } catch( IOException ioe ) {
60 LOG.error( "Unabled to access emergency info source url.", ioe );
61 } catch (Exception e) {
62 LOG.error( "If you see this, something really, really strange happened.", e);
63 }
64 }
65
66 public EntityManager getEntityManager() {
67 return entityManager;
68 }
69
70 public void setEntityManager(EntityManager entityManager) {
71 this.entityManager = entityManager;
72 }
73
74 @Override
75 public EmergencyInfo findEmergencyInfoById(Long id) {
76
77 return null;
78 }
79
80 @Override
81 public List<? extends EmergencyInfo> findAllEmergencyInfo() {
82 if( null == contacts ) {
83 initData();
84 }
85 return contacts;
86 }
87
88 @Override
89 public List<? extends EmergencyInfo> findAllEmergencyInfoByCampus(String campus) {
90 if( null == contacts ) {
91 initData();
92 }
93 List<? extends EmergencyInfo> campusContacts = new ArrayList<EmergencyInfoImpl>();
94 campusContacts.addAll( CollectionUtils.select( contacts, new CampusPredicate(campus)) );
95 return campusContacts;
96 }
97
98 @Override
99 public Long saveEmergencyInfo(EmergencyInfo emergencyInfo) {
100
101 return null;
102 }
103
104 @Override
105 public void deleteEmergencyInfoById(Long id) {
106
107 }
108
109 @Override
110 public void reorder(Long id, boolean up) {
111
112 }
113
114
115
116
117 public String getSourceUrl() {
118 return sourceUrl;
119 }
120
121
122
123
124 public void setSourceUrl(String sourceUrl) {
125 this.sourceUrl = sourceUrl;
126 }
127
128
129
130
131 public DataMapper getDataMapper() {
132 return dataMapper;
133 }
134
135
136
137
138 public void setDataMapper(DataMapper dataMapper) {
139 this.dataMapper = dataMapper;
140 }
141 }