cache = JCache :: getInstance(); $this -> http = new JHttp(); $parameters = JComponentHelper :: getParams('com_openaire'); $socket = new TSocket($parameters -> get('thriftHost'), intval($parameters -> get('thriftPort'))); $socket -> setRecvTimeout(intval($parameters -> get('thriftTimeout'))); $this -> transport = new TBufferedTransport($socket); $this -> client = new OpenAIREConnectorClient(new TBinaryProtocol($this -> transport)); $this -> transport -> open(); } // Close Thrift transport public function __destruct() { $this -> transport -> close(); } // Get the selected projects stored in session. // return the selected projects (array) or NULL if any errors occur public function getSelectedProjects($suffix = self :: CLAIM) { try { $projects = unserialize(JFactory :: getSession() -> get(self :: SELECTED_PROJECTS . $suffix, serialize(array()))); JLog :: add('Retrieved ' . count($projects) . ' selected projects', JLog :: INFO, self :: LOG); return $projects; } catch (Exception $e) { JLog :: add('Error retrieving selected projects: ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Add a project to the selected projects stored in session. // $project the project to add public function addSelectedProject($project, $suffix = self :: CLAIM) { try { $session = JFactory :: getSession(); $projects = unserialize($session -> get(self :: SELECTED_PROJECTS . $suffix, serialize(array()))); $projects[$project -> id] = $project; $session -> set(self :: SELECTED_PROJECTS . $suffix, serialize($projects)); JLog :: add('Added project ' . $project -> id . ' to selected projects', JLog :: INFO, self :: LOG); } catch (Exception $e) { JLog :: add('Error adding project ' . $project -> id . ' to selected projects: ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); } } // Remove a project from the selected projects stored in session. // $projectId the identifier of the project to remove public function removeSelectedProject($projectId, $suffix = self :: CLAIM) { try { $session = JFactory :: getSession(); $projects = unserialize($session -> get(self :: SELECTED_PROJECTS . $suffix, serialize(array()))); unset($projects[$projectId]); $session -> set(self :: SELECTED_PROJECTS . $suffix, serialize($projects)); JLog :: add('Removed project ' . $projectId . ' from selected projects', JLog :: INFO, self :: LOG); } catch (Exception $e) { JLog :: add('Error removing project ' . $projectId . ' from selected projects: ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); } } //empties selected concepts public function emptySelectedProjects($suffix = self :: CLAIM) { try { $session = JFactory :: getSession(); $session -> set(self :: SELECTED_PROJECTS . $suffix, serialize(array())); } catch (Exception $e) { ; } } //Get concept using id //returns concept object or error public function getConcept($conceptId, $withChildren = false){ $contexts = $this->getContexts(); $concept = new JObject(); $concept->context = new JObject(); $concept->category = new JObject(); $concept->concepts = array(); $concept->id = $conceptId; $data = explode("::", $conceptId); if (count($data) > 1){ list ($context, $category) = $data; $category = $context . "::" . $category; } else{ $context = $data[0]; $category = null; } if (!isset($contexts[$context])) return NULL; $concept->context->id = $context; $concept->context->name = $contexts[$context]->name; if ($category == null){ $concept->category = null; $concept->path = $this->getConceptPath($concept); return $concept; } if (!isset($contexts[$context]->categories[$category])) return NULL; $concept->category->id = $category; $concept->category->name = $contexts[$context]->categories[$category]->name; $concepts = $contexts[$context]->categories[$category]->concepts; $conceptId2 = $category; for ($i = 2; $i < count($data); $i++){ $conceptId2 = $conceptId2 . "::" . $data[$i]; $concept_s = new JObject(); $concept_s -> id = $conceptId2; $concept_s -> name = $concepts[$conceptId2] -> name; $concepts = isset($concepts[$conceptId2] -> concepts)?$concepts[$conceptId2] -> concepts:array(); $concept_s -> concepts = $concepts; $concept -> concepts[] = $concept_s; } $concept->path = $this->getConceptPath($concept); return $concept; } //Get concept using id //returns concept object or error public function getConceptPath($concept){ $path = $concept->context->name . ($concept->category != null?" > " . $concept->category->name:""); $concept_parts = array(); foreach ($concept -> concepts as $concept_part){ $concept_parts[] = $concept_part -> name; } $path = $path . (count($concept_parts)?" > " . implode(" > ", $concept_parts):""); return $path; } // Get the selected concepts stored in session. // return the selected concepts (array) or NULL if any errors occur public function getSelectedConcepts($suffix = self :: CLAIM) { try { $concepts = unserialize(JFactory :: getSession() -> get(self :: SELECTED_CONCEPTS . $suffix, serialize(array()))); JLog :: add('Retrieved ' . count($concepts) . ' selected concepts', JLog :: INFO, self :: LOG); return $concepts; } catch (Exception $e) { JLog :: add('Error retrieving selected concepts: ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Add a project to the selected projects stored in session. // $project the project to add public function addSelectedConcept($concept, $suffix = self :: CLAIM) { try { $session = JFactory :: getSession(); $concepts = unserialize($session -> get(self :: SELECTED_CONCEPTS . $suffix, serialize(array()))); $concepts[$concept -> id] = $concept; $session -> set(self :: SELECTED_CONCEPTS . $suffix, serialize($concepts)); JLog :: add('Added project ' . $concept -> id . ' to selected projects', JLog :: INFO, self :: LOG); } catch (Exception $e) { JLog :: add('Error adding project ' . $concept -> id . ' to selected projects: ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); } } // Remove a project from the selected projects stored in session. // $projectId the identifier of the project to remove public function removeSelectedConcept($conceptId, $suffix = self :: CLAIM) { try { $session = JFactory :: getSession(); $concepts = unserialize($session -> get(self :: SELECTED_CONCEPTS . $suffix, serialize(array()))); unset($concepts[$conceptId]); $session -> set(self :: SELECTED_CONCEPTS . $suffix, serialize($concepts)); JLog :: add('Removed project ' . $conceptId . ' from selected projects', JLog :: INFO, self :: LOG); } catch (Exception $e) { JLog :: add('Error removing project ' . $conceptId . ' from selected projects: ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); } } //empties selected concepts public function emptySelectedConcepts($suffix = self :: CLAIM) { try { $session = JFactory :: getSession(); $session -> set(self :: SELECTED_CONCEPTS . $suffix, serialize(array())); } catch (Exception $e) { ; } } // Get the selected publications stored in session. // return the selected publications (arary) or NULL if any errors occur public function getSelectedPublications($suffix = self :: CLAIM) { try { $publications = unserialize(JFactory :: getSession() -> get(self :: SELECTED_PUBLICATIONS . $suffix, serialize(array()))); JLog :: add('Retrieved ' . count($publications) . ' selected publications', JLog :: INFO, self :: LOG); return $publications; } catch (Exception $e) { JLog :: add('Error retrieving selected publications: ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Add a publication to the selected publications stored in session. // $publication the publication to add public function addSelectedPublication($publication, $suffix = self :: CLAIM) { try { $session = JFactory :: getSession(); $publications = unserialize($session -> get(self :: SELECTED_PUBLICATIONS . $suffix, serialize(array()))); $publications[$publication -> source . $publication -> id] = $publication; $session -> set(self :: SELECTED_PUBLICATIONS . $suffix, serialize($publications)); JLog :: add('Added ' . $publication -> source . ' publication ' . $publication -> id . ' to selected publications', JLog :: INFO, self :: LOG); } catch (Exception $e) { JLog :: add('Error adding ' . $publication -> source . ' publication ' . $publication -> id . ' to selected publications: ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); } } // Remove a publication from the selected publications stored in session. // $source the source of the publication to remove // $publicationId the identifier of the publication to remove public function removeSelectedPublication($source, $publicationId, $suffix = self :: CLAIM) { try { $session = JFactory :: getSession(); $publications = unserialize($session -> get(self :: SELECTED_PUBLICATIONS . $suffix, serialize(array()))); unset($publications[$source . $publicationId]); $session -> set(self :: SELECTED_PUBLICATIONS, serialize($publications)); JLog :: add('Removed ' . $source . ' publication ' . $publicationId . ' from selected publications', JLog :: INFO, self :: LOG); } catch (Exception $e) { JLog :: add('Error removing ' . $source . ' publication ' . $publicationId . ' from selected publications: ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); } } // Claim all the selected publications. // $user the user to claim publications for public function claimSelectedPublications($user, $mode = self :: CLAIM, $activePublication = NULL, $suffix = "", $activePublicationType = "publication") { try { $projects = array_map(function ($project) { $project2 = new Project(); $project2 -> projectId = $project -> id; $project2 -> type = NULL; return $project2;}, $this -> getSelectedProjects($mode.$suffix)); $concepts = array_map(function ($concept) {return $concept -> id;}, $this -> getSelectedConcepts($mode.$suffix)); if ($mode != self :: CLAIMINLINE){ $selectedPublications = $this -> getSelectedPublications($mode.$suffix); } else { $selectedPublications = array($activePublication); } $dcSource = NULL; $subjects = array(); $category = NULL; foreach ($selectedPublications as $publication) { $authors = array_map(function ($author) { $a = array(); $a['id'] = $author -> id; $a['firstName'] = $author -> firstName; $a['lastName'] = $author -> lastName; if (($author -> lastName == NULL) && ($author -> fullName != NULL)) $a['lastName'] = $author -> fullName; return new Author($a); }, $publication -> authors); $doi = (($publication -> source == self :: DOI) || ($publication -> source == self :: DATACITE)) ? $publication -> id : NULL; if ($mode != self :: CLAIMINLINE and $publication -> source != "openaire"){ $docId = $this -> client -> insertDocument($publication -> id, $publication -> source, $publication -> title, $publication -> description, isset($publication -> license)?"":"", $publication -> embargoEndDate, $authors, $publication -> url, $dcSource, $user -> email, $subjects, $publication -> year, $publication -> publisher, $publication -> language, $category, $doi); }else{ $docId = $publication->id; } foreach ($concepts as $concept) $this -> client -> insertConcept($docId, $publication -> source, $concept, $user -> email); foreach ($projects as $project) $this -> client -> insertProjectRelation($docId, $publication -> source, $project, $user -> email); if ($activePublication != NULL && $mode == self::CLAIMINLINE2){ $this -> client -> insertResultRelation($activePublication -> id, $activePublicationType, $activePublication -> source, $docId, $publication -> claim_type, $user -> email); } } if ($this -> cache -> getCaching()){ $cacheId = self :: CLAIMED_PUBLICATIONS_CACHE_ID . '.' . $user -> username; $this -> cache ->remove($cacheId); } JLog :: add('Claimed ' . count($selectedPublications) . ' publications (user: ' . $user -> username . ')', JLog :: INFO, self :: LOG); } catch (Exception $e) { JLog :: add('Error claiming selected publications (user: ' . $user -> username . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); } } // Get the publications claimed by a user using caching if enabled. // $user the user whose claimed publications to retrieve // return an array of publications public function getClaimedPublications($user) { if ($this -> cache -> getCaching()) { $cacheId = self :: CLAIMED_PUBLICATIONS_CACHE_ID . '.' . $user -> username; $publications = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($publications === FALSE) { $publications = $this -> _getClaimedPublications($user); if ($publications !== NULL) $this -> cache -> store($publications, $cacheId, self :: CACHE_GROUP); } } else $publications = $this -> _getClaimedPublications($user); return $publications; } // Get the publications claimed by a user using caching if enabled. // $user the user whose claimed publications to retrieve // return an array of publications public function getAllClaimedPublications($from, $to) { if ($this -> cache -> getCaching()) { $cacheId = self :: CLAIMED_PUBLICATIONS_CACHE_ID . '.' . $from . "." . $to; $publications = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($publications === FALSE) { $publications = $this -> _getAllClaimedPublications($from, $to); if ($publications !== NULL) $this -> cache -> store($publications, $cacheId, self :: CACHE_GROUP); } } else $publications = $this -> _getAllClaimedPublications($from, $to); return $publications; } // Search for a publication DOI using caching if enabled. // $doi the publication DOI to search for // return an array of results public function searchDOI($doi) { if ($this -> cache -> getCaching()) { $cacheId = self :: SEARCH_DOI_CACHE_ID . '.' . $doi; $results = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($results === FALSE) { $results = $this -> _searchDOI($doi); if ($results !== NULL) $this -> cache -> store($results, $cacheId, self :: CACHE_GROUP); } } else $results = $this -> _searchDOI($doi); return $results; } // Search for a dataset DOI using caching if enabled. // $doi the dataset DOI to search for // return a result (object) containing publications and total public function searchDataCite($doi) { if ($this -> cache -> getCaching()) { $cacheId = self :: SEARCH_DATASET_CACHE_ID . '.' . $doi; $results = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($results === FALSE) { $results = $this -> _searchDataCite($doi); if ($results !== NULL) $this -> cache -> store($results, $cacheId, self :: CACHE_GROUP); } } else $results = $this -> _searchDataCite($doi); return $results; } // Search for publications in ORCID using caching if enabled. // $doi the ORCID id to search for // $page the result page to retrieve // $size the result page size to use // return a result (object) containing datasets and total public function searchORCID($orcid, $page, $size) { if ($this -> cache -> getCaching()) { $cacheId = self :: SEARCH_ORCID_CACHE_ID . '.' . $orcid . '.' . $page . '.' . $size; $results = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($results === FALSE) { $results = $this -> _searchORCID($orcid, $page, $size); if ($results !== NULL) $this -> cache -> store($results, $cacheId, self :: CACHE_GROUP); } } else $results = $this -> _searchORCID($orcid, $page, $size); return $results; } // Get the publications claimed by a user. // $user the user whose claimed publications to retrieve // return an array of publications or NULL if any errors occur private function _getClaimedPublications($user) { try { $locale = JFactory :: getLanguage()->getTag(); $claimedPublications = array(); $claimedPublicationsGrouped = array(); $time = microtime(TRUE); $claims = $this -> client -> getClaimedPublications($user -> email); foreach ($claims as $claim){ $parsedClaim = $this -> parseClaimedPublication($claim); if ($parsedClaim == null) continue; $claimedPublications[] = $parsedClaim; } $resultsToGet = array(); $projectsToGet = array(); $claimedDocuments = array(); foreach ($claimedPublications as $claimedPublication){ if ($claimedPublication -> publication != null and $claimedPublication -> publication -> id != null) $claimedDocuments[$claimedPublication->publicationId] = $claimedPublication -> publication; if ($claimedPublication -> projectId !== null){ $projectsToGet[] = $claimedPublication -> projectId; } if ($claimedPublication -> targetPublicationId !== null){ $resultsToGet[] = $claimedPublication -> targetPublicationId; } if ($claimedPublication -> targetDatasetId !== null){ $resultsToGet[] = $claimedPublication -> targetDatasetId; } if (($claimedPublication -> publication == null || ($claimedPublication -> publication != null and $claimedPublication -> publication -> id == null))){ $resultsToGet[] = $claimedPublication -> publicationId; } if ($claimedPublication -> publication == null && $claimedPublication -> type == "dataset"){ $resultsToGet[] = $claimedPublication -> publicationId; } } $resultsToGet = array_unique($resultsToGet); $projectsToGet = array_unique($projectsToGet); $searchModel = new OpenAireModelSearch(); $results = $searchModel->getResults($resultsToGet, $locale); $projects = $searchModel->getProjects($projectsToGet, $locale); $keydResults = array(); $keydProjects = array(); foreach ($results as $result) $keydResults[$result->id] = $result; foreach ($projects as $project) $keydProjects[$project->id] = $project; foreach ($claimedPublications as $claimedPublication){ if (!isset($claimedPublicationsGrouped[$claimedPublication -> publicationId])){ if ($claimedPublication -> publication == null || $claimedPublication -> publication -> id == null){ $publication = isset($keydResults[$claimedPublication -> publicationId])?$keydResults[$claimedPublication -> publicationId]:null; } else{ $publication = $claimedPublication -> publication; } if ($publication == null || $publication -> id == null) continue; $claimedPublicationsGrouped[$claimedPublication -> publicationId] = new stdClass(); $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> publicationId = $claimedPublication -> publicationId; $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> date = $claimedPublication -> date; $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> publication = $publication; $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> publications = array(); $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> datasets = array(); $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> projects = array(); $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> concepts = array(); } if ($claimedPublicationsGrouped[$claimedPublication -> publicationId] -> date < $claimedPublication -> date) $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> date = $claimedPublication -> date; if ($claimedPublication -> publication != null){ $claimedConcepts = array(); foreach ($claimedPublication -> publication -> concepts as $concept){ $concept = $this->getConcept($concept); $claimedConcept = new stdClass(); $claimedConcept->id = $concept->id; $claimedConcept->title = $concept->path; $claimedConcept->date = $claimedPublication->date; $claimedConcepts[] = $claimedConcept; } $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> concepts = array_merge($claimedPublicationsGrouped[$claimedPublication -> publicationId] -> concepts, $claimedConcepts); } if ($claimedPublication -> targetPublicationId !== null){ $claimedPublication->title = isset($keydResults[$claimedPublication -> targetPublicationId ])?$keydResults[$claimedPublication -> targetPublicationId ]->title:null; if ($claimedPublication->title == null){ $claimedPublication->title = isset($claimedDocuments[$claimedPublication -> targetDatasetId ])?$claimedDocuments[$claimedPublication -> targetDatasetId ]->title:null; } $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> publications[] = $claimedPublication; } if ($claimedPublication -> targetDatasetId !== null){ $claimedPublication->title = isset($keydResults[$claimedPublication -> targetDatasetId ])?$keydResults[$claimedPublication -> targetDatasetId ]->title:null; if ($claimedPublication->title == null){ $claimedPublication->title = isset($claimedDocuments[$claimedPublication -> targetDatasetId ])?$claimedDocuments[$claimedPublication -> targetDatasetId ]->title:null; } $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> datasets[] = $claimedPublication; } if ($claimedPublication -> projectId !== null){ $claimedPublication->title = isset($keydProjects[$claimedPublication -> projectId ])?$keydProjects[$claimedPublication -> projectId ]->title:null; $claimedPublicationsGrouped[$claimedPublication -> publicationId] -> projects[] = $claimedPublication; } } JLog :: add('Retrieved ' . count($claimedPublications) . ' claimed publications (user: ' . $user -> username . ') in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG); return $claimedPublicationsGrouped; } catch (Exception $e) { JLog :: add('Error retrieving claimed publications (user: ' . $user -> username . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } public function _getAllClaimedPublications($from, $to) { try { // submit the docs $claimedPublications = array(); $time1 = strtotime(str_replace("/", "-", $from)) * 1000; $time2 = strtotime(str_replace("/", "-", $to)) * 1000; $list = $this->client ->getAllClaimedPublications($time1, $time2); foreach ($list as $claim){ $claimedPublications[] = $this -> parseClaimedPublication($claim); } } catch (Exception $e) { JLog :: add('Error retrieving all claims (from: ' . $from . ', to: '. $to .'): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } return $claimedPublications; } // Search for a publication DOI. // $doi the publication DOI to search for // return a result (object) containing publications and total private function _searchDOI($doi) { try { $request = self :: CROSSREF_URL . urlencode(self :: DOI_SCHEME . trim($doi)); JLog :: add('Requesting ' . $request, JLog :: INFO, self :: LOG); $time = microtime(TRUE); $response = $this -> http -> get($request); JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG); if ($response == NULL) throw new Exception('no HTTP response'); if ($response -> code != self :: HTTP_OK) throw new Exception('HTTP response code ' . $response -> code); $document = new DOMDocument(); $document -> recover = TRUE; if ($document -> loadXML(trim($response -> body)) == FALSE) throw new Exception('invalid XML response'); $xpath = new DOMXPath($document); if ((($crossrefNodes = $xpath -> query('/doi_records/doi_record/crossref')) == FALSE) || (($crossrefNode = $crossrefNodes -> item(0)) == NULL)) throw new Exception('error parsing DOI record'); if (($journalNodes = $xpath -> query('./journal', $crossrefNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($bookNodes = $xpath -> query('./book', $crossrefNode)) == FALSE) throw new Exception('error parsing DOI record'); /* if (($conferenceNodes = $xpath -> query('./conference', $crossrefNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($dissertationNodes = $xpath -> query('./dissertation', $crossrefNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($reportPaperNodes = $xpath -> query('./report-paper', $crossrefNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($standardNodes = $xpath -> query('./standard', $crossrefNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($saComponentNodes = $xpath -> query('./sa_component', $crossrefNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($databaseNodes = $xpath -> query('./database', $crossrefNode)) == FALSE) throw new Exception('error parsing DOI record');*/ if (($errorNodes = $xpath -> query('./error', $crossrefNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($journalNode = $journalNodes -> item(0)) != NULL) { $result = $this -> parseJournal($doi, $xpath, $journalNode); JLog :: add('Retrieved journal in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG); return $result; } else if (($bookNode = $bookNodes -> item(0)) != NULL) { $result = $this -> parseBook($doi, $xpath, $bookNode); JLog :: add('Retrieved book in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG); return result; /* else if (($conferenceNode = $conferenceNodes -> item(0)) != NULL) return conference; else if (($dissertationNode = $dissertationNodes -> item(0)) != NULL) return dissertation; else if (($reportPaperNode = $reportPaperNodes -> item(0)) != NULL) return reportPaper; else if (($standardNode = $standardNodes -> item(0)) != NULL) return standard; else if (($saComponentNode = $saComponentNodes -> item(0)) != NULL) return saComponent; else if (($databaseNode = $databaseNodes -> item(0)) != NULL) return database;*/ } else if (($errorNode = $errorNodes -> item(0)) != NULL) { $result = new JObject(); $result -> publications = array(); $result -> totalPublications = 0; JLog :: add('Retrieved 0 DOI records in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG); return $result; } else throw new Exception('error parsing DOI record'); } catch (Exception $e) { JLog :: add('Error performing DOI search (doi: ' . $doi . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Search for a dataset DOI using caching if enabled. // $doi the dataset DOI to search for // return a result (object) containing datasets and total private function _searchDataCite($doi) { try { $request = self :: DATACITE_URL . urlencode(trim($doi)); JLog :: add('Requesting ' . $request, JLog :: INFO, self :: LOG); $time = microtime(TRUE); $response = $this -> http -> get($request); JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG); if ($response== NULL) throw new Exception('no HTTP response'); if ($response -> code == self :: HTTP_NOT_FOUND) { // no dataset found; just return empty result $result = new JObject(); $result -> datasets = array(); $result -> totalDatasets = 0; JLog :: add('Retrieved 0 DataCite records in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG); return $result; } if ($response -> code != self :: HTTP_OK) throw new Exception('HTTP response code ' . $response -> code); $document = new DOMDocument(); $document -> recover = TRUE; if ($document -> loadXML(trim($response -> body)) == FALSE) throw new Exception('invalid XML response'); $xpath = new DOMXPath($document); if ((($descriptionNodes = $xpath -> query('/rdf:RDF/rdf:Description')) == FALSE) || (($descriptionNode = $descriptionNodes -> item(0)) == NULL)) throw new Exception('error parsing DataCite record'); if (($idNodes = $xpath -> query('./j.0:identifier', $descriptionNode)) == FALSE) throw new Exception('error parsing DataCite record'); if (($titleNodes = $xpath -> query('./j.0:title', $descriptionNode)) == FALSE) throw new Exception('error parsing DataCite record'); if (($authorNodes = $xpath -> query('./j.0:creator', $descriptionNode)) == FALSE) throw new Exception('error parsing DataCite record'); if (($yearNodes = $xpath -> query('./j.0:date', $descriptionNode)) == FALSE) throw new Exception('error parsing DataCite record'); if (($publisherNodes = $xpath -> query('./j.0:publisher', $descriptionNode)) == FALSE) throw new Exception('error parsing DataCite record'); $dataset = new JObject(); $dataset -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $dataset -> source = self :: DATACITE; $dataset -> url = self :: DOI_URL . urlencode(trim($doi)); $dataset -> accessMode = NULL; $dataset -> datasources = array(); $dataset -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $dataset -> authors = array(); $dataset -> publisher = (($publisherNode = $publisherNodes -> item(0)) == NULL) ? NULL : trim($publisherNode -> nodeValue); $dataset -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $dataset -> language = NULL; $dataset -> projects = array(); $dataset -> embargoEndDate = NULL; $dataset -> description = NULL; foreach ($authorNodes as $authorNode) { $author = new JObject(); $author -> id = NULL; $author -> lastName = NULL; $author -> firstName = NULL; $author -> fullName = trim($authorNode -> nodeValue); if ($author -> fullName != NULL) $dataset -> authors[] = $author; } $result = new JObject(); $result -> datasets = array(); $result -> totalDatasets = 0; if (($dataset -> id != NULL) || ($dataset -> url != NULL) || ($dataset -> title != NULL) || ($dataset -> authors != NULL) || ($dataset -> year != NULL)) { $result -> datasets[] = $dataset; $result -> totalDatasets = 1; } JLog :: add('Retrieved DataCite record in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing DataCite search (doi: ' . $doi . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Parse a journal out of a DOI record. // $doi the DOI of the record // $xpath the DOMXPath to parse // $journalNode the journal node to start from // return a result (object) containing publications and total private function parseJournal($doi, $xpath, $journalNode) { if (($resourceNodes = $xpath -> query('./journal_article/doi_data/resource', $journalNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($titleNodes = $xpath -> query('./journal_article/titles/title', $journalNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($contributorNodes = $xpath -> query('./journal_article/contributors', $journalNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($yearNodes = $xpath -> query('./journal_article/publication_date/year', $journalNode)) == FALSE) throw new Exception('error parsing DOI record'); $publication = new JObject(); $publication -> id = $doi; $publication -> source = self :: DOI; $publication -> url = (($resourceNode = $resourceNodes -> item(0)) == NULL) ? NULL : trim($resourceNode -> nodeValue); $publication -> accessMode = NULL; $publication -> datasources = array(); $publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $publication -> authors = $this -> parseContributors($xpath, $contributorNodes); $publication -> publisher = NULL; $publication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $publication -> language = NULL; $publication -> projects = array(); $publication -> embargoEndDate = NULL; $publication -> description = NULL; $result = new JObject(); $result -> publications = array(); $result -> totalPublications = 0; if (($publication -> id != NULL) || ($publication -> url != NULL) || ($publication -> title != NULL) || ($publication -> authors != NULL) || ($publication -> year != NULL)) { $result -> publications[] = $publication; $result -> totalPublications = 1; } return $result; } // Parse a book out of a DOI record. // $doi the DOI of the record // $xpath the DOMXPath to parse // $bookNode the book node to start from // return a result (object) containing publications and total private function parseBook($doi, $xpath, $bookNode) { if (($bookMetadataNodes = $xpath -> query('./book_metadata', $bookNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($bookSeriesMetadataNodes = $xpath -> query('./book_series_metadata', $bookNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($bookSetMetadataNodes = $xpath -> query('./book_set_metadata', $bookNode)) == FALSE) throw new Exception('error parsing DOI record'); if ((($metadataNode = $bookMetadataNodes -> item(0)) == NULL) && (($metadataNode = $bookSeriesMetadataNodes -> item(0)) == NULL) && (($metadataNode = $bookSetMetadataNodes -> item(0)) == NULL)) throw new Exception('error parsing DOI record'); if (($resourceNodes = $xpath -> query('./doi_data/resource', $metadataNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($titleNodes = $xpath -> query('./titles/title', $metadataNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($contributorNodes = $xpath -> query('./contributors', $metadataNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($yearNodes = $xpath -> query('./publication_date/year', $metadataNode)) == FALSE) throw new Exception('error parsing DOI record'); $publication = new JObject(); $publication -> id = $doi; $publication -> source = self :: DOI; $publication -> url = (($resourceNode = $resourceNodes -> item(0)) == NULL) ? NULL : trim($resourceNode -> nodeValue); $publication -> accessMode = NULL; $publication -> datasources = array(); $publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $publication -> authors = $this -> parseContributors($xpath, $contributorNodes); $publication -> publisher = NULL; $publication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $publication -> language = NULL; $publication -> projects = array(); $publication -> embargoEndDate = NULL; $publication -> description = NULL; $result = new JObject(); $result -> publications = array(); $result -> totalPublications = 0; if (($publication -> id != NULL) || ($publication -> url != NULL) || ($publication -> title != NULL) || ($publication -> authors != NULL) || ($publication -> year != NULL)) { $result -> publications[] = $publication; $result -> totalPublications = 1; } return $result; } // Parse contributor metadata out of a DOI record. // $doi the DOI of the record // $xpath the DOMXPath to parse // $contributorNodes the contributor nodes to start from // return authors (array) private function parseContributors($xpath, $contributorNodes) { $authors = array(); foreach ($contributorNodes as $contributorNode) { if (($personNameNodes = $xpath -> query('./person_name', $contributorNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($organizationNodes = $xpath -> query('./organization', $contributorNode)) == FALSE) throw new Exception('error parsing DOI record'); foreach ($personNameNodes as $personNameNode) { if (($surnameNodes = $xpath -> query('./surname', $personNameNode)) == FALSE) throw new Exception('error parsing DOI record'); if (($givenNameNodes = $xpath -> query('./given_name', $personNameNode)) == FALSE) throw new Exception('error parsing DOI record'); $author = new JObject(); $author -> id = NULL; $author -> lastName = (($surnameNode = $surnameNodes -> item(0)) == NULL) ? NULL : trim($surnameNode -> nodeValue); $author -> firstName = (($givenNameNode = $givenNameNodes -> item(0)) == NULL) ? NULL : trim($givenNameNode -> nodeValue); $author -> fullName = NULL; if (($author -> id != NULL) || ($author -> lastName != NULL) || ($author -> firstName != NULL) || ($author -> fullName != NULL)) $authors[] = $author; } foreach ($organizationNodes as $organizationNode) { $author = new JObject(); $author -> id = NULL; $author -> lastName = NULL; $author -> firstName = NULL; $author -> fullName = trim($organizationNode -> nodeValue); if (($author -> id != NULL) || ($author -> lastName != NULL) || ($author -> firstName != NULL) || ($author -> fullName != NULL)) $authors[] = $author; } } return $authors; } // Search ORCID. // $orcid the ORCID id to search for // $page the result page to retrieve // $size the result page size to use // return an array of results or NULL if any errors occur private function _searchORCID($orcid, $page, $size) { try { $time = microtime(TRUE); $authorRequest = self :: ORCID_URL_PREFIX . trim($orcid) . self :: ORCID_URL_AUTHOR_SUFFIX; JLog :: add('Requesting ' . $authorRequest, JLog :: INFO, self :: LOG); $authorResponse = $this -> http -> get($authorRequest); JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s'); if ($authorResponse == NULL) throw new Exception('no HTTP response'); if ($authorResponse -> code != self :: HTTP_OK) throw new Exception('HTTP response code ' . $authorResponse -> code); $authorDocument = new DOMDocument(); $authorDocument -> recover = TRUE; if ($authorDocument -> loadXML(trim($authorResponse -> body)) == FALSE) throw new Exception('invalid XML response'); $authorXpath = new DOMXPath($authorDocument); if ($authorXpath -> registerNamespace('orcid', $authorDocument -> lookupNamespaceUri(NULL)) == FALSE) throw new Exception('error parsing ORCID bio record'); if (($familyNameNodes = $authorXpath -> query('/orcid:orcid-message/orcid:orcid-profile/orcid:orcid-bio/orcid:personal-details/orcid:family-name')) == FALSE) throw new Exception('error parsing ORCID bio record'); if (($givenNamesNodes = $authorXpath -> query('/orcid:orcid-message/orcid:orcid-profile/orcid:orcid-bio/orcid:personal-details/orcid:given-names')) == FALSE) throw new Exception('error parsing ORCID bio record'); $publicationsRequest = self :: ORCID_URL_PREFIX . trim($orcid) . self :: ORCID_URL_PUBLICATIONS_SUFFIX; JLog :: add('Requesting ' . $publicationsRequest, JLog :: INFO, self :: LOG); if (($publicationsResponse = $this -> http -> get($publicationsRequest)) == NULL) throw new Exception('no HTTP response'); if ($publicationsResponse -> code != self :: HTTP_OK) throw new Exception('HTTP response code ' . $publicationsResponse -> code); $publicationsDocument = new DOMDocument(); $publicationsDocument -> recover = TRUE; if ($publicationsDocument -> loadXML(trim($publicationsResponse -> body)) == FALSE) throw new Exception('invalid XML response'); $publicationsXpath = new DOMXPath($publicationsDocument); if ($publicationsXpath -> registerNamespace('orcid', $publicationsDocument -> lookupNamespaceUri(NULL)) == FALSE) throw new Exception('error parsing ORCID works record'); if (($orcidWorkNodes = $publicationsXpath -> query('/orcid:orcid-message/orcid:orcid-profile/orcid:orcid-activities/orcid:orcid-works/orcid:orcid-work')) == FALSE) throw new Exception('error ORCID works record'); $author = new JObject(); $author -> id = NULL; $author -> lastName = (($familyNameNode = $familyNameNodes -> item(0)) == NULL) ? NULL : trim($familyNameNode -> nodeValue); $author -> firstName = (($givenNamesNode = $givenNamesNodes ->item(0)) == NULL) ? NULL : trim($givenNamesNode -> nodeValue); $author -> fullName = NULL; $result = new JObject(); $result -> publications = array(); foreach ($orcidWorkNodes as $orcidWorkNode) { if (($putCodeNodes = $publicationsXpath -> query('./@put-code', $orcidWorkNode)) == FALSE) throw new Exception('error ORCID works record'); if (($urlNodes = $publicationsXpath -> query('./orcid:url', $orcidWorkNode)) == FALSE) throw new Exception('error ORCID works record'); if (($titleNodes = $publicationsXpath -> query('./orcid:work-title/orcid:title', $orcidWorkNode)) == FALSE) throw new Exception('error ORCID works record'); if (($yearNodes = $publicationsXpath -> query('./orcid:publication-date/orcid:year', $orcidWorkNode)) == FALSE) throw new Exception('error ORCID works record'); if (($shortDescriptionNodes = $publicationsXpath -> query('./orcid:short-description', $orcidWorkNode)) == FALSE) throw new Exception('error ORCID works record'); if (($doiNodes = $publicationsXpath -> query('./orcid:work-external-identifiers/orcid:work-external-identifier[orcid:work-external-identifier-type = "doi"]/orcid:work-external-identifier-id', $orcidWorkNode)) == FALSE) throw new Exception('error ORCID works record'); $publication = new JObject(); $publication -> id = (($putCodeNode = $putCodeNodes -> item(0)) == NULL) ? NULL : ($orcid . '-' . trim($putCodeNode -> nodeValue)); $publication -> source = self :: ORCID; $publication -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue); $publication -> accessMode = NULL; $publication -> datasources = array(); $publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $publication -> authors = array(); $publication -> publisher = NULL; $publication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $publication -> language = NULL; $publication -> projects = array(); $publication -> embargoEndDate = NULL; $publication -> description = (($shortDescriptionNode = $shortDescriptionNodes -> item(0)) == NULL) ? NULL : trim($shortDescriptionNode -> nodeValue); if (($author -> lastName != NULL) || ($author -> firstName != NULL)) $publication -> authors[] = $author; if ((($doiNode = $doiNodes -> item(0)) != NULL) && (($doiResult = $this -> searchDOI(trim($doiNode -> nodeValue))) != NULL) && ($doiResult -> totalPublications > 0)) { // resolve via DOI if ($publication -> url == NULL) // set URL if missing $publication -> url = $doiResult -> publications[0] -> url; if ($publication -> title == NULL) // set title if missing $publication -> title = $doiResult -> publications[0] -> title; foreach ($doiResult -> publications[0] -> authors as $doiAuthor) { // merge authors if ((count($publication -> authors) == 0) || ($doiAuthor -> id != $publication -> authors[0] -> id) || ($doiAuthor -> lastName != $publication -> authors[0] -> lastName) || ($doiAuthor -> firstName != $publication -> authors[0] -> firstName) || ($doiAuthor -> fullName != $publication -> authors[0] -> fullName)) $publication -> authors[] = $doiAuthor; } if ($publication -> year == NULL) // set year if missing $publication -> year = $doiResult -> publications[0] -> year; } if (($publication -> id != NULL) || ($publication -> title != NULL) || ($publication -> authors != NULL) || ($publication -> year != NULL) || ($publication -> description != NULL)) $result -> publications[] = $publication; } $result -> totalPublications = count($result -> publications); $result -> publications = array_slice($result -> publications, ($page - 1) * $size, $size); JLog :: add('ORCID search retrieved ' . count($result -> publications) . ' publications in ' . (microtime(TRUE) - $time) . ' s (ORCID: ' . $orcid . ', page: ' . $page . ', size: ' . $size . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing ORCID search (ORCID: ' . $orcid . ', page: ' . $page . ', size: ' . $size . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } private function parseClaimedPublication($claim) { $claimedPublication = new JObject(); $claimedPublication -> date = $claim -> date; $document = new DOMDocument(); $document -> recover = TRUE; if ($document -> loadXML(trim($claim -> xml)) == FALSE) throw new Exception('invalid XML response'); $xPath = new DOMXPath($document); switch ($claim -> type) { case self :: RELATION: if ((($relationNodes = $xPath -> query('/RELATIONS/RELATION')) == FALSE) || (($relationNode = $relationNodes -> item(0)) == NULL)) throw new Exception('error parsing relation'); if ((($sourceNodes = $xPath -> query('./@source', $relationNode)) == FALSE) || (($sourceNode = $sourceNodes -> item(0)) == NULL)) throw new Exception('error parsing relation source'); if ((($targetNodes = $xPath -> query('./@target', $relationNode)) == FALSE) || (($targetNode = $targetNodes -> item(0)) == NULL)) throw new Exception('error parsing relation target'); if ((($relationTypeNodes = $xPath -> query('./@type', $relationNode)) == FALSE) || (($relationTypeNode = $relationTypeNodes -> item(0)) == NULL)) throw new Exception('error parsing relation type'); $claimedPublication -> projectId = NULL; $claimedPublication -> targetDatasetId = NULL; $claimedPublication -> targetPublicationId = NULL; $claimedPublication -> date = $claim -> date; $claimedPublication -> type = "publication"; if ($relationTypeNode -> nodeValue == "resultProject"){ $claimedPublication -> projectId = trim($targetNode -> nodeValue); } else if ($relationTypeNode -> nodeValue == "resultResult_publicationpublication_isRelatedTo"){ $sourceNode -> nodeValue = str_replace("50|", "", $sourceNode -> nodeValue); $claimedPublication -> targetPublicationId = trim(str_replace("50|", "", $targetNode -> nodeValue)); } else if ($relationTypeNode -> nodeValue == "resultResult_publicationdataset_isRelatedTo"){ $sourceNode -> nodeValue = str_replace("50|", "", $sourceNode -> nodeValue); $claimedPublication -> targetDatasetId = trim(str_replace("50|", "", $targetNode -> nodeValue)); $claimedPublication -> type = "publication"; } else { return null; } $claimedPublication -> publication = NULL; $claimedPublication -> publicationId = trim($sourceNode -> nodeValue); $claimedPublication -> userEmail = $claim -> userEmail; break; case self :: DMF: $claimedPublication -> targetDatasetId = NULL; $claimedPublication -> targetPublicationId = NULL; $claimedPublication -> date = $claim -> date; $claimedPublication -> publication = $this -> parseDMF($xPath); $claimedPublication -> publicationId = $claim->resultid; $claimedPublication -> projectId = NULL; $claimedPublication -> userEmail = $claim -> userEmail; } return $claimedPublication; } private function parseDMF($xpath) { $xpath -> registerNamespace('openaire', 'http://namespace.openaire.eu/'); $xpath -> registerNamespace('dc', 'http://purl.org/dc/elements/1.1/'); $xpath -> registerNamespace('oaf', 'http://namespace.openaire.eu/oaf'); $xpath -> registerNamespace('dr', 'http://www.driver-repository.eu/namespace/dr'); if (($identifierNodes = $xpath -> query('/record/openaire:metadata/dc:identifier')) == FALSE) throw new Exception('error parsing DMF'); if (($accessModeNodes = $xpath -> query('/record/openaire:metadata/oaf:accessrights/text()')) == FALSE) throw new Exception('error parsing DMF'); if (($titleNodes = $xpath -> query('/record/openaire:metadata/dc:title/text()')) == FALSE) throw new Exception('error parsing DMF'); if (($authorNodes = $xpath -> query('/record/openaire:metadata/dc:creator/text()')) == FALSE) throw new Exception('error parsing DMF'); if (($dateNodes = $xpath -> query('/record/openaire:metadata/dc:dateAccepted/text()')) == FALSE) throw new Exception('error parsing DMF'); if (($publisherNodes = $xpath -> query('/record/openaire:metadata/dc:publisher/text()')) == FALSE) throw new Exception('error parsing DMF'); if (($languageNodes = $xpath -> query('/record/openaire:metadata/dc:language/text()')) == FALSE) throw new Exception('error parsing DMF'); if (($typeNodes = $xpath -> query('/record/openaire:metadata/dr:CObjCategory/text()')) == FALSE) throw new Exception('error parsing DMF'); if (($descriptionNodes = $xpath -> query('/record/openaire:metadata/dc:description/text()')) == FALSE) throw new Exception('error parsing DMF'); if (($datasourceNodes = $xpath -> query('/record/openaire:metadata/oaf:hostedBy')) == FALSE) throw new Exception('error parsing DMF'); if (($collectedFromNodes = $xpath -> query('/record/openaire:metadata/oaf:collectedFrom')) == FALSE) throw new Exception('error parsing DMF'); if (($sourceNodes = $xpath -> query('/record/openaire:metadata/dc:source/text()')) == FALSE) throw new Exception('error parsing DMF'); if (($projectNodes = $xpath -> query('/record/openaire:metadata/oaf:projectid/text()')) == FALSE) throw new Exception('error parsing DMF'); $conceptNodes = $xpath -> query('/record/openaire:metadata/oaf:concept/@id'); $publication = new JObject(); $publication -> id = NULL; $publication -> source = NULL; $publication -> accessMode = (($accessModeNode = $accessModeNodes -> item(0)) == NULL) ? NULL : trim($accessModeNode -> nodeValue); $publication -> url = NULL; $publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $publication -> authors = array(); $publication -> year = (($dateNode = $dateNodes -> item(0)) == NULL) ? NULL : intval(trim($dateNode -> nodeValue)); $publication -> date = ($dateNode == NULL) ? NULL : strtotime(trim($dateNode -> nodeValue)); $publication -> publisher = (($publisherNode = $publisherNodes -> item(0)) == NULL) ? NULL : trim($publisherNode -> nodeValue); $publication -> languages = array(); $publication -> type = (($typeNode = $typeNodes -> item(0)) == NULL) ? NULL : trim($typeNode -> nodeValue); $publication -> subjects = array(); $publication -> concepts = array(); $publication -> embargoEndDate = NULL; $publication -> description = (($descriptionNode = $descriptionNodes -> item(0)) == NULL) ? NULL : trim($descriptionNode -> nodeValue); $publication -> datasources = array(); $publication -> collectedFrom = array(); $publication -> sources = array(); $publication -> projects = array(); $publication -> pids = array(); $publication -> relatedPublications = array(); $publication -> relatedDatasets = array(); $publication -> externalPublications = array(); $publication -> externalDatasets = array(); if ($conceptNodes !== false){ foreach ($conceptNodes as $conceptNode) { $publication -> concepts[] = trim($conceptNode -> nodeValue); } } foreach ($authorNodes as $authorNode) { if (($idNodes = $xpath -> query('./field[@name = "personId"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing publication'); if (($fullNameNodes = $xpath -> query('./field[@name = "fullname"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing publication'); if (($rankingNodes = $xpath -> query('./field[@name = "ranking"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing publication'); $author = new JObject(); $author -> id = NULL; $author -> lastName = NULL; $author -> firstName = NULL; $author -> fullName = trim($authorNode -> nodeValue); $author -> ranking = 0; if ($author -> fullName != NULL) $publication -> authors[] = $author; usort($publication -> authors, function ($author1, $author2) {return $author1 -> ranking - $author2 -> ranking;}); } foreach ($languageNodes as $languageNode) { if ((($language = trim($languageNode -> nodeValue)) != NULL) && ($language != self :: UNDETERMINED)) $publication -> languages[] = $language; } foreach ($datasourceNodes as $datasourceNode) { if (($idNodes = $xpath -> query('./@id', $datasourceNode)) == FALSE) throw new Exception('error parsing DMF'); if (($nameNodes = $xpath -> query('./@name', $datasourceNode)) == FALSE) throw new Exception('error parsing DMF'); $datasource = new JObject(); $datasource -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $datasource -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $datasource -> url = NULL; $datasource -> accessMode = NULL; if (($datasource -> id != NULL) || ($datasource -> name != NULL)) $publication -> datasources[] = $datasource; } foreach ($collectedFromNodes as $collectedFromNode) { if (($idNodes = $xpath -> query('./@id', $collectedFromNode)) == FALSE) throw new Exception('error parsing DMF'); if (($nameNodes = $xpath -> query('./@name', $collectedFromNode)) == FALSE) throw new Exception('error parsing DMF'); $collectedFrom = new JObject(); $collectedFrom -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $collectedFrom -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); if (($collectedFrom -> id != NULL) || ($collectedFrom -> name != NULL)) $publication -> collectedFrom[] = $collectedFrom; } foreach ($sourceNodes as $sourceNode) { if (($source = trim($sourceNode -> nodeValue)) != NULL) $publication -> sources[] = $source; } foreach ($projectNodes as $projectNode) { $project = new JObject(); $project -> id = trim($projectNode -> nodeValue); $project -> acronym = NULL; $project -> title = NULL; $project -> code = NULL; if ($project -> id != NULL) $publication -> projects[] = $project; } foreach ($identifierNodes as $identifierNode) { if (($textNodes = $xpath -> query('./text()', $identifierNode)) == FALSE) throw new Exception('error parsing DMF'); if (($typeNodes = $xpath -> query('./@identifierType', $identifierNode)) == FALSE) throw new Exception('error parsing DMF'); $pid = new JObject(); $pid -> clazz = (($typeNode = $typeNodes -> item(0)) == NULL) ? NULL : trim($typeNode -> nodeValue); $pid -> value = (($textNode = $textNodes -> item(0)) == NULL) ? NULL : trim($textNode -> nodeValue); if ($pid -> value != NULL) { if ($pid -> clazz == NULL) $publication -> url = $pid -> value; else { $publication -> id = $pid -> value; $publication -> source = $pid -> clazz; $publication -> pids[] = $pid; } } } return $publication; } private function _parseContextsConcepts($conceptNodes, &$parent, $xpath){ foreach ($conceptNodes as $conceptNode) { if (($includeNodes = $xpath -> query('./@claim', $conceptNode)) == FALSE) throw new Exception('error parsing publication'); if (($idNodes = $xpath -> query('./@id', $conceptNode)) == FALSE) throw new Exception('error parsing publication'); if (($nameNodes = $xpath -> query('./@label', $conceptNode)) == FALSE) throw new Exception('error parsing publication'); if (($subConceptNodes = $xpath -> query('./concept', $conceptNode)) == FALSE) throw new Exception('error parsing publication'); $concept = new JObject(); $concept -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $concept -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $concept -> claim = (($includeNode = $includeNodes -> item(0)) == NULL) ? NULL : trim($includeNode -> nodeValue); if ($concept -> claim != NULL){ $concept -> claim = ($concept -> claim == "true") ? true : false; } $concept -> concepts = array(); $this->_parseContextsConcepts($subConceptNodes, $concept -> concepts, $xpath); if (($concept -> id != NULL) || ($concept -> name != NULL)) $parent[$concept -> id] = $concept; } } public function parseContexts($context_source){ $document = new DOMDocument(); $document -> recover = TRUE; if ($document -> loadXML($context_source) == FALSE) throw new Exception('invalid XML response'); $xpath = new DOMXPath($document); if ((($configurationNodes = $xpath -> query('./BODY/CONFIGURATION')) == FALSE) || (($configurationNode = $configurationNodes -> item(0)) == NULL)) throw new Exception('error parsing contexts'); if (($contextNodes = $xpath -> query('./context', $configurationNode)) == FALSE) throw new Exception('error parsing contexts'); $contexts = array(); foreach ($contextNodes as $contextNode) { if (($includeNodes = $xpath -> query('./@claim', $contextNode)) == FALSE) throw new Exception('error parsing publication'); if (($idNodes = $xpath -> query('./@id', $contextNode)) == FALSE) throw new Exception('error parsing publication'); if (($nameNodes = $xpath -> query('./@label', $contextNode)) == FALSE) throw new Exception('error parsing publication'); if (($categoryNodes = $xpath -> query('./category', $contextNode)) == FALSE) throw new Exception('error parsing publication'); $context = new JObject(); $context -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $context -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $context -> claim = (($includeNode = $includeNodes -> item(0)) == NULL) ? NULL : trim($includeNode -> nodeValue); if ($context -> claim != NULL){ $context -> claim = ($context -> claim == "true") ? true : false; } $context -> categories = array(); foreach ($categoryNodes as $categoryNode) { if (($includeNodes = $xpath -> query('./@claim', $categoryNode)) == FALSE) throw new Exception('error parsing publication'); if (($idNodes = $xpath -> query('./@id', $categoryNode)) == FALSE) throw new Exception('error parsing publication'); if (($nameNodes = $xpath -> query('./@label', $categoryNode)) == FALSE) throw new Exception('error parsing publication'); if (($conceptNodes = $xpath -> query('./concept', $categoryNode)) == FALSE) throw new Exception('error parsing publication'); $category = new JObject(); $category -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $category -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $category -> claim = (($includeNode = $includeNodes -> item(0)) == NULL) ? NULL : trim($includeNode -> nodeValue); if ($category -> claim != NULL){ $category -> claim = ($category -> claim == "true") ? true : false; } $category -> concepts = array(); $this->_parseContextsConcepts($conceptNodes, $category -> concepts, $xpath); if (($category -> id != NULL) || ($category -> name != NULL) || ($category -> concepts != NULL)) $context -> categories[$category -> id] = $category; } if (($context -> id != NULL) || ($context -> name != NULL) || ($context -> categories != NULL)) $contexts[$context -> id] = $context; } return $contexts; } public function getContexts() { try { $time = microtime(TRUE); $contexts = $this -> client -> getContexts(); $contexts = $this -> parseContexts($contexts[0]); JLog :: add('Retrieved ' . count($contexts) . ' contexts in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG); return $contexts; } catch (Exception $e) { JLog :: add('Error retrieving contexts ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } }