Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
ENH: Refs #0963. Moved more existing apis to new REST apis
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhengZ committed Apr 3, 2013
1 parent 89cac1b commit e7aa956
Show file tree
Hide file tree
Showing 12 changed files with 919 additions and 427 deletions.
53 changes: 33 additions & 20 deletions core/controllers/api/ApidocsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function init()
}


/** Index function */
/** Index resource */
function indexAction()
{
$results = array();
Expand All @@ -44,56 +44,69 @@ function indexAction()
$results['basePath'] = $baseUrl. '/apidocs';
$results['apis'] = array();

$apiDocs = $this->Component->Apidocs->getWebApiDocs();
$models = array_keys($apiDocs);
foreach($models as $modelPath)
$resources = $this->Component->Apidocs->getEnabledResources();
foreach($resources as $resourcePath)
{
if(strpos($modelPath, '/') > 0)
if(strpos($resourcePath, '/') > 0)
{
$modelPath = '/' . $modelPath;
$resourcePath = '/' . $resourcePath;
}
$curModel = array();
$curModel['path'] = $modelPath;
$curModel['discription'] = 'Operations about '. $modelPath;
array_push($results['apis'], $curModel);
$curResource = array();
$curResource['path'] = $resourcePath;
$curResource['discription'] = 'Operations about '. $resourcePath;
array_push($results['apis'], $curResource);
}
echo $this->Component->Json->encode($results);
}

/** Item function */
/** System resource */
function systemAction()
{
$results = $this->Component->Apidocs->getResourceApiDocs('system');
echo $this->Component->Json->encode($results);
}

/** Item resource */
function itemAction()
{
$results = $this->Component->Apidocs->getModelApiDocs('item');
$results = $this->Component->Apidocs->getResourceApiDocs('item');
echo $this->Component->Json->encode($results);
}

/** Folder function */
/** Folder resource */
function folderAction()
{
$results = $this->Component->Apidocs->getModelApiDocs('folder');
$results = $this->Component->Apidocs->getResourceApiDocs('folder');
echo $this->Component->Json->encode($results);
}


/** Community function */
/** Community resource */
function communityAction()
{
$results = $this->Component->Apidocs->getModelApiDocs('community');
$results = $this->Component->Apidocs->getResourceApiDocs('community');
echo $this->Component->Json->encode($results);
}


/** Bitstream function */
/** Bitstream resource */
function bitstreamAction()
{
$results = $this->Component->Apidocs->getModelApiDocs('bitstream');
$results = $this->Component->Apidocs->getResourceApiDocs('bitstream');
echo $this->Component->Json->encode($results);
}

/** User function */
/** User resource */
function userAction()
{
$results = $this->Component->Apidocs->getModelApiDocs('user');
$results = $this->Component->Apidocs->getResourceApiDocs('user');
echo $this->Component->Json->encode($results);
}

/** Group resource */
function groupAction()
{
$results = $this->Component->Apidocs->getResourceApiDocs('group');
echo $this->Component->Json->encode($results);
}

Expand Down
6 changes: 4 additions & 2 deletions core/controllers/api/BitstreamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
=========================================================================*/

