Example #1
0
 def handle_update_claim(self, req_post):
     logging.info("Hit 'update_claim'")
     claim_id = req_post['claim']
     assert claim_id == self.ref_id, "claim_id {0}, ref_id {1}".format(claim_id, self.ref_id)
     session = self.session
     claim = session.query(Claim).filter_by(ref_id=claim_id).first()
     scf = self.set_claim_form_choices(ClaimEdit(req_post))
     self.claim_form = scf
     if scf.validate():
         logging.info("Validated claim form")
         claim.publication = expand_curie(scf.publication.data)
         if scf.narrative.data == "None":
             claim.narrative = None
         else:
             claim.narrative = expand_curie(scf.narrative.data)
         claim.behavior_term = expand_curie(scf.behavior_term.data)
         claim.publication_behavior = scf.publication_behavior.data
         claim.evidence = expand_curie(scf.evidence.data)
     parts, part_links, _ = get_participants(session, claim_id)
     participant_id = req_post['participant']
     participant = get_participant(session, participant_id)
     element_id = req_post['element']
     element = get_pelement(session, element_id)
     self.set_participant_form(participant, parts)
     self.set_element_form(element, element_choices(session, participant))
     if part_links:
         self.update_graph(claim, parts, part_links)
     self.set_hidden_fields(claim_id, participant_id, element_id)
Example #2
0
 def handle_commit_element(self, part_links, parts, req_post):
     logging.info("Hit commit element")
     claim_id = req_post['claim']
     assert self.ref_id == claim_id, "{0} != {1}".format(repr(self.ref_id), repr(claim_id))
     session = self.session
     claim = session.query(Claim).filter_by(ref_id=claim_id).first()
     e_choice = self.int_post_field('element_choice')
     if e_choice:
         active_element = get_pelement(session, e_choice)
         participant = active_element.participant
     else:
         participant = self.find_participant_without_elements(claim)
         active_element = None  # best choice here?
     form = ElementCreate(req_post)
     form.element_choice.choices = element_choices(session, participant)
     form = self.set_element_form_choices(form)
     participant_id = participant.ref_id
     if self.enforce_element_type_constraints(form):
         self.report_bad_fields(form)
         logging.info("errors(1): {0}".format(form.errors))
         new_element = ParticipantElement(participant_id=participant_id, old_id=0)
         expression_type = form.expression_type.data
         new_element.expression_type = expression_type
         session.add(new_element)
         transaction.commit()
         element_id = new_element.element_id
         logging.info("New element is {0}".format(repr(element_id)))
         if expression_type == "individual":
             p2i = Pelement2Individual()
             p2i.element = element_id
             p2i.individual = expand_curie(form.individual.data)
             p2i.dummy_id = 0
             session.add(p2i)
         elif expression_type == 'some_term':
             p2t = Pelement2Term()
             p2t.element = element_id
             p2t.term = expand_curie(form.term.data)
             p2t.dummy_id = 0
             session.add(p2t)
             if active_element:
                 plink = ParticipantLink()
                 plink.child = element_id
                 plink.parent = active_element.element_id
                 session.add(plink)
             else:
                 self.update_participant_links(participant_id, element_id)
     else:
         logging.info("errors(2): {0}".format(form.errors))
         form.element_choice.choices = [("None", "None")]
         form.expression_type.choices = expression_type_choice(session)
         form.parent_link_property.choices = property_choice(session)
         element_id = NOELEMENT
     self.set_claim_form(claim)
     participant = get_participant(session, participant_id)
     self.set_participant_form(participant, parts)
     self.element_form = form
     transaction.commit()
     self.update_graph(claim, parts, part_links)
     self.set_hidden_fields(claim_id, participant_id, element_id)
Example #3
0
 def test_expand_curie(self):
     """Test the conversion from curie to URI."""
     from arachcurator.views.curie_utils import expand_curie
     curie1 = "arachb:ARACHB_000000322"
     url1 = expand_curie(curie1)
     self.assertEqual("http://arachb.org/arachb/ARACHB_000000322", url1)
     curie2 = "obo:BFO_0000050"
     url2 = expand_curie(curie2)
     self.assertEqual("http://purl.obolibrary.org/obo/BFO_0000050", url2)
     url3 = "OWL:TransitiveProperty"
     curie3 = expand_curie(url3)
     self.assertEqual(url3, curie3)
     url4 = ""
     curie4 = expand_curie(url4)
     self.assertEqual(url4, curie4)
