Beispiel #1
0
    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)
Beispiel #2
0
    def checkRequests(self, checklist_filter=['1'], role_filter='reviewer', exclusive=True, startPage=1):
        """ A customised query for arms at arms-review
            Get a list of requests filtered by provisioning_checklist

            For assessor, it is user based and queries against committee-responses.metadata
        """
        workflowStep = "arms-review"
        if self.packageType:
            req = SearchRequest(self.packageType)
        else:
            req = SearchRequest("packageType:arms")
        req.addParam("fq", 'workflow_step:' + workflowStep)
        for item in ['1','2','3','4']:
            if item in checklist_filter:
                req.addParam("fq", '-provisioning_checklist.' + item + ':null' + ' AND provisioning_checklist.' + item + ':[* TO *]')
            else:
                if exclusive:
                    # ensure that brand new submissions (not yet saved by reviewer) are also returned
                    req.addParam("fq", 'provisioning_checklist.' + item + ':null' + ' OR (*:* -provisioning_checklist.' + item + ':[* TO *])')
        req.setParam("sort", "date_object_modified desc, f_dc_title asc")
        req.setParam("fl",self.returnFields)
        out = ByteArrayOutputStream()
        self.indexer.search(req, out)
        solrResults = SolrResult(ByteArrayInputStream(out.toByteArray()))

        if solrResults:
            results = solrResults.getResults()
            if results:
                packageResults = results
                results = self.mergeEvents(packageResults, ["arms_draft","arms_redraft","arms_review","arms_approved","arms_rejected"])
            returnArray = JSONArray()
            if role_filter.startswith('assessor'):
                if role_filter == 'assessor':
                    query_status = ['new', 'draft']
                elif role_filter == 'assessor-assessed':
                    query_status = ['submitted']
                x = Assessment()
                x.activate(self.velocityContext)
                i = 0
                rows = self.recordsPerPage
                start = (startPage - 1) * self.recordsPerPage
                for r in results:
                    status = x.queryStatus(r.get("id"))
                    if status in query_status:
                        if i >= start and i - start < rows:
                            if status == 'submitted':
                                assessment_submitted_date = x.queryMyAttr('date')
                                if assessment_submitted_date:
                                    r.getJsonObject().put('date', assessment_submitted_date)
                            returnArray.add(r)
                        i = i + 1
            else:
                returnArray = results

            self._setPaging(returnArray.size())
            return returnArray
        else:
            return ArrayList()
Beispiel #3
0
 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
Beispiel #4
0
    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
Beispiel #5
0
    def getVersions(self, storedObj):
        indF = File(storedObj.getPath() + "/Version_Index.json")

        versions = []
        if indF.exists():
            versions = JsonSimple(indF).getJsonArray()
            # reverse to the order to from latest to oldest
            r = JSONArray()
            for s in reversed(versions):
                r.add(s)
            versions = r

        return versions
 def listUserAttributes(self):
     """ Query HibernateUserAttribute to get the stored user attributes supported by current authentication manager 
         Return a JSONArray: can be empty if only internal manager is used
     """
     authUserAttrbDao = ApplicationContextProvider.getApplicationContext().getBean("hibernateAuthUserAttributeDao")
     attributeList = authUserAttrbDao.query("getUserAttributeList",HashMap())
     
     aList = JSONArray()
     if attributeList.size() > 0:
         filtered = [attribName for attribName in attributeList if attribName not in self.ATTRIB_FILTER]
         for a in filtered:
             aList.add(a)
     return aList
Beispiel #7
0
    def getVersions(self, storedObj):
        indF = File(storedObj.getPath() + "/Version_Index.json")
        
        versions = []
        if indF.exists():
            versions = JsonSimple(indF).getJsonArray()
            # reverse to the order to from latest to oldest 
            r = JSONArray()
            for s in reversed(versions):
                r.add(s)
            versions = r

        return versions
