summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rwxr-xr-xserver/Test/AppTestClass.php12
-rwxr-xr-xserver/core/Image.php279
2 files changed, 133 insertions, 158 deletions
diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php
index b398088..5e8efc7 100755
--- a/server/Test/AppTestClass.php
+++ b/server/Test/AppTestClass.php
@@ -1,24 +1,12 @@
<?php
include_once("../core/Plugin_Api.php");
include_once("../core/LibOverride/genTokenOptions.php");
-<<<<<<< HEAD
-<<<<<<< Updated upstream
-=======
include_once("../core/ErrorManagement.php");
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
->>>>>>> Stashed changes
-=======
-include_once("../core/ErrorManagement.php");
-
-use OpenStack\Common\Error\BadResponseError;
-use OpenStack\Common\Error\BaseError;
-use OpenStack\Common\Error\NotImplementedError;
-use OpenStack\Common\Error\UserInputError;
->>>>>>> develop
class AppTest{
diff --git a/server/core/Image.php b/server/core/Image.php
index d37c828..f309943 100755
--- a/server/core/Image.php
+++ b/server/core/Image.php
@@ -9,15 +9,13 @@
*
* @todo Complete the functions with errors detection and finish the descriptions
*/
-use OpenStack\Common\Error\BadResponseError;
-use OpenStack\Common\Error\BaseError;
-use OpenStack\Common\Error\NotImplementedError;
-use OpenStack\Common\Error\UserInputError;
-
+use OpenCloud\Common\Error\BadResponseError;
+use OpenCloud\Common\Error\BaseError;
+use OpenCloud\Common\Error\NotImplementedError;
+use OpenCloud\Common\Error\UserInputError;
include("CoreInterface.php");
-
/**
* Image Class of the back-end application
*
@@ -37,13 +35,11 @@ class image implements Core{
*
* @param App $app the main app object
*
- * @throws [Type] [<description>]
- *
* @return Image
*/
public function __construct($app){
if(!isset($app)){
- $this->app->setOutput("Error", "Incorrect parameter");
+ $this->app->setOutput("Error", "Incorrect parameter app");
}
$this->app = $app;
$this->libClass = $app->getLibClass("Image");
@@ -58,47 +54,46 @@ class image implements Core{
* @return void
*/
public function action($action){
-
- $this->{$action.""}();
-
+ $this->{$action.""}();
}
/**
- * Details about an image
+ * Create a new image
*
- * @param array $opt
- * options for the image creation
+ * @param array $opt Options for the image creation (name is required, others are optionals)
*
- **/
+ * @return Image
+ */
private function createImage(){
$opt = $this->app->getPostParam("opt");
-
if(!isset($opt)){
- $this->app->setOutput("Error", "Incorrect parameter");
+ $this->app->setOutput("Error", "Incorrect parameter opt");
}
-
try{
- // VOIR SI MAUVAIS TYPE
$options = Array();
- if(isset($opt['name'])){ // if the image name already exists -> error
+
+ // Check the image name
+ if(isset($opt['name'])){
$imagesList = listImage();
- if(isset($images)){
+ if(isset($imagesList)){
foreach($imagesList as $image){
- if(strcmp($image->name, $opt['name']) == 0){
-
+ if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error
+ $this->app->setOutput("Error", "Image name already exists");
}
}
}
}
else{
- $this->app->setOutput("Error", "Image name already exists");
+ $this->app->setOutput("Error", "Missing parameter 'name' for the new image");
}
+
+ // Check optionals arguments
if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error
-
+ $this->app->setOutput("Error", "Image id already exists");
}
$options['id'] = $opt['id'];
}
@@ -131,11 +126,11 @@ class image implements Core{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
$this->app->setOutput("Images", $image);
@@ -144,7 +139,7 @@ class image implements Core{
/**
* List the images of the server
*
- * @return the list with all images on the server
+ * @return List of Image
*/
private function listImage(){
try{
@@ -156,11 +151,11 @@ class image implements Core{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
$this->app->setOutput("Images", $result);
@@ -170,10 +165,10 @@ class image implements Core{
/**
* Details about an image
*
- * @param string $id
- * identifier of the image
- *
- **/
+ * @param String $id Identifier of the image
+ *
+ * @return Image
+ */
private function detailsImage(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
@@ -186,29 +181,26 @@ class image implements Core{
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
-
$this->app->setOutput("Images", $image);
-
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
}
/**
- * Details about an image
+ * Update informations about an image
*
- * @param string $id
- * id of the image
- *
- * @param array $opt
- * options for the image creation
- **/
+ * @param String $id id of the image
+ * @param array $opt Options for the image creation
+ *
+ * @return Image
+ */
private function updateImage(){
$id = $this->app->getPostParam("id");
@@ -254,11 +246,11 @@ class image implements Core{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
$this->app->setOutput("Images", $image);
}
@@ -266,9 +258,10 @@ class image implements Core{
/**
* Delete an image
*
- * @param string $id
- * identifier of the image
- **/
+ * @param String $id Identifier of the image
+ *
+ * @return void
+ */
private function deleteImage(){
// si protected = true, demander de le mettre a false
// vérifier existence image
@@ -280,27 +273,28 @@ class image implements Core{
try{
$service = $this->libClass;
$image = $this->libClass->getImage($id);
- if($image == null){ // if the image don't exists -> error
+ if($image == null){ // if the image doesn't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$image->delete();
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
}
/**
* Resactive an image
*
- * @param string $id
- * identifier of the image
- **/
+ * @param String $id Identifier of the image
+ *
+ * @return void
+ */
private function reactivateImage(){
$id = $this->app->getPostParam("id");
@@ -308,7 +302,6 @@ class image implements Core{
$this->app->setOutput("Error", "Incorrect parameter");
}
try{
- // vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
@@ -318,20 +311,21 @@ class image implements Core{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
}
/**
* Desactive an image
*
- * @param string $id
- * identifier of the image
- **/
+ * @param String $id Identifier of the image
+ *
+ * @return void
+ */
private function desactivateImage(){
$id = $this->app->getPostParam("id");
@@ -349,23 +343,22 @@ class image implements Core{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
}
/**
* Upload an image
*
- * @param string $id
- * identifier of the image
- *
- * @param string $file_name
- * path of the image
- **/
+ * @param String $id Identifier of the image
+ * @param String $file_name Path of the image
+ *
+ * @return void
+ */
private function uploadImage(){
$id = $this->app->getPostParam("id");
$file_name = $this->app->getPostParam("file_name");
@@ -375,7 +368,7 @@ class image implements Core{
$this->app->setOutput("Error", "Incorrect id parameter");
}
if(!isset($file_name)){
- $this->app->setOutput("Error", "Incorrect file_name parameter");
+ $this->app->setOutput("Error", "Incorrect file name parameter");
}
try{
// vérifier existence image
@@ -389,25 +382,26 @@ class image implements Core{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
}
/**
* Download an image
*
- * @param string $id
- * identifier of the image
- **/
+ * @param String $id Identifier of the image
+ *
+ * @return Stream
+ */
private function downloadImage(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
- $this->app->setOutput("Error", "Incorrect parameter");
+ $this->app->setOutput("Error", "Incorrect id parameter");
}
try{
// vérifier existence image
@@ -420,11 +414,11 @@ class image implements Core{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
$this->app->setOutput("Images", $stream);
}
@@ -432,21 +426,20 @@ class image implements Core{
/**
* Add a member to image
*
- * @param string $image_id
- * identifier of the image
- *
- * @param string $member_id
- * identifier of the member
- **/
+ * @param String $image_id Identifier of the image
+ * @param String $member_id Identifier of the member
+ *
+ * @return Member
+ */
private function addMemberImage(){
$image_id = $this->app->getPostParam("image_id");
$member_id = $this->app->getPostParam("member_id");
if(!isset($image_id)){
- $this->app->setOutput("Error", "Incorrect parameter image_id");
+ $this->app->setOutput("Error", "Incorrect image id parameter");
}
if(!isset($member_id)){
- $this->app->setOutput("Error", "Incorrect parameter member_id");
+ $this->app->setOutput("Error", "Incorrect member id parameter");
}
try{
$service = $this->libClass;
@@ -456,14 +449,15 @@ class image implements Core{
$this->app->setOutput("Error", "Image doesn't exist");
}
$member_id = $image->addMember($member_id);
+ $this->app->setOutput("Images", $member_id);
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
}
@@ -471,18 +465,19 @@ class image implements Core{
/**
* List members of an image
*
- * @param string $image_id
- * identifier of the image
- **/
+ * @param String $image_id identifier of the image
+ *
+ * @return List of Member
+ */
private function listMemberImage(){
$image_id = $this->app->getPostParam("image_id");
$member_id = $this->app->getPostParam("member_id");
if(!isset($image_id)){
- $this->app->setOutput("Error", "Incorrect parameter image_id");
+ $this->app->setOutput("Error", "Incorrect image id parameter");
}
if(!isset($member_id)){
- $this->app->setOutput("Error", "Incorrect parameter member_id");
+ $this->app->setOutput("Error", "Incorrect member id parameter");
}
try{
// vérifier existence image
@@ -492,44 +487,40 @@ class image implements Core{
$this->app->setOutput("Error", "Image doesn't exist");
}
$members = $image->listMembers();
- if($member == null){ // if the image don't exists -> error
+ if($members == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "No member");
}
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
- $this->app->setOutput("Images", $member);
+ $this->app->setOutput("Images", $members);
}
/**
* Show details of a member of an image
*
- * @param string $image_id
- * identifier of the image
+ * @param String $image_id Identifier of the image
+ * @param String $member_id Identifier of the member
*
- * @param string $member_id
- * identifier of the member
- **/
+ * @return Member
+ */
private function detailMemberImage(){
$image_id = $this->app->getPostParam("image_id");
$member_id = $this->app->getPostParam("member_id");
if(!isset($image_id)){
- $this->app->setOutput("Error", "Incorrect parameter image_id");
+ $this->app->setOutput("Error", "Incorrect image id parameter");
}
if(!isset($member_id)){
- $this->app->setOutput("Error", "Incorrect parameter member_id");
+ $this->app->setOutput("Error", "Incorrect member id parameter");
}
try{
- // vérifier existence image
- // on doit être le proprio de l'image
- // vérifier membre existe
$service = $this->libClass;
$image = $service->getImage($id);
@@ -544,11 +535,11 @@ class image implements Core{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
$this->app->setOutput("Images", $member);
}
@@ -556,21 +547,20 @@ class image implements Core{
/**
* Remove a member of an image
*
- * @param string $image_id
- * identifier of the image
- *
- * @param string $member_id
- * identifier of the member
- **/
+ * @param String $image_id Identifier of the image
+ * @param String $member_id Identifier of the member
+ *
+ * @return void
+ */
private function removeMemberImage(){
$image_id = $this->app->getPostParam("image_id");
$member_id = $this->app->getPostParam("member_id");
if(!isset($image_id)){
- $this->app->setOutput("Error", "Incorrect parameter image_id");
+ $this->app->setOutput("Error", "Incorrect image id parameter");
}
if(!isset($member_id)){
- $this->app->setOutput("Error", "Incorrect parameter member_id");
+ $this->app->setOutput("Error", "Incorrect member id parameter");
}
try{
$service = $this->libClass;
@@ -587,25 +577,22 @@ class image implements Core{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
}
/**
* Update a member of an image
*
- * @param string $image_id
- * identifier of the image
- *
- * @param string $member_id
- * identifier of the member
+ * @param String $image_id Identifier of the image
+ * @param String $member_id Identifier of the member
+ * @param String $status New status for the member
*
- * @param string $status
- * new status for the member
+ * @return void
**/
private function updateMemberImage(){
$image_id = $this->app->getPostParam("image_id");
@@ -613,10 +600,10 @@ class image implements Core{
$status = $this->app->getPostParam("status");
if(!isset($image_id)){
- $this->app->setOutput("Error", "Incorrect parameter image_id");
+ $this->app->setOutput("Error", "Incorrect image id parameter");
}
if(!isset($member_id)){
- $this->app->setOutput("Error", "Incorrect parameter member_id");
+ $this->app->setOutput("Error", "Incorrect member id parameter");
}
try{
$service = $this->libClass;
@@ -633,11 +620,11 @@ class image implements Core{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- $this->app->getErrorInstance->UserInputHandler($e);
+ $this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- $this->app->getErrorInstance->BaseErrorHandler($e);
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- $this->app->getErrorInstance->NotImplementedHandler($e);
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
}
}