Example #4
0
 def handle_commit_participant(self, req_post):
     logging.info("Hit 'commit_participant'")
     ref_id = self.ref_id
     session = self.session
     assert req_post['claim'] == ref_id
     claim = session.query(Claim).filter_by(ref_id=ref_id).first()
     claim_id = claim.ref_id
     self.set_claim_form(claim)
     form = ParticipantCreate(req_post)
     self.set_participant_form_no_navigator_choices(form)
     form.participant_choice.data = "None"
     form.participant_choice.choices = [("None", "None")]
     form.validate()
     if form.errors:
         logging.warning("Participant Create Errors: {0}".format(repr(form.errors)))
         self.participant_form = form
         self.element_form = InactiveElementEdit(None)
         self.set_hidden_fields(claim_id, req_post['participant'], NOELEMENT)
     else:
         form = ParticipantEdit(self.request.POST)
         participant = Participant()
         new_ref_id = request_uid(self.session)
         transaction.commit()  # maybe not needed
         participant.ref_id = new_ref_id
         participant.type = form.type.data
         participant.label = form.label.data
         participant.publication_taxon = form.publication_taxon.data
         participant.publication_anatomy = form.publication_anatomy.data
         participant.publication_substrate = form.publication_substrate.data
         participant.publication_text = form.publication_text.data
         participant.participation_property = expand_curie(form.participation_property.data)
         participant.claim_id = ref_id
         parts, part_links, _ = get_participants(self.session, ref_id)
         parts[participant.ref_id] = participant
         self.participant_form = form
         property_key = expand_curie(form.participation_property.data)
         property_term = session.query(Property).filter_by(ref_id=property_key).one()
         part_links[participant.ref_id] = property_term
         self.set_participant_form(participant, parts)
         self.set_participant_form(participant, parts)
         self.element_form = ElementCreateOnly()
         self.element_form.expression_type.data = "None"
         self.element_form.expression_type.choices = expression_type_choice(session)
         session.add(participant)
         transaction.commit()
         self.update_graph(claim, parts, part_links)
         self.set_hidden_fields(claim_id, new_ref_id, NOELEMENT)
         logging.info("Exiting commit participant")
Example #5
0
 def test_c_form_commit_claim_success_redirect(self):
     """Test committing a claim form with valid data."""
     from pyramid.httpexceptions import HTTPFound
     from arachcurator.models.models import Claim
     from arachcurator.views.curie_utils import expand_curie
     request = self.__make_request_no_param__(post_fields=CLAIM_COMMIT_DATA2)
     response = self._callFUT(request)
     self.assertTrue(isinstance(response, HTTPFound))
     self.assertEqual('302 Found', response.status)
     redirect = get_redirect(response)
     where = redirect.find('ref_id=') + len('ref_id=')
     claim_id = redirect[where:]
     target = self.session.query(Claim).filter(Claim.ref_id == claim_id).one()
     self.assertEqual(expand_curie(TEST_PUBLICATION_CURIE), target.publication)
     self.assertEqual(expand_curie(TEST_BEHAVIOR_TERM_CURIE), target.behavior_term)
     self.assertEqual(expand_curie(NON_TRACABLE_AUTHOR_STATEMENT_CURIE), target.evidence)
Example #6
0
 def handle_update_participant(self, req_post):
     logging.info("Hit 'update_participant'")
     claim_id = req_post['claim']
     assert claim_id == self.ref_id, "claim_id {0}, ref_id {1}".format(claim_id, self.ref_id)
     session = self.session
     claim = session.query(Claim).filter_by(ref_id=claim_id).one()
     self.set_claim_form(claim)
     participant_id = req_post['participant_choice']
     participant = get_participant(session, participant_id)
     parts, part_links, _ = get_participants(session, claim_id)
     form = ParticipantEdit(req_post)
     form.ref_id = participant_id
     form = self.finish_participant_form(form, parts)
     form.validate()
     if form.errors:
         active_element = get_head_element(session, participant)
         self.choose_element_form(req_post,
                                  active_element,
                                  element_choices(session, participant))
     else:
         logging.info("participant_choice: {0}".format(participant_id))
         participant.type = form.type.data
         participant.label = form.label.data
         participant.publication_taxon = form.publication_taxon.data
         participant.publication_anatomy = form.publication_anatomy.data
         participant.publication_substrate = form.publication_substrate.data
         participant.publication_text = form.publication_text.data
         participant.participation_property = expand_curie(form.participation_property.data)
     self.participant_form = form
     element_id = req_post['element']
     element = get_pelement(session, element_id)
     self.set_element_form(element, element_choices(session, participant))
     self.update_graph(claim, parts, part_links)
     self.set_hidden_fields(claim_id, participant_id, element_id)
