當前位置: 首頁>>代碼示例>>Python>>正文


Python common.JsonObject類代碼示例

本文整理匯總了Python中com.googlecode.fascinator.common.JsonObject的典型用法代碼示例。如果您正苦於以下問題:Python JsonObject類的具體用法?Python JsonObject怎麽用?Python JsonObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了JsonObject類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process

    def process(self):
        #We'll return a list with 1 JsonSimple object
        jsonList = []
        data = None
        reader = None
        inStream = None
        document = None
        
        # Run the XML through our parser
        try:
            inStream = FileInputStream(File(self.file))
            reader = InputStreamReader(inStream, "UTF-8")
            document = self.saxReader.read(reader)
        # Parse fails
        except:
            raise
        # Close our file access objects
        finally:
            if reader is not None:
                reader.close()
            if inStream is not None:
                inStream.close()

        # Now go looking for all our data
        data = JsonObject()
        data.put("workflow_source", "XML Alert") # Default
        self.__mapXpathToFields(document, self.map, data)
        
        if data is None:
            return None
        
        jsonList.append(JsonSimple(data))
        return jsonList
開發者ID:andrewbrazzatti,項目名稱:redbox-core-dev-build,代碼行數:33,代碼來源:XMLAlertHandler.py

示例2: __getRvtManifest

 def __getRvtManifest(self, manifest):
     rvtMap = HashMap()
     rvtMap.put("title", manifest.getTitle())
     rvtMap.put("toc", self.__getRvtNodes(manifest.getTopNodes()))
     json = JsonObject(rvtMap)
     #print json.toString()
     return json.toString()
開發者ID:Deakin,項目名稱:the-fascinator,代碼行數:7,代碼來源:organiser.py

示例3: __getJson

 def __getJson(self):
     rvtMap = JsonObject()
     try:
         oid = self.vc("formData").get("oid")
         object = Services.storage.getObject(oid)
         payload = object.getPayload("imsmanifest.xml")
         try:
             from xml.etree import ElementTree
             xmlStr = IOUtils.toString(payload.open(), "UTF-8")
             payload.close()
             xml = ElementTree.XML(xmlStr.encode("UTF-8"))
             ns = xml.tag[:xml.tag.find("}")+1]
             resources = {}
             for res in xml.findall(ns+"resources/"+ns+"resource"):
                 resources[res.attrib.get("identifier")] = res.attrib.get("href")
             organizations = xml.find(ns+"organizations")
             defaultName = organizations.attrib.get("default")
             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()
開發者ID:Deakin,項目名稱:the-fascinator,代碼行數:28,代碼來源:jsonIms.py

示例4: __getUserInfo

    def __getUserInfo(self, username):
        """
            Query HibernateUser to get a user information
            There are users managed by internal auth manager with no attributes other than password
            There are users managed by external auth managers e.g. shibboleth who have attributes
            Each user, at the time of writing: 20140904, each user has multiple identical attribute sets,
            so, only the first one is used
            We put all available attributes of a user in to return value 
        """
        username = username.strip()

        authUserDao = ApplicationContextProvider.getApplicationContext().getBean("hibernateAuthUserDao")
        parameters = HashMap()
        parameters.put("username", username)
        userObjectList = authUserDao.query("getUser", parameters)

        userJson = JsonObject()
        userJson.put("username", username) 
        try:
            if userObjectList.size() > 0:
                # One hit will be enough to get user object
                userJson = self.__constructUserAttribs(userObjectList.get(0), self.ATTRIB_FILTER)
            else:
               # This should not be reached with external sourced users
                self.log.warn("Wrong username or internal user is queried")
        except Exception, e:
            self.log.error("%s: cannot construct user attribute JSON, detail = %s" % (self.__class__.__name__ , str(e)))
開發者ID:the-fascinator,項目名稱:fascinator-portal,代碼行數:27,代碼來源:userlookup.py

示例5: __activate__

    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)
開發者ID:qcif,項目名稱:qcloud-arms,代碼行數:31,代碼來源:committee.py

示例6: __getPackageTypes

 def __getPackageTypes(self):
     object = self.sysConfig.getObject(["portal", "packageTypes"])
     packageTypes = JsonSimple.toJavaMap(object)
     if packageTypes.isEmpty():
         defaultPackage = JsonObject()
         defaultPackage.put("jsonconfig", "packaging-config.json")
         packageTypes.put("default", JsonSimple(defaultPackage))
     return packageTypes
開發者ID:Deakin,項目名稱:the-fascinator,代碼行數:8,代碼來源:package.py

示例7: getCurationData

    def getCurationData(self, oid):
        json = JsonObject()
        try:
            # Get the object from storage
            storage = self.Services.getStorage()
            object = storage.getObject(oid)

            # Find the package payload
            payload = object.getPayload("metadata.json")
            # Not found?
            if payload is None:
                self.log.error(" * detail.py => Can't find package data!")
                json.put("error", True)
                return json

            # Parse the data
            data = JsonSimple(payload.open())
            payload.close()

            # Return it
            json.put("error", False)
            json.put("relationships", data.writeArray("relationships"))
            return json
        except StorageException, ex:
            self.log.error(" * detail.py => Storage Error accessing data: ", ex)
            json.put("error", True)
            return json
開發者ID:Paul-Nguyen,項目名稱:mint,代碼行數:27,代碼來源:detail.py

示例8: __activate__

    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")
開發者ID:redbox-mint,項目名稱:redbox,代碼行數:60,代碼來源:notifyCuration.py

