summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--business/businesslayer.php96
-rw-r--r--business/feedbusinesslayer.php78
-rw-r--r--business/feeddoesnotexistexception.php39
-rw-r--r--business/feedexistsexception.php39
-rw-r--r--business/multiplefeedsreturnedexception.php39
-rw-r--r--business/objectexistsexception.php (renamed from business/feed.php)11
-rw-r--r--business/permissionexception.php37
-rw-r--r--db/objectexistsexception.php0
8 files changed, 333 insertions, 6 deletions
diff --git a/business/businesslayer.php b/business/businesslayer.php
new file mode 100644
index 000000000..d1e43de56
--- /dev/null
+++ b/business/businesslayer.php
@@ -0,0 +1,96 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @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\Business;
+
+use \OCA\AppFramework\Db\DoesNotExistException;
+use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
+
+// use \OCA\News\Db\Entity;
+
+
+abstract class BusinessLayer {
+
+ protected $mapper;
+
+ public function __construct($mapper){
+ $this->mapper = $mapper;
+ }
+
+
+ public function create($entity){
+ $this->validate($entity);
+ $this->mapper->create($entity);
+ }
+
+
+ public function update($entity){
+ try {
+ $this->validate($entity);
+ $this->mapper->update($entity);
+ } catch(DoesNotExistException $ex){
+ $this->throwDoesNotExistException($ex);
+ }
+ }
+
+
+ public function delete($id){
+ try {
+ $this->mapper->delete($id);
+ } catch(DoesNotExistException $ex){
+ $this->throwDoesNotExistException($ex);
+ }
+ }
+
+
+ public function getAll(){
+ return $this->mapper->getAllByUserId($this->api->getUserId());
+ }
+
+
+ public function getById($id){
+ try {
+ $entity = $this->mapper->getByIdAndUserId($id, $this->api->getUserId());
+ if($feed->getUserId() !== $this->api->getUserId()){
+ throw new PermissionException('Not allowed to change the ' +
+ 'feeds of a user other than the current one');
+ } else {
+ return $entity;
+ }
+ } catch(DoesNotExistException $ex){
+ $this->throwDoesNotExistException($ex);
+ } catch(MultipleObjectsReturnedException $ex){
+ $this->throwMultipleObjectsReturnedException($ex);
+ }
+ }
+
+
+ protected abstract function validate($entity);
+
+ protected abstract function throwDoesNotExistException(DoesNotExistException $ex);
+ protected abstract function throwMultipleObjectsReturnedException(MultipleObjectsReturnedException $ex);
+ protected abstract function throwObjectExistsException(ObjectExistsException $ex);
+
+}
diff --git a/business/feedbusinesslayer.php b/business/feedbusinesslayer.php
new file mode 100644
index 000000000..6905a9b4a
--- /dev/null
+++ b/business/feedbusinesslayer.php
@@ -0,0 +1,78 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @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\Business;
+
+use \OCA\AppFramework\Core\API;
+use \OCA\AppFramework\Db\DoesNotExistException;
+use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
+
+use \OCA\News\Db\ObjectExistsException;
+
+
+class FeedBusinessLayer extends BusinessLayer {
+
+ private $updater;
+
+ public function __construct(API $api, $feedMapper, $updater) {
+ parent::__construct($api, $feedMapper);
+ $this->updater = $updater;
+ }
+
+
+ /**
+ * Sets all items with id lower than $idLowerThan as read
+ * @param int $feedId the id of the feed
+ * @param int $idLowerThan all items lower than this id will be marked read
+ * @throws FeedDoesNotExistException if feed with id $id does not exist
+ * @throws MultipleFeedsReturnedException if more feeds than one exist with
+ * the same id
+ */
+ public function setRead($feedId, $idLowerThan){
+ $feed = $this->getById($feedId);
+ $mapper->setAllReadWithIdLowerThan($feed->getId(), $idLowerThan);
+ }
+
+
+ protected function validate($feed){
+ // TODO: validate feed (length, required fields etc)
+ }
+
+
+ protected function throwDoesNotExistException(DoesNotExistException $ex){
+ throw new FeedDoesNotExistException($ex->getMessage());
+ }
+
+
+ protected function throwMultipleObjectsReturnedException(MultipleObjectsReturnedException $ex){
+ throw new MultipleFeedsReturnedException($ex->getMessage());
+ }
+
+
+ protected function throwObjectExistsException(ObjectExistsException $ex){
+ throw new FeedExistsException($ex->getMessage());
+ }
+
+} \ No newline at end of file
diff --git a/business/feeddoesnotexistexception.php b/business/feeddoesnotexistexception.php
new file mode 100644
index 000000000..27c812b01
--- /dev/null
+++ b/business/feeddoesnotexistexception.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @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\Business;
+
+use \OCA\AppFramework\Db\DoesNotExistException;
+
+
+class FeedDoesNotExistException extends DoesNotExistException {
+
+
+ public function __construct($message){
+ parent::__construct($message);
+ }
+
+
+} \ No newline at end of file
diff --git a/business/feedexistsexception.php b/business/feedexistsexception.php
new file mode 100644
index 000000000..7e1561c4c
--- /dev/null
+++ b/business/feedexistsexception.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @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\Business;
+
+use \OCA\News\Db\ObjectExistsException;
+
+
+class FeedExistsException extends ObjectExistsException {
+
+
+ public function __construct($message){
+ parent::__construct($message);
+ }
+
+
+} \ No newline at end of file
diff --git a/business/multiplefeedsreturnedexception.php b/business/multiplefeedsreturnedexception.php
new file mode 100644
index 000000000..556d02e33
--- /dev/null
+++ b/business/multiplefeedsreturnedexception.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @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\Business;
+
+use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
+
+
+class MultipleFeedsReturnedException extends MultipleObjectsReturnedException {
+
+
+ public function __construct($message){
+ parent::__construct($message);
+ }
+
+
+} \ No newline at end of file
diff --git a/business/feed.php b/business/objectexistsexception.php
index ad11a90b6..dd6cb1341 100644
--- a/business/feed.php
+++ b/business/objectexistsexception.php
@@ -23,16 +23,15 @@
*
*/
-namespace OCA\News\Business;
+namespace OCA\News\Db;
-class Feed {
-
- public function __construct($feedMapper) {
- $this->feedMapper = $feedMapper;
- }
+class ObjectExistsException extends \Excpetion {
+ public function __construct($message){
+ parent::__construct($message);
+ }
} \ No newline at end of file
diff --git a/business/permissionexception.php b/business/permissionexception.php
new file mode 100644
index 000000000..da99e236a
--- /dev/null
+++ b/business/permissionexception.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @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 PermissionException extends \Excpetion {
+
+
+ public function __construct($message){
+ parent::__construct($message);
+ }
+
+
+} \ No newline at end of file
diff --git a/db/objectexistsexception.php b/db/objectexistsexception.php
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/db/objectexistsexception.php