Beispiel #8
0
    def getVersions(self, storedObj, extension):

        versions = []
        try:
            indF = storedObj.getPayload(extension + "_Version_Index.json")

            versions = JsonSimple(indF.open()).getJsonArray()
            # reverse to the order to from latest to oldest
            r = JSONArray()
            for s in reversed(versions):
                r.add(s)
            versions = r
        except:
            self.log.debug("Versioning file not found for "+extension +". Perhaps versioning not enabled.")

        return versions
Beispiel #9
0
    def getVersions(self, storedObj, extension):

        versions = []
        try:
            indF = storedObj.getPayload(extension + "_Version_Index.json")

            versions = JsonSimple(indF.open()).getJsonArray()
            # reverse to the order to from latest to oldest
            r = JSONArray()
            for s in reversed(versions):
                r.add(s)
            versions = r
        except:
            self.log.debug("Versioning file not found for " + extension +
                           ". Perhaps versioning not enabled.")

        return versions
Beispiel #10
0
    def __getUsers(self, oid):
        indexer = Services.getIndexer()
        req = SearchRequest("id:" + oid)
        req.setParam("fl", "security_exception,owner")
        out = ByteArrayOutputStream()
        indexer.search(req, out)
        rtJson = ""
        try:
            qresult = SolrResult(ByteArrayInputStream(
                out.toByteArray())).getResults().get(0)
            owner = qresult.getString(None, 'owner')
            secException = qresult.getArray('security_exception')

            if secException is None:
                secException = JSONArray()

            self.log.debug("Owner of object: " + owner)
            self.log.debug("Viewer(s) of object: " + secException.toString())
            if secException.contains(owner):
                secException.remove(owner)
            return '{"owner":"' + owner + '", "viewers": ' + secException.toString(
            ) + '}'
        except Exception, e:
            self.log.error("Error during query/package ownership data" +
                           str(e))
    def listUserAttributes(self):
        """ Query HibernateUserAttribute to get the stored user attributes supported by current authentication manager 
            Return a JSONArray: can be empty if only internal manager is used
        """
        authUserAttrbDao = ApplicationContextProvider.getApplicationContext(
        ).getBean("hibernateAuthUserAttributeDao")
        attributeList = authUserAttrbDao.query("getUserAttributeList",
                                               HashMap())

        aList = JSONArray()
        if attributeList.size() > 0:
            filtered = [
                attribName for attribName in attributeList
                if attribName not in self.ATTRIB_FILTER
            ]
            for a in filtered:
                aList.add(a)
        return aList
    def getUsers(self, k, v):
        """ Query HibernateUserAttribute with supported key:value pair against supported attributes 
            when query against username, it returns a JSON object as there could be only one user. 
            Otherwise returns a JSONArray of JSON which contains user's attributes but can be empty
        """
        if k == "username":
            return self.__getUserInfo(v)
        
        users = JSONArray()
        parameters = HashMap()

        parameters.put("key", k)
        parameters.put("value", v)
        authUserAttrbDao = ApplicationContextProvider.getApplicationContext().getBean("hibernateAuthUserAttributeDao")
        userObjectList = authUserAttrbDao.query("getUserAttributeByKeyAndValueDistinct", parameters)
        if userObjectList.size() > 0:
            for userObj in userObjectList:
                users.add(self.__constructUserAttribs(userObj[0], self.ATTRIB_FILTER))
        return users
