summaryrefslogtreecommitdiffstats
path: root/businesslayer
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-08-31 02:58:56 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-08-31 02:58:56 +0200
commit7036a1407c3dce54a6ac5e283ba55720f85ba7de (patch)
tree7c5fae7ab816a2b0c56b92ca74ebc7cc591d5a3d /businesslayer
parent6f23208ff68d4a8bf2fc20b1fcad6b5e636fb584 (diff)
Throw proper error codes when creating invalid folders through the API, fix #297
Diffstat (limited to 'businesslayer')
-rw-r--r--businesslayer/businesslayerconflictexception.php (renamed from businesslayer/businesslayerexistsexception.php)2
-rw-r--r--businesslayer/businesslayervalidationexception.php39
-rw-r--r--businesslayer/feedbusinesslayer.php4
-rw-r--r--businesslayer/folderbusinesslayer.php20
4 files changed, 55 insertions, 10 deletions
diff --git a/businesslayer/businesslayerexistsexception.php b/businesslayer/businesslayerconflictexception.php
index 2e2fd2665..a65bbf2d6 100644
--- a/businesslayer/businesslayerexistsexception.php
+++ b/businesslayer/businesslayerconflictexception.php
@@ -26,7 +26,7 @@
namespace OCA\News\BusinessLayer;
-class BusinessLayerExistsException extends BusinessLayerException {
+class BusinessLayerConflictException extends BusinessLayerException {
/**
* Constructor
diff --git a/businesslayer/businesslayervalidationexception.php b/businesslayer/businesslayervalidationexception.php
new file mode 100644
index 000000000..c4f2c2387
--- /dev/null
+++ b/businesslayer/businesslayervalidationexception.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 dev@bernhard-posselt.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 BusinessLayerValidationException 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 cf79d0b22..034209add 100644
--- a/businesslayer/feedbusinesslayer.php
+++ b/businesslayer/feedbusinesslayer.php
@@ -88,7 +88,7 @@ class FeedBusinessLayer extends BusinessLayer {
* @param string $feedUrl the url to the feed
* @param int $folderId the folder where it should be put into, 0 for root folder
* @param string $userId for which user the feed should be created
- * @throws BusinessLayerExistsException if the feed exists already
+ * @throws BusinessLayerConflictException if the feed exists already
* @throws BusinessLayerException if the url points to an invalid feed
* @return Feed the newly created feed
*/
@@ -100,7 +100,7 @@ class FeedBusinessLayer extends BusinessLayer {
// try again if feed exists depending on the reported link
try {
$this->mapper->findByUrlHash($feed->getUrlHash(), $userId);
- throw new BusinessLayerExistsException(
+ throw new BusinessLayerConflictException(
$this->api->getTrans()->t('Can not add feed: Exists already'));
} catch(DoesNotExistException $ex){}
diff --git a/businesslayer/folderbusinesslayer.php b/businesslayer/folderbusinesslayer.php
index ee0f8c8af..e43c705c6 100644
--- a/businesslayer/folderbusinesslayer.php
+++ b/businesslayer/folderbusinesslayer.php
@@ -58,13 +58,17 @@ class FolderBusinessLayer extends BusinessLayer {
}
- private function allowNoNameTwice($folderName, $userId){
+ private function validateFolder($folderName, $userId){
$existingFolders = $this->mapper->findByName($folderName, $userId);
if(count($existingFolders) > 0){
- throw new BusinessLayerExistsException(
+ throw new BusinessLayerConflictException(
$this->api->getTrans()->t('Can not add folder: Exists already'));
}
+
+ if(mb_strlen($folderName) === 0) {
+ throw new BusinessLayerValidationException('Folder name can not be empty');
+ }
}
@@ -73,11 +77,12 @@ class FolderBusinessLayer extends BusinessLayer {
* @param string $folderName the name of the folder
* @param string $userId the name of the user for whom it should be created
* @param int $parentId the parent folder id, deprecated we dont nest folders
- * @throws BusinessLayerExistsException if name exists already
+ * @throws BusinessLayerConflictException if name exists already
+ * @throws BusinessLayerValidationException if the folder has invalid parameters
* @return Folder the newly created folder
*/
public function create($folderName, $userId, $parentId=0) {
- $this->allowNoNameTwice($folderName, $userId);
+ $this->validateFolder($folderName, $userId);
$folder = new Folder();
$folder->setName($folderName);
@@ -87,6 +92,7 @@ class FolderBusinessLayer extends BusinessLayer {
return $this->mapper->insert($folder);
}
+
/**
* @throws BusinessLayerException if the folder does not exist
*/
@@ -102,13 +108,13 @@ class FolderBusinessLayer extends BusinessLayer {
* @param int $folderId the id of the folder that should be deleted
* @param string $folderName the new name of the folder
* @param string $userId the name of the user for security reasons
- * @throws BusinessLayerExistsException if name exists already
- * @throws BusinessLayerInvalidParameterException if the foldername is invalid
+ * @throws BusinessLayerConflictException if name exists already
+ * @throws BusinessLayerValidationException if the folder has invalid parameters
* @throws BusinessLayerException if the folder does not exist
* @return Folder the updated folder
*/
public function rename($folderId, $folderName, $userId){
- $this->allowNoNameTwice($folderName, $userId);
+ $this->validateFolder($folderName, $userId);
$folder = $this->find($folderId, $userId);
$folder->setName($folderName);