示例9: __constructUserJson

    def __constructUserJson(self, username):
        """
            There are users managed by internal auth manager with no attributes
            There are users managed by external auth manages e.g. shibboleth who have attributes
            These users username is not necessarily the same as there normal display name
            This function currently solves this issue by checking commonName attribute for shibboleth users  
        """
        username = username.strip()
        userJson = JsonObject()
        userJson.put("userName", username) 
        parameters = HashMap()
#         print "Checking user info for %s" % username
        parameters.put("username", username)
        userObjectList = self.authUserDao.query("getUser", parameters)
#         print "Returned size = %d" % userObjectList.size() 
        if userObjectList.size() > 0:
            userObject = userObjectList.get(0)
            #Check if this is a user with attributes?
            attrb = userObject.getAttributes().get("commonName")
            if attrb is None:
#                 print "We cannot find so called commonName, use %s instead" % username
                userJson.put("realName", username)
            else:
#                 print "We found so called commonName, use %s instead of %s" % (attrb.getValStr(), username)
                userJson.put("realName", attrb.getValStr().strip())
        else:
            # This should not be reached
            self.log.warn("What is going on here? why ends up here?")
            userJson.put("realName", username)
            
        return userJson
開發者ID:qcif,項目名稱:qcloud-arms,代碼行數:31,代碼來源:grantAccess.py

示例10: _addRelatedOid

    def _addRelatedOid(self, tfPackageJson, relatedOid):
        relatedOids = tfPackageJson.getArray("related.datasets")
        if relatedOids is None:
            relatedOids = JSONArray()

        relatedOidJsonObject = JsonObject()
        relatedOidJsonObject.put("oid", relatedOid)
        relatedOids.add(relatedOidJsonObject)
        jsonObject = tfPackageJson.getJsonObject()
        jsonObject.put("related.datasets", relatedOids)
        return jsonObject
開發者ID:nishen,項目名稱:redbox,代碼行數:11,代碼來源:copyTfPackage.py

示例11: _readReviewers

 def _readReviewers(self, storedObj, tfpackage):
     """Read from TFPACKAGE for reviewer's recommendation and map to a json with short keys:
          reviewer-recommend-for : for
          reviewer-recommended-storage : storage   
     """
     reviewersPayload = storedObj.getPayload(tfpackage)
     reviewersRecommends = JsonSimple(reviewersPayload.open()).getJsonObject()
     reviewers = JsonObject()
     reviewers.put("for", reviewersRecommends.get("reviewer-recommend-for"))
     reviewers.put("storage", reviewersRecommends.get("reviewer-recommended-storage"))
     return reviewers
開發者ID:qcif,項目名稱:rdsi-arms,代碼行數:11,代碼來源:assess.py

示例12: __activate__

    def __activate__(self, context):
        self.log = context["log"]
        self.services = context["Services"]

        auth = context["page"].authentication
        username = auth.get_username() # get system username

        try:
            result = self.__constructInfoJson(username)
        except Exception, e:
             self.log.error("%s: cannot get user attributes, detail = %s" % (self.__class__.__name__ , str(e)))
             result = JsonObject()
             result.put("realName", auth.get_name()) # default value: user's realName
開發者ID:qcif,項目名稱:rdsi-arms,代碼行數:13,代碼來源:userinfo.py

示例13: regenerate_key

    def regenerate_key(self):
        clientArray = self.getKeysArray()
        name = self.formData.get("name")
        clientToBeReplaced = None
        index = 0
        for client in clientArray:
            if client.get("name") == name:
                clientToBeReplaced = client
                break
            index = index + 1

        if clientToBeReplaced is not None:
            clientObject = JsonObject()
            clientObject.put("name", self.formData.get("name"))
            clientObject.put("key", self.get_random_key())
            clientArray.set(index,clientObject)
            self.apiKeyService.updateAndSaveKeys(clientArray)
開發者ID:redbox-mint,項目名稱:redbox,代碼行數:17,代碼來源:apiAdmin.py

示例14: __constructInfoJson

    def __constructInfoJson(self, username):
        """
            There are users managed by internal auth manager with no attributes
            There are users managed by external auth managers e.g. shibboleth who have attributes
            We put all available attributes of a user in to return value 
        """
        # print "Query username = %s" % username
        username = username.strip()

        authUserDao = ApplicationContextProvider.getApplicationContext().getBean("hibernateAuthUserDao")
        parameters = HashMap()
        parameters.put("username", username)
        userObjectList = authUserDao.query("getUser", parameters)

        # print "Returned object = %s" % str(userObjectList)
        # print "Returned size = %d" % userObjectList.size() 
        userJson = JsonObject()
        try:
            if userObjectList.size() > 0:
                # One hit will be enough to get user object
                userObj = userObjectList.get(0)
                attrbs = userObj.getAttributes()
                for attrb in attrbs.keySet():
#                     print "Attribute %s = %s) % (attrb, attrbs.get(attrb).getValStr())
                    userJson.put(attrb, attrbs.get(attrb).getValStr())
            else:
               # This should not be reached with external sourced users
                self.log.warn("Wrong username? Every user should have a record")
                userJson.put("userName", username) 
        except Exception, e:
            self.log.error("%s: cannot construct user attribute JSON, detail = %s" % (self.__class__.__name__ , str(e)))
            userJson.put("userName", username)
開發者ID:qcif,項目名稱:rdsi-arms,代碼行數:32,代碼來源:userinfo.py

示例15: updateRelationships

    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)
開發者ID:ozej8y,項目名稱:mint,代碼行數:33,代碼來源:updateRelationships.py


注:本文中的com.googlecode.fascinator.common.JsonObject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。