function loadDataFromList()
 {
     $list = $this->getListOfUris();
     $viewerUri = $this->getViewer();
     logDebug("Viewer URI is {$viewerUri}");
     $this->viewQuery = $this->SparqlWriter->getViewQueryForUriList($list, $viewerUri);
     if (LOG_VIEW_QUERIES) {
         logViewQuery($this->Request, $this->viewQuery);
     }
     $response = $this->SparqlEndpoint->graph($this->viewQuery, PUELIA_RDF_ACCEPT_MIMES);
     if ($response->is_success()) {
         $rdf = $response->body;
         if (isset($response->headers['content-type'])) {
             if (strpos($response->headers['content-type'], 'turtle')) {
                 $this->DataGraph->add_turtle($rdf);
             } else {
                 $this->DataGraph->add_rdf($rdf);
             }
         } else {
             $this->DataGraph->add_rdf($rdf);
         }
         $listUri = $this->Request->getUriWithoutParam(array('_view', '_page'), 'strip extension');
         $this->listUri = $listUri;
         $pageUri = $this->Request->getUriWithPageParam();
         $currentPage = $this->Request->getPage();
         $this->DataGraph->add_resource_triple($listUri, API . 'definition', $this->endpointUrl);
         $this->DataGraph->add_resource_triple($listUri, RDF_TYPE, API . 'List');
         $this->DataGraph->add_resource_triple($pageUri, RDF_TYPE, API . 'Page');
         if ($label = $this->ConfigGraph->getPageTitle()) {
             $this->DataGraph->add_literal_triple($pageUri, RDFS_LABEL, $label);
         }
         $this->DataGraph->add_resource_triple($listUri, DCT . 'hasPart', $pageUri);
         $this->DataGraph->add_resource_triple($pageUri, DCT . 'isPartOf', $listUri);
         $this->DataGraph->add_resource_triple($pageUri, XHV . 'first', $this->Request->getUriWithPageParam(1));
         if (count($list) >= $this->SparqlWriter->getLimit()) {
             $this->DataGraph->add_resource_triple($pageUri, XHV . 'next', $this->Request->getUriWithPageParam($currentPage + 1));
         }
         if ($currentPage > 1) {
             $this->DataGraph->add_resource_triple($pageUri, XHV . 'prev', $this->Request->getUriWithPageParam($currentPage - 1));
         }
         $this->DataGraph->add_literal_triple($pageUri, OPENSEARCH . 'itemsPerPage', $this->SparqlWriter->getLimit(), null, XSD . 'integer');
         $this->DataGraph->add_literal_triple($pageUri, OPENSEARCH . 'startIndex', $this->SparqlWriter->getOffset(), null, XSD . 'integer');
         $this->DataGraph->add_literal_triple($pageUri, DCT . 'modified', date("Y-m-d\\TH:i:s"), null, XSD . 'dateTime');
         $rdfListUri = '_:itemsList';
         if ($datasetUri = $this->ConfigGraph->getDatasetUri()) {
             $this->DataGraph->add_resource_triple($pageUri, VOID . 'inDataset', $datasetUri);
         }
         $this->DataGraph->add_resource_triple($pageUri, API . 'items', $rdfListUri);
         $this->DataGraph->add_resource_triple($rdfListUri, RDF_TYPE, RDF_LIST);
         foreach ($list as $no => $resourceUri) {
             $nextNo = $no + 1;
             $nextList = $no + 1 == count($list) ? RDF_NIL : '_:itemsList' . $nextNo;
             $this->DataGraph->add_resource_triple($rdfListUri, RDF_FIRST, $resourceUri);
             $this->DataGraph->add_resource_triple($rdfListUri, RDF_REST, $nextList);
             $rdfListUri = $nextList;
         }
     } else {
         logError("Endpoint returned {$response->status_code} {$response->body} View Query <<<{$this->viewQuery}>>> failed against {$this->SparqlEndpoint->uri}");
         $this->setStatusCode(HTTP_Internal_Server_Error);
         $this->errorMessages[] = "The SPARQL endpoint used by this URI configuration did not return a successful response.";
     }
 }
 function loadDataFromExternalService()
 {
     $uriWithoutExtension = $this->Request->getOrderedUriWithoutExtensionAndReservedParams();
     logDebug("Generating graph name from: {$uriWithoutExtension}");
     $graphName = OPS_API . '/' . hash("crc32", $uriWithoutExtension);
     $checkDatastore = $this->decideToCheckTripleStore($uriWithoutExtension);
     if ($checkDatastore == true) {
         //build query
         $this->pageUri = $this->Request->getUriWithoutPageParam();
         $viewer = $this->getViewer();
         $this->viewQuery = $this->SparqlWriter->getViewQueryForExternalService($graphName, $this->pageUri, $viewer);
         if (LOG_VIEW_QUERIES) {
             logViewQuery($this->Request, $this->viewQuery);
         }
         //query the data store
         $response = $this->SparqlEndpoint->graph($this->viewQuery, PUELIA_RDF_ACCEPT_MIMES);
         //TODO use appropriate mime in the future
         if ($response->is_success()) {
             $this->DataGraph->add_rdf($response->body);
             if (!$this->DataGraph->is_empty()) {
                 //no data returned
                 $this->DataGraph->add_resource_triple($this->Request->getUri(), API . 'definition', $this->endpointUrl);
                 //we have data in the datastore, so serve it directly
                 return;
             } else {
                 logDebug("Data not found at: {$this->SparqlEndpoint->uri}, going to external service");
             }
         } else {
             logError("Endpoint returned {$response->status_code} {$response->body} View Query <<<{$this->viewQuery}>>> failed against {$this->SparqlEndpoint->uri}");
         }
     }
     //match api:uriTemplate, extract parameters and fill in api:externalRequestTemplate
     $externalServiceRequest = $this->ConfigGraph->getExternalServiceRequest();
     logDebug("External service request: " . $externalServiceRequest);
     try {
         $rdfData = $this->retrieveRDFDataFromExternalService($externalServiceRequest, '');
     } catch (EmptyResponseException $e) {
         logError("EmptyResponseException: " . $e->getMessage());
         $this->setStatusCode(HTTP_Not_Found);
         $this->errorMessages[] = $e->getMessage();
         $this->serve();
         exit;
     } catch (TimeoutException $e) {
         logError("TimeoutException: " . $e->getMessage());
         $this->setStatusCode(HTTP_Gateway_Timeout);
         $this->errorMessages[] = $e->getMessage();
         $this->serve();
         exit;
     } catch (Exception $e) {
         logError("Error while loading data from external service: " . $e->getMessage());
         $this->setStatusCode(HTTP_Internal_Server_Error);
         $this->errorMessages[] = $e->getMessage();
         $this->serve();
         exit;
     }
     if ($this->useDatastore) {
         $this->insertRDFDataIntoTripleStore($graphName, $rdfData);
     }
     //if we went to the external service we cache the path without extension
     if ($this->decideToCacheResponse($checkDatastore)) {
         LinkedDataApiCache::cacheURI($uriWithoutExtension);
     }
 }