Beispiel #13
0
    def __activate__(self, context):
        pageSize = 10
        self.velocityContext = context
        client = OrcidPublicClient()
        self.response = context["response"]
        self.request = context["request"]
        self.writer = self.response.getPrintWriter("text/plain; charset=UTF-8")

        givenNames = self.request.getParameter("givenNames")
        familyName = self.request.getParameter("familyName")
        pageNumber = self.request.getParameter("page")
        if pageNumber is None:
            pageNumber = "1"

        query = ""
        if givenNames == "" or givenNames is None:
            query = OrcidSearchField.FAMILY_NAME.buildPrefixQuery(familyName)
        else:
            if familyName == "" or familyName is None:
                query = OrcidSearchField.GIVEN_NAMES.buildPrefixQuery(givenNames)
            else:
                query = OrcidSearchField.FAMILY_NAME.buildPrefixQuery(familyName) + " AND " + OrcidSearchField.GIVEN_NAMES.buildPrefixQuery(givenNames)

        results = client.search(query, int(pageNumber)-1, pageSize)
        responseObject = JsonObject()
        responseObject.put("pageNumber",int(pageNumber))
        responseObject.put("totalPages",results.getNumFound().divide(BigInteger(String(str(pageSize)))).add(BigInteger("1")))
        responseObject.put("totalFound",results.getNumFound())
        recordResults = JSONArray()
        for searchResult in results.getOrcidSearchResult():
             personalDetails = searchResult.getOrcidProfile().getOrcidBio().getPersonalDetails()
             orcidUri = self.getOrcid(searchResult.getOrcidProfile().getOrcidIdentifier(), "uri")
             orcid = self.getOrcid(searchResult.getOrcidProfile().getOrcidIdentifier(), "path")
             resultObject = JsonObject()
             resultObject.put("given_names",personalDetails.getGivenNames())
             resultObject.put("family_name",personalDetails.getFamilyName())
             resultObject.put("orcid_uri",orcidUri)
             resultObject.put("orcid",orcid)
             recordResults.add(resultObject)

        responseObject.put("search_results",recordResults)
        self.writer.println(JsonSimple(responseObject).toString(True))
        self.writer.close()
Beispiel #14
0
 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
Beispiel #15
0
 def getAttachedFiles(self, oid):
     # Build a query
     req = SearchRequest("attached_to:%s" % oid)
     req.setParam("rows", "1000")
     # Run a search
     out = ByteArrayOutputStream()
     self.Services.getIndexer().search(req, out)
     result = SolrResult(ByteArrayInputStream(out.toByteArray()))
     # Process results
     docs = JSONArray()
     for doc in result.getResults():
         attachmentType = self.escapeHtml(WordUtils.capitalizeFully(doc.getFirst("attachment_type").replace("-", " ")))
         accessRights = self.escapeHtml(WordUtils.capitalizeFully(doc.getFirst("access_rights")))
         entry = JsonObject()
         entry.put("filename",        self.escapeHtml(doc.getFirst("filename")))
         entry.put("attachment_type", attachmentType)
         entry.put("access_rights",   accessRights)
         entry.put("id",              self.escapeHtml(doc.getFirst("id")))
         docs.add(entry)
     return docs
Beispiel #16
0
 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
Beispiel #17
0
 def getViewers(self, oid):
     indexer = self.services.getIndexer()
     req = SearchRequest("id:" + oid)
     req.setParam("fl", "security_exception,owner")
     out = ByteArrayOutputStream()
     indexer.search(req, out)
     try:
         qresult = SolrResult(ByteArrayInputStream(out.toByteArray())).getResults().get(0)
         owner = qresult.getString(None, 'owner')
         secException = qresult.getArray('security_exception')
         
         if secException is None:
             secException = JSONArray()
             
         self.log.debug("Owner of object: " + owner)
         self.log.debug("Viewer(s) of object: " + secException.toString())
         if secException.contains(owner):
             secException.remove(owner)
         return secException
     except Exception, e:
         self.log.error("Error during query/package ownership data" + str(e))
