View Javadoc

1   /**
2    * Copyright 2011-2013 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.mobility.emergencyinfo.service;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import javax.jws.WebService;
21  import javax.ws.rs.GET;
22  import javax.ws.rs.Path;
23  import javax.ws.rs.QueryParam;
24  
25  import org.kuali.mobility.emergencyinfo.dao.EmergencyInfoDao;
26  import org.springframework.beans.factory.annotation.Autowired;
27  import org.springframework.stereotype.Service;
28  import org.springframework.transaction.annotation.Transactional;
29  
30  import javax.ws.rs.PathParam;
31  import org.apache.commons.collections.CollectionUtils;
32  import org.apache.log4j.Logger;
33  import org.kuali.mobility.emergencyinfo.entity.EmergencyInfo;
34  import org.kuali.mobility.emergencyinfo.entity.EmergencyInfoImpl;
35  import org.kuali.mobility.emergencyinfo.util.EmergencyInfoTransform;
36  import org.springframework.beans.factory.annotation.Qualifier;
37  
38  @Service(value="EmergencyInfoService")
39  @WebService(endpointInterface="org.kuali.mobility.emergencyinfo.service.EmergencyInfoService")
40  public class EmergencyInfoServiceImpl implements EmergencyInfoService {
41  	private static final Logger LOG = Logger.getLogger( EmergencyInfoServiceImpl.class );
42  	private String emergencyinfoSourceUrl;
43  
44      public String getEmergencyinfoSourceUrl() {
45  		return emergencyinfoSourceUrl;
46  	}
47  
48  	public void setEmergencyinfoSourceUrl(String emergencyinfoSourceUrl) {
49  		this.emergencyinfoSourceUrl = emergencyinfoSourceUrl;
50  	}
51  
52  	@Autowired
53  	@Qualifier("emergencyInfoDao")
54      private EmergencyInfoDao emergencyInfoDao;
55  
56  //    @DELETE
57  //    @Path("information/delete")
58  //    @Transactional
59  //    @Override
60      public void deleteEmergencyInfoById(@QueryParam(value = "id") Long id) {
61          emergencyInfoDao.deleteEmergencyInfoById(id);
62      }
63  
64      @GET
65      @Path("information/lookup")
66      @Transactional
67      @Override
68      public List<EmergencyInfoImpl> findAllEmergencyInfo() {
69          List<EmergencyInfoImpl> contacts = new ArrayList<EmergencyInfoImpl>();
70  		CollectionUtils.collect( getEmergencyInfoDao().findAllEmergencyInfo(), new EmergencyInfoTransform(), contacts );
71  		return contacts;
72      }
73  
74      @GET
75      @Path("information/search")
76      @Transactional
77      @Override
78      public EmergencyInfoImpl findEmergencyInfoById(@QueryParam(value = "id") Long id) {
79  		EmergencyInfoTransform transform = new EmergencyInfoTransform();
80  		return transform.transform( getEmergencyInfoDao().findEmergencyInfoById(id) );
81      }
82  
83  //    @PUT
84  //    @Path("information/save")
85  //    @Transactional
86  //    @Override
87      public Long saveEmergencyInfo(EmergencyInfo emergencyInfo) {
88          return emergencyInfoDao.saveEmergencyInfo(emergencyInfo);
89      }
90  
91  //    @PUT
92  //    @Path("information/reorder/{id}")
93  //    @Transactional
94  //    @Override
95      public void reorder(@QueryParam(value = "id") Long id, @QueryParam(value = "up") boolean up) {
96          emergencyInfoDao.reorder(id, up);
97      }
98  
99      @GET
100     @Path("information/bycampus/{campus}")
101     @Transactional
102     @Override
103     public List<EmergencyInfoImpl> findAllEmergencyInfoByCampus(@PathParam(value = "campus") String campus) {
104         List<EmergencyInfoImpl> contacts = new ArrayList<EmergencyInfoImpl>();
105 		CollectionUtils.collect( getEmergencyInfoDao().findAllEmergencyInfoByCampus(campus), new EmergencyInfoTransform(), contacts );
106 		LOG.debug( "Filtering emergency contacts for campus ["+campus+"] and found "+contacts.size() );
107 		return contacts;
108     }
109 
110 //    @Override
111 //    public EmergencyInfoJPAImpl fromJsonToEntity(String json) {
112 //        return new JSONDeserializer<EmergencyInfo>().use(null, EmergencyInfoJPAImpl.class).deserialize(json);
113 //    }
114 //
115 //    @Override
116 //    public String toJson(Collection<EmergencyInfo> collection) {
117 //        return new JSONSerializer().exclude("*.class").serialize(collection);
118 //    }
119 //
120 //    @Override
121 //    public Collection<EmergencyInfo> fromJsonToCollection(String json) {
122 //        return new JSONDeserializer<List<EmergencyInfo>>().use(null, ArrayList.class).use("values", EmergencyInfoJPAImpl.class).deserialize(json);
123 //    }
124 
125 	/**
126 	 * @return the emergencyInfoDao
127 	 */
128 	public EmergencyInfoDao getEmergencyInfoDao() {
129 		return emergencyInfoDao;
130 	}
131 
132 	/**
133 	 * @param emergencyInfoDao the emergencyInfoDao to set
134 	 */
135 	public void setEmergencyInfoDao(EmergencyInfoDao emergencyInfoDao) {
136 		this.emergencyInfoDao = emergencyInfoDao;
137 	}
138 
139 }