/**
* WebApi Controller for Bitstreadm Resource
* WebApi Controller for Bitstream Resource
*/
class Rest_BitstreamController extends ApiController
{
Expand All @@ -29,7 +29,9 @@ class Rest_BitstreamController extends ApiController
*/
public function indexAction()
{
$this->_forward('get');
$apiFunctions['default'] = 'bitstreamCount';
$apiFunctions['count'] = 'bitstreamCount';
$this->_genericAction($this->_request->getParams(), 'index', $apiFunctions);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions core/controllers/api/CommunityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public function getAction()
{
$apiFunctions = array(
'default' => 'communityGet',
'children' => 'communityChildren'
'children' => 'communityChildren',
'group' => 'communityListGroups'
);
$this->_genericAction($this->_request->getParams(), 'get', $apiFunctions);
}
Expand Down Expand Up @@ -85,7 +86,7 @@ public function deleteAction()
*/
public function optionsAction()
{
$this->_response->setHeader('Allow', 'OPTIONS, HEAD, GET, PUT, DELETE');
$this->_response->setHeader('Allow', 'OPTIONS, HEAD, GET, POST, DELETE');
}

}
102 changes: 102 additions & 0 deletions core/controllers/api/GroupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/**
* WebApi Controller for Group Resource
*/
class Rest_GroupController extends ApiController
{
/**
* The index action handles index/list requests; it should respond with a
* list of the requested resources.
*/
public function indexAction()
{
$this->_forward('get');
}

/**
* The head action handles HEAD requests; it should respond with an
* identical response to the one that would correspond to a GET request,
* but without the response body.
*/
public function headAction()
{
$this->_response->setHttpResponseCode(200); // 200 OK
}

/**
* The get action handles GET requests and receives an 'id' parameter; it
* should respond with the server resource state of the resource identified
* by the 'id' value.
*/
public function getAction()
{
$apiFunctions['default'] = 'groupListUsers';
$apiFunctions['users'] = 'groupListUsers';
$this->_genericAction($this->_request->getParams(), 'get', $apiFunctions);
}

/**
* The put action handles PUT requests and receives an 'id' parameter; it
* should update the server resource state of the resource identified by
* the 'id' value.
*/
public function putAction()
{
$apiFunctions = array(
'default' => 'groupAddUser',
'adduser'=> 'groupAddUser',
'removeuser' => 'groupRemoveUser',
);
$this->_genericAction($this->_request->getParams(), 'put', $apiFunctions);
}

/**
* The post action handles POST requests; it should accept and digest a
* POSTed resource representation and persist the resource state.
*/
public function postAction()
{
$apiFunctions['default'] = 'groupAdd';
$this->_genericAction($this->_request->getParams(), 'post', $apiFunctions);
}

/**
* The delete action handles DELETE requests and receives an 'id'
* parameter; it should update the server resource state of the resource
* identified by the 'id' value.
*/
public function deleteAction()
{
$apiFunctions['default'] = 'groupRemove';
$this->_genericAction($this->_request->getParams(), 'delete', $apiFunctions);
}

/**
* The options action handles OPTIONS requests; it should respond with
* the HTTP methods that the server supports for specified URL.
*/
public function optionsAction()
{
$this->_response->setHeader('Allow', 'OPTIONS, HEAD, GET, PUT, POST, DELETE');
}

}
4 changes: 3 additions & 1 deletion core/controllers/api/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public function preDispatch()
/** Index function */
function indexAction()
{
$this->view->header = 'REST Web API';
$header = '<img style="position: relative; top: 3px;" alt="" src="'.$this->view->coreWebroot.'/public/images/icons/page_white_code_red.png" />';
$header .= ' REST Web API';
$this->view->header = $header;
$this->view->serverURL = $this->getServerURL();
}
}
89 changes: 89 additions & 0 deletions core/controllers/api/SystemController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/**
* WebApi Controller for System Resource
*/
class Rest_SystemController extends ApiController
{
/**
* The index action handles index/list requests; it should respond with a
* list of the requested resources.
*/
public function indexAction()
{
$apiFunctions = array(
'default' => 'info',
'info' => 'info',
'version' => 'version',
'module' => 'modulesList',
'resource' => 'resourcesList',
'login' => 'login',
'metadataqualifiers' => 'metadataQualifiersList',
'uploadeoffset' => 'uploadGetoffset',
'metadatatypes' => 'metadataTypesList',
'metadaelements' => 'metadataElementsList'
);
$this->_genericAction($this->_request->getParams(), 'index', $apiFunctions);
}

/**
* The head action handles HEAD requests; it should respond with an
* identical response to the one that would correspond to a GET request,
* but without the response body.
*/
public function headAction()
{
$this->_response->setHttpResponseCode(200); // 200 OK
}

/**
* The get action handles GET requests and receives an 'id' parameter; it
* should respond with the server resource state of the resource identified
* by the 'id' value.
*/
public function getAction()
{
$this->_response->setHttpResponseCode(200); // 200 OK
}

/**
* The post action handles POST requests; it should accept and digest a
* POSTed resource representation and persist the resource state.
*/
public function postAction()
{
$apiFunctions = array(
'default' => 'adminDatabaseCleanup',
'databasecleanup' => 'adminDatabaseCleanup',
);
$this->_genericAction($this->_request->getParams(), 'post', $apiFunctions);
}

/**
* The options action handles OPTIONS requests; it should respond with
* the HTTP methods that the server supports for specified URL.
*/
public function optionsAction()
{
$this->_response->setHeader('Allow', 'OPTIONS, HEAD, GET, POST, PUT');
}

}

0 comments on commit e7aa956

Please sign in to comment.