correct error in test with empty document returned by query
authorymh <ymh.work@gmail.com>
Thu, 08 Sep 2016 19:15:46 +0200
changeset 276 ef32bf573d9c
parent 275 a4d8618c2f1b
child 277 bd4bc1db4f40
correct error in test with empty document returned by query
server/src/app/Repositories/RdfDocumentRepository.php
--- a/server/src/app/Repositories/RdfDocumentRepository.php	Tue Sep 06 16:50:41 2016 +0200
+++ b/server/src/app/Repositories/RdfDocumentRepository.php	Thu Sep 08 19:15:46 2016 +0200
@@ -89,6 +89,11 @@
     }
 
     private function getResGraph($doc) {
+
+        if(empty((array)$doc)) {
+            return null;
+        }
+
         $newGraph = new Graph($doc->uri->getUri());
         $newGraph->add($doc->uri, "rdf:type", $newGraph->resource("http://www.openarchives.org/ore/terms/Aggregation"));
         $newGraph->add($doc->uri, "http://www.europeana.eu/schemas/edm/aggregatedCHO", $doc->doc);
@@ -136,6 +141,9 @@
         $docs = $this->sparqlClient->query(self::BASE_DOC_QUERY.$limitsClausesStr);
         foreach($docs as $doc) {
             $graph = $this->getResGraph($doc);
+            if(is_null($graph)) {
+                continue;
+            }
             $uri = $doc->uri->getUri();
             $resDocs[$uri] = $graph;
         }
@@ -150,6 +158,9 @@
             $docs = $this->sparqlClient->query(sprintf($query, $filterUris));
             foreach($docs as $doc) {
                 $graph = $this->getResGraph($doc);
+                if(is_null($graph)) {
+                    continue;
+                }
 
                 $uri = $doc->uri->getUri();
                 if(array_key_exists($uri, $resDocs)) {