Example #1
0
 def __extract_and_validate_nexson(request, repo_nexml2json, kwargs):
     try:
         nexson = __extract_nexson_from_http_call(request, **kwargs)
         bundle = validate_and_convert_nexson(nexson,
                                              repo_nexml2json,
                                              allow_invalid=False)
         nexson, annotation, validation_log, nexson_adaptor = bundle
     except GitWorkflowError, err:
         _LOG = api_utils.get_logger(request, 'ot_api.default.v1')
         _LOG.exception('PUT failed in validation')
         _raise_HTTP_from_msg(err.msg or 'No message found')
 def ingest_new_study(self,
                      new_study_nexson,
                      repo_nexml2json,
                      auth_info,
                      new_study_id=None):
     placeholder_added = False
     if new_study_id is not None:
         if new_study_id.startswith(self._new_study_prefix):
             m = 'Study IDs with the "{}" prefix can only be automatically generated.'.format(
                 self._new_study_prefix)
             raise ValueError(m)
         if not STUDY_ID_PATTERN.match(new_study_id):
             raise ValueError(
                 'Study ID does not match the expected pattern of alphabeticprefix_numericsuffix'
             )
         with self._index_lock:
             if new_study_id in self._study2shard_map:
                 raise ValueError('Study ID is already in use!')
             self._study2shard_map[new_study_id] = None
             placeholder_added = True
     try:
         gd, new_study_id = self.create_git_action_for_new_study(
             new_study_id=new_study_id)
         try:
             nexml = new_study_nexson['nexml']
             nexml['^ot:studyId'] = new_study_id
             bundle = validate_and_convert_nexson(new_study_nexson,
                                                  repo_nexml2json,
                                                  allow_invalid=True)
             nexson, annotation, nexson_adaptor = bundle[0], bundle[
                 1], bundle[3]
             r = self.annotate_and_write(git_data=gd,
                                         nexson=nexson,
                                         study_id=new_study_id,
                                         auth_info=auth_info,
                                         adaptor=nexson_adaptor,
                                         annotation=annotation,
                                         parent_sha=None,
                                         master_file_blob_included=None)
         except:
             self._growing_shard.delete_study_from_index(new_study_id)
             raise
     except:
         if placeholder_added:
             with self._index_lock:
                 if new_study_id in self._study2shard_map:
                     del self._study2shard_map[new_study_id]
         raise
     with self._index_lock:
         self._study2shard_map[new_study_id] = self._growing_shard
     return new_study_id, r
 def ingest_new_study(self,
                      new_study_nexson,
                      repo_nexml2json,
                      auth_info,
                      new_study_id=None):
     placeholder_added = False
     if new_study_id is not None:
         if new_study_id.startswith(self._new_study_prefix):
             m = 'Document IDs with the "{}" prefix can only be automatically generated.'
             m = m.format(self._new_study_prefix)
             raise ValueError(m)
         if not STUDY_ID_PATTERN.match(new_study_id):
             raise ValueError('Document ID does not match the expected pattern of alphabeticprefix_numericsuffix')
         with self._index_lock:
             if new_study_id in self._doc2shard_map:
                 raise ValueError('Document ID is already in use!')
             self._doc2shard_map[new_study_id] = None
             placeholder_added = True
     try:
         gd, new_study_id = self.create_git_action_for_new_study(new_study_id=new_study_id)
         try:
             nexml = new_study_nexson['nexml']
             nexml['^ot:studyId'] = new_study_id
             bundle = validate_and_convert_nexson(new_study_nexson,
                                                  repo_nexml2json,
                                                  allow_invalid=True)
             nexson, annotation, nexson_adaptor = bundle[0], bundle[1], bundle[3]
             r = self.annotate_and_write(git_data=gd,
                                         nexson=nexson,
                                         doc_id=new_study_id,
                                         auth_info=auth_info,
                                         adaptor=nexson_adaptor,
                                         annotation=annotation,
                                         parent_sha=None,
                                         master_file_blob_included=None)
         except:
             self._growing_shard.delete_doc_from_index(new_study_id)
             raise
     except:
         if placeholder_added:
             with self._index_lock:
                 if new_study_id in self._doc2shard_map:
                     del self._doc2shard_map[new_study_id]
         raise
     with self._index_lock:
         self._doc2shard_map[new_study_id] = self._growing_shard
     return new_study_id, r
Example #4
0
 def testValidFilesPass(self):
     format_list = ['1.0', '1.2']
     TESTS_WITH_GT_ONE_TREE = ['9']
     for d in TESTS_WITH_GT_ONE_TREE:
         for nf in format_list:
             frag = os.path.join(d, 'v{f}.json'.format(f=nf))
             nexson = pathmap.nexson_obj(frag)
             annotation = ot_validate(nexson)[0]
             self.assertTrue(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             bundle = validate_and_convert_nexson(nexson,
                                              nf,
                                              allow_invalid=True,
                                              max_num_trees_per_study=1)
             nexson, annotation, validation_log, nexson_adaptor = bundle
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
Example #5
0
 def testValidFilesPass(self):
     format_list = ['1.0', '1.2']
     TESTS_WITH_GT_ONE_TREE = ['9']
     for d in TESTS_WITH_GT_ONE_TREE:
         for nf in format_list:
             frag = os.path.join(d, 'v{f}.json'.format(f=nf))
             nexson = pathmap.nexson_obj(frag)
             annotation = ot_validate(nexson)[0]
             self.assertTrue(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             bundle = validate_and_convert_nexson(nexson,
                                                  nf,
                                                  allow_invalid=True,
                                                  max_num_trees_per_study=1)
             annotation = bundle[1]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])