Merge branch 'develop' into feature/facets_ES

This commit is contained in:
Mateus Machado Luna 2019-02-28 16:38:49 -03:00
commit 679ae1dc25
14 changed files with 217 additions and 35 deletions

View File

@ -34,7 +34,8 @@
v-if="formHooks != undefined &&
formHooks['collection'] != undefined &&
formHooks['collection']['begin-left'] != undefined">
<form
<form
class="form-hook-region"
id="form-collection-begin-left"
v-html="this.formHooks['collection']['begin-left'].join('')"/>
</template>
@ -245,6 +246,7 @@
<form
ref="form-collection-end-left"
id="form-collection-end-left"
class="form-hook-region"
v-html="formHooks['collection']['end-left'].join('')"/>
</template>
@ -319,6 +321,7 @@
formHooks['collection']['begin-right'] != undefined">
<form
id="form-collection-begin-right"
class="form-hook-region"
v-html="formHooks['collection']['begin-right'].join('')"/>
</template>
@ -430,6 +433,7 @@
formHooks['collection']['end-right'] != undefined">
<form
id="form-collection-end-right"
class="form-hook-region"
v-html="formHooks['collection']['end-right'].join('')"/>
</template>
</div>

View File

@ -30,6 +30,7 @@
formHooks['filter']['begin-left'] != undefined">
<form
id="form-filter-begin-left"
class="form-hook-region"
v-html="formHooks['filter']['begin-left'].join('')"/>
</template>
@ -152,6 +153,7 @@
formHooks['filter']['end-left'] != undefined">
<form
id="form-filter-end-left"
class="form-hook-region"
v-html="formHooks['filter']['end-left'].join('')"/>
</template>
</div>

View File

@ -44,6 +44,7 @@
formHooks['item']['begin-left'] != undefined">
<form
id="form-item-begin-left"
class="form-hook-region"
v-html="formHooks['item']['begin-left'].join('')"/>
</template>
@ -349,6 +350,7 @@
formHooks['item']['end-left'] != undefined">
<form
id="form-item-end-left"
class="form-hook-region"
v-html="formHooks['item']['end-left'].join('')"/>
</template>
@ -362,6 +364,7 @@
formHooks['item']['begin-right'] != undefined">
<form
id="form-item-begin-right"
class="form-hook-region"
v-html="formHooks['item']['begin-right'].join('')"/>
</template>
@ -438,6 +441,7 @@
formHooks['item']['end-right'] != undefined">
<form
id="form-item-end-right"
class="form-hook-region"
v-html="formHooks['item']['end-right'].join('')"/>
</template>
</div>

View File

@ -31,6 +31,7 @@
formHooks['metadatum']['begin-left'] != undefined">
<form
id="form-metadatum-begin-left"
class="form-hook-region"
v-html="formHooks['metadatum']['begin-left'].join('')"/>
</template>
@ -223,6 +224,7 @@
formHooks['metadatum']['end-left'] != undefined">
<form
id="form-metadatum-end-left"
class="form-hook-region"
v-html="formHooks['metadatum']['end-left'].join('')"/>
</template>
</div>

View File

@ -38,6 +38,7 @@
formHooks['taxonomy']['begin-left'] != undefined">
<form
id="form-taxonomy-begin-left"
class="form-hook-region"
v-html="formHooks['taxonomy']['begin-left'].join('')"/>
</template>
@ -145,6 +146,7 @@
formHooks['taxonomy']['end-left'] != undefined">
<form
id="form-taxonomy-end-left"
class="form-hook-region"
v-html="formHooks['taxonomy']['end-left'].join('')"/>
</template>

View File

@ -70,6 +70,7 @@
formHooks['term']['begin-left'] != undefined">
<form
id="form-term-begin-left"
class="form-hook-region"
v-html="formHooks['term']['begin-left'].join('')"/>
</template>
@ -139,6 +140,7 @@
formHooks['term']['end-left'] != undefined">
<form
id="form-term-end-left"
class="form-hook-region"
v-html="formHooks['term']['end-left'].join('')"/>
</template>

View File

