View Javadoc
1   /******************************************************************************
2    * SyncServiceImpl.java - Define the sync service endpoint
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2014 - Dick Balaska
6    * 
7    */
8   package com.buckosoft.PicMan.service.sync;
9   
10  import java.util.List;
11  
12  import javax.ws.rs.Consumes;
13  import javax.ws.rs.GET;
14  import javax.ws.rs.POST;
15  import javax.ws.rs.Path;
16  import javax.ws.rs.Produces;
17  import javax.ws.rs.core.MediaType;
18  
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  
22  import com.buckosoft.PicMan.business.PicManFacade;
23  import com.buckosoft.PicMan.business.SpringGlue;
24  import com.buckosoft.PicMan.db.DatabaseFacade;
25  import com.buckosoft.PicMan.domain.SyncClient;
26  import com.buckosoft.PicMan.domain.SyncServer;
27  import com.buckosoft.PicMan.service.SyncService;
28  
29  /** Implement the sync service endpoint.
30   * @author Dick Balaska
31   * @since 2014/06/07
32   * @version $Revision: 1.4 $ <br> $Date: 2014/08/23 01:38:49 $
33   * @see <a href="http://cvs.buckosoft.com/Projects/PicMan/PicMan/src/main/java/com/buckosoft/PicMan/service/sync/SyncServiceImpl.java">SyncServiceImpl.java</a>
34   */
35  //@WebService(endpointInterface = "com.buckosoft.PicMan.sync.service.SyncService")
36  @Path("/sync")
37  @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
38  @Produces({ MediaType.APPLICATION_JSON })
39  public class SyncServiceImpl implements SyncService {
40      protected final Log log = LogFactory.getLog(getClass());
41  
42  	private PicManFacade pmf = null;
43  	
44  	/** Set the reference to the PicMan API.
45  	 * @param pmf The PicManFacade
46  	 */
47  	public void setPicMan(PicManFacade pmf) { this.pmf = pmf; }
48  
49  	private	DatabaseFacade getDB() {
50  		if (pmf == null) {
51  			 //BeanFactoryLocator bfl = SingletonBeanFactoryLocator.getInstance();
52  			 //BeanFactoryReference bf = bfl.useBeanFactory("picMan");
53  			 //pmf = (PicManFacade)bf.getFactory().getBean("picMan");
54  			pmf = SpringGlue.getInstance().getPicMan();
55  		}
56  		return(pmf.getDB());
57  	}
58  	
59  	/* (non-Javadoc)
60  	 * @see com.buckosoft.PicMan.sync.service.SyncService#getServers()
61  	 */
62  	@Override
63  	@GET
64  	@Path("/servers")
65  	public List<SyncServer> getServers() {
66  		List<SyncServer> list = getDB().getSyncServers();
67  		return list;
68  	}
69  
70  	/* (non-Javadoc)
71  	 * @see com.buckosoft.PicMan.sync.service.SyncService#persistServer(com.buckosoft.PicMan.domain.SyncServer)
72  	 */
73  	@Override
74  	@POST
75  	@Path("/persist/server")
76  	@Consumes("application/json")
77  	public void persistServer(SyncServer syncServer) {
78  		log.info("persistS: id=" + syncServer.getId() + " name=" + syncServer.getName() + " rid=" + syncServer.getRid() + " sid=" + syncServer.getSid()
79  				+ " active=" + syncServer.isActive() + " push=" + syncServer.isAllowPush() + " pull=" + syncServer.isAllowPull());
80  		getDB().storeSyncServer(syncServer);
81  	}
82  	
83  	@Override
84  	@GET
85  	@Path("/clients")
86  	public List<SyncClient> getClients() {
87  		List<SyncClient> list = getDB().getSyncClients();
88  		return list;
89  	}
90  
91  	/* (non-Javadoc)
92  	 * @see com.buckosoft.PicMan.service.SyncService#persistClient(com.buckosoft.PicMan.domain.SyncClient)
93  	 */
94  	@Override
95  	@POST
96  	@Path("/persist/client")
97  	public void persistClient(SyncClient syncClient) {
98  		log.info("persistC: id=" + syncClient.getId() + " name=" + syncClient.getName() + " rid=" + syncClient.getRid() + " sid=" + syncClient.getSid()
99  				+ " active=" + syncClient.isActive() + " push=" + syncClient.isAllowPush() + " pull=" + syncClient.isAllowPull());
100 		getDB().storeSyncClient(syncClient);
101 	}
102 
103 
104 }