def rebuild(): """ A GET method that will rebuild the internal TDB index with all of the Annotation objects in Fedora """ try: query = "prefix fm: <info:fedora/fedora-system:def/model#> select ?s where {?s fm:hasModel <info:fedora/%s> }" \ % app.config.get('DEFUALT_ANNOTATION_CONTENT_MODEL') all_pids = (p.lstrip('info:fedora/') for p in Fedora.get_sparql_query_resuts(query)) result, mimetype = Annotation.serialize(all_pids, format='nt', check_object=False) dataset = TDBFactory.createDataset(app.config['STORE_LOCATION']) # Remove all entries from the default model dataset.begin(ReadWrite.WRITE) try: model = dataset.getDefaultModel() model.begin() model.removeAll() model.commit() model.close() dataset.commit() except Exception, exc: raise finally: dataset.end() TDB.sync(dataset) # Load the triples dataset.begin(ReadWrite.WRITE) try: model = dataset.getDefaultModel() model.begin() n3_input_stream = ByteArrayInputStream(String(result).getBytes()) model.read(n3_input_stream, None, "N-TRIPLE") model.commit() model.close() dataset.commit() except Exception, exc: raise
def flush(): """ A GET method that will serialize (dump) all Annotation objects in Fedora. An optional 'format' parameter to output the serialization in different formats. Format options are: - nt (default) - rdf/xml or xml - rdf/json or json - turtle or ttl - n3 """ try: format = request.args.get('format', 'nt') query = "prefix fm: <info:fedora/fedora-system:def/model#> select ?s where {?s fm:hasModel <info:fedora/%s> }" \ % app.config.get('DEFUALT_ANNOTATION_CONTENT_MODEL') all_pids = (p.lstrip('info:fedora/') for p in Fedora.get_sparql_query_resuts(query)) result, mimetype = Annotation.serialize(all_pids, format=format, check_object=False) except AnnotationError, ex: return jsonify({'value' : ex.value, 'trace' : traceback.format_stack()})
def test_sparql(self): rows = Fedora.get_sparql_query_resuts("prefix fm: <info:fedora/fedora-system:def/model#> select ?s where {?s fm:hasModel <info:fedora/bdr-cmodel:oa-annotation> }") non_it = list(rows) assert len(non_it) > 0 assert non_it[0].find("info:fedora/changeme:") != -1 assert non_it[-1].find("info:fedora/changeme:") != -1