001/** 002 * Copyright 2011 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016package org.kuali.mobility.push.service; 017 018import org.apache.log4j.Logger; 019import org.kuali.mobility.push.dao.PushDao; 020import org.kuali.mobility.push.entity.Device; 021import org.kuali.mobility.push.entity.Push; 022import org.kuali.mobility.push.entity.PushDeviceTuple; 023import org.kuali.mobility.push.service.send.SendServiceDelegator; 024import org.springframework.beans.factory.annotation.Autowired; 025import org.springframework.beans.factory.annotation.Qualifier; 026import org.springframework.transaction.annotation.Transactional; 027 028import java.util.Iterator; 029import java.util.List; 030 031/** 032 * Implementation of the <code>PushService</code> 033 * 034 * @since 2.0.0 035 * @author Kuali Mobility Team (mobility.dev@kuali.org) 036 */ 037//@Service 038public class PushServiceImpl implements PushService { 039 040 /** A reference to a logger for this service */ 041 private static Logger LOG = Logger.getLogger(PushServiceImpl.class); 042 043 /** A reference to the <code>SendServiceDelegator</code> object used by this ServiceImpl */ 044 @Autowired 045 @Qualifier("sendServiceDelegator") 046 private SendServiceDelegator sendService; 047 048 /** A reference to the <code>DeviceService</code> object used by this ServiceImpl */ 049 @Autowired 050 private DeviceService deviceService; 051 052 /** A reference to the <code>PushDeviceTupleService</code> object used by this ServiceImpl */ 053 @Autowired 054 private PushDeviceTupleService pdtService; 055 056 /** A reference to the <code>PushDao</code> */ 057 @Autowired 058 private PushDao pushDao; 059 060 /* 061 * (non-Javadoc) 062 * @see org.kuali.mobility.push.service.PushService#savePush(org.kuali.mobility.push.entity.Push) 063 */ 064 @Override 065 @Transactional 066 public void savePush(Push push){ 067 pushDao.savePush(push); 068 } 069 070 071 /* 072 * (non-Javadoc) 073 * @see org.kuali.mobility.push.service.PushService#removePush(org.kuali.mobility.push.entity.Push) 074 */ 075 @Override 076 @Transactional 077 public boolean removePush(Push push){ 078 return pushDao.removePush(push); 079 } 080 081 082 /* 083 * (non-Javadoc) 084 * @see org.kuali.mobility.push.service.PushService#savePush(org.kuali.mobility.push.entity.Push, java.util.List) 085 */ 086 @Override 087 @Transactional 088 public void savePush(Push push, List<Device> devices){ 089 pushDao.savePush(push, devices); 090 } 091 092 /* 093 * (non-Javadoc) 094 * @see org.kuali.mobility.push.service.PushService#findPushById(java.lang.Long) 095 */ 096 @Transactional 097 public Push findPushById(Long id){ 098 return pushDao.findPushById(id); 099 } 100 101 /* 102 * (non-Javadoc) 103 * @see org.kuali.mobility.push.service.PushService#findDevicesForPush(org.kuali.mobility.push.entity.Push) 104 */ 105 @Transactional 106 public List<Device> findDevicesForPush(Push push){ 107 return pushDao.findDevicesForPush(push); 108 } 109 110 /* 111 * (non-Javadoc) 112 * @see org.kuali.mobility.push.service.PushService#findUnsentPushTuples() 113 */ 114 @Transactional 115 public List<PushDeviceTuple> findUnsentPushTuples(){ 116 return pushDao.findUnsentPushTuples(); 117 } 118 119 /* 120 * (non-Javadoc) 121 * @see org.kuali.mobility.push.service.PushService#findAllPush() 122 */ 123 @Transactional 124 public List<Push> findAllPush() { 125 return pushDao.findAllPush(); 126 } 127 128 /* 129 * (non-Javadoc) 130 * @see org.kuali.mobility.push.service.PushService#countPushes() 131 */ 132 @Transactional 133 public int countPushes() { 134 return pushDao.countPushes(); 135 } 136 137 /* 138 * (non-Javadoc) 139 * @see org.kuali.mobility.push.service.PushService#sendPush(org.kuali.mobility.push.entity.Push, org.kuali.mobility.push.entity.Device) 140 */ 141 public int sendPush(Push push, Device device){ 142 this.getSendService().sendPush(push, device); 143 return -1; 144 } 145 146 147 /* 148 * (non-Javadoc) 149 * @see org.kuali.mobility.push.service.PushService#sendPush(org.kuali.mobility.push.entity.Push, java.util.List) 150 */ 151 public int sendPush(Push push, List<Device> devices){ 152 this.getSendService().sendPush(push, devices); 153 return -1; 154 } 155 156 /* 157 * (non-Javadoc) 158 * @see org.kuali.mobility.push.service.PushService#sendPush(java.util.List) 159 */ 160 @Transactional 161 public int sendPush(List<PushDeviceTuple> tuples){ 162 Iterator<PushDeviceTuple> i = tuples.iterator(); 163 Push p = null; 164 Device d = null; 165 while(i.hasNext()){ 166 PushDeviceTuple pdt = (PushDeviceTuple)i.next(); 167 LOG.info("Push id : " + pdt.getPushId() + " Device id: " + pdt.getDeviceId()); 168 p = this.findPushById(pdt.getPushId()); 169 LOG.info("Push Title: " + p.getTitle()); 170 d = getDeviceService().findDeviceById(pdt.getDeviceId()); 171 LOG.info("Device Name:" + d.getDeviceName()); 172 getPdtService().markTupleAsSent(pdt); 173 } 174 return 0; 175 } 176 177 /** 178 * Sets the reference to the <code>PushDao</code> 179 * @param dao Reference to the <code>PushDao</code> 180 */ 181 public void setPushDao(PushDao dao) { 182 this.pushDao = dao; 183 } 184 185 /** 186 * Gets the reference to the <code>PushDao</code> 187 * @return 188 */ 189 public PushDao getPushDao() { 190 return pushDao; 191 } 192 193 /** 194 * A reference to the <code>SendServiceDelegator</code> responsible for delegating 195 * push messages to appropriate implementations for different devices. 196 */ 197 public SendServiceDelegator getSendService() { 198 return sendService; 199 } 200 201 /** 202 * Set the reference to the <code>SendServiceDelegator</code> for this ServiceImpl. 203 * @param sendService 204 */ 205 public void setSendService(SendServiceDelegator sendService) { 206 this.sendService = sendService; 207 } 208 209 /** Get reference to the <code>DeviceService</code> */ 210 public DeviceService getDeviceService() { 211 return deviceService; 212 } 213 214 /** 215 * Set the reference to the <code>DeviceService</code> for this ServiceImpl. 216 * @param deviceService 217 */ 218 public void setDeviceService(DeviceService deviceService) { 219 this.deviceService = deviceService; 220 } 221 222 /** A reference to the <code>PushDeviceTupleService</code>*/ 223 public PushDeviceTupleService getPdtService() { 224 return pdtService; 225 } 226 227 /** 228 * Set the reference to the <code>PushDeviceTupleService</code> for this ServiceImpl. 229 * @param pdtService 230 */ 231 public void setPdtService(PushDeviceTupleService pdtService) { 232 this.pdtService = pdtService; 233 } 234}