add exception management, correct mistakes in error management in Image.php and add function to simplify parameters using in tests

This commit is contained in:
Yoggzo 2016-03-17 11:34:56 +01:00
parent e01936a73e
commit fe0eb3a9e2
4 changed files with 338 additions and 289 deletions

View file

@ -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;
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);
}
$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);
}
}
}
}