1 package net.systemeD.potlatch2.utils {
3 import net.systemeD.halcyon.connection.*;
4 import flash.events.Event;
8 * A connection to a Snapshot server. A Snapshot server serves OSM map requests and can also
9 * track the "status" of an entity. Most other types of XMLConnection requests will fail. See
10 * http://www.github.com/gravitystorm/snapshot-server for example code based on the database
11 * structure created by osmosis pgsnapshot schema.
14 public class SnapshotConnection extends XMLConnection {
16 public function SnapshotConnection(cname:String,api:String,policy:String,initparams:Object=null) {
17 super(cname,api,policy,initparams);
21 // As it stands, the following two functions could be refactored further.
24 * Post a status update call to the server and update entity.status if successful.
26 public function markComplete(entity:Entity):void {
27 var urlReq:URLRequest;
30 var node:Node = Node(entity);
31 if (node == getNode(node.id)) { // confirm it's from this connection
32 makeRequest(entity, 'complete');
35 } else if (entity is Way) {
36 var way:Way = Way(entity);
37 if (way == getWay(way.id)) { // confirm it's from this connection
38 makeRequest(entity, 'complete');
44 * Send a "complete" call to the server and update entity.status if successful.
46 public function markNotComplete(entity:Entity):void {
47 var urlReq:URLRequest;
50 var node:Node = Node(entity);
51 if (node == getNode(node.id)) { // confirm it's from this connection
52 makeRequest(entity, 'incomplete');
55 } else if (entity is Way) {
56 var way:Way = Way(entity);
57 if (way == getWay(way.id)) { // confirm it's from this connection
58 makeRequest(entity, 'incomplete');
63 private function makeRequest(entity:Entity, status:String):void {
64 var urlReq:URLRequest = new URLRequest(apiBaseURL+entity.getType()+"/"+entity.id+"/status");
65 urlReq.method = "POST";
67 var loader:URLLoader = new URLLoader();
68 loader.addEventListener(Event.COMPLETE, function(e:Event):void { updateStatus(entity, status) });
72 private function updateStatus(e:Entity, s:String):void {