本文整理汇总了Python中com.googlecode.fascinator.common.storage.StorageUtils.createOrUpdatePayload方法的典型用法代码示例。如果您正苦于以下问题:Python StorageUtils.createOrUpdatePayload方法的具体用法?Python StorageUtils.createOrUpdatePayload怎么用?Python StorageUtils.createOrUpdatePayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.fascinator.common.storage.StorageUtils
的用法示例。
在下文中一共展示了StorageUtils.createOrUpdatePayload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveResponse
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def saveResponse(self, context):
""" Save into object storage key to assessor's name
It has four keys: status, recommendation, size-agreement and comments
when status == "submitted", reviewer sees it
"""
oid = self.request.getParameter("oid")
action = self.request.getParameter("action")
if action and re.match("submit", action, re.I):
status = "submitted"
else:
status = "draft"
recommendation = self.request.getParameter("recommendation")
sizeAgreement = self.request.getParameter("size-agreement")
comments = self.request.getParameter("comments")
storedObj, fileExisted = self.hasResponses(oid)
if fileExisted:
committeeResponses = self.getResponses(storedObj)
else:
committeeResponses = JsonObject()
assessorResponse = JsonObject()
assessorResponse.put("status", status)
if status == 'submitted':
assessorResponse.put("date",self._getToday())
assessorResponse.put("recommendation",recommendation)
assessorResponse.put("size-agreement",sizeAgreement)
assessorResponse.put("comments",comments)
committeeResponses.put(self.assessor,assessorResponse)
StorageUtils.createOrUpdatePayload(storedObj,self.PAYLOAD,IOUtils.toInputStream(committeeResponses.toString(), "UTF-8"))
context["response"].sendRedirect(context["portalPath"] +"/detail/"+oid)
示例2: __activate__
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def __activate__(self, context):
self.auth = context["page"].authentication
self.errorMsg = ""
self.request = context["request"]
self.response = context["response"]
self.formData = context["formData"]
self.storage = context["Services"].getStorage()
self.log = context["log"]
self.reportManager = context["Services"].getService("reportManager")
fromOid = self.formData.get("fromOid")
fromObject = self.storage.getObject(fromOid)
if (self.auth.is_logged_in()):
if (self.auth.is_admin() == True):
pass
elif (self.__isOwner(fromObject)):
pass
else:
self.errorMsg = "Requires Admin / Librarian / Reviewer / owner access."
else:
self.errorMsg = "Please login."
if self.errorMsg == "":
toOid = self.formData.get("toOid")
toObject = self.storage.getObject(toOid)
storeRelatedData = self.formData.get("relatedData")
fromTFPackage = self._getTFPackage(fromObject)
toTFPackage = self._getTFPackage(toObject)
fromInputStream = fromTFPackage.open()
try:
StorageUtils.createOrUpdatePayload(toObject, toTFPackage.getId(), fromInputStream)
except StorageException:
print "error setting tfPackage"
fromTFPackage.close()
fromTFPackageJson = JsonSimple(fromTFPackage.open()).getJsonObject()
if storeRelatedData != "false" :
# add relatedOid info
fromTFPackageJson = self._addRelatedOid(JsonSimple(fromTFPackage.open()), toOid)
inStream = IOUtils.toInputStream(fromTFPackageJson.toJSONString(), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(fromObject, fromTFPackage.getId(), inStream)
except StorageException:
print "error setting tfPackage"
tfMetaPropertyValue = self.formData.get("tfMetaPropertyValue")
self._addPropertyValueToTFMeta(toObject, tfMetaPropertyValue)
self._reharvestPackage()
result = '{"status": "ok", "url": "%s/workflow/%s", "oid": "%s" }' % (context["portalPath"], toOid , toOid)
else:
result = '{"status": "err", "message": "%s"}' % self.errorMsg
writer = self.response.getPrintWriter("application/json; charset=UTF-8")
writer.println(result)
writer.close()
示例3: __createFromSelected
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def __createFromSelected(self):
self.vc("log").debug("Creating package from selected...")
packageType, jsonConfigFile = self.__getPackageTypeAndJsonConfigFile()
#self.vc("log").debug("packageType = '{}'", packageType)
#self.vc("log").debug("jsonConfigFile = '{}'", jsonConfigFile)
# if modifying existing manifest, we already have an identifier,
# otherwise create a new one
manifestId = self.__getActiveManifestId()
if manifestId is None:
manifestHash = "%s.tfpackage" % uuid.uuid4()
else:
manifestHash = self.__getActiveManifestPid()
# store the manifest file for harvesting
packageDir = FascinatorHome.getPathFile("packages")
packageDir.mkdirs()
manifestFile = File(packageDir, manifestHash)
outStream = FileOutputStream(manifestFile)
outWriter = OutputStreamWriter(outStream, "UTF-8")
manifest = self.__getActiveManifest()
oldType = manifest.getType()
if oldType is None:
manifest.setType(packageType)
else:
manifest.setType(oldType)
#self.vc("log").debug("Manifest: {}", manifest)
outWriter.write(manifest.toString(True))
outWriter.close()
try:
if manifestId is None:
# harvest the package as an object
username = self.vc("sessionState").get("username")
if username is None:
username = "guest" # necessary?
harvester = None
# set up config files, and make sure they are both deployed
workflowsDir = FascinatorHome.getPathFile("harvest/workflows")
configFile = self.__getFile(workflowsDir, jsonConfigFile)
rulesFile = self.__getFile(workflowsDir, "packaging-rules.py")
# run the harvest client with our packaging workflow config
harvester = HarvestClient(configFile, manifestFile, username)
harvester.start()
manifestId = harvester.getUploadOid()
harvester.shutdown()
else:
# update existing object
object = StorageUtils.getDigitalObject(Services.getStorage(), manifestId)
manifestStream = FileUtils.openInputStream(manifestFile)
StorageUtils.createOrUpdatePayload(object, manifestHash, manifestStream)
manifestStream.close()
object.close()
except Exception, ex:
error = "Packager workflow failed: %s" % str(ex)
self.vc("log").error(error, ex)
if harvester is not None:
harvester.shutdown()
return '{ "status": "failed" }'
示例4: __checkMetadataPayload
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [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
示例5: __activate__
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def __activate__(self, context):
request = context["request"]
storage = context["Services"].getStorage()
auth = context["page"].authentication
log = context["log"]
username = auth.get_name()
oid = request.getParameter("oid")
approval = request.getParameter("approval")
approval_comment = request.getParameter("approval_comment")
storedObj = storage.getObject(oid)
committeeResponses = None
payloadList = storedObj.getPayloadIdList()
if payloadList.contains("committee-responses.metadata"):
committeeResponsePayload = storedObj.getPayload("committee-responses.metadata")
committeeResponses = JsonSimple(committeeResponsePayload.open()).getJsonObject()
else:
committeeResponses = JsonObject()
committeeResponse = JsonObject()
committeeResponse.put("approval",approval)
committeeResponse.put("approval_comment",approval_comment)
committeeResponses.put(username,committeeResponse)
log.debug(" %s: Committee %s, approval = %s, comment = %s" % ( oid, username, approval, approval_comment))
StorageUtils.createOrUpdatePayload(storedObj,"committee-responses.metadata",IOUtils.toInputStream(committeeResponses.toString(), "UTF-8"))
context["response"].sendRedirect(context["portalPath"] +"/detail/"+oid)
示例6: updateLocalRecordRelations
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def updateLocalRecordRelations(self, jobItems):
oidIdentifierMap = HashMap()
for jobItem in jobItems:
oidIdentifierMap.put(jobItem.get("oid"),jobItem.get("required_identifiers")[0].get("identifier"))
for jobItem in jobItems:
type = jobItem.get("type");
targetSystem = self.systemConfig.getString(None, "curation", "supported-types", type);
if targetSystem == "redbox":
oid = jobItem.get("oid")
digitalObject = StorageUtils.getDigitalObject(self.services.getStorage(), oid)
tfPackagePid = self.getPackageData(digitalObject)
metadataJsonPayload = digitalObject.getPayload(tfPackagePid)
metadataJsonInstream = metadataJsonPayload.open()
metadataJson = JsonSimple(metadataJsonInstream)
metadataJsonPayload.close()
relationships = metadataJson.getArray("relationships")
if relationships is not None:
for relationship in relationships:
system = relationship.get("system")
if system != "redbox" or system != None:
url = self.systemConfig.getString("can't find it", "curation","external-system-urls","get-oid-for-identifier",system)
client = BasicHttpClient(url+ "&identifier="+relationship.get("identifier"))
get = GetMethod(url+ "&identifier="+relationship.get("identifier"))
client.executeMethod(get)
if get.getStatusCode() == 200:
response = JsonSimple(get.getResponseBodyAsString())
relationship.put("curatedPid",oidIdentifierMap.get(response.getString(None,"oid")))
relationship.put("isCurated",True)
#Now update the relationship on Mint's side
break
istream = ByteArrayInputStream(String(metadataJson.toString(True)).getBytes())
StorageUtils.createOrUpdatePayload(digitalObject,tfPackagePid,istream)
示例7: __activate__
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def __activate__(self, context):
try:
self.log = context["log"]
self.response = context["response"]
self.request = context["request"]
self.systemConfig = context["systemConfig"]
self.storage = context["Services"].getStorage()
self.indexer = context["Services"].getIndexer()
self.sessionState = context["sessionState"]
self.sessionState.set("username", "admin")
out = self.response.getPrintWriter("text/plain; charset=UTF-8")
relationshipMapper = ApplicationContextProvider.getApplicationContext().getBean("relationshipMapper")
externalCurationMessageBuilder = ApplicationContextProvider.getApplicationContext().getBean("externalCurationMessageBuilder")
oid = self.request.getParameter("oid")
if oid is None :
identifier = self.request.getParameter("identifier")
oid = self.findOidByIdentifier(identifier)
relationshipType = self.request.getParameter("relationship")
curatedPid = self.request.getParameter("curatedPid")
sourceId = self.request.getParameter("sourceIdentifier")
digitalObject = StorageUtils.getDigitalObject(self.storage, oid)
metadataJson = self.getTfPackage(digitalObject)
relationships = metadataJson.getArray("relationships")
found = False
for relationship in relationships:
if relationship.get("identifier") == sourceId:
relationship.put("isCurated",True)
relationship.put("curatedPid",curatedPid)
found = True
if not found:
relationship = JsonObject()
relationship.put("isCurated",True)
relationship.put("curatedPid",curatedPid)
relationship.put("relationship",relationshipType)
relationship.put("identifier",sourceId)
relationships.add(relationship)
self.log.info(metadataJson.toString(True))
out.println(metadataJson.toString(True))
istream = ByteArrayInputStream(String(metadataJson.toString(True)).getBytes())
for pid in digitalObject.getPayloadIdList():
if pid.endswith(".tfpackage"):
StorageUtils.createOrUpdatePayload(digitalObject,pid,istream)
out.close()
finally:
self.sessionState.remove("username")
示例8: updateRelationships
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [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)
示例9: _addPropertyValueToTFMeta
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def _addPropertyValueToTFMeta(self, object, tfMetaPropertyValue):
objectMetadata = object.getMetadata()
objectMetadata.setProperty("copyTFPackage", tfMetaPropertyValue)
output = ByteArrayOutputStream()
objectMetadata.store(output, None)
input = ByteArrayInputStream(output.toByteArray())
StorageUtils.createOrUpdatePayload(object, "TF-OBJ-META", input)
示例10: updateWorkFlowMetadata
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def updateWorkFlowMetadata(self, workflowMetadata, toWorkflowId, toWorkflowStage):
workflowMetaDataJson = JsonSimple(workflowMetadata.open()).getJsonObject()
workflowMetaDataJson.put("id", toWorkflowId)
workflowMetaDataJson.put("step", toWorkflowStage)
inStream = IOUtils.toInputStream(workflowMetaDataJson.toString(), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(self.object, "workflow.metadata", inStream)
except StorageException:
print " ERROR updating dataset payload"
示例11: _addPropertyValueToTFMeta
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def _addPropertyValueToTFMeta(self, obj, tfMetaPropertyValue):
objectMetadata = obj.getMetadata()
objectMetadata.setProperty("copyTFPackage", tfMetaPropertyValue)
objectMetadata.setProperty("render-pending", "true")
output = ByteArrayOutputStream();
objectMetadata.store(output, None);
input = ByteArrayInputStream(output.toByteArray());
StorageUtils.createOrUpdatePayload(obj,"TF-OBJ-META",input);
示例12: updatePackageType
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def updatePackageType(self, tfPackage, toWorkflowId):
tfPackageJson = JsonSimple(tfPackage.open()).getJsonObject()
tfPackageJson.put("packageType", toWorkflowId)
inStream = IOUtils.toInputStream(tfPackageJson.toString(), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(self.object, tfPackage.getId(), inStream)
except StorageException:
print " ERROR updating dataset payload"
示例13: __createOrUpdateArrayPayload
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def __createOrUpdateArrayPayload(self, oid, payloadName, newObject):
"""
Create or update a payload object in storage defined by oid
The content of this digital object is a JsonArray of objects
payloadName: name of the payload
newObject: new object to be appended, e.g. a JsonObject
"""
objList = self.__getPayloadJsonArray(oid, payloadName)
objList.add(newObject)
storedObj = self.Services.getStorage().getObject(oid)
StorageUtils.createOrUpdatePayload(storedObj, payloadName,IOUtils.toInputStream(objList.toString(), "UTF-8"))
示例14: __change
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def __change(self, context, oid, new_owner):
storage = self.services.getStorage()
object = storage.getObject(oid)
objectMetadata = object.getMetadata()
owner = objectMetadata.getProperty("owner")
objectMetadata.setProperty("owner", new_owner)
self.log.debug("grantAccess.py: Changed ownership from {} to {} ", owner, new_owner)
output = ByteArrayOutputStream()
objectMetadata.store(output, None)
input = ByteArrayInputStream(output.toByteArray())
StorageUtils.createOrUpdatePayload(object, "TF-OBJ-META", input)
try:
auth = context["page"].authentication
source = context["formData"].get("source")
self.log.debug("grantAccess.py: authentication plugin: = {}", source)
auth.set_access_plugin(source)
# special condition when setting admin as owner - revoke all viewers
if new_owner == "admin":
viewers = self.getViewers(oid)
self.log.debug("grantAccess.py: New owner is admin, revoking all viewers")
self.log.debug("grantAccess.py: Viewers: " + viewers.toString())
for viewer in viewers:
self.log.debug("Revoking:%s" % viewer)
auth.revoke_user_access(oid, viewer)
# when there are viewers, the previous owner somehow joins the read-only list, revoke access to the previous owner as well.
if viewers.size() > 0:
auth.revoke_user_access(oid, owner)
else:
self.log.info("Grant previous owner {} view access by adding them to security_execption.", owner)
auth.grant_user_access(oid, owner) # give previous owner read access
err = auth.get_error()
if err is None or err == 'Duplicate! That user has already been applied to this record.':
Services.indexer.index(oid)
Services.indexer.commit()
return '{"status":"ok", "new_owner": "' + new_owner + '"}'
else:
self.log.error("grantAccess.py: Error raised during calling authentication for changing ownership. Exception: " + err)
except Exception, e:
self.log.error("grantAccess.py: Unexpected error raised during changing ownership of data. Exception: " + str(e))
示例15: __change
# 需要导入模块: from com.googlecode.fascinator.common.storage import StorageUtils [as 别名]
# 或者: from com.googlecode.fascinator.common.storage.StorageUtils import createOrUpdatePayload [as 别名]
def __change(self, context, oid, new_owner):
try:
storage = context["Services"].getStorage()
object = storage.getObject(oid)
objectMetadata = object.getMetadata()
owner = objectMetadata.getProperty("owner")
objectMetadata.setProperty("owner", new_owner)
self.log.debug("Changing ownership to : " + new_owner)
output = ByteArrayOutputStream()
objectMetadata.store(output, None)
input = ByteArrayInputStream(output.toByteArray())
StorageUtils.createOrUpdatePayload(object,"TF-OBJ-META",input)
auth = context["page"].authentication
#special condition when setting admin as owner - revoke all viewers
if new_owner == "admin":
self.log.debug("New owner is admin, revoking all viewers")
viewers = self.getViewers(oid)
self.log.debug("Viewers: " + viewers.toString())
for viewer in viewers:
self.log.debug("Revoking:%s" % viewer)
auth.revoke_user_access(oid, viewer)
auth.revoke_user_access(oid, owner)
# don't know what's going on but this was originally set to "owner", changed it to new_owner.
auth.grant_user_access(oid, new_owner)
err = auth.get_error()
if err is None or err == 'Duplicate! That user has already been applied to this record.':
Services.indexer.index(oid)
Services.indexer.commit()
return '{"status":"ok", "new_owner": "' + new_owner + '"}'
else:
self.log.error("Error during changing ownership of data. Exception: " + err)
except Exception, e:
self.log.error("Error during changing ownership of data. Exception: " + str(e))