Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative Islandora ResourceService using providers #135

Merged
merged 7 commits into from
Jan 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ install/downloads
site/

services/ResourceService/composer.lock

services/ResourceServiceProvider/composer.lock
1 change: 1 addition & 0 deletions services/CollectionService/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
32 changes: 32 additions & 0 deletions services/CollectionService/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "islandora/collection-service",
"description": "RESTful service providing resources in Fedora 4",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Islandora-CLAW/chullo"

},
{
"type": "path",
"url": "/Users/dpino/Desktop/Development/ISLANDORAWORK/CLAW_MICRO/islandora/services/ResourceServiceProvider"
}
],
"require": {
"islandora/chullo": "dev-master",
"islandora/resource-service" : "dev-sprint-002",
"silex/silex": "^1.3",
"symfony/config": "^3.0",
"twig/twig": "^1.23",
"symfony/yaml": "^3.0"
},
"autoload": {
"psr-4": {"Islandora\\CollectionService\\": "src/"}
},
"authors": [
{
"name": "Diego Pino Navarro",
"email": "dpino@krayon.cl"
}
]
}
9 changes: 9 additions & 0 deletions services/CollectionService/config/settings.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Islandora Dev Settings to be used with $app['debug'] == TRUE
islandora:
fedoraProtocol: http
fedoraHost: "localhost:8080"
fedoraPath: /rest
tripleProtocol: http
tripleHost: "localhost:9999"
triplePath: /bigdata/sparql
resourceIdRegex: "(?:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})?"
8 changes: 8 additions & 0 deletions services/CollectionService/config/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
islandora:
fedoraProtocol: http
fedoraHost: "localhost:8080"
fedoraPath: /fcrepo/rest
tripleProtocol: http
tripleHost: "localhost:8080"
triplePath: /bigdata/sparql
resourceIdRegex: "(?:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})?"
106 changes: 106 additions & 0 deletions services/CollectionService/src/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace Islandora\CollectionService;

require_once __DIR__.'/../vendor/autoload.php';

use Silex\Application;
use Islandora\Chullo\FedoraApi;
use Islandora\Chullo\TriplestoreClient;
use Islandora\ResourceService\Provider\ResourceServiceProvider;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Psr\Http\Message\ResponseInterface;
use Silex\Provider\TwigServiceProvider;
use Symfony\Component\Yaml\Yaml;

date_default_timezone_set('UTC');

$app = new Application();

$app['debug'] = true;
$app->register(new \Silex\Provider\ServiceControllerServiceProvider());
$app->register(new \Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../templates',
));

$app['twig'] = $app->share($app->extend('twig', function($twig, $app) {
return $twig;
}));
$islandoraResourceServiceProvider = new \Islandora\ResourceService\Provider\ResourceServiceProvider;

$app->register($islandoraResourceServiceProvider);
$app->mount("/islandora", $islandoraResourceServiceProvider);
$app->register(new \Islandora\ResourceService\Provider\UuidServiceProvider(), array(
'UuidServiceProvider.default_namespace' => $app['config']['islandora']['defaultNamespaceDomainUuuidV5'],
));

//$app['uuid'] = $app['islandora.uuid5'](rand());
$app['uuid'] = $app['islandora.uuid4'];

/**
* Still Not used, this function will check for content type
*/
$isFedora4Content = function (Request $request) use ($app) {
$rdf_content_types = array(
"text/turtle",
"text/rdf+n3",
"application/n3",
"text/n3",
"application/rdf+xml",
"application/n-triples",
"application/sparql-update"
);
if (in_array($request->headers->get('Content-type'), $rdf_content_types)) {
return true;
}
return false;
};

/**
* Convert returned Guzzle responses to Symfony responses.
*/

$app->view(function (ResponseInterface $psr7) {
return new Response($psr7->getBody(), $psr7->getStatusCode(), $psr7->getHeaders());
});

/**
* Collection POST route test. Does nothing more than redirect from collection to mounted
* takes 'rx' and/or 'checksum' as optional query arguments
*/
$app->post("/islandora/collection",function (Application $app, Request $request) {
error_log($app['uuid']);
$tx = $request->query->get('tx', "");
$url = $request->getUriForPath('/islandora/resource/');
error_log($url);
//static public Request create(string $uri, string $method = 'GET', array $parameters = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)
$subRequest = Request::create($url, 'GET', array(), $request->cookies->all(), $request->files->all(), $request->server->all());
error_log($subRequest->__toString());
$response = $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
return $response;
});

$app->error(function (\Symfony\Component\HttpKernel\Exception\HttpException $e, $code) use ($app){
if ($app['debug']) {
return;
}
return new response(sprintf('Islandora Resource Service exception: %s / HTTP %d response', $e->getMessage(), $code), $code);
});
$app->error(function (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e, $code) use ($app){
if ($app['debug']) {
return;
}
//Not sure what the best "verbose" message is
return new response(sprintf('Islandora Resource Service exception: %s / HTTP %d response', $e->getMessage(), $code), $code);
});
$app->error(function (\Exception $e, $code) use ($app){
if ($app['debug']) {
return;
}
return new response(sprintf('Islandora Resource Service uncatched exception: %s %d response', $e->getMessage(), $code), $code);
});


