From e01936a73e75350a40fafd80995b1525a11c9da1 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 17 Mar 2016 09:46:32 +0100 Subject: add commentaries, update error management and correct some mistakes in Image.php, resolve conflict in AppTestClass.php --- server/core/Image.php | 279 ++++++++++++++++++++++++-------------------------- 1 file changed, 133 insertions(+), 146 deletions(-) (limited to 'server/core/Image.php') 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] [] - * * @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); } } -- cgit v1.2.3 From fe0eb3a9e259b4fe09df364f0660ebc62185f9dd Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 17 Mar 2016 11:34:56 +0100 Subject: add exception management, correct mistakes in error management in Image.php and add function to simplify parameters using in tests --- server/Test/AppTestClass.php | 8 +- server/Test/imageTests.php | 68 ++--- server/core/ErrorManagement.php | 4 + server/core/Image.php | 549 ++++++++++++++++++++++------------------ 4 files changed, 339 insertions(+), 290 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 5e8efc7..e1631c5 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -89,10 +89,16 @@ class AppTest{ } public function getPostParam($name){ - + return $this->postParams[$name]; } + + public function setPostParam($name, $value){ + + $this->postParams[$name] = $value; + + } public function setOutput($key, $out){ diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 3af12fc..883387d 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -14,55 +14,39 @@ $opt['minDisk'] = 1; $opt['protected'] = false; $opt['minRam'] = 10; -//$new_image = $image->createImage($opt); +//$App->setPostParam('id', 'sdfihlus154dfhj'); +$err = $image->action("createImage"); + //Liste des images $image->action("listImage"); -//$images = $image->listImage(); $im = $App->show(); -$images = json_decode($im, true)["Images"]; -if(isset($images)){ - echo "Images présentes :"; - echo "
"; - foreach($images as $i){ - echo $i['name']; - echo "
"; - } +$images = json_decode($im, true)["Images"]; +$recup; + +echo "Images présentes :"; +echo "
"; +foreach($images as $i){ + $recup = $i; + echo $recup['name']; echo "
"; + //echo $recup['id']; + } +echo "
"; +echo "Erreur capturée: "; +echo "
"; + + /* + //$App->setPostParam('id', $recup['id']); + $App->setPostParam('id', 'sdfihlus154dfhj'); + $err = $image->action("detailsImage"); + $temp = $App->show(); + $ret = json_decode($temp, true)["Images"]; + echo $ret['id']; + */ + //$App->getPostParam("id"); - if(isset($list)){ - foreach ($list as $l) { - echo $l; - echo "
"; - } -} -} -else{ - echo "Aucune image présente\n"; -} - - - -// Détails Image -//$details = $image->imageDetails($id_image); - -//$image->deleteImage('123456'); - -//$image->desactivateImage($id_image); -//$image->reactivateImage($id_image); - -//$file_name = "/home/yogg/Downloads/TinyCore-6.4.1.iso"; -//$image->uploadImage($id_image, $file_name); - -//$image->downloadImage($id_image); -/* -$opt_update = Array(); -$opt_update['name'] = "Test"; -$opt_update['tags'] = null; -$update = $image->updateImage($id_image, $opt_update); -echo $update->name; -*/ ?> \ No newline at end of file diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php index 4ba3493..ff66339 100755 --- a/server/core/ErrorManagement.php +++ b/server/core/ErrorManagement.php @@ -32,6 +32,10 @@ Class errorManagement{ public function UserInputHandler($error){ } + + public function OtherException($error){ + $this->app->setOutput("Error", $error->getMessage); + } } diff --git a/server/core/Image.php b/server/core/Image.php index f309943..71e19ce 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -131,6 +131,8 @@ class image implements Core{ $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); } $this->app->setOutput("Images", $image); @@ -156,6 +158,8 @@ class image implements Core{ $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); } $this->app->setOutput("Images", $result); @@ -171,26 +175,33 @@ class image implements Core{ */ private function detailsImage(){ $id = $this->app->getPostParam("id"); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); - } - try{ - $service = $this->libClass; - $image = $service->getImage($id); - 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); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else{ + try{ + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + else{ + echo 'toto'; + $this->app->setOutput("Images", $image); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** @@ -209,50 +220,53 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - if(!isset($opt)){ + else if(!isset($opt)){ $this->app->setOutput("Error", "Incorrect opt parameter"); } + else{ + try{ + //vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } - try{ - //vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - - $options = Array(); + $options = Array(); - // Voir vérification des types - if(isset($opt['name'])){ //string - $options['name'] = $opt['name']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; - } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; - } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - $image->update($options); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } - $this->app->setOutput("Images", $image); + // Voir vérification des types + if(isset($opt['name'])){ //string + $options['name'] = $opt['name']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + $image->update($options); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $image); + } } /** @@ -269,23 +283,26 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Image doesn't exist"); } - - try{ - $service = $this->libClass; - $image = $this->libClass->getImage($id); - 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); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else{ + try{ + $service = $this->libClass; + $image = $this->libClass->getImage($id); + 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); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** @@ -301,22 +318,27 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } - try{ - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->reactivate(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else + { + try{ + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->reactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** @@ -332,23 +354,28 @@ class image implements Core{ if(!isset($id)){ $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 - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->deactivate(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else + { + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->deactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** @@ -367,26 +394,30 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - if(!isset($file_name)){ + else if(!isset($file_name)){ $this->app->setOutput("Error", "Incorrect file name parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); - $image->uploadData($stream); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); + $image->uploadData($stream); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } } } @@ -403,24 +434,28 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $stream = $image->downloadData(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } - $this->app->setOutput("Images", $stream); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = $image->downloadData(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $stream); + } } /** @@ -438,27 +473,31 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $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); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $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); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } @@ -476,30 +515,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($image_id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $members = $image->listMembers(); - 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); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } - $this->app->setOutput("Images", $members); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($image_id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $members = $image->listMembers(); + 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); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $members); + } } /** @@ -517,31 +560,35 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } - $member = $image->getMember($member_id); - if($member == null){ // if the member don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } - $this->app->setOutput("Images", $member); + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $member); + } } /** @@ -559,30 +606,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; - - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member = $image->getMember($member_id); - if($member == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - $member->delete(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else{ + try{ + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->delete(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** @@ -602,30 +653,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member = $image->getMember($member_id); - if($member == null){ // if the member don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - $member->updateStatus($status); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->updateStatus($status); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } } -- cgit v1.2.3 From e9c7477ff0acedf9b49e508e1543395bbcbf7533 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Sun, 27 Mar 2016 19:24:03 +0200 Subject: Modifications in error management and correct error in Image.php --- server/Test/AppTestClass.php | 8 ++-- server/Test/imageTests.php | 95 +++++++++++++++++++++++++++++++---------- server/core/App.php | 15 ++++--- server/core/ErrorManagement.php | 37 ++++++++++++++-- server/core/Image.php | 8 ++-- 5 files changed, 124 insertions(+), 39 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 3f8abbe..a663514 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -89,9 +89,11 @@ class AppTest{ } public function getPostParam($name){ - - return $this->postParams[$name]; - + if(isset($this->postParams[$name])){ + return $this->postParams[$name]; + }else{ + $this->setOutput("Error", "Missing parameter ".$name); + } } public function setPostParam($name, $value){ diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index d86c664..4adec08 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -6,6 +6,9 @@ include_once("../core/Compute.php"); $image = new Image($App); $compute = new Compute($App); +// Création image +/* +echo "Création image :
"; $opt = Array(); $opt['name'] = "Test"; $opt['tags'] = ['test', 'openstack']; @@ -16,28 +19,86 @@ $opt['minDisk'] = 1; $opt['protected'] = false; $opt['minRam'] = 10; -//$App->setPostParam('id', 'sdfihlus154dfhj'); -//$err = $image->action("createImage"); +$App->setPostParam('opt', $opt); +$image->action("createImage"); +$retCreate = json_decode($App->show(), true)["Images"]; +$idNew = $retCreate['id']; +*/ +/* +// Delete Image +$App->setPostParam('id', $idNew); +$image->action("deleteImage"); +*/ -//Liste des images +// Liste images $image->action("listImage"); $im = $App->show(); $images = json_decode($im, true)["Images"]; -echo "Images présentes :"; -echo "
"; +echo "List images :
"; foreach($images as $i){ - $recup = $i; - echo $recup['name']; + echo $i['name']."
"; // Nom + echo $i['status']."
"; // Status + $id = $i['id']; // Id + echo $id."
"; + foreach ($i['tags'] as $tag) { // Tags + echo $tag."
"; + } echo "
"; - //echo $recup['id']; - } + } + + +// Details images +echo "Détail image :
"; +$App->setPostParam('id', $id); +$image->action("detailsImage"); +$retDetails = json_decode($App->show(), true)["Images"]; +echo $retDetails['id']."
"; +echo "
"; + + +/* +// Download image +$App->setPostParam('id', $id); +$image->action("downloadImage"); +*/ + + +// Desactivate Images +echo "Desactivate image :
"; +echo $id."
"; +$App->setPostParam('id', $id); +$err = $image->action("desactivateImage"); echo "
"; + +/* +// Resactivate Images +echo $id."
"; +$App->setPostParam('id', $id); +$err = $image->action("resactivateImage"); +*/ + + +/* +// Details images +echo "Update image :
"; +$optUpdate = Array(); +$optUpdate['tags'] = ['ciros', 'testUpdate']; +$App->setPostParam('id', $id); +$App->setPostParam('opt', $optUpdate); +$image->action("updateImage"); +$retDetails = json_decode($App->show(), true)["Images"]; +foreach ($retDetails['tags'] as $tag) { // Tags + echo $tag."
"; +} +*/ + + +/* echo "Flavors: "; echo "
"; - $compute->action("listFlavors"); $flavors = json_decode($App->show(), true)["Flavors"]; @@ -49,17 +110,5 @@ foreach($flavors as $f){ echo "vcpus=".$f['vcpus']; echo "
"; } - -/* -$App->setPostParam('id', 354); -$err = $image->action("deleteImage"); -$temp = $App->show(); -$ret = json_decode($temp, true)["Images"]; -echo $ret['id']; -*/ - - - - - +*/ ?> \ No newline at end of file diff --git a/server/core/App.php b/server/core/App.php index 10813bd..48bb9ab 100755 --- a/server/core/App.php +++ b/server/core/App.php @@ -112,15 +112,20 @@ class App{ } public function getPostParam($name){ - - return $this->postParams[$name]; + + if(isset($this->postParams[$name])){ + return $this->postParams[$name]; + }else{ + $this->setOutput("Error", "Missing parameter ".$name); + } } - public function setPostParam($name, $value){ - - $this->postParams[$name]= $value; + + public function setPostParam($param, $value){ + $this->postParams[$param] = $value; + } public function setOutput($key, $out){ diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php index 3257dd3..e7cb83e 100755 --- a/server/core/ErrorManagement.php +++ b/server/core/ErrorManagement.php @@ -18,19 +18,48 @@ Class errorManagement{ } public function BaseErrorHandler($error){ - + $this->app->setOutput("Error", "BaseError"); } public function BadResponseHandler($error){ - $this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!"); + $statusCode = $error->getResponse()->getStatusCode(); + switch ($statusCode) { + case 400: + $this->app->setOutput("Error", "Invalid input."); + break; + + case 401: + $this->app->setOutput("Error", "Authentification failed."); + break; + + case 403: + $this->app->setOutput("Error", "Operation forbidden."); + break; + + case 404: + $this->app->setOutput("Error", "Ressource not found."); + break; + + case 500: + $this->app->setOutput("Error", "Internal server error, please contact an administrator."); + break; + + case 503: + $this->app->setOutput("Error", "Service unvailable for the moment."); + break; + + default: + $this->app->setOutput("Error", "Unknow error, please contact an administrator."); + break; + } } public function NotImplementedHandler($error){ - $this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!"); + $this->app->setOutput("Error", "Internal error (not implemented yet), please contact an administrator"); } public function UserInputHandler($error){ - + $this->app->setOutput("Error", "UserInputError"); } public function OtherException($error){ diff --git a/server/core/Image.php b/server/core/Image.php index 71e19ce..e9736a2 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -76,7 +76,7 @@ class image implements Core{ // Check the image name if(isset($opt['name'])){ - $imagesList = listImage(); + $imagesList = $this->listImage(); if(isset($imagesList)){ foreach($imagesList as $image){ if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error @@ -84,7 +84,7 @@ class image implements Core{ } } } - + $options['name'] = $opt['name']; } else{ $this->app->setOutput("Error", "Missing parameter 'name' for the new image"); @@ -118,7 +118,7 @@ class image implements Core{ if(isset($opt['protected'])){ // boolean $options['protected'] = $opt['protected']; } - if(isset($opt['properties'])){ // type dict ? + if(isset($opt['properties'])){ // type dict $options['properties'] = $opt['properties']; } @@ -187,7 +187,6 @@ class image implements Core{ $this->app->setOutput("Error", "Image doesn't exist"); } else{ - echo 'toto'; $this->app->setOutput("Images", $image); } }catch(BadResponseError $e){ @@ -326,6 +325,7 @@ class image implements Core{ if($image == null){ // if the image don't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } + $image->reactivate(); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); -- cgit v1.2.3 From 19d84e2ae4c6710aac2236df4f135409ef519fc8 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Sun, 27 Mar 2016 19:40:36 +0200 Subject: Update commentaries --- server/core/Automating.php | 15 +++++++---- server/core/ErrorManagement.php | 55 ++++++++++++++++++++++++++++++++++++++--- server/core/Image.php | 4 +-- 3 files changed, 64 insertions(+), 10 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/core/Automating.php b/server/core/Automating.php index 2665541..065cf5e 100644 --- a/server/core/Automating.php +++ b/server/core/Automating.php @@ -1,11 +1,11 @@ {$action.""}(); } - + /** + * Create a new image on a new server + * + * @param $error the error triggered + * + * @return Image the new image created + */ private function createImageOnNewServer(){ try{ $image = new Image($this->app); @@ -87,9 +93,8 @@ class automating implements Core{ }catch(Exception $e){ $this->app->getErrorInstance()->OtherException($e); } + $this->app->setOutput("Auto", $res); } - - } ?> \ No newline at end of file diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php index e7cb83e..be7080b 100755 --- a/server/core/ErrorManagement.php +++ b/server/core/ErrorManagement.php @@ -1,4 +1,13 @@ app = $args; } + /** + * Put an error message corresponding to a base error in the output + * + * @param $error the error triggered + * + * @return String BaseError message + */ public function BaseErrorHandler($error){ $this->app->setOutput("Error", "BaseError"); } + /** + * Put an error message corresponding to a bad response in function of the status code in the output + * + * @param $error the error triggered + * + * @return String Error message + */ public function BadResponseHandler($error){ $statusCode = $error->getResponse()->getStatusCode(); switch ($statusCode) { @@ -54,19 +83,39 @@ Class errorManagement{ } } + /** + * Put an error message corresponding to a not implemented yet error in the output + * + * @param $error the error triggered + * + * @return String internal error message + */ public function NotImplementedHandler($error){ $this->app->setOutput("Error", "Internal error (not implemented yet), please contact an administrator"); } + /** + * Put an error message corresponding to a user input error in the output + * + * @param $error the error triggered + * + * @return String User input error message + */ public function UserInputHandler($error){ $this->app->setOutput("Error", "UserInputError"); } + /** + * Put an error message corresponding to an other error in the output + * + * @param $error the error triggered + * + * @return String error message + */ public function OtherException($error){ $this->app->setOutput("Error", $error->getMessage()); } - } ?> diff --git a/server/core/Image.php b/server/core/Image.php index e9736a2..c595135 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -5,7 +5,7 @@ * @version 1.0 Initialisation of this file * @since 1.0 Core application's file * -* @author Yogg 'yogg at epsina . com' +* @author Evan Pisani 'yogg at epsina . com' * * @todo Complete the functions with errors detection and finish the descriptions */ @@ -19,7 +19,7 @@ include("CoreInterface.php"); /** * Image Class of the back-end application * -* ADD CLASS DESCRIPTION +* Management of images * */ class image implements Core{ -- cgit v1.2.3 From a7bf9306d3844acd160034bb5c64e1ca7ef77ddc Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Sun, 3 Apr 2016 11:15:52 +0200 Subject: Test --- client/js/controllers/image/upload.js | 2 +- client/js/services/Image.js | 12 ++++++------ client/partials/image/upload.html | 14 +++++++++----- server/core/Image.php | 9 +++++---- server/vendor/php-opencloud/openstack | 2 +- 5 files changed, 22 insertions(+), 17 deletions(-) (limited to 'server/core/Image.php') diff --git a/client/js/controllers/image/upload.js b/client/js/controllers/image/upload.js index eca9406..d9587d0 100644 --- a/client/js/controllers/image/upload.js +++ b/client/js/controllers/image/upload.js @@ -56,5 +56,5 @@ mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', }; - + $scope.token=Identity.getToken(); }]); diff --git a/client/js/services/Image.js b/client/js/services/Image.js index d6c9fed..4947a1d 100644 --- a/client/js/services/Image.js +++ b/client/js/services/Image.js @@ -47,11 +47,11 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ var uploadImage=function(fileToUpload, callback) { var form_data = new FormData(); form_data.append('file', fileToUpload); - console.log(fileToUpload) - form_data.append("task" , "image") - form_data.append("token" , Identity.getToken()) - form_data.append('action',"uploadImage") - form_data.append('id','6564') + console.log(fileToUpload); + form_data.append("task" , "image"); + form_data.append("token" , Identity.getToken()); + form_data.append('action',"uploadImage"); + form_data.append('id','6564'); form_data.append('file_name', fileToUpload); $.ajax({ @@ -68,7 +68,7 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ processData:false, // To send DOMDocument or non processed data file it is set to false success: function(data) // A function to be called if request succeeds { - alert("success") + alert("success"); } }); diff --git a/client/partials/image/upload.html b/client/partials/image/upload.html index 72a8e01..3120fe9 100644 --- a/client/partials/image/upload.html +++ b/client/partials/image/upload.html @@ -12,11 +12,15 @@