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

For #153 #154

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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 services/CollectionService/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
vendor/
composer.lock
composer.phar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From personal experience, including the lock files always ends with some sort of confusion over why things won't update when people are testing changes.

I understand this is contrary to what stack overflow says.

It's bitten me before many many times, and I make it a habit not to. With the understanding that I need to know what I'm doing if deploying straight from the git repo on a production environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, maybe I'm being too biased. Let's try it the 'correct' way. But if it turns out to be a serious PITA I'll issue a PR to get rid of them.

2 changes: 1 addition & 1 deletion services/CollectionService/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "RESTful service providing PCDM Collections in Fedora 4",
"repositories": [{
"type": "path",
"url": "../ResourceServiceProvider"
"url": "../ResourceService"
}],
"require": {
"islandora/chullo": "^0.0",
Expand Down
2 changes: 2 additions & 0 deletions services/ResourceService/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
vendor/
composer.lock
composer.phar
11 changes: 3 additions & 8 deletions services/ResourceService/composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
{
"name": "islandora/resource-service",
"description": "RESTful service providing resources in Fedora 4",
"repositories": [
{
"type": "vcs",
"url": "/Users/dpino/Desktop/Development/ISLANDORAWORK/CLAW_MICRO/chullo"
}
],
"require": {
"islandora/chullo": "dev-api",
"islandora/chullo": "^0.0",
"silex/silex": "^1.3",
"symfony/config": "^3.0",
"twig/twig": "^1.23",
"symfony/yaml": "^3.0"
"symfony/yaml": "^3.0",
"ramsey/uuid": "^3.1"
},
"autoload": {
"psr-4": {"Islandora\\ResourceService\\": "src/"}
Expand Down
4 changes: 3 additions & 1 deletion services/ResourceService/config/settings.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ islandora:
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})?"
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"
4 changes: 3 additions & 1 deletion services/ResourceService/config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ islandora:
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})?"
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"
201 changes: 9 additions & 192 deletions services/ResourceService/src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,234 +12,51 @@
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Psr\Http\Message\ResponseInterface;
use Silex\Provider\TwigServiceProvider;
use Symfony\Component\Yaml\Yaml;
use Islandora\ResourceService\Provider\ResourceServiceProvider;

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',
));

$islandoraResourceServiceProvider = new \Islandora\ResourceService\Provider\ResourceServiceProvider;

$app['twig'] = $app->share($app->extend('twig', function($twig, $app) {
return $twig;
}));

$app['api'] = $app->share(function() use ($app) {
return FedoraApi::create($app['config']['islandora']['fedoraProtocol'].'://'.$app['config']['islandora']['fedoraHost'].$app['config']['islandora']['fedoraPath']);
});

$app['triplestore'] = $app->share(function() use ($app) {
return TriplestoreClient::create($app['config']['islandora']['tripleProtocol'].'://'.$app['config']['islandora']['tripleHost'].$app['config']['islandora']['triplePath']);
});

/**
* Ultra simplistic YAML settings loader.
*/
$app['config'] = $app->share(function() use ($app){
if ($app['debug']) {
$configFile = __DIR__.'/../config/settings.dev.yml';
}
else {
$configFile = __DIR__.'/../config/settings.yml';
}
$settings = Yaml::parse(file_get_contents($configFile));
return $settings;
});

/**
* before middleware to handle browser requests.
*/
$htmlHeaderToTurtle = function(Request $request) {
// In case the request was made by a browser, avoid
// returning the whole Fedora4 API Rest interface page.
if (0 === strpos($request->headers->get('Accept'),'text/html')) {
$request->headers->set('Accept', 'text/turtle', TRUE);
}
};


/**
* before middleware to normalize host header to same as fedora's running
* instance.
*/
$hostHeaderNormalize = function(Request $request) use ($app) {
// Normalize Host header to Repo's real location
$request->headers->set('Host', $app['config']['islandora']['fedoraHost'], TRUE);
};

