예제 #1
0
 /**
  * @see DOIExportPlugin::registerDoi()
  */
 function registerDoi(&$request, &$journal, &$object, $filename)
 {
     $shoulder = $this->getSetting($journal->getId(), 'shoulder');
     // Transmit CrossRef XML metadata.
     assert(is_readable($filename));
     $payload = file_get_contents($filename);
     assert($payload !== false && !empty($payload));
     // we only consider articles and issues here
     $result = true;
     if (is_a($object, 'PublishedArticle') || is_a($object, 'Issue')) {
         $input = "_profile: crossref" . PHP_EOL;
         $input .= "crossref: " . $this->_doiMetadataEscape($payload) . PHP_EOL;
         // TODO: SHOW BOTH DATACITE METADATA AS WELL
         //5 required datacite fields:
         $input .= "datacite.creator: ";
         if (is_a($object, 'PublishedArticle')) {
             foreach ($object->getAuthors() as $author) {
                 $input .= $author->getLastName() . ", " . $author->getFirstName() . " " . $author->getMiddleName() . "; ";
             }
         }
         $input .= PHP_EOL;
         $input .= "datacite.title: " . $object->getLocalizedTitle() . PHP_EOL;
         $input .= "datacite.publisher: " . $journal->getSetting('publisherInstitution') . PHP_EOL;
         $input .= "datacite.publicationyear: " . date('Y', strtotime($object->getDatePublished())) . PHP_EOL;
         $input .= "datacite.resourcetype: " . $object->getLocalizedData('type') . PHP_EOL;
         if ($object->getData('ezid::registeredDoi')) {
             $webServiceRequest = new WebServiceRequest(EZID_API_CRUD_URL . $object->getData('ezid::registeredDoi'), $input, 'POST');
             $expectedResponse = EZID_API_RESPONSE_OK;
         } else {
             $webServiceRequest = new WebServiceRequest(EZID_API_MINT_URL . $shoulder, $input, 'POST');
             $expectedResponse = EZID_API_RESPONSE_CREATED;
         }
         $webServiceRequest->setHeader('Content-Type', 'text/plain; charset=UTF-8');
         $webServiceRequest->setHeader('Content-Length', strlen($input));
         $webService = new WebService();
         $username = $this->getSetting($journal->getId(), 'username');
         $password = $this->getSetting($journal->getId(), 'password');
         $webService->setAuthUsername($username);
         $webService->setAuthPassword($password);
         $response =& $webService->call($webServiceRequest);
         if ($response === false) {
             $result = array(array('plugins.importexport.common.register.error.mdsError', __('plugins.importexport.ezid.error.webserviceNoResponse')));
         } else {
             if ($response === NULL) {
                 $result = array(array('plugins.importexport.ezid.error.webserviceInvalidRequest'));
             } else {
                 $status = $webService->getLastResponseStatus();
                 if ($status != $expectedResponse) {
                     $result = array(array('plugins.importexport.common.register.error.mdsError', "{$status} - " . htmlentities($response)));
                 }
             }
         }
     } else {
         return false;
     }
     if ($result === true) {
         # trim off "success: doi:"
         $trimmed_body = preg_replace('/(success: doi:)/', '', $response);
         if (strstr($trimmed_body, ' | ark:') !== FALSE) {
             list($doi, $ark) = explode(' | ark:', $trimmed_body, 2);
             $ark = 'ark:' . $ark;
         } else {
             $doi = $trimmed_body;
             $ark = '';
         }
         if (is_a($object, 'Issue')) {
             $dao =& DAORegistry::getDAO('IssueDAO');
             $dao->changePubId($object->getId(), 'doi', $doi);
             $object->setStoredPubId('doi', $doi);
         } elseif (is_a($object, 'Article')) {
             $dao =& DAORegistry::getDAO('ArticleDAO');
             $dao->changePubId($object->getId(), 'doi', $doi);
             $object->setStoredPubId('doi', $doi);
         }
         // Mark the object as registered.
         $this->markRegistered($request, $object, $shoulder);
     }
     return $result;
 }
예제 #2
0
 /**
  * Make a request
  *
  * @param $url string The request URL
  * @param $params mixed array (key value pairs) or string request parameters
  * @param $method string GET or POST
  *
  * @return DOMXPath An XPath object with the response loaded. Null if an error occurred.
  *  See _serviceMessage for more details about the error.
  */
 function &_makeRequest($url, $params = array(), $method = 'GET')
 {
     $webServiceRequest = new WebServiceRequest($url, $params, $method);
     if ($method == 'POST') {
         $webServiceRequest->setHeader('Content-Type', 'text/xml; charset=utf-8');
     }
     $this->setReturnType(XSL_TRANSFORMER_DOCTYPE_DOM);
     $response = $this->call($webServiceRequest);
     $nullValue = null;
     // Did we get a response at all?
     if (!$response) {
         $this->_serviceMessage = __('plugins.generic.lucene.message.searchServiceOffline');
         return $nullValue;
     }
     // Did we get a "200 - OK" response?
     $status = $this->getLastResponseStatus();
     if ($status !== WEBSERVICE_RESPONSE_OK) {
         // We show a generic error message to the end user
         // to avoid information leakage and log the exact error.
         $application = PKPApplication::getApplication();
         error_log($application->getName() . ' - Lucene plugin:' . PHP_EOL . "The Lucene web service returned a status code {$status} and the message" . PHP_EOL . $response->saveXML());
         $this->_serviceMessage = __('plugins.generic.lucene.message.webServiceError');
         return $nullValue;
     }
     // Prepare an XPath object.
     assert(is_a($response, 'DOMDocument'));
     $result = new DOMXPath($response);
     // Return the result.
     return $result;
 }
예제 #3
0
 /**
  * Call web service with the given parameters
  * @param $url string
  * @param $params array GET or POST parameters
  * @param $method string (optional)
  * @return JSON or null in case of error
  */
 function &_callWebService($url, &$params, $method = 'GET')
 {
     // Create a request
     if (!is_array($params)) {
         $params = array();
     }
     $params['api_key'] = $this->_apiKey;
     $webServiceRequest = new WebServiceRequest($url, $params, $method);
     // Can't strip slashes from the result, we have a JSON
     // response with escaped characters.
     $webServiceRequest->setCleanResult(false);
     // Configure and call the web service
     $webService = new WebService();
     $result =& $webService->call($webServiceRequest);
     return $result;
 }