/**
  * find a timezone
  *
  * @param string $tzId
  * @param string $userId
  * @throws Exception
  * @return \OCA\Calendar\ITimezone
  */
 public function find($tzId, $userId)
 {
     try {
         return $this->mapper->find($tzId, $userId);
     } catch (DoesNotExistException $ex) {
         throw Exception::fromException($ex);
     } catch (MultipleObjectsReturnedException $ex) {
         throw Exception::fromException($ex);
     }
 }
 /**
  * delete an object from a calendar
  *
  * @param \OCA\Calendar\IObject $object
  * @throws \OCA\Calendar\BusinessLayer\Exception
  */
 public function delete(IObject $object)
 {
     try {
         $this->checkCalendarSupports(Permissions::DELETE);
         if (!$this->api instanceof BackendUtils\IObjectAPIDelete) {
             throw new Exception('Backend does not support deleting objects');
         }
         Util::emitHook('\\OCA\\Calendar', 'preDeleteObject', array($object));
         $this->api->delete($object);
         if ($this->isCachingEnabled) {
             $this->updater->propagate($object->getUri());
         }
         Util::emitHook('\\OCA\\Calendar', 'postDeleteObject', array($object));
     } catch (BackendUtils\Exception $ex) {
         throw Exception::fromException($ex);
     }
 }
 /**
  * Delete a calendar
  * @param \OCA\Calendar\ICalendar $calendar
  * @throws \OCA\Calendar\BusinessLayer\Exception
  */
 public function delete(ICalendar $calendar)
 {
     try {
         $api = $calendar->getBackend()->getCalendarAPI();
         if (!$api instanceof BackendUtils\ICalendarAPIDelete) {
             throw new Exception('Backend does not support deleting calendars!');
         }
         $backendId = $calendar->getBackend()->getId();
         $privateUri = $calendar->getPrivateUri();
         $userId = $calendar->getUserId();
         $api->delete($privateUri, $userId);
         $this->updater->remove($backendId, $privateUri, $userId);
     } catch (BackendUtils\Exception $ex) {
         \OC::$server->getLogger()->debug($ex->getMessage());
         throw Exception::fromException($ex);
     }
 }
 /**
  * validate a subscription
  *
  * @param ISubscription $subscription
  * @throws Exception
  */
 private function validateSubscription(ISubscription &$subscription)
 {
     $backend = $this->backends->bySubscriptionType($subscription->getType());
     if ($backend === null) {
         throw new Exception('Subscription-type not supported');
     }
     try {
         $backend->getBackendAPI()->validateSubscription($subscription);
     } catch (BackendUtils\Exception $ex) {
         throw Exception::fromException($ex);
     }
 }