diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 19:40:10 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 19:40:10 +0200 |
commit | 5ae697ac9dbaf999d51fa7805078249f33c301dc (patch) | |
tree | a4f408c9462ff4353820e266efad4864043d08f2 /businesslayer | |
parent | e9878cb5b583bc993a9f3a482d0b371bbeea5bd2 (diff) |
added proper exception handling for all controllers and businesslayer
Diffstat (limited to 'businesslayer')
-rw-r--r-- | businesslayer/businesslayerexistsexception.php | 39 | ||||
-rw-r--r-- | businesslayer/feedbusinesslayer.php | 12 | ||||
-rw-r--r-- | businesslayer/folderbusinesslayer.php | 11 | ||||
-rw-r--r-- | businesslayer/itembusinesslayer.php | 28 |
4 files changed, 77 insertions, 13 deletions
diff --git a/businesslayer/businesslayerexistsexception.php b/businesslayer/businesslayerexistsexception.php new file mode 100644 index 000000000..40a483528 --- /dev/null +++ b/businesslayer/businesslayerexistsexception.php @@ -0,0 +1,39 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\BusinessLayer; + + +class BusinessLayerExistsException extends BusinessLayerException { + + /** + * Constructor + * @param string $msg the error message + */ + public function __construct($msg){ + parent::__construct($msg); + } + +}
\ No newline at end of file diff --git a/businesslayer/feedbusinesslayer.php b/businesslayer/feedbusinesslayer.php index aba234989..284147242 100644 --- a/businesslayer/feedbusinesslayer.php +++ b/businesslayer/feedbusinesslayer.php @@ -62,11 +62,15 @@ class FeedBusinessLayer extends BusinessLayer { } + /** + * @throws BusinessLayerExistsException if the feed exists already + * @throws BusinessLayerException if the url points to an invalid feed + */ public function create($feedUrl, $folderId, $userId){ // first try if the feed exists already try { $this->mapper->findByUrlHash(md5($feedUrl), $userId); - throw new BusinessLayerException( + throw new BusinessLayerExistsException( $this->api->getTrans()->t('Can not add feed: Exists already')); } catch(DoesNotExistException $ex){} @@ -123,6 +127,9 @@ class FeedBusinessLayer extends BusinessLayer { } + /** + * @throws BusinessLayerException if the feed does not exist + */ public function update($feedId, $userId){ try { $existingFeed = $this->mapper->find($feedId, $userId); @@ -179,6 +186,9 @@ class FeedBusinessLayer extends BusinessLayer { } + /** + * @throws BusinessLayerException if the feed does not exist + */ public function move($feedId, $folderId, $userId){ $feed = $this->find($feedId, $userId); $feed->setFolderId($folderId); diff --git a/businesslayer/folderbusinesslayer.php b/businesslayer/folderbusinesslayer.php index 916476896..a4c025b18 100644 --- a/businesslayer/folderbusinesslayer.php +++ b/businesslayer/folderbusinesslayer.php @@ -51,13 +51,13 @@ class FolderBusinessLayer extends BusinessLayer { $existingFolders = $this->mapper->findByName($folderName, $userId); if(count($existingFolders) > 0){ - throw new BusinessLayerException( + throw new BusinessLayerExistsException( $this->api->getTrans()->t('Can not add folder: Exists already')); } } /** - * @throws BusinessLayerException if name exists already + * @throws BusinessLayerExistsException if name exists already */ public function create($folderName, $userId, $parentId=0) { $this->allowNoNameTwice($folderName, $userId); @@ -70,7 +70,9 @@ class FolderBusinessLayer extends BusinessLayer { return $this->mapper->insert($folder); } - + /** + * @throws BusinessLayerException if the folder does not exist + */ public function open($folderId, $opened, $userId){ $folder = $this->find($folderId, $userId); $folder->setOpened($opened); @@ -79,7 +81,8 @@ class FolderBusinessLayer extends BusinessLayer { /** - * @throws BusinessLayerException if name exists already + * @throws BusinessLayerExistsException if name exists already + * @throws BusinessLayerException if the folder does not exist */ public function rename($folderId, $folderName, $userId){ $this->allowNoNameTwice($folderName, $userId); diff --git a/businesslayer/itembusinesslayer.php b/businesslayer/itembusinesslayer.php index 72323f413..176669971 100644 --- a/businesslayer/itembusinesslayer.php +++ b/businesslayer/itembusinesslayer.php @@ -93,19 +93,28 @@ class ItemBusinessLayer extends BusinessLayer { } + /** + * @throws BusinessLayerException if the item does not exist + */ public function star($feedId, $guidHash, $isStarred, $userId){ - // FIXME: this can throw two possible exceptions - $item = $this->mapper->findByGuidHash($guidHash, $feedId, $userId); - $item->setLastModified($this->timeFactory->getTime()); - if($isStarred){ - $item->setStarred(); - } else { - $item->setUnstarred(); + try { + $item = $this->mapper->findByGuidHash($guidHash, $feedId, $userId); + $item->setLastModified($this->timeFactory->getTime()); + if($isStarred){ + $item->setStarred(); + } else { + $item->setUnstarred(); + } + $this->mapper->update($item); + } catch(DoesNotExistException $ex) { + throw new BusinessLayerException($ex->getMessage()); } - $this->mapper->update($item); } + /** + * @throws BusinessLayerException if the item does not exist + */ public function read($itemId, $isRead, $userId){ $item = $this->find($itemId, $userId); $item->setLastModified($this->timeFactory->getTime()); @@ -134,6 +143,9 @@ class ItemBusinessLayer extends BusinessLayer { } + /** + * @throws BusinessLayerException if there is no newest item + */ public function getNewestItemId($userId) { try { return $this->mapper->getNewestItemId($userId); |