当前位置: 首页>>代码示例>>Python>>正文


Python JsonSimple.toJSONString方法代码示例

本文整理汇总了Python中com.googlecode.fascinator.common.JsonSimple.toJSONString方法的典型用法代码示例。如果您正苦于以下问题:Python JsonSimple.toJSONString方法的具体用法?Python JsonSimple.toJSONString怎么用?Python JsonSimple.toJSONString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.googlecode.fascinator.common.JsonSimple的用法示例。


在下文中一共展示了JsonSimple.toJSONString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __activate__

# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import toJSONString [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()
开发者ID:ozej8y,项目名称:redbox,代码行数:62,代码来源:copyTfPackage.py

示例2: __activate__

# 需要导入模块: from com.googlecode.fascinator.common import JsonSimple [as 别名]
# 或者: from com.googlecode.fascinator.common.JsonSimple import toJSONString [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)
            # get relevant dc:description from new object before you overwrite it with 'from' data, as this should exist from form data created in initial object packaging (packaging.py)
            toTFPackageJson = JsonSimple(toTFPackage.open()).getJsonObject()
            relevant_description = toTFPackageJson.get("dc:description")
            fromInputStream = fromTFPackage.open()
            try:
                StorageUtils.createOrUpdatePayload(toObject, toTFPackage.getId(), fromInputStream)
            except StorageException:
                print "error setting tfPackage"
            finally:
                fromTFPackage.close()

            tfMetaPropertyValue = self.formData.get("tfMetaPropertyValue")
            if tfMetaPropertyValue == 'dmpToSelfSub':
                # fetch recently created new 'to' object from storage to get all data
                toTFPackage = self._getTFPackage(toObject)
                toTFPackageJson = JsonSimple(toTFPackage.open()).getJsonObject()
                self.setMultiDescription(toTFPackageJson, relevant_description)
                inStream = IOUtils.toInputStream(toTFPackageJson.toJSONString(), "UTF-8")
                try:
                    StorageUtils.createOrUpdatePayload(toObject, toTFPackage.getId(), inStream)
                except StorageException:
                    print "error setting description text in tfPackage"
                finally:
                    inStream.close()
                self.log.info(
                    "Completed migrating 'dc:description' to dc:decription.1.text' for oid: %s." % toTFPackage.getId())
                self.log.debug("Result: %r" % toTFPackageJson)

            fromTFPackageJson = JsonSimple(fromTFPackage.open()).getJsonObject()
            self.log.debug('from json is: %r' % fromTFPackageJson)
            if storeRelatedData != "false":
                # add relatedOid info
                fromTFPackageJson = self._addRelatedOid(JsonSimple(fromTFPackage.open()), toOid)

            self.log.debug('from tfPackage json is now: %r' % fromTFPackageJson)
            inStream = IOUtils.toInputStream(fromTFPackageJson.toJSONString(), "UTF-8")

            try:
                StorageUtils.createOrUpdatePayload(fromObject, fromTFPackage.getId(), inStream)
            except StorageException:
                print "error setting tfPackage"
            finally:
                inStream.close()

            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()
开发者ID:redbox-mint,项目名称:redbox,代码行数:85,代码来源:copyTfPackage.py


注:本文中的com.googlecode.fascinator.common.JsonSimple.toJSONString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。