@ -31,6 +31,7 @@
formHooks['view-item']['begin-left'] != undefined">
<div
id="view-item-begin-left"
class="form-hook-region"
v-html="formHooks['view-item']['begin-left'].join('')"/>
</template>
@ -197,6 +198,7 @@
formHooks['view-item']['end-left'] != undefined">
<div
id="view-item-end-left"
class="form-hook-region"
v-html="formHooks['view-item']['end-left'].join('')"/>
</template>
@ -210,6 +212,7 @@
formHooks['view-item']['begin-right'] != undefined">
<div
id="view-item-begin-right"
class="form-hook-region"
v-html="formHooks['view-item']['begin-right'].join('')"/>
</template>
@ -306,6 +309,7 @@
formHooks['view-item']['end-right'] != undefined">
<div
id="view-item-end-right"
class="form-hook-region"
v-html="formHooks['view-item']['end-right'].join('')"/>
</template>
</b-tab-item>

View File

@ -122,4 +122,20 @@
white-space: initial !important;
}
}
.form-hook-region {
background-color: $gray1;
padding: 1rem 1.875rem 2rem 1.875rem;
h4 {
font-weight: 600;
color: #298596;
margin-bottom: 6px;
}
hr {
margin-top: 8px;
height: 1px;
background-color: #298596;
}
}
}

View File

@ -16,6 +16,7 @@
.tainacan-grid-item {
max-width: 255px;
min-height: 300px;
max-height: 300px;
flex-basis: 0;
margin: 15px;
text-align: center;

View File

@ -52,14 +52,14 @@ class Importer_Handler {
'manual_mapping' => false,
]);
// $this->register_importer([
// 'name' => 'OAI PMH',
// 'description' => __('Import structure from a OAI PMH repository', 'tainacan'),
// 'slug' => 'oaipmh_importer',
// 'class_name' => '\Tainacan\Importer\Oaipmh_Importer',
// 'manual_collection' => false,
// 'manual_mapping' => false,
// ]);
$this->register_importer([
'name' => 'OAI PMH',
'description' => __('Import structure from a OAI PMH repository', 'tainacan'),
'slug' => 'oaipmh_importer',
'class_name' => '\Tainacan\Importer\Oaipmh_Importer',
'manual_collection' => false,
'manual_mapping' => false,
]);
do_action('tainacan_register_importers');

View File