Beispiel #18
0
 def getAttachedFiles(self, oid):
     # Build a query
     req = SearchRequest("attached_to:%s" % oid)
     req.setParam("rows", "1000")
     # Run a search
     out = ByteArrayOutputStream()
     self.Services.getIndexer().search(req, out)
     result = SolrResult(ByteArrayInputStream(out.toByteArray()))
     # Process results
     docs = JSONArray()
     for doc in result.getResults():
         attachmentType = self.escapeHtml(
             WordUtils.capitalizeFully(
                 doc.getFirst("attachment_type").replace("-", " ")))
         accessRights = self.escapeHtml(
             WordUtils.capitalizeFully(doc.getFirst("access_rights")))
         entry = JsonObject()
         entry.put("filename", self.escapeHtml(doc.getFirst("filename")))
         entry.put("attachment_type", attachmentType)
         entry.put("access_rights", accessRights)
         entry.put("id", self.escapeHtml(doc.getFirst("id")))
         docs.add(entry)
     return docs
    def getUsers(self, k, v):
        """ Query HibernateUserAttribute with supported key:value pair against supported attributes 
            when query against username, it returns a JSON object as there could be only one user. 
            Otherwise returns a JSONArray of JSON which contains user's attributes but can be empty
        """
        if k == "username":
            return self.__getUserInfo(v)

        users = JSONArray()
        parameters = HashMap()

        parameters.put("key", k)
        parameters.put("value", v)
        authUserAttrbDao = ApplicationContextProvider.getApplicationContext(
        ).getBean("hibernateAuthUserAttributeDao")
        userObjectList = authUserAttrbDao.query(
            "getUserAttributeByKeyAndValueDistinct", parameters)
        if userObjectList.size() > 0:
            for userObj in userObjectList:
                users.add(
                    self.__constructUserAttribs(userObj[0],
                                                self.ATTRIB_FILTER))
        return users
Beispiel #20
0
    def getFilteredAssessments(self, packageType, stageName, filterType, startPage=1):
        """ A customised query to use filter to get certain assessment with desired status """
        ## reference /redbox-rdsi-arms/src/main/config/home/lib/jython/util/Assessment.py for methods
        filters = {'assessment-draft': ['new','draft'], 'assessment-submitted':['submitted']}
        statusFilter = filters[filterType]

        req = SearchRequest("packageType:" + packageType)
        req.addParam("fq", 'workflow_step:' + stageName)
        req.setParam("sort", "date_object_modified desc, f_dc_title asc")
        req.setParam("fl",self.returnFields)
        out = ByteArrayOutputStream()
        self.indexer.search(req, out)
        solrResults = SolrResult(ByteArrayInputStream(out.toByteArray()))

        if solrResults:
            results = solrResults.getResults()
            returnArray = JSONArray()
            x = Assessment()
            x.activate(self.velocityContext)
            i = 0
            rows = self.recordsPerPage
            start = (startPage - 1) * self.recordsPerPage
            for r in results:
                status = x.queryStatus(r.get("id"))
                if status in statusFilter:
                    if i >= start and i - start < rows:
                        assessment_submitted_date = x.queryAttr(r.get("id"), 'date')
                        if assessment_submitted_date:
                            r.getJsonObject().put('date', assessment_submitted_date)
                        returnArray.add(r)
                    i = i + 1

            self._setPaging(returnArray.size())
            return returnArray
        else:
            return ArrayList()
Beispiel #21
0
    def __getPayloadJsonArray(self, oid, payloadName):
        """
        Get the content (JsonArray) of a payload
        return the JSONArray or an empty (new) one 
        """
        storedObj = self.Services.getStorage().getObject(oid)

        payloadList = storedObj.getPayloadIdList()
        if payloadList.contains(payloadName):
            # print "Updating existing"
            payloadObj = storedObj.getPayload(payloadName)
            payloadJson = JsonSimple(payloadObj.open())
            objList = payloadJson.getJsonArray()
        else:
            # print "Creating new one"
            objList = JSONArray()

        return objList
Beispiel #22
0
    def __getUsers(self, oid):
        storage = self.services.getStorage()
        object = storage.getObject(oid)
        objectMetadata = object.getMetadata()
        owner = objectMetadata.getProperty("owner")
        ownerJson = self.__constructUserJson(owner)
            
        users = self.getViewers(oid,owner)
        
        returningViewers = []
        for user in users:
            parameters = HashMap()
