setQuery('SELECT `value` FROM `#__openaire` WHERE `key` = \'thriftConnectorHost\''); $host = $db -> loadResult(); $db -> setQuery('SELECT `value` FROM `#__openaire` WHERE `key` = \'thriftConnectorPort\''); $port = $db -> loadResult(); // Create a thrift connection (Boiler plate) $socket = new TSocket($host, $port); $socket->setRecvTimeout(10000); $this->transport = new TBufferedTransport($socket); $protocol = new TBinaryProtocol($this->transport); $this->client = new OpenAireConnectorClient($protocol); } function getSelectedDocuments() { $session =& JFactory::getSession(); $docs = $session->get('selectedDocuments', array()); $ret = array(); foreach ($docs as $doc) $ret[] = unserialize($doc); return $ret; } public function addSelectDocument($doc) { $session =& JFactory::getSession(); $selected = $session->get('selectedDocuments'); foreach ($selected as $sdoc) { if (unserialize($sdoc)->identifier == $doc->identifier) { return; } } $selected[] = serialize($doc); $session->set('selectedDocuments', $selected); } public function unselectDocument($docId) { $session =& JFactory::getSession(); $selected = $session->get('selectedDocuments'); unset($selected[$docId]); $selected = array_values($selected); $session->set('selectedDocuments', $selected); } function identifyDoi($doi) { $params = array( "noredirect" => "true", "pid" => "antleb@di.uoa.gr", "format" => "unixref", "id" => "doi:".trim($doi)); $url = "http://www.crossref.org/openurl"; $resp = trim(load($url, $params)); $doc = $this->parseCrossrefResponse($resp); if ($doc != null) { $doc->type = 'doi'; $doc->identifier = $doi; return $doc; } else { return null; } } public function reset() { $session =& JFactory::getSession(); $session->set('selectedDocuments', null); $session->set('selectedProjects', null); } public function addSelectedProject($projectInfo) { $projects = unserialize(JFactory::getSession()->get('selectedProjects', serialize(array()))); $projects[$projectInfo->projectId] = $projectInfo; JFactory::getSession()->set('selectedProjects', serialize($projects)); } public function removeSelectedProject($projectId) { $projects = unserialize(JFactory::getSession()->get('selectedProjects'), serialize(array())); if ($projects != null) { unset($projects[$projectId]); } JFactory::getSession()->set('selectedProjects', serialize($projects)); } public function getSelectedProjects() { $projects = unserialize(JFactory::getSession()->get('selectedProjects', serialize(array()))); return $projects; } public function getClaimedDocuments() { $email = JFactory::getUser()->email; // Open up the connection $this->transport->open(); // submit the docs $list = $this->client->getClaimedDocuments($email); $this->transport->close(); return $list; } public function getAllClaimedDocuments($from, $to) { // Open up the connection $this->transport->open(); // submit the docs $list = $this->client->getAllClaimedDocuments($from, $to); $this->transport->close(); return $list; } public function submitClaimedDocuments() { $selectedDocuments = $this->getSelectedDocuments(); $claims = array(); foreach ($selectedDocuments as $sDoc) { $cDoc = new ClaimedDocument; $fields = get_object_vars($sDoc->fields); // 1-1 from local->thrift $cDoc->title = $sDoc->title; $cDoc->description = $fields['Description'][0]; $cDoc->language = $fields['Language(s)'][0]; $cDoc->repositoryName = $fields['Repository'][0]; $cDoc->publicationDate = $fields['Publication Date(s)'][0]; // n-1 from local to thrift $cDoc->publisher = isset($fields['Publisher(s)'])?$fields['Publisher(s)'][0]:null; foreach ($fields['Subject(s)'] as $subj) $cDoc->subjects = $subj.', '; // n-n foreach ($fields['Author(s)'] as $author) $cDoc->authors[] = $author; // meta info foreach ($this->getSelectedProjects() as $proj) { $projInfo = new ShortProjectInfo; $projInfo->projectId = $proj->projectId; $cDoc->projects[] = $projInfo; } $cDoc->accessMode = $sDoc->accessRights; $cDoc->embargoEndDate = $sDoc->embargoEndDate; $claims[] = $cDoc; } /* public $email = null; public $firstName = null; public $lastName = null; */ $juser = JFactory::getUser(); $userInfo = new UserInfo; $userInfo->email = $juser->email; $userInfo->lastName = $juser->name; // Open up the connection $this->transport->open(); // submit the docs $this->client->claimDocuments($userInfo, $claims); $this->transport->close(); } private function parseCrossrefResponse($xml) { $xmldoc = new SimpleXMLElement(str_replace('xmlns=', 'ns=', $xml)); if (count ($xmldoc->xpath("/doi_records")) > 0) { if (count ($xmldoc->xpath("//doi_record/crossref/joornal")) > 0) { $doc = new DocumentInfo; $res = $xmldoc->xpath('//journal_article//titles/title'); while(list( , $node) = each($res)) { $doc->title = (string) $node; } $res = $xmldoc->xpath("//journal_article//contributors/person_name[@contributor_role='author']"); while(list( , $node) = each($res)) { $name = ((string)$node->surname).", ".((string)$node->given_name); $doc->fields['Author(s)'][] = $name; } $res = $xmldoc->xpath('//journal_article/publication_date/year'); while(list( , $node) = each($res)) { $doc->fields['Publication Date'][] = (string) $node; } $res = $xmldoc->xpath('//doi_data/resource'); while(list( , $node) = each($res)) { $doc->fields['Url'][] = (string) $node; } return $doc; } else if (count ($xmldoc->xpath("//doi_record/crossref/book")) > 0) { $doc = new DocumentInfo; $res = $xmldoc->xpath('//content_item//titles/title'); while(list( , $node) = each($res)) { $doc->title = (string) $node; } $res = $xmldoc->xpath("//content_item//contributors/person_name[@contributor_role='author']"); while(list( , $node) = each($res)) { $name = ((string)$node->surname).", ".((string)$node->given_name); $doc->fields['Author(s)'][] = $name; } $res = $xmldoc->xpath('//content_item/publication_date/year'); while(list( , $node) = each($res)) { $doc->fields['Publication Date'][] = (string) $node; } $res = $xmldoc->xpath('//doi_data/resource'); while(list( , $node) = each($res)) { $doc->fields['Url'][] = (string) $node; } return $doc; } else { return null; } } else { return null; } } public function parseSearchResult($fields) { $doc = new DocumentInfo; foreach ($fields as $field) { switch (trim($field['name'])) { case '${title}': if (count($field['values']) > 0) $doc->title = $field['values'][0]['displayValue']; else $doc->title = "-"; break; // multiple value fields case 'Author(s)': case 'Publisher(s)': case 'Subject(s)': foreach ($field['values'] as $value) { $name = trim($value['displayValue']); $doc->fields[$field['name']][] = $name; } break; // single value fields case 'Language(s)': case 'Description': case 'Repository': case 'Publication Date(s)': if (count($field['values']) > 0) $doc->fields[$field['name']][] = trim($field['values'][0]['displayValue']); else $doc->fields[$field['name']][] = "-"; break; } } $doc->type = "driver"; $doc->identifier = "$doc->title"; return $doc; } } ?>