create verb list metadata formats (ref. #181)

This commit is contained in:
Eduardo Humberto 2019-01-28 23:54:28 -02:00
parent ce180d87d6
commit 3540fa6a60
4 changed files with 97 additions and 8 deletions

View File

@ -22,6 +22,7 @@ class REST_Oaipmh_Expose_Controller extends REST_Controller {
public function init_objects() {
$this->controller_oai = new \Tainacan\OAIPMHExpose\OAIPMH_Expose();
$this->list_sets = new \Tainacan\OAIPMHExpose\OAIPMH_List_Sets();
$this->list_metadata_formats = new \Tainacan\OAIPMHExpose\OAIPMH_List_Metadata_Formats();
}
public function register_routes() {
@ -66,11 +67,17 @@ class REST_Oaipmh_Expose_Controller extends REST_Controller {
$this->list_sets->list_sets($request);
break;
case 'ListMetadataFormats':
$this->list_metadata_formats->list_metadata_formats($request);
break;
default:
$this->controller_oai->config();
$this->controller_oai->errors[] = $this->controller_oai->oai_error('noVerb');
$this->controller_oai->oai_exit( $request, $this->controller_oai->errors);
break;
}
die;
}
}

View File

@ -2,6 +2,8 @@
namespace Tainacan\OAIPMHExpose;
use Tainacan;
/**
* Support Dublin Core Mapping
* http://purl.org/dc/elements/1.1/
@ -442,13 +444,21 @@ class OAIPMH_Expose {
}
/**
* function get_metadata_formats($collection_id)
* @param int $object_id
* function get_metadata_formats
* @param int $item_id
* @return boolean
* @description metodo responsavel em verificar os tipos de metadados
* @author: Eduardo Humberto
*/
public function get_metadata_formats($object_id) {
public function get_metadata_formats( $item_id = null ) {
$types = [
'oai_dc'
];
$Tainacan_Exposers = \Tainacan\Mappers_Handler::get_instance();
$metadatum_mappers = $Tainacan_Exposers->get_mappers();
$types = array_keys($metadatum_mappers);
return $types;
}
}

View File

@ -0,0 +1,71 @@
<?php
namespace Tainacan\OAIPMHExpose;
use Tainacan\Repositories;
use Tainacan\Entities;
class OAIPMH_List_Metadata_Formats extends OAIPMH_Expose {
/** \var $working_node
* O noh que esta sendo utilizado atualmente
*/
protected $working_node;
public $errors;
public $xml_creater;
public $restoken = '-';
public $expirationdatetime;
public $num_rows;
public $cursor;
public $deliveredrecords;
public $from;
public $until;
public $sets;
public $metadataPrefix;
/**
* @signature - list_metadata_formats
* @author: Eduardo
*/
public function list_metadata_formats( $data ) {
session_write_close();
$formats = array();
$this->config();
$this->xml_creater = new Xml_Response($data);
if( isset($data['identifier']) ){// se estiver olhando por metadados de um unico objeto
$item_id = str_replace('oai:'.$this->repositoryIdentifier.':','', $data['identifier']);
$item = new \Tainacan\Entities\Item($item_id);
if( $item->get_id() && $item->get_status() =='publish' ){
$formats = $this->get_metadata_formats($item->get_id());
if(empty($formats)){
$this->errors[] = $this->oai_error('noMetadataFormats');
$this->oai_exit($data,$this->errors);
}
}else{
$this->errors[] = $this->oai_error('idDoesNotExist');
$this->oai_exit($data,$this->errors);
}
}
foreach ( $this->get_metadata_formats() as $metadata_format) {
if(!empty($formats)&&!in_array($metadata_format['metadataPrefix'], $formats)){
continue;
}
$description_node = $this->xml_creater->add2_verbNode('metadataFormat');
$this->xml_creater->addChild($description_node, 'metadataPrefix', $metadata_format);
//$this->xml_creater->addChild($description_node, 'schema', $metadata_format['schema']);
//$this->xml_creater->addChild($description_node, 'metadataNamespace', $metadata_format['metadataNamespace']);
}
header($this->CONTENT_TYPE);
if (isset($this->xml_creater)) {
$this->xml_creater->display();
} else {
exit("There is a bug in codes");
}
}
}

View File

@ -43,7 +43,6 @@ class OAIPMH_List_Sets extends OAIPMH_Expose {
$collections->the_post();
$collection = new Entities\Collection($collections->post);
array_push($response, $collection);
}
@ -93,6 +92,7 @@ class OAIPMH_List_Sets extends OAIPMH_Expose {
$this->xml_creater = new Xml_Response($data);
foreach ($collections as $collection) {
$setNode = $this->xml_creater->add2_verbNode("set");
$this->xml_creater->addChild($setNode,'setSpec',$collection->get_id());
$this->xml_creater->addChild($setNode,'setName',$collection->get_name());
@ -103,9 +103,9 @@ class OAIPMH_List_Sets extends OAIPMH_Expose {
$this->working_node->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
$this->working_node->setAttribute('xsi:schemaLocation', 'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd');
$this->xml_creater->addChild($this->working_node, 'dc:description',htmlspecialchars($collection->get_description()));
// $this->insert_xml($object);
}
//resumptionToken
$this->add_resumption_token_xml($numRows);
header($this->CONTENT_TYPE);
if (isset($this->xml_creater)) {
@ -119,8 +119,9 @@ class OAIPMH_List_Sets extends OAIPMH_Expose {
* @param $data
*/
public function initiate_variables($data) {
$query = '';
if (isset($data['resumptionToken'])) {
if (!file_exists(TOKEN_PREFIX . $data['resumptionToken'])) {
$this->errors[] = $this->oai_error('badResumptionToken', '', $data['resumptionToken']);
} else {
@ -131,7 +132,7 @@ class OAIPMH_List_Sets extends OAIPMH_Expose {
list($this->deliveredrecords, $this->from, $this->until, $this->sets, $this->metadataPrefix) = $readings;
}
}
//
} else {
$this->deliveredrecords = 0;
$this->sets = '-';