$app->run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PREFIX nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.2/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?s WHERE {
?s nfo:uuid "{{uuid}}"^^<http://www.w3.org/2001/XMLSchema#string> .
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PREFIX nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.2/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?s WHERE {
?s nfo:uuid "{{uuid}}"^^<http://www.w3.org/2001/XMLSchema#string> .
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PREFIX nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.2/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?s WHERE {
?s nfo:uuid "{{uuid}}"^^<http://www.w3.org/2001/XMLSchema#string> .
}
1 change: 1 addition & 0 deletions services/ResourceServiceProvider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
27 changes: 27 additions & 0 deletions services/ResourceServiceProvider/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "islandora/resource-service",
"description": "RESTful service providing resources in Fedora 4",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Islandora-CLAW/chullo"
}
],
"require": {
"islandora/chullo": "dev-master",
"silex/silex": "^1.3",
"symfony/config": "^3.0",
"twig/twig": "^1.23",
"symfony/yaml": "^3.0",
"ramsey/uuid": "^3.1"
},
"autoload": {
"psr-4": {"Islandora\\ResourceService\\": "src/"}
},
"authors": [
{
"name": "Diego Pino Navarro",
"email": "dpino@krayon.cl"
}
]
}
11 changes: 11 additions & 0 deletions services/ResourceServiceProvider/config/settings.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Islandora Dev Settings to be used with $app['debug'] == TRUE
islandora:
fedoraProtocol: http
fedoraHost: "localhost:8080"
fedoraPath: /rest
tripleProtocol: http
tripleHost: "localhost:9999"
triplePath: /bigdata/sparql
resourceIdRegex: "(?:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})?"
# This domain is used as namespace (hashed) when generating UUID V5 identifiers
defaultNamespaceDomainUuuidV5: "www.islandora.ca"
10 changes: 10 additions & 0 deletions services/ResourceServiceProvider/config/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
islandora:
fedoraProtocol: http
fedoraHost: "localhost:8080"
fedoraPath: /fcrepo/rest
tripleProtocol: http
tripleHost: "localhost:8080"
triplePath: /bigdata/sparql
resourceIdRegex: "(?:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})?"
# This domain is used as namespace (hashed) when generating UUID V5 identifiers, replace with your own
defaultNamespaceDomainUuuidV5: "www.islandora.ca"
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Islandora\ResourceService\Controller;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class ResourceController {
/**
* Resource GET controller takes $id (valid UUID or empty) as first value to match, optional a child resource path
* takes 'rx' and/or 'metadata' as optional query arguments
* @see https://wiki.duraspace.org/display/FEDORA40/RESTful+HTTP+API#RESTfulHTTPAPI-GETRetrievethecontentoftheresource
*/
public function get(Application $app, Request $request, $id, $child) {
$tx = $request->query->get('tx', "");
$metadata = $request->query->get('metadata', FALSE) ? '/fcr:metadata' : "";
try {
$response = $app['api']->getResource($app->escape($id).'/'.$child.$metadata, $request->headers->all(), $tx);
}
catch (\Exception $e) {
$app->abort(503, 'Chullo says "Fedora4 Repository Not available"');
}
return $response;
}
/**
* Resource POST route controller. takes $id (valid UUID or empty) for the parent resource as first value to match
* takes 'rx' and/or 'checksum' as optional query arguments
* @see https://wiki.duraspace.org/display/FEDORA40/RESTful+HTTP+API#RESTfulHTTPAPI-BluePOSTCreatenewresourceswithinaLDPcontainer
*/
public function post(Application $app, Request $request, $id) {
$tx = $request->query->get('tx', "");
$checksum = $request->query->get('checksum', "");
try {
$response = $app['api']->createResource($app->escape($id), $request->getContent(), $request->headers->all(), $tx, $checksum);
}
catch (\Exception $e) {
$app->abort(503, '"Chullo says Fedora4 Repository is Not available"');
}
return $response;
}
/**
* Resource PUT route. takes $id (valid UUID or empty) for the resource to be update/created as first value to match,
* optional a Child resource relative path
* takes 'rx' and/or 'checksum' as optional query arguments
* @see https://wiki.duraspace.org/display/FEDORA40/RESTful+HTTP+API#RESTfulHTTPAPI-YellowPUTCreatearesourcewithaspecifiedpath,orreplacethetriplesassociatedwitharesourcewiththetriplesprovidedintherequestbody.
*/
public function put(Application $app, Request $request, $id, $child) {
$tx = $request->query->get('tx', "");
$checksum = $request->query->get('checksum', "");
try {
$response = $app['api']->saveResource($app->escape($id).'/'.$child, $request->getContent(), $request->headers->all(), $tx, $checksum);
}
catch (\Exception $e) {
$app->abort(503, '"Chullo says Fedora4 Repository is Not available"');
}
return $response;
}
public function patch(Application $app, Request $request, $id, $child) {
$tx = $request->query->get('tx', "");
try {
$response = $app['api']->modifyResource($app->escape($id).'/'.$child, $request->getContent(), $request->headers->all(), $tx);
}
catch (\Exception $e) {
$app->abort(503, '"Chullo says Fedora4 Repository is Not available"');
}
return $response;
}
public function delete(Application $app, Request $request, $id, $child) {
$tx = $request->query->get('tx', "");
$force = $request->query->get('force', FALSE);
try {
$response = $app['api']->deleteResource($app->escape($id).'/'.$child, $tx);
//remove tombstone also if 'force' == true and previous response is 204
if ((204 == $response->getStatusCode() || 410 == $response->getStatusCode()) && $force) {
$response= $app['api']->deleteResource($app->escape($id).'/'.$child.'/fcr:tombstone', $tx);
}
}
catch (\Exception $e) {
$app->abort(503, '"Chullo says Fedora4 Repository is Not available"');
}
return $response;
}

}
Loading