@ -10,7 +10,13 @@ class Oaipmh_Importer extends Importer {
'name' => 'Create Collections',
'progress_label' => 'Create Collections',
'callback' => 'create_collections'
]
],
[
'name' => 'Import Items',
'progress_label' => 'Import Items',
'callback' => 'process_collections',
'total' => 2
],
];
protected $tainacan_api_address, $wordpress_api_address, $actual_collection;
@ -36,7 +42,71 @@ class Oaipmh_Importer extends Importer {
* @return int
*/
public function process_item( $index, $collection_id ){
return true;
$this->add_log('Proccess item index' . $index . ' in set ' . $collection_id['source_id'] );
$records = [ 'records' => [] , 'collection_definition' => $collection_id ];
$record_processed = [];
if( $index === 0 ){
$info = $this->requester( $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc&set=" . $collection_id['source_id'] );
} else {
$token = $this->get_transient('resumptionToken');
$info = $this->requester( $this->get_url() . "?verb=ListRecords&resumptionToken=" . $token);
}
if( !isset($info['body']) ){
$this->add_log('no answer');
return false;
}
try {
$xml = new \SimpleXMLElement($info['body']);
if ( isset($xml->ListRecords) && isset($xml->ListRecords->resumptionToken) ){
$resumptionToken = $xml->ListRecords->resumptionToken;
if ($resumptionToken) {
$this->add_transient('resumptionToken',(string) $resumptionToken);
}
}
} catch (Exception $e) {
$this->add_log('error on read xml and get ');
return false;
}
if( $xml->ListRecords ){
$size = count($xml->ListRecords->record); // verifico o tamanho dos list record para o for
for ($j = 0; $j < $size; $j++) {
$record = $record = $xml->ListRecords->record[$j];
$dc = $record->metadata->children("http://www.openarchives.org/OAI/2.0/oai_dc/");
if ($record->metadata->Count() > 0 ) {
$metadata = $dc->children('http://purl.org/dc/elements/1.1/');
$tam_metadata = count($metadata);
for ($i = 0; $i < $tam_metadata; $i++) {
$value = (string) $metadata[$i];
$identifier = $this->get_identifier($metadata[$i]);
$record_processed['dc:' . $identifier ][] = $value;
}
}
if( $record_processed ){
$records['records'][] = $record_processed;
$record_processed = [];
}
}
}
if( $records['records'] ){
return $records;
} else {
$this->add_log('proccessing an item empty');
return false;
}
}
/**
@ -59,12 +129,13 @@ class Oaipmh_Importer extends Importer {
$metadata_map = $this->create_collection_metadata($collection);
$total = intval($this->get_total_items_from_source($setSpec));
$this->add_log('total in collection: ' . $total);
$this->add_log('collection id ' . (string) $collection->get_id());
$this->add_collection([
'id' => $collection->get_id(),
'mapping' => $metadata_map,
'total_items' => $total,
'source_id' => $setSpec
'total_items' =>ceil( $total / 100 ),
'source_id' => $setSpec,
]);
}
}
@ -72,8 +143,86 @@ class Oaipmh_Importer extends Importer {
return false;
}
/**
* insert processed item from source to Tainacan
*
* @param array $processed_item Associative array with metadatum source's as index with
* its value or values
* @param integet $collection_index The index in the $this->collections array of the collection the item is beeing inserted into
*
* @return Tainacan\Entities\Item Item inserted
*/
public function insert( $processed_item, $collection_index ) {
$this->items_repo->disable_logs();
$records = $processed_item['records'];
$collection_id = $processed_item['collection_definition'];
$collection = new Entities\Collection($collection_id['id']);
$map = $collection_id['mapping'];
foreach ( $records as $record ) {
$item = new Entities\Item();
$item->set_status('publish');
$item->set_collection( $collection );
$item->set_title( ( isset($record['dc:title']) ) ? $record['dc:title'][0] : 'title' );
$item->set_description( '' );
$this->add_log( ( isset($record['dc:title']) ) ? $record['dc:title'][0] : 'title' );
if( $record && $item->validate() ){
$insertedItem = $this->items_repo->insert( $item );
foreach ( $record as $index => $value ){
$this->add_log( $index . ' ' . serialize($map) );
$this->add_log( $insertedItem->get_id() );
if( in_array( $index, $map ) && $insertedItem->get_id()){
$metadatum_id = array_search($index, $map );
$newMetadatum = new Entities\Metadatum($metadatum_id);
$item_metadata = new Entities\Item_Metadata_Entity( $insertedItem, $newMetadatum );
$unique = !$item_metadata->is_multiple();
$value_final = ( is_array($value) && $unique ) ? $value[0] : $value;
$item_metadata->set_value($value_final);
if( $item_metadata->validate() ){
$inserted = $this->item_metadata_repo->insert( $item_metadata );
$this->add_log('Item Metadata inserted for item ' .$item->get_title() . ' and metadata ' . $newMetadatum->get_name() );
} else {
$this->add_log( 'Error inserting metadatum' . $newMetadatum->get_name() );
$this->add_log( 'Values' . $value );
$this->add_log( $item_metadata->get_errors() );
}
}
}
} else {
$this->add_log( (is_array($item->get_errors())) ? serialize($item->get_errors()) : $item->get_errors() );
}
}
return isset($insertedItem) ? $insertedItem : false;
}
//protected functions
/**
* @signature - get_identifyier($metadata)
* @param \SimpleXMLElement $metadata
* @return string O identifier
*/
protected function get_identifier($metadata) {
$attributes = $metadata->attributes(); // atributos
if ($attributes) {
foreach ($attributes as $a => $b) {
return $metadata->getName().'_'.(string) $b;
}
} else {
return $metadata->getName();
}
}
/**
* Method implemented by the child importer class to return the number of items to be imported
* @return int
@ -92,17 +241,14 @@ class Oaipmh_Importer extends Importer {
$xml = new \SimpleXMLElement($info['body']);
if( isset($xml->ListRecords) && !isset($xml->ListRecords->resumptionToken) ){
$this->add_log('NO resumptiontoken ');
$cont = 0;
foreach ($xml->ListRecords->record as $record) $cont++;
return $cont;
} elseif ( isset($xml->ListRecords) && !isset($xml->ListRecords->resumptionToken) ){
} elseif ( isset($xml->ListRecords) && isset($xml->ListRecords->resumptionToken) ){
$resumptionToken_attributes = $xml->ListRecords->resumptionToken->attributes();
foreach ($resumptionToken_attributes as $tag => $attribute) {
$this->add_log('resumptiontoken: ' . (string) $tag . ' ' . (string) $attribute );
if ($tag == 'completeListSize') {
return (string) $attribute;
}
@ -113,7 +259,6 @@ class Oaipmh_Importer extends Importer {
return 0;
}
$this->add_log('SKIP');
return 0;
}

View File

@ -97,16 +97,16 @@ export default {
this.$route.query.orderby = 'author_name';
} else if (orderBy.metadata_type_object.primitive_type == 'float' || orderBy.metadata_type_object.primitive_type == 'int') {
this.$route.query.orderby = 'meta_value_num';
this.$route.query.meta_key = orderBy.id;
this.$route.query.metakey = orderBy.id;
} else if (orderBy.metadata_type_object.primitive_type == 'date') {
this.$route.query.orderby = 'meta_value';
this.$route.query.meta_key = orderBy.id;
this.$route.query.meta_type = 'DATETIME';
this.$route.query.metakey = orderBy.id;
this.$route.query.metatype = 'DATETIME';
} else if (orderBy.metadata_type_object.core) {
this.$route.query.orderby = orderBy.metadata_type_object.related_mapped_prop;
} else {
this.$route.query.orderby = 'meta_value';
this.$route.query.meta_key = orderBy.id;
this.$route.query.metakey = orderBy.id;
}
} else {

View File

@ -85,28 +85,28 @@ export const setOrderBy = ({ state, commit }, orderBy ) => {
// Primitive Types: string, date, item, term, compound, float
if (orderBy.slug == 'creation_date') {
commit('setPostQueryAttribute', { attr: 'orderby', value: 'date' } );
commit('removePostQueryAttribute', 'meta_key');
commit('removePostQueryAttribute', 'meta_type');
commit('removePostQueryAttribute', 'metakey');
commit('removePostQueryAttribute', 'metatype');
} else if (orderBy.slug == 'author_name') {
commit('setPostQueryAttribute', { attr: 'orderby', value: 'author_name' } );
commit('removePostQueryAttribute', 'meta_key');
commit('removePostQueryAttribute', 'meta_type');
commit('removePostQueryAttribute', 'metakey');
commit('removePostQueryAttribute', 'metatype');
} else if (orderBy.metadata_type_object.primitive_type == 'float' || orderBy.metadata_type_object.primitive_type == 'int') {
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value_num' } );
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
commit('removePostQueryAttribute', 'meta_type');
commit('setPostQueryAttribute', { attr: 'metakey', value: orderBy.id } );
commit('removePostQueryAttribute', 'metatype');
} else if (orderBy.metadata_type_object.primitive_type == 'date') {
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value' } );
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
commit('setPostQueryAttribute', { attr: 'meta_type', value: 'DATETIME' } );
commit('setPostQueryAttribute', { attr: 'metakey', value: orderBy.id } );
commit('setPostQueryAttribute', { attr: 'metatype', value: 'DATETIME' } );
} else if (orderBy.metadata_type_object.core) {
commit('setPostQueryAttribute', { attr: 'orderby', value: orderBy.metadata_type_object.related_mapped_prop } );
commit('removePostQueryAttribute', 'meta_key');
commit('removePostQueryAttribute', 'meta_type');
commit('removePostQueryAttribute', 'metakey');
commit('removePostQueryAttribute', 'metatype');
} else {
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value' } );
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
commit('removePostQueryAttribute', 'meta_type');
commit('setPostQueryAttribute', { attr: 'metakey', value: orderBy.id } );
commit('removePostQueryAttribute', 'metatype');
}
commit('setOrderByName', orderBy.name);

View File

@ -69,7 +69,7 @@ export const getOrderByName = state => {
};
export const getMetaKey = state => {
return state.postquery.meta_key;
return state.postquery.metakey;
};
export const getFetchOnlyMeta = state => {