def __messages(self): # Generic workflow messages if self.message_list is not None and len(self.message_list) > 0: msg = JsonSimple() msg.getJsonObject().put("oid", self.oid) message = msg.toString() for target in self.message_list: self.utils.sendMessage(target, message) # Camtasia integration emailStep = self.params.getProperty("emailStep") # First pass though... harvest queue if emailStep is None: emailStep = "emailOne" # The next message self.params.setProperty("emailStep", "emailTwo") else: # Second step... render queue if emailStep == "emailTwo": self.params.setProperty("emailStep", "completed") if emailStep is not None and emailStep != "completed": email = self.params.getProperty("relayEmail") body = self.__getEmailBody(emailStep) if email is not None and body is not None: msg = JsonSimple() msg.getJsonObject().put("to", email) msg.getJsonObject().put("body", body) message = msg.toString() self.utils.sendMessage("emailnotification", message)
def __messages(self): if self.message_list is not None and len(self.message_list) > 0: msg = JsonSimple() msg.getJsonObject().put("oid", self.oid) message = msg.toString() for target in self.message_list: self.utils.sendMessage(target, message)
def queryMoodle(self): username = self.vc("formData").get("username") # We are going to bypass the authentication Jython # object to directly access the moodle plugin. self.roleManager.setActivePlugin("moodle") roles = self.roleManager.getRoles(username) if len(roles) == 0: self.throw_error("The given user is invalid or has no courses.") else: roleIds = [] roleList = [] # For each role (courseId) for role in roles: thisRole = JsonSimple() # Query the database for the course's name name = self.__dbGet(role) if name is not None: roleIds.append("\"" + role + "\"") thisRole.getJsonObject().put("name", name) psData = self.__dbGetPS(role) if psData is not None: thisRole.getJsonObject().put("psData", psData) roleList.append("\"" + role + "\" : " + thisRole.toString()) keys = "\"keys\" : [" + ",".join(roleIds) + "]" data = "\"data\" : {" + ",".join(roleList) + "}" response = "{" + keys + "," + data + "}" self.writer.println(response) self.writer.close()
def get_image(self): self.type = "http://www.purl.org/anotar/ns/type/0.1#Tag" mediaFragType = "http://www.w3.org/TR/2009/WD-media-frags-20091217" result = '{"result":' + self.search_solr() + "}" if result: imageTagList = [] imageTags = JsonSimple(result).getJsonSimpleList(["result"]) for imageTag in imageTags: imageAno = JsonSimple() # We only want tags with locators, not basic tags locators = imageTag.getJsonSimpleList(["annotates", "locators"]) if locators and not locators.isEmpty(): locatorValue = locators.get(0).getString(None, ["value"]) locatorType = locators.get(0).get(None, ["type"]) if locatorValue and locatorValue.find("#xywh=") > -1 and locatorType == mediaFragType: _, locatorValue = locatorValue.split("#xywh=") left, top, width, height = locatorValue.split(",") object = imageAno.getJsonObject() object.put("top", top) object.put("left", left) object.put("width", width) object.put("height", height) object.put("creator", imageTag.getString(None, ["creator", "literal"])) object.put("creatorUri", imageTag.getString(None, ["creator", "uri"])) object.put("id", imageTag.getString(None, ["id"])) # tagCount = imageTag.getString(None, ["tagCount"]) object.put("text", imageTag.getString(None, ["content", "literal"])) object.put("editable", "true") imageTagList.append(imageAno.toString()) result = "[" + ",".join(imageTagList) + "]" return result
def process_tags(self, result): tags = [] tagsDict = {} # Build a dictionary of the tags for doc in result: # Get Anotar data from Solr data doc = JsonSimple(doc.get("jsonString")) # Get actual tag text tag = doc.getString(None, ["content", "literal"]) # Find out if they have locators locs = doc.getJsonSimpleList(["annotates", "locators"]).size() if locs == 0: # Basic tags, just aggregate counts if tag in tagsDict: # We've seen it before, just increment the counter existing = tagsDict[tag] count = existing.getInteger(0, ["tagCount"]) existing.getJsonObject().put("tagCount", str(count + 1)) else: # First time, store this object doc.getJsonObject().put("tagCount", str(1)) tagsDict[tag] = doc else: # Tags with a locator, special case for images etc. tags.append(doc.toString()) # Push all the 'basic' counts into the list to return for tag in tagsDict: tags.append(tagsDict[tag].toString()) return "[" + ",".join(tags) + "]"
def modify_json(self): # print "**** anotar.py : add_json() : adding json : " + json jsonSimple = JsonSimple(self.json) jsonObj = jsonSimple.getJsonObject() jsonObj.put("id", self.pid) rootUri = jsonSimple.getString(None, ["annotates", "rootUri"]) if rootUri is not None: baseUrl = "http://%s:%s/" % (self.vc("request").serverName, self.vc("serverPort")) myUri = baseUrl + rootUri + "#" + self.pid jsonObj.put("uri", myUri) jsonObj.put("schemaVersionUri", "http://www.purl.org/anotar/schema/0.1") self.json = jsonSimple.toString()
class IndexData: def __init__(self): pass def __activate__(self, context): # Prepare variables self.index = context["fields"] self.object = context["object"] self.payload = context["payload"] self.params = context["params"] self.utils = context["pyUtils"] self.config = context["jsonConfig"] self.wfSecurityExceptions = None self.message_list = None # Because the workflow messaging system wants access to this data # BEFORE it actual hits the index we are going to cache it into an # object payload too. self.directIndex = JsonSimple() # Common data self.__newDoc() # Real metadata if self.itemType == "object": self.__previews() self.__basicData() self.__metadata() # Update the 'direct.index' payload - BEFORE messages are sent directString = String(self.directIndex.toString()) inStream = ByteArrayInputStream(directString.getBytes("UTF-8")) try: StorageUtils.createOrUpdatePayload(self.object, "direct.index", inStream) except StorageException, e: print " * direct-files.py : Error updating direct payload" self.__messages() self.__displayType() # Make sure security comes after workflows self.__security()
def __activate__(self, context): request = context["request"] response = context["response"] writer = response.getPrintWriter("text/javascript; charset=UTF-8") result = JsonSimple() ## Look for the JSONP callback to use jsonpCallback = request.getParameter("callback") if jsonpCallback is None: jsonpCallback = request.getParameter("jsonp_callback") if jsonpCallback is None: response.setStatus(403) writer.println("Error: This interface only responds to JSONP") writer.close() return if context["page"].authentication.is_logged_in(): result.getJsonObject().put("isAuthenticated", "true") else: result.getJsonObject().put("isAuthenticated", "false") writer.println(jsonpCallback + "(" + result.toString() + ")") writer.close()
organizations = organizations.findall(ns+"organization") organizations = [o for o in organizations if o.attrib.get("identifier")==defaultName] organization = organizations[0] title = organization.find(ns+"title").text rvtMap.put("title", title) items = organization.findall(ns+"item") rvtMap.put("toc", self.__getJsonItems(ns, items, resources)) except Exception, e: data["error"] = "Error - %s" % str(e) print data["error"] object.close() except StorageException, e: data["DEBUG"] = str(e.getMessage()) rvtManifest = JsonSimple(rvtMap) return rvtManifest.toString() def __getJsonItems(self, ns, items, resources): rvtNodes = ArrayList() for item in items: attr = item.attrib isvisible = attr.get("isvisible") == "true" idref = attr.get("identifierref") id = resources.get(idref) title = item.find(ns+"title").text if isvisible and id and id.endswith(".htm"): rvtNode = HashMap() rvtNode.put("visible", True) rvtNode.put("relPath", id) rvtNode.put("title", title) rvtNode.put("children", self.__getJsonItems(ns, item.findall(ns+"item"), resources))