def __delete_pub(self, attributes, request_id): if not validator.attributesPresent(["name"], attributes): self.reportBadSyntax("'name' attribute missing", request_id) return if not publication.Collection.nameTaken(attributes["name"]): self.respond(420, "error", "publication name does not exist", request_id) return publication.Collection.delete(attributes["name"]) self.respondOK("ok", request_id)
def __replace_pub(self, attributes, request_id): if not validator.attributesPresent(["pub_name", "new_content"], attributes): self.reportBadSyntax("some attributes missing",request_id) return if not publication.Collection.nameTaken(attributes["pub_name"]): self.respond(404, "error", "publication name not found",request_id) return pub = publication.Collection.getPublicationByName(attributes["pub_name"]) pub.setContentByObject(attributes["new_content"]) self.respondOK(pub.getContentsAsObject(),request_id) pub.propagate("replace")
def __new_pub(self, attributes, request_id): if not validator.attributesPresent(["name", "content"], attributes): self.reportBadSyntax("some attributes missing", request_id) return if publication.Collection.nameTaken(attributes["name"]): self.respond(420, "error", "publication name already exists", request_id) return #if not validator.isCorerctJSON(attributes["content"]): # self.reportBadSyntax("incorrect json in content", request_id) # return publication.Collection.createPublication(attributes["name"], attributes["content"]) self.respondOK(None, request_id)
def __replace_pub(self, attributes, request_id): if not validator.attributesPresent(["pub_name", "new_content"], attributes): self.reportBadSyntax("some attributes missing", request_id) return if not publication.Collection.nameTaken(attributes["pub_name"]): self.respond(404, "error", "publication name not found", request_id) return pub = publication.Collection.getPublicationByName( attributes["pub_name"]) pub.setContentByObject(attributes["new_content"]) self.respondOK(pub.getContentsAsObject(), request_id) pub.propagate("replace")
def __sub(self, attributes, request_id): print("handling SUB request") if not validator.attributesPresent(["id", "pub_name"], attributes): self.reportBadSyntax("", request_id) return hasSub = self.hasSubID(attributes["id"]) if hasSub: self.respond(422, "error", "you already have that id assigned to a publication. Unsub first or choose a different ID", request_id) return try: pub = publication.Collection.getPublicationByName(attributes["pub_name"]) except publication.PubNotFoundError: self.respond(404, "error", "publication not found", request_id) return sub = subscription.Collection.new(self, pub, attributes["id"]) self.subscriptions.append(sub) self.respondOK(pub.getContentsAsObject(), request_id)
def __update_pub(self, attributes, request_id): if not validator.attributesPresent(["pub_name", "changes"], attributes): self.reportBadSyntax("some attributes missing",request_id) return if not publication.Collection.nameTaken(attributes["pub_name"]): self.respond(404, "error", "publication name not found", request_id) return if not isinstance(attributes["changes"], list): self.reportBadSyntax("changes attribute must be a [] list",request_id) return patch = jsonpatch.JsonPatch(attributes["changes"]) pub = publication.Collection.getPublicationByName(attributes['pub_name']) try: pub.applyPatch(patch) except: self.reportBadSyntax("badly formatted JsonPatch") self.respondOK(pub.getContentsAsObject(), request_id) pub.propagate("update")
def __sub(self, attributes, request_id): print("handling SUB request") if not validator.attributesPresent(["id", "pub_name"], attributes): self.reportBadSyntax("", request_id) return hasSub = self.hasSubID(attributes["id"]) if hasSub: self.respond( 422, "error", "you already have that id assigned to a publication. Unsub first or choose a different ID", request_id) return try: pub = publication.Collection.getPublicationByName( attributes["pub_name"]) except publication.PubNotFoundError: self.respond(404, "error", "publication not found", request_id) return sub = subscription.Collection.new(self, pub, attributes["id"]) self.subscriptions.append(sub) self.respondOK(pub.getContentsAsObject(), request_id)
def __update_pub(self, attributes, request_id): if not validator.attributesPresent(["pub_name", "changes"], attributes): self.reportBadSyntax("some attributes missing", request_id) return if not publication.Collection.nameTaken(attributes["pub_name"]): self.respond(404, "error", "publication name not found", request_id) return if not isinstance(attributes["changes"], list): self.reportBadSyntax("changes attribute must be a [] list", request_id) return patch = jsonpatch.JsonPatch(attributes["changes"]) pub = publication.Collection.getPublicationByName( attributes['pub_name']) try: pub.applyPatch(patch) except: self.reportBadSyntax("badly formatted JsonPatch") self.respondOK(pub.getContentsAsObject(), request_id) pub.propagate("update")