View Javadoc
1   package org.kuali.mobility.push.dao;
2   
3   import java.util.List;
4   
5   import org.apache.log4j.Logger;
6   import org.kuali.mobility.push.entity.PushDeviceTuple;
7   import org.kuali.mobility.push.service.PushService;
8   import org.springframework.beans.factory.annotation.Autowired;
9   
10  
11  /**
12   * A task which will run at a configured interval to check for notifications that has to be sent.
13   * 
14   * @author Kuali Mobility Team (mobility.dev@kuali.org)
15   * @since 2.1.0
16   */
17  public class PushInitBean {
18  
19  	/** A reference to a logger */
20  	private static final Logger LOG = Logger.getLogger(PushInitBean.class);
21  
22  	/**
23  	 * A reference to the <code>PushService</code>
24  	 */
25  	@Autowired
26  	private PushService pushService;
27  	
28  	/**
29  	 * Runs the task to send notifications
30  	 */
31  	public void checkPushes() {
32  		try{
33  			List<PushDeviceTuple> tuplelist = this.pushService.findUnsentPushTuples();
34  			int numberOfPendingPushes = tuplelist.size();
35  			if(numberOfPendingPushes > 0){
36  				LOG.info("Checked for unsent Push notifications, found " + numberOfPendingPushes + " pending push notification.");
37  				pushService.sendPush(tuplelist);						
38  			}else{
39  				LOG.info("Checked for unsent Push notifications, found 0 pending push notifications.");
40  			}
41  		}catch(Exception e){
42  			LOG.error("Exception while running Task", e);
43  		}
44  	}
45  	
46  	/**
47  	 * Sets the reference to the <code>PushService</code>
48  	 * @param pushService
49  	 */
50  	public void setPushService(PushService pushService){
51  		this.pushService = pushService;
52  	}
53  }