-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from whikloj/make_txService_use_providers
Use ServiceProvider and ControllerProvider for the Transaction Service
- Loading branch information
Showing
6 changed files
with
208 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: /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 | ||
defaultNamespaceDomainUuuidV5: "www.islandora.ca" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
47 changes: 47 additions & 0 deletions
47
services/TransactionService/src/Controller/TransactionController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Islandora\TransactionService\Controller; | ||
|
||
use Silex\Application; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class TransactionController { | ||
|
||
public function create(Application $app, Request $request) { | ||
try { | ||
$response = $app['api']->createTransaction(); | ||
} catch (\Exception $e) { | ||
$app->abort(503, 'Chullo says "Fedora4 Repository Not available"'); | ||
} | ||
return $response; | ||
} | ||
|
||
public function extend(Application $app, Request $request, $id) { | ||
try { | ||
$response = $app['api']->extendTransaction($id); | ||
} catch (\Exception $e) { | ||
$app->abort(503, 'Chullo says "Fedora4 Repository Not available"'); | ||
} | ||
return $response; | ||
} | ||
|
||
public function commit(Application $app, Request $request, $id) { | ||
try { | ||
$response = $app['api']->commitTransaction($id); | ||
} catch (\Exception $e) { | ||
$app->abort(503, 'Chullo says "Fedora4 Repository Not available"'); | ||
} | ||
return $response; | ||
} | ||
|
||
public function rollback(Application $app, Request $request, $id) { | ||
try { | ||
$response = $app['api']->rollbackTransaction($id); | ||
} catch (\Exception $e) { | ||
$app->abort(503, 'Chullo says "Fedora4 Repository Not available"'); | ||
} | ||
return $response; | ||
} | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
services/TransactionService/src/Provider/TransactionServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Islandora\TransactionService\Provider; | ||
|
||
use Silex\Application; | ||
use Silex\ServiceProviderInterface; | ||
use Silex\ControllerProviderInterface; | ||
use Islandora\Chullo\FedoraApi; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\Yaml\Yaml; | ||
use Islandora\ResourceService\Controller\ResourceController; | ||
use Islandora\TransactionService\Controller\TransactionController; | ||
|
||
class TransactionServiceProvider implements ServiceProviderInterface, ControllerProviderInterface { | ||
|
||
/** | ||
* Part of ServiceProviderInterface | ||
*/ | ||
public function register(Application $app) { | ||
// | ||
// Define controller services | ||
// | ||
$app['islandora.transactioncontroller'] = $app->share(function() use ($app) { | ||
return new \Islandora\TransactionService\Controller\TransactionController($app); | ||
}); | ||
|
||
if (!isset($app['islandora.resourcecontroller'])) { | ||
$app['islandora.resourcecontroller'] = $app->share(function() use ($app) { | ||
return new \Islandora\ResourceService\Controller\ResourceController($app); | ||
}); | ||
} | ||
|
||
if (!isset($app['api'])) { | ||
$app['api'] = $app->share(function() use ($app) { | ||
return FedoraApi::create($app['config']['islandora']['fedoraProtocol'].'://'.$app['config']['islandora']['fedoraHost'].$app['config']['islandora']['fedoraPath']); | ||
}); | ||
} | ||
|
||
// Common simple YAML config parser. | ||
if (!isset($app['config'])) { | ||
$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; | ||
}); | ||
} | ||
|
||
} | ||
|
||
public function boot(Application $app) {} | ||
|
||
public function connect(Application $app) { | ||
$controllers = $app['controllers_factory']; | ||
|
||
$controllers->get("/transaction/{id}", "islandora.resourcecontroller:get") | ||
->value('id',"") | ||
->value('child', "") | ||
->before(function(Request $request) { | ||
if (isset($request->attributes->parameters) && $request->attributes->parameters->has('id')) { | ||
// To get this to work we need to GET /islandora/resource//tx:id | ||
// So we move the $id to the $child parameter. | ||
$id = $request->attributes->parameters->get('id'); | ||
$request->attributes->parameters->set('child', $id); | ||
$request->attributes->parameters->set('id', ''); | ||
} | ||
}) | ||
->bind('islandora.transactionGet'); | ||
|
||
$controllers->post("/transaction", "islandora.transactioncontroller:create") | ||
->bind('islandora.transactionCreate'); | ||
|
||
$controllers->post("/transaction/{id}/extend", "islandora.transactioncontroller:extend") | ||
->value('id',"") | ||
->bind('islandora.transactionExtend'); | ||
|
||
$controllers->post("/transaction/{id}/commit", "islandora.transactioncontroller:commit") | ||
->value('id',"") | ||
->bind('islandora.transactionCommit'); | ||
|
||
$controllers->post("/transaction/{id}/rollback", "islandora.transactioncontroller:rollback") | ||
->value('id',"") | ||
->bind('islandora.transactionRollback'); | ||
|
||
return $controllers; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters