Skip to content

Commit

Permalink
First pass at addressing #150.
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Rosner committed Apr 25, 2016
1 parent b65db61 commit a7b1fc6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
37 changes: 29 additions & 8 deletions services/ResourceService/src/Controller/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,38 @@ public function patch(Application $app, Request $request, $id, $child) {
public function delete(Application $app, Request $request, $id, $child) {
$tx = $request->query->get('tx', "");
$force = $request->query->get('force', FALSE);

error_log('---START OF DELETE RESOURCE REQUEST: ');
error_log($id);

$delete_queue = array($app->escape($id).'/'.$child, );
$sparql_query = $app['twig']->render('findAllOreProxy.sparql', array(
'resource' => $id,
));
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);
}
$sparql_result = $app['triplestore']->query($sparql_query);
}
catch (\Exception $e) {
$app->abort(503, '"Chullo says Fedora4 Repository is Not available"');
$app->abort(503, 'Chullo says "Triple Store Not available"');
}
if (count($sparql_result) > 0) {
foreach ($sparql_result as $ore_proxy) {
$delete_queue[] = $ore_proxy->obj->getUri();
}
}
error_log(implode(',', $delete_queue));
foreach($delete_queue as $object_uri) {
try {
$response = $app['api']->deleteResource($object_uri, $tx);
//remove tombstone also if 'force' == true and previous response is 204
if ((204 == $response->getStatusCode() || 410 == $response->getStatusCode()) && $force) {
$response = $app['api']->deleteResource($object_uri.'/fcr:tombstone', $tx);
}
}
catch (\Exception $e) {
$app->abort(503, '"Chullo says Fedora4 Repository is Not available"');
}
error_log($response->getStatusCode());
}
return $response;
}

}
5 changes: 5 additions & 0 deletions services/ResourceService/templates/findAllOreProxy.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PREFIX ore: <http://www.openarchives.org/ore/terms/>
PREFIX ldp: <http://www.w3.org/ns/ldp#>
SELECT ?obj WHERE {
?obj ore:proxyFor <{{ resource }}> .
}

2 comments on commit a7b1fc6

@DiegoPino
Copy link
Contributor

Choose a reason for hiding this comment

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

@br2490 will take a look tomorrow AM (well, some test drive)

@br2490
Copy link

@br2490 br2490 commented on a7b1fc6 Apr 26, 2016 via email

Choose a reason for hiding this comment

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

Please sign in to comment.