Example #7
0
 def handle_commit_claim(self, req_post):
     logging.info("Hit 'commit_claim'")
     scf = ClaimCreate(req_post)
     self.set_claim_form_choices(scf)
     if scf.validate():
         scf = ClaimEdit(req_post)
         self.set_claim_form_choices(scf)
         claim = Claim()
         new_ref_id = request_uid(self.session)
         claim.ref_id = new_ref_id
         claim.publication = expand_curie(scf.publication.data)
         if scf.narrative.data == "None":
             claim.narrative = None
         else:
             claim.narrative = expand_curie(scf.narrative.data)
         claim.behavior_term = expand_curie(scf.behavior_term.data)
         claim.publication_behavior = scf.publication_behavior.data
         claim.evidence = expand_curie(scf.evidence.data)
         transaction.commit()  # make sure the ref_id is committed first
         self.session.add(claim)
         # commit so HTTPFound 'exception' doesn't drop transaction (TODO - is there a better way)
         transaction.commit()
         logging.info("About to redirect to {0}".format(generate_route_id(self.request, 'claim_edit', new_ref_id)))
         # TODO - can this setup forms and return normally?
         # self.set_hidden_fields("test claim", "test participant", "test element")
         return HTTPFound(location=generate_route_id(self.request, 'claim_edit', new_ref_id))
     else:
         session = self.session
         old_claim_id = req_post['claim']
         old_participant_id = req_post['participant']
         old_element_id = req_post['element']
         parts, part_links, _ = get_participants(session, old_claim_id)
         self.claim_form = scf
         participant = parts[old_participant_id]
         self.set_participant_form(participant, parts)
         element = session.query(ParticipantElement).filter_by(element_id=old_element_id).one()
         self.set_element_form(element, element_choices(session, participant))
         self.set_hidden_fields(old_claim_id, old_participant_id, old_element_id)
         return self.render()
Example #8
0
 def __check_update_participant__(self, response):
     from arachcurator.models.models import Participant
     from arachcurator.views.curie_utils import expand_curie
     from arachcurator.views.forms.ParticipantForm import ParticipantEdit
     update_data = PARTICIPANT_UPDATE_DATA
     self.assertIsInstance(response['p_form'], ParticipantEdit)
     p_form = response['p_form']
     self.assertIsNotNone(p_form.ref_id)
     self.assertEqual({}, p_form.errors)
     updated_participant = self.session.query(Participant).filter(Participant.ref_id == p_form.ref_id).one()
     for field in PARTICIPANT_EDIT_FIELDS:
         with self.subTest(field=field):
             field_value = updated_participant.__getattribute__(field)
             self.assertIsNotNone(field_value)
             if field_value.startswith('http:'):
                 self.assertEqual(expand_curie(update_data[field]), field_value)
             else:
                 self.assertEqual(update_data[field], field_value)
Example #9
0
import transaction
from pyramid import testing
from pyramid.i18n import TranslationStringFactory
from webob.multidict import MultiDict

from arachcurator.views.curie_utils import expand_curie
from arachcurator.views.claim_edit import NOELEMENT


_ = TranslationStringFactory('arachcurator')

POSTGRES_SPEC = "postgresql+psycopg2://arachcurator:''@localhost:5432/testadmin"

TEST_CLAIM_REF_ID2 = 'arachb:ARACHB_0000343'

TEST_CLAIM_REF_URL2 = expand_curie(TEST_CLAIM_REF_ID2)

TEST_CLAIM_URI3 = 'http://arachb.org/arachb/ARACHB_0000412'

TEST_PUBLICATION_CURIE = 'arachb:ARACHB_0000099'

TEST_PUBLICATION_CURIE2 = 'arachb:ARACHB_0000311'

TEST_PUBLICATION_URI2 = expand_curie(TEST_PUBLICATION_CURIE2)

TEST_BEHAVIOR_TERM_CURIE = 'obo:NBO_0000001'

TEST_BEHAVIOR_TERM_CURIE2 = 'obo:NBO_0000002'

ACTIVELY_PARTICIPATES_IN_CURIE = 'obo:RO_0002217'