本文整理汇总了Python中com.googlecode.fascinator.common.JsonSimple.getJsonObject方法的典型用法代码示例。如果您正苦于以下问题:Python JsonSimple.getJsonObject方法的具体用法?Python JsonSimple.getJsonObject怎么用?Python JsonSimple.getJsonObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.fascinator.common.JsonSimple
的用法示例。
在下文中一共展示了JsonSimple.getJsonObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateRelationships
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
def updateRelationships(self, relationship,pid,identifier):
oid = self.findOidByIdentifier(relationship.get("identifier"))
self.writer.println(oid)
digitalObject = StorageUtils.getDigitalObject(self.storage, oid)
metadataJsonPayload = digitalObject.getPayload("metadata.json")
metadataJsonInstream = metadataJsonPayload.open()
metadataJson = JsonSimple(metadataJsonInstream)
metadataJsonPayload.close()
relationships = metadataJson.getArray("relationships")
found = False
if relationships is None:
relationships = JSONArray()
metadataJson.getJsonObject().put("relationships",relationships)
for relationship1 in relationships:
if relationship1.get("identifier") == identifier:
relationship1.put("isCurated",True)
relationship1.put("curatedPid",pid)
found = True
if not found:
newRelationship = JsonObject()
newRelationship.put("isCurated",True)
newRelationship.put("curatedPid",pid)
newRelationship.put("relationship",relationship.get("relationship"))
newRelationship.put("identifier",identifier)
relationships.add(newRelationship)
istream = ByteArrayInputStream(String(metadataJson.toString(True)).getBytes())
StorageUtils.createOrUpdatePayload(digitalObject,"metadata.json",istream)
示例2: process_tags
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
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) + "]"
示例3: __checkMetadataPayload
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
def __checkMetadataPayload(self, identifier):
# We are just going to confirm the existance of
# 'metadata.json', or create an empty one if it
# doesn't exist. Makes curation function for this
# option and removes some log errors on the details
# screen.
try:
self.object.getPayload("metadata.json")
# all is good, the above will throw an exception if it doesn't exist
return
except Exception:
self.log.info("Creating 'metadata.json' payload for object '{}'", self.oid)
# Prep data
metadata = JsonSimple()
metadata.getJsonObject().put("recordIDPrefix", "")
metadata.writeObject("data")
# The only real data we require is the ID for curation
idHolder = metadata.writeObject("metadata")
idHolder.put("dc.identifier", identifier)
# Store it
inStream = IOUtils.toInputStream(metadata.toString(True), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(self.object, "metadata.json", inStream)
except StorageException, e:
self.log.error("Error creating 'metadata.json' payload for object '{}'", self.oid, e)
return
示例4: __activate__
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
def __activate__(self, context):
self.request = context["request"]
self.response = context["response"]
self.formData = context["formData"]
self.log = context["log"]
# Basic response text
message = JsonSimple()
self.metadata = message.writeObject(["metadata"])
self.results = message.writeArray(["results"])
# Prepare response Object
format = self.formData.get("format")
if format == "json":
out = self.response.getPrintWriter("application/json; charset=UTF-8")
else:
out = self.response.getPrintWriter("text/plain; charset=UTF-8")
# Success Response
try:
self.searchNla()
out.println(message.toString(True))
out.close()
except Exception, ex:
self.log.error("Error during search: ", ex)
self.response.setStatus(500)
message = JsonSimple()
message.getJsonObject().put("error", ex.getMessage())
out.println(message.toString(True))
out.close()
示例5: __messages
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
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)
示例6: get_image
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
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
示例7: __activate__
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
def __activate__(self, context):
self.velocityContext = context
formData = self.vc("formData")
# build the URL and query parameters to retrieve
proxyUrls = JsonSimple(self.vc("systemConfig").getObject("proxy-urls"))
url = ""
key = formData.get("ns", "")
if proxyUrls.getJsonObject().containsKey(key):
url = proxyUrls.getString("", [key])
queryStr = formData.get("qs")
if queryStr == "searchTerms={searchTerms}":
queryStr = None
if queryStr:
if formData.get("jaffa2autocomplete", "false") == "true":
url += "?searchTerms=%s" % queryStr
else:
url += "?%s" % queryStr
self.vc("log").debug("Proxy URL = '{}'", url)
data = None
try:
data = self.__wget(url)
except Exception, e:
data = '{"error":"%s"}' % str(e)
self.vc("log").error("ERROR accessing URL:", e)
示例8: __activate__
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
def __activate__(self, context):
response = context["response"]
writer = response.getPrintWriter("text/plain; charset=UTF-8")
auth = context["page"].authentication
result = JsonSimple()
obj = result.getJsonObject()
obj.put("status", "error")
obj.put("message", "An unknown error has occurred")
if auth.is_logged_in():
services = context["Services"]
formData = context["formData"]
sessionState = context["sessionState"]
urlBase = context["urlBase"]
if urlBase.endswith("/"):
urlBase = urlBase[:-1]
func = formData.get("func")
portalManager = services.portalManager
if func == "create-view":
try:
fq = [q for q in sessionState.get("fq") if q != 'item_type:"object"']
id = formData.get("id")
description = formData.get("description")
print "Creating view '%s': '%s'" % (id, description)
portal = Portal(id)
portal.setDescription(formData.get("description"))
portal.setQuery(" OR ".join(fq))
portal.setSearchQuery(sessionState.get("searchQuery"))
portal.setFacetFields(portalManager.default.facetFields)
portalManager.add(portal)
portalManager.save(portal)
obj.put("status", "ok")
obj.put("message", "View '%s' successfully created" % id)
obj.put("url", "%s/%s/home" % (urlBase, id))
except Exception, e:
response.setStatus(500)
obj.put("message", str(e))
elif func == "delete-view":
defaultPortal = context["defaultPortal"]
portalId = formData.get("view")
if auth.is_admin():
if not portalId:
response.setStatus(500)
obj.put("message", "No view specified to be deleted")
elif portalId != defaultPortal:
# sanity check: don't delete default portal
print "Deleting view '%s'" % portalId
try:
portalManager.remove(portalId)
obj.put("status", "ok")
obj.put("message", "View '%s' successfully removed" % portalId)
obj.put("url", "%s/%s/home" % (urlBase, defaultPortal))
except Exception, e:
obj.put("message", str(e))
else:
response.setStatus(500)
obj.put("message", "The default view cannot be deleted")
else:
response.setStatus(403)
obj.put("message", "Only administrative users can access this API")
示例9: __activate__
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
def __activate__(self, context):
self.request = context["request"]
self.response = context["response"]
self.formData = context["formData"]
self.log = context["log"]
oid = self.formData.get("oid")
self.log.debug("Curation request recieved: '{}'", oid)
message = JsonSimple()
message.getJsonObject().put("task", "curation")
message.getJsonObject().put("oid", oid)
out = self.response.getPrintWriter("text/plain; charset=UTF-8")
if self.queueMessage(message.toString()):
out.println("Request successful. The system will now process.")
else:
self.response.setStatus(500)
out.println("Error sending message, see system logs.")
out.close()
示例10: __updateMetadataPayload
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
def __updateMetadataPayload(self, data):
# Get and parse
payload = self.object.getPayload("formData.tfpackage")
json = JsonSimple(payload.open())
payload.close()
# Basic test for a mandatory field
title = json.getString(None, ["dc:title"])
if title is not None:
# We've done this before
return
# Merge
json.getJsonObject().putAll(data)
# Store it
inStream = IOUtils.toInputStream(json.toString(True), "UTF-8")
try:
self.object.updatePayload("formData.tfpackage", inStream)
except StorageException, e:
self.log.error("Error updating 'formData.tfpackage' payload for object '{}'", self.oid, e)
示例11: modify_json
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
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()
示例12: __activate__
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
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()
示例13: __upgrade
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
def __upgrade(self, formData):
# These fields are handled specially
ignoredFields = ["metaList", "redbox:formVersion", "redbox:newForm"]
# Prepare a new JSON setup for upgraded data
newJsonSimple = JsonSimple()
newJsonObject = newJsonSimple.getJsonObject()
metaList = newJsonSimple.writeArray(["metaList"])
oldJsonObject = formData.getJsonObject()
for key in oldJsonObject.keySet():
oldField = str(key)
if oldField not in ignoredFields:
newField = self.__parseFieldName(oldField)
metaList.add(newField)
newJsonObject.put(newField, oldJsonObject.get(key))
# Form management
newJsonObject.put("redbox:formVersion", self.redboxVersion)
newForm = oldJsonObject.get("redbox:newForm")
if newForm is not None:
newJsonObject.put("redbox:newForm", newForm)
#########
# Some final custom modifications more complicated than most fields
#########
# Old URL checkbox 'on' equals new ID Origin 'internal'
urlOrigin = oldJsonObject.get("url_useRecordId")
if urlOrigin is not None and urlOrigin == "on":
newJsonObject.put("dc:identifier.redbox:origin", "internal")
# Related data should default to being unlinked if from legacy forms
counter = 1
template = "dc:relation.vivo:Dataset"
newIdField = "%s.%s.dc:identifier" % (template, counter)
while newJsonObject.containsKey(newIdField):
newOriginField = "%s.%s.redbox:origin" % (template, counter)
newJsonObject.put(newOriginField, "external")
newPublishField = "%s.%s.redbox:publish" % (template, counter)
newJsonObject.put(newPublishField, "off")
counter += 1
newIdField = "%s.%s.dc:identifier" % (template, counter)
self.audit.add("Migration tool. Version upgrade performed '%s' => '%s'" % (self.version, self.redboxVersion))
return newJsonSimple
示例14: __activate__
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
def __activate__(self, context):
writer = context["response"].getPrintWriter("application/json; charset=UTF-8")
jsonResponse = "{}"
try:
oid = context["formData"].get("oid")
object = context["Services"].getStorage().getObject(oid);
payload = object.getPayload("metadata.json")
json = JsonSimple(payload.open())
payload.close()
object.close()
# We are only going to send the 'data' node though
data = JsonSimple(json.getJsonObject().get("data"))
jsonResponse = data.toString(True)
except Exception, e:
jsonResponse = '{"message": "%s"}' % e.getMessage()
示例15: getJson
# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import getJsonObject [as 别名]
def getJson(self, state="open"):
title = "%s (%s)" % (self.getName(), self.getCount())
json = JsonSimple()
jsonObj = json.getJsonObject()
attributes = JsonObject()
attributes.put("id", self.getId())
attributes.put("fq", self.getFacetQuery())
attributes.put("title", title)
jsonObj.put("data", title)
jsonObj.put("attributes", attributes)
hasSubFacets = not self.getSubFacets().isEmpty()
if hasSubFacets:
jsonObj.put("state", state)
subFacetList = ArrayList()
for subFacet in self.getSubFacets():
subFacetList.add(subFacet.getJson("closed"))
children = JSONArray()
children.addAll(subFacetList)
jsonObj.put("children", children)
return json