Example #1
0
    def process_payload(self, claim, **kwargs):
        """
        :param claim: contains the message inside the packet
            {'bibcode': '....',
            'orcidid': '.....',
            'name': 'author name',
            'facts': 'author name variants',
            }
        :return: no return
        """
        
        if not isinstance(claim, dict):
            raise ProcessingException('Received unknown payload {0}'.format(claim))
        
        if not claim.get('orcidid'):
            raise ProcessingException('Unusable payload, missing orcidid {0}'.format(claim))

        bibcode = claim['bibcode']
        rec = updater.retrieve_record(bibcode)
        
        
        cl = updater.update_record(rec, claim)
        if cl:
            updater.record_claims(bibcode, rec['claims'], rec['authors'])
            self.publish({'authors': rec.get('authors'), 'bibcode': rec['bibcode'], 'claims': rec.get('claims')})
        else:
            self.logger.warning('Claim refused for bibcode:{0} and orcidid:{1}'
                            .format(claim['bibcode'], claim['orcidid']))
Example #2
0
 def test_update_database(self):
     """Inserts a record (of claims) into the database"""
     updater.record_claims('bibcode', {'verified': ['foo', '-', 'bar'], 'unverified': ['-', '-', '-']})
     with app.session_scope() as session:
         r = session.query(Records).filter_by(bibcode='bibcode').first()
         self.assertEquals(json.loads(r.claims), {'verified': ['foo', '-', 'bar'], 'unverified': ['-', '-', '-']})
         self.assertTrue(r.created == r.updated)
         self.assertFalse(r.processed)
         
     updater.record_claims('bibcode', {'verified': ['foo', 'zet', 'bar'], 'unverified': ['-', '-', '-']})
     with app.session_scope() as session:
         r = session.query(Records).filter_by(bibcode='bibcode').first()
         self.assertEquals(json.loads(r.claims), {'verified': ['foo', 'zet', 'bar'], 'unverified': ['-', '-', '-']})
         self.assertTrue(r.created != r.updated)
         self.assertFalse(r.processed)
     
     updater.mark_processed('bibcode')
     with app.session_scope() as session:
         r = session.query(Records).filter_by(bibcode='bibcode').first()
         self.assertTrue(r.processed)