Skip to content
This repository has been archived by the owner on Jul 17, 2019. It is now read-only.

Commit

Permalink
Restructure derivative assets (thumbnails/previews) to be stored as c…
Browse files Browse the repository at this point in the history
…hildren of the parent original asset. Allow for category to be loaded without associated items.
  • Loading branch information
haydenyoung committed Jan 9, 2019
1 parent 22de509 commit 8c18199
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 62 deletions.
2 changes: 1 addition & 1 deletion build.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ id=dspace
src=.
path.joomla=/var/www/html/
package.extensions=
package.version=1.0.2
package.version=1.1.0
6 changes: 3 additions & 3 deletions manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<element>plg_jcar_dspace</element>
<type>plugin</type>
<folder>jcar</folder>
<version>1.0.2</version>
<version>1.1.0</version>
<client>site</client>
<infourl title="JCar DSpace Plugin">https://github.com/knowledgearcdotorg/jcar-dspace-plugin/releases/tag/1.0.2</infourl>
<infourl title="JCar DSpace Plugin">https://github.com/knowledgearcdotorg/jcar-dspace-plugin/releases/tag/1.1.0</infourl>
<downloads>
<downloadurl type="full" format="zip">https://github.com/knowledgearcdotorg/jcar-dspace-plugin/releases/download/1.0.2/plg_jcar_dspace.zip</downloadurl>
<downloadurl type="full" format="zip">https://github.com/knowledgearcdotorg/jcar-dspace-plugin/releases/download/1.1.0/plg_jcar_dspace.zip</downloadurl>
</downloads>
<tags>
<tag>stable</tag>
Expand Down
128 changes: 84 additions & 44 deletions plugins/jcar/dspace/dspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,16 @@ public function onJCarCategoriesRetrieve()
* category and paging information to allow for browsing across the entire
* recordset.
*
* @return A DSpace collection's information, the items within the
* @param int $id The id of an item to retrieve from the
* DSpace archive.
* @param bool $loadItems True if items should be loaded, false
* otherwises. Defaults to true.
*
* @return stdClass A DSpace collection's information, the items within the
* category and paging information to allow for browsing across the entire
* recordset.
*/
public function onJCarCategoryRetrieve($id)
public function onJCarCategoryRetrieve($id, $loadItems = true)
{
$category = null;

Expand All @@ -104,8 +109,11 @@ public function onJCarCategoryRetrieve($id)
$data = json_decode($response->body);

$category = $this->parseCollection($data);
$category->items = $this->getItems($id);
$category->pagination = $this->getPagination();

if ($loadItems) {
$category->items = $this->getItems($id);
$category->pagination = $this->getPagination($id);
}
} else {
JLog::add(print_r($response, true), JLog::DEBUG, 'jcardspace');

Expand Down Expand Up @@ -284,7 +292,7 @@ public function getCommunity($id)

$id = JCarHelper::parseId($id);

$endpoint = '/communities/'.(int)$id.'.json?collections=true';
$endpoint = '/communities/'.(int)$id.'.json?collections=true&children=true';
$url = $this->params->get('rest_url').$endpoint;

JLog::add($url, JLog::DEBUG, 'jcardspace');
Expand Down Expand Up @@ -321,10 +329,10 @@ private function parseCommunity($community)
$community->copyright = $community->copyrightText;

for ($i = 0; $i < count($community->subCommunities); $i++) {
$subCommunity = ArrayHelper($community->subCommunities, $i);
$subCommunity = ArrayHelper::getValue($community->subCommunities, $i);
$subCommunity = $this->parseCommunity($subCommunity);

$community->subCommunities[$i] = subCommunity;
$community->subCommunities[$i] = $subCommunity;
}

for ($i = 0; $i < count($community->collections); $i++) {
Expand All @@ -341,9 +349,9 @@ private function parseCommunity($community)
* Parses a DSpace collection, adding additional content to the collection
* object.
*
* @param stdClass $collection The collection to parse.
* @param stdClass $collection The collection to parse.
*
* @return stdClass A DSpace collection with additional content.
* @return stdClass A DSpace collection with additional content.
*
* @throws Exception Thrown if the API endpoint does not return the html
* code 200.
Expand Down Expand Up @@ -380,17 +388,17 @@ private function parseCollection($collection)
* Gets a list of items based on a collection from the REST API-enabled
* DSpace archive.
*
* @param int $cid The id of a collection.
* @param int $cid The id of a collection.
*
* @return mixed An item from the REST API-enabled DSpace archive, or
* @return mixed An item from the REST API-enabled DSpace archive, or
* null if nothing could be found.
*
* @throws Exception Thrown if the API endpoint does not return the html
* code 200.
*/
private function getItems($cid)
{
$pagination = $this->getPagination();
$pagination = $this->getPagination($cid);

$items = array();

Expand Down Expand Up @@ -453,12 +461,12 @@ private function getItemsCount($cid)
return 0;
}

private function getPagination()
private function getPagination($id)
{
$app = JFactory::getApplication();

// @TODO these should be passed as method params.
$total = $this->getItemsCount($app->input->getInt('id'));
$total = $this->getItemsCount($id);
$start = $app->input->getInt('limitstart', 0);
$limit = $app->input->getInt('limit', 20);

Expand All @@ -476,15 +484,13 @@ private function getPagination()
*/
private function getBundles($item)
{
$hierarchicalBitstreams = [];

$url = $this->params->get('rest_url');
$url .= '/items/'.$item.'/bundles.json';

$url = new JUri($url);

if ($showBundles = $this->params->get('show_bundles', null)) {
$url->setVar('type', $showBundles);
}

JLog::add($url, JLog::DEBUG, 'jcardspace');

$http = JHttpFactory::getHttp();
Expand All @@ -495,39 +501,48 @@ private function getBundles($item)

for ($i = 0; $i < count($bundles); $i++) {
$bundle = ArrayHelper::getValue($bundles, $i);
$bitstreams = $bundle->bitstreams;

for ($j = 0; $j < count($bitstreams); $j++) {
$bitstream = ArrayHelper::getValue($bitstreams, $j);

if ($this->isBitstreamAccessible($bitstream)) {
if ((bool)$this->params->get('stream')) {
$url = new JUri('index.php');

$url->setQuery(
array(
'option'=>'com_jcar',
'view'=>'asset',
'format'=>'raw',
'id'=>$this->_name.':'.$bitstream->id,
'name'=>$bitstream->name,
'Itemid'=>JFactory::getApplication()->input->getInt('Itemid')));

if ($bundle->name != 'THUMBNAIL' && $bundle->name != 'TEXT') {
$bitstreams = $bundle->bitstreams;

for ($j = 0; $j < count($bitstreams); $j++) {
$bitstream = ArrayHelper::getValue($bitstreams, $j);

if ($this->isBitstreamAccessible($bitstream)) {
if ((bool)$this->params->get('stream')) {
$url = new JUri('index.php');

$url->setQuery(
array(
'option'=>'com_jcar',
'view'=>'asset',
'format'=>'raw',
'id'=>$this->_name.':'.$bitstream->id,
'name'=>$bitstream->name,
'Itemid'=>JFactory::getApplication()->input->getInt('Itemid')));
} else {
$url = new JUri(
$this->params->get('rest_url').
'/bitstreams/'.
$bitstream->id.
'/download');
}

$bitstream->url = (string)$url;

if ($bundles[$i]->name == 'ORIGINAL') {
$bitstream->derivatives = $this->getDerivatives($bundles, $bundles[$i]);
}
} else {
$url = new JUri(
$this->params->get('rest_url').
'/bitstreams/'.
$bitstream->id.
'/download');
$bitstream->url = null;
}

$bundles[$i]->bitstreams[$j]->url = (string)$url;
} else {
$bundles[$i]->bitstreams[$j]->url = null;
$hierarchicalBitstreams[$bundle->name][] = $bitstream;
}
}
}

return $bundles;
return $hierarchicalBitstreams;
} else {
JLog::add(print_r($response, true), JLog::DEBUG, 'jcardspace');

Expand All @@ -537,6 +552,31 @@ private function getBundles($item)
}
}

private function getDerivatives($bundles, $original)
{
$derivatives = [];

foreach ($bundles as $bundle) {
if ($bundle->name == 'THUMBNAIL' || $bundle->name == 'TEXT') {
$fileInfo = pathinfo($bundle->bitstreams[0]->name);

if (strcmp($original->bitstreams[0]->name, $fileInfo['filename']) === 0) {
$url = new JUri(
$this->params->get('rest_url').
'/bitstreams/'.
$bundle->bitstreams[0]->id.
'/download');

$bundle->bitstreams[0]->url = (string)$url;

$derivatives[$bundle->name] = $bundle->bitstreams[0];
}
}
}

return $derivatives;
}

private function isBitstreamAccessible($bitstream)
{
$url = new JUri(
Expand Down
14 changes: 3 additions & 11 deletions plugins/jcar/dspace/dspace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<extension version="3.3" type="plugin" group="jcar" method="upgrade">
<name>plg_jcar_dspace</name>
<author>KnowledgeArc</author>
<creationDate>2016-11-29</creationDate>
<copyright>Copyright (C) 2015-2016 KnowledgeArc Ltd. All rights reserved.</copyright>
<creationDate>2019-01-09</creationDate>
<copyright>Copyright (C) 2015-2019 KnowledgeArc Ltd. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.knowledgearc.org</authorUrl>
<version>1.0.2</version>
<version>1.2.0-dev</version>
<description>PLG_JCAR_DSPACE_XML_DESCRIPTION</description>

<files>
Expand Down Expand Up @@ -43,14 +43,6 @@
<fieldset
name="display"
label="PLG_JCAR_DSPACE_FIELDSET_DISPLAY_LABEL">
<field
name="show_bundles"
type="text"
label="PLG_JCAR_DSPACE_FIELD_SHOW_BUNDLES_LABEL"
description="PLG_JCAR_DSPACE_FIELD_SHOW_BUNDLES_DESC"
size="40"
class="inputbox"/>

<field
name="stream"
type="radio"
Expand Down
3 changes: 0 additions & 3 deletions plugins/jcar/dspace/language/en-GB/en-GB.plg_jcar_dspace.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ PLG_JCAR_DSPACE_REST_SECRET_DESC="A REST API secret for validating REST requests

PLG_JCAR_DSPACE_FIELDSET_DISPLAY_LABEL="Display Options"

PLG_JCAR_DSPACE_FIELD_SHOW_BUNDLES_LABEL="Show Bundles"
PLG_JCAR_DSPACE_FIELD_SHOW_BUNDLES_DESC="A comma-delimited list of bundle types JCAR should display (E.g. ORIGINAL,THUMBNAIL,LICENSE). Leave blank to show all bundles."

PLG_JCAR_DSPACE_FIELD_STREAM_LABEL="Stream Assets via JCAR"
PLG_JCAR_DSPACE_FIELD_STREAM_DESC="Download assets through JCAR rather than directly from the source archive. Use for SEF-friendly URLs."

Expand Down

0 comments on commit 8c18199

Please sign in to comment.