#             print "Checking user= %s" % user
            parameters.put("username",user)
            userObjectList = self.authUserDao.query("getUser",parameters)
            if userObjectList is not None or userObjectList.size() > 0:
                returningViewers.append(self.__constructUserJson(user))
                
        return '{"owner":' + ownerJson.toJSONString() + ', "viewers": ' + JSONArray.toJSONString(returningViewers) + '}'
Beispiel #23
0
    def __getUsers(self, oid):
        storage = self.services.getStorage()
        object = storage.getObject(oid)
        objectMetadata = object.getMetadata()
        owner = objectMetadata.getProperty("owner")
        ownerJson = self.__constructUserJson(owner)

        users = self.getViewers(oid, owner)

        returningViewers = []
        for user in users:
            parameters = HashMap()
            #             print "Checking user= %s" % user
            parameters.put("username", user)
            userObjectList = self.authUserDao.query("getUser", parameters)
            if userObjectList is not None or userObjectList.size() > 0:
                returningViewers.append(self.__constructUserJson(user))

        return '{"owner":' + ownerJson.toJSONString(
        ) + ', "viewers": ' + JSONArray.toJSONString(returningViewers) + '}'
Beispiel #24
0
    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")
             system = self.request.getParameter("system")

             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 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)
                 relationship.put("system",system)
                 relationships.add(relationship)

             out.println(metadataJson.toString(True))
             istream = ByteArrayInputStream(String(metadataJson.toString(True)).getBytes())
             StorageUtils.createOrUpdatePayload(digitalObject,"metadata.json",istream)

             out.close()
         finally:
             self.sessionState.remove("username")
Beispiel #25
0
    def searchNla(self):
        # Start row
        start = self.formData.get("start")
        if start is None:
            start = "1"

        # Row limit
        rows = self.formData.get("rows")
        if rows is None:
            rows = "10"

        # Query
        query = ""
        # Test searches
        #query = "pa.surname=\"Smith\""
        #query = "cql.anywhere=\"monash\""

        if query == "":
            # Surname
            surname = self.formData.get("surname")
            if surname is not None:
                query = "pa.surname=\"%s\"" % (surname)

            # Firstname
            firstName = self.formData.get("firstName")
            if firstName is not None:
                if query != "":
                    query += " AND "
                query += "pa.firstname=\"%s\"" % (firstName)

        if query != "":
            query += " AND "
        query += "pa.type=\"person\""

        # Some basic metadata we already know
        self.metadata.put("searchString", query)
        self.metadata.put("startRecord", start)
        self.metadata.put("rowsRequested", rows)

        # Search NLA
        self.log.debug("Submitting query to NLA: '{}', Start: '{}', Rows: '{}'", [query, start, rows])
        sru = SRUClient()
        # If using the NLA's test server, comment out the line above and uncomment the line below
        # sru = SRUClient("http://www-test.nla.gov.au/apps/srw/search/peopleaustralia")
        
        response =  sru.nlaGetResponseBySearch(query, start, rows)
        if response is None:
            raise Exception("Error searching NLA. Please check system logs for details.")

        self.metadata.put("rowsReturned", response.getRows())
        self.metadata.put("totalHits", response.getTotalResults())

        identities = NLAIdentity.convertNodesToIdentities(response.getResults())
        for id in identities:
            idEntry = JsonObject()
            idEntry.put("nlaId", id.getId())
            idEntry.put("displayName", id.getDisplayName())
            idEntry.put("firstName", id.getFirstName())
            idEntry.put("surname", id.getSurame())
            idEntry.put("institution", id.getInstitution())
            knownIds = JSONArray()
            idEntry.put("knownIdentities", knownIds)

            for knownId in id.getKnownIdentities():
                thisId = JsonObject()
                thisId.put("displayName", knownId.get("displayName"))
                thisId.put("institution", knownId.get("institution"))
                knownIds.add(thisId)

            self.results.add(idEntry)

        return True