| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 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 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
@Path("/sync") |
| 37 | |
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) |
| 38 | |
@Produces({ MediaType.APPLICATION_JSON }) |
| 39 | 0 | public class SyncServiceImpl implements SyncService { |
| 40 | 0 | protected final Log log = LogFactory.getLog(getClass()); |
| 41 | |
|
| 42 | 0 | private PicManFacade pmf = null; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | 0 | public void setPicMan(PicManFacade pmf) { this.pmf = pmf; } |
| 48 | |
|
| 49 | |
private DatabaseFacade getDB() { |
| 50 | 0 | if (pmf == null) { |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | 0 | pmf = SpringGlue.getInstance().getPicMan(); |
| 55 | |
} |
| 56 | 0 | return(pmf.getDB()); |
| 57 | |
} |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
@Override |
| 63 | |
@GET |
| 64 | |
@Path("/servers") |
| 65 | |
public List<SyncServer> getServers() { |
| 66 | 0 | List<SyncServer> list = getDB().getSyncServers(); |
| 67 | 0 | return list; |
| 68 | |
} |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
@Override |
| 74 | |
@POST |
| 75 | |
@Path("/persist/server") |
| 76 | |
@Consumes("application/json") |
| 77 | |
public void persistServer(SyncServer syncServer) { |
| 78 | 0 | log.info("persistS: id=" + syncServer.getId() + " name=" + syncServer.getName() + " rid=" + syncServer.getRid() + " sid=" + syncServer.getSid() |
| 79 | 0 | + " active=" + syncServer.isActive() + " push=" + syncServer.isAllowPush() + " pull=" + syncServer.isAllowPull()); |
| 80 | 0 | getDB().storeSyncServer(syncServer); |
| 81 | 0 | } |
| 82 | |
|
| 83 | |
@Override |
| 84 | |
@GET |
| 85 | |
@Path("/clients") |
| 86 | |
public List<SyncClient> getClients() { |
| 87 | 0 | List<SyncClient> list = getDB().getSyncClients(); |
| 88 | 0 | return list; |
| 89 | |
} |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
@Override |
| 95 | |
@POST |
| 96 | |
@Path("/persist/client") |
| 97 | |
public void persistClient(SyncClient syncClient) { |
| 98 | 0 | log.info("persistC: id=" + syncClient.getId() + " name=" + syncClient.getName() + " rid=" + syncClient.getRid() + " sid=" + syncClient.getSid() |
| 99 | 0 | + " active=" + syncClient.isActive() + " push=" + syncClient.isAllowPush() + " pull=" + syncClient.isAllowPull()); |
| 100 | 0 | getDB().storeSyncClient(syncClient); |
| 101 | 0 | } |
| 102 | |
|
| 103 | |
|
| 104 | |
} |