/**
* Converts request $id (uuid) into a fedora4 resourcePath
*/
$idToUri = function ($id) use ($app) {
// Run only if $id given /can also be refering root resource,
// we accept only UUID V4 or empty
if (NULL != $id) {
$sparql_query = $app['twig']->render('getResourceByUUIDfromTS.sparql', array(
'uuid' => $id,
));
try {
$sparql_result = $app['triplestore']->query($sparql_query);
}
catch (\Exception $e) {
$app->abort(503, 'Chullo says "Triple Store Not available"');
}
// We only assign one in case of multiple ones
// Will have to check for edge cases?
foreach ($sparql_result as $triple) {
return $triple->s->getUri();
}
// Abort the routes if we don't get a subject from the tripple.
$app->abort(404, sprintf('Failed getting resource Path for "%s" from triple store', $id));
}
else {
// If $id is empty then assume we are dealing with fedora base rest endpoint
return $app['config']['islandora']['fedoraProtocol'].'://'.$app['config']['islandora']['fedoraHost'].$app['config']['islandora']['fedoraPath'];
}
};

/**
* Apply middleware to all controllers
*/
$app['controllers']
->convert('id', $idToUri)
->assert('id',$app['config']['islandora']['resourceIdRegex'])
->before($htmlHeaderToTurtle)
->before($hostHeaderNormalize)
;
$app->register($islandoraResourceServiceProvider);
$app->mount("/islandora", $islandoraResourceServiceProvider);

/**
* Convert returned Guzzle responses to Symfony responses.
* Convert returned Guzzle responses to Symfony responses, type hinted.
*/
$app->view(function (ResponseInterface $psr7) {
return new Response($psr7->getBody(), $psr7->getStatusCode(), $psr7->getHeaders());
});

/**
* Resource GET route. 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
*/
$app->get("/islandora/resource/{id}/{child}",function (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;
})
->value('id',"")
->value('child',"");

/**
* Resource POST route. 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
*/
$app->post("/islandora/resource/{id}",function (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;
})
->value('id',"");

/**
* 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.
*/
$app->put("/islandora/resource/{id}/{child}",function (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;
})
->value('id',"")
->value('child',"");

/**
* Resource PATCH route. takes $id (valid UUID or empty) for the resource to be modified via SPARQL as first value to match,
* optional a Child resource relative path
* takes 'rx' as optional query argument
* @see https://wiki.duraspace.org/display/FEDORA40/RESTful+HTTP+API#RESTfulHTTPAPI-GreenPATCHModifythetriplesassociatedwitharesourcewithSPARQL-Update
*/
$app->patch("/islandora/resource/{id}/{child}",function (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;
})
->value('id',"")
->value('child',"");

/**
* Resource DELETE route. takes $id (valid UUID or empty) for the resource to be modified via SPARQL as first value to match,
* optional a Child resource relative path
* takes 'rx' as optional query argument, also 'force' to remove the tombstone in one step
* @see https://wiki.duraspace.org/display/FEDORA40/RESTful+HTTP+API#RESTfulHTTPAPI-RedDELETEDeletearesource
*/
$app->delete("/islandora/resource/{id}/{child}",function (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;
})
->value('id',"")
->value('child',"");

$app->after(function (Request $request, Response $response, Application $app) {
// Todo a closing controller, not sure what now but i had an idea.
});
$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);
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);
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);
return new Response(sprintf('Islandora Resource Service uncatched exception: %s %d response', $e->getMessage(), $code), $code);
});


Expand Down
1 change: 0 additions & 1 deletion services/ResourceServiceProvider/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions services/ResourceServiceProvider/composer.json

This file was deleted.

11 changes: 0 additions & 11 deletions services/ResourceServiceProvider/config/settings.dev.yml

This file was deleted.

10 changes: 0 additions & 10 deletions services/ResourceServiceProvider/config/settings.yml

This file was deleted.

Loading