/**
  * @param  DownloadTokenModel $downloadToken
  * @return DownloadTokenModel
  */
 public function create(models\ModelAbstract $downloadToken)
 {
     if (!$downloadToken instanceof DownloadTokenModel) {
         throw new InvalidArgumentException('Supplied data must be a download token model');
     }
     $downloadToken->token = UserService::getInstance()->generatePassword(60);
     $brandService = BrandService::getInstance();
     $brand = $brandService->loadByOrganization(\App::getOrgUserLogged());
     $router = \Zend_Controller_Front::getInstance()->getRouter();
     $downloadToken->url = $brand->endPoint . $router->assemble(array('controller' => $downloadToken->controller, 'action' => $downloadToken->action, 'token' => $downloadToken->token), 'downloadToken');
     $downloadToken->orgId = \App::getOrgUserLogged()->getId();
     $downloadToken->expireDatetime = \App::config('downloadTokenLifeTime', "+1 day");
     $ident = \Zend_Auth::getInstance()->getIdentity();
     if (isset($ident['username'])) {
         $downloadToken->username = $ident['username'];
     }
     if (isset($ident['authType'])) {
         $downloadToken->authType = $ident['authType'];
     }
     if (isset($ident['apiId'])) {
         $downloadToken->apiId = $ident['apiId'];
     }
     if (isset($ident['impersonation'])) {
         $downloadToken->impersonation = $ident['impersonation'];
     }
     return parent::create($downloadToken);
 }
 public function postAction()
 {
     $this->_helper->output('json');
     $data = $this->_helper->requestData(true);
     $data = $this->_helper->filter($data)->blacklist($this->_blacklistCreateFields);
     $item = new $this->_modelClass($data);
     $this->_preCreate($item);
     $this->_helper->allowed('create', $item);
     $this->_service->create($item);
     $this->view->data = $item->getId();
 }
 /**
  * @param  TemplateModel $template
  * @return TemplateModel
  */
 public function create(ModelAbstract $template, $org = null)
 {
     if ($template->getId()) {
         throw new InvalidArgumentException('Supplied template model already has an Id');
     }
     if (!$template->getType()) {
         throw new InvalidArgumentException('Supplied template model needs a type');
     }
     if (!$org) {
         $org = \App::getOrgUserLogged();
     }
     $template->setOrganizationId($org->getId());
     return parent::create($template);
 }
 public function create(ModelAbstract $model)
 {
     if (!$model instanceof WatcherModel) {
         throw new InvalidArgumentException("Watcher model expected");
     }
     if (!$model->status) {
         $model->status = WatcherModel::STATUS_ACTIVE;
     }
     if (!$model->priority) {
         $model->priority = WatcherModel::PRIORITY_LOW;
     }
     if (is_null($model->tags)) {
         $model->tags = array();
     }
     $model->eventCount = 0;
     $model->eventList = array();
     $result = parent::create($model);
     \App::log()->info("{WATCHERS}{PUSH} Created new Watcher (ID: {$model->id}) for {$model->entityType}: " . implode(', ', $model->entityIds));
     return $result;
 }
 /**
  * Create a model
  *
  * @param  ModelAbstract $model
  * @return ModelAbstract
  */
 public function create(ModelAbstract $model)
 {
     $result = parent::create($model);
     $this->_sendEvent('create', $model);
     return $result;
 }
 /**
  * @param  Application\Model\ServicePackModel $service
  * @return Application\Model\ServicePackModel
  */
 public function create(Model\ModelAbstract $service)
 {
     if (strlen((string) $service->getId())) {
         throw new AppEx\InvalidArgumentException("A new service pack can not have an Id already set");
     }
     $service->published = ServicePackModel::STATUS_NOT_PUBLISHED;
     $tariffService = TariffPlanService::getInstance();
     if ($tariff = $service->getTariffPlanLifeCycle()) {
         $tariff->setName(uniqid('', true));
         $tariff->setId(null);
         try {
             $tariffService->create($tariff);
             $service->setTariffPlanLifeCycleId($tariff->getId());
         } catch (\Exception $e) {
             throw $e;
         }
     }
     if ($tariff = $service->getTariffPlanServices()) {
         $tariff->setName(uniqid('', true));
         $tariff->setId(null);
         try {
             $tariffService->create($tariff);
             $service->setTariffPlanServicesId($tariff->getId());
         } catch (\Exception $e) {
             try {
                 TariffPlanService::getInstance()->delete($service->getTariffPlanLifeCycleId(), TariffPlanService::TYPE_LIFECYCLE);
             } catch (\Exception $e2) {
                 \App::log()->warn($e2);
             }
             throw $e;
         }
     }
     $lcService = LifeCycleService::getInstance();
     if ($lc = $service->getLifeCycle()) {
         $lc->setName(uniqid('', true));
         $lc->setId(null);
         try {
             $lcService->create($lc);
             $service->setLifeCycleId($lc->getId());
         } catch (\Exception $e) {
             try {
                 TariffPlanService::getInstance()->delete($service->getTariffPlanLifeCycleId(), TariffPlanService::TYPE_LIFECYCLE);
             } catch (\Exception $e2) {
                 \App::log()->warn($e2);
             }
             try {
                 TariffPlanService::getInstance()->delete($service->getTariffPlanServicesId(), TariffPlanService::TYPE_SERVICES);
             } catch (\Exception $e2) {
                 \App::log()->warn($e2);
             }
             throw $e;
         }
     }
     $restricService = RestrictionService::getInstance();
     if ($re = $service->getRestrictions()) {
         $re->setName(uniqid('', true));
         $re->setId(null);
         try {
             $restricService->create($re);
             $service->setRestrictionsId($re->getId());
         } catch (\Exception $e) {
             try {
                 TariffPlanService::getInstance()->delete($service->getTariffPlanLifeCycleId(), TariffPlanService::TYPE_LIFECYCLE);
             } catch (\Exception $e2) {
                 \App::log()->warn($e2);
             }
             try {
                 TariffPlanService::getInstance()->delete($service->getTariffPlanServicesId(), TariffPlanService::TYPE_SERVICES);
             } catch (\Exception $e2) {
                 \App::log()->warn($e2);
             }
             try {
                 LifeCycleService::getInstance()->delete($service->getLifeCycleId());
             } catch (\Exception $e2) {
                 \App::log()->warn($e2);
             }
             throw $e;
         }
     }
     try {
         $result = parent::create($service);
     } catch (Exception $e) {
         try {
             TariffPlanService::getInstance()->delete($service->getTariffPlanLifeCycleId(), TariffPlanService::TYPE_LIFECYCLE);
         } catch (\Exception $e2) {
             \App::log()->warn($e2);
         }
         try {
             TariffPlanService::getInstance()->delete($service->getTariffPlanServicesId(), TariffPlanService::TYPE_SERVICES);
         } catch (\Exception $e2) {
             \App::log()->warn($e2);
         }
         try {
             LifeCycleService::getInstance()->delete($service->getLifeCycleId());
         } catch (\Exception $e2) {
             \App::log()->warn($e2);
         }
         try {
             RestrictionService::getInstance()->delete($service->getRestrictionsId());
         } catch (\Exception $e2) {
             \App::log()->warn($e2);
         }
         throw $e;
     }
     try {
         $steeringListService = SteeringListService::getInstance();
         $steeringListService->applySteering($re, $result->getId());
     } catch (Exception $ex) {
         try {
             TariffPlanService::getInstance()->delete($service->getTariffPlanLifeCycleId(), TariffPlanService::TYPE_LIFECYCLE);
         } catch (\Exception $e2) {
             \App::log()->warn($e2);
         }
         try {
             TariffPlanService::getInstance()->delete($service->getTariffPlanServicesId(), TariffPlanService::TYPE_SERVICES);
         } catch (\Exception $e2) {
             \App::log()->warn($e2);
         }
         try {
             LifeCycleService::getInstance()->delete($service->getLifeCycleId());
         } catch (\Exception $e2) {
             \App::log()->warn($e2);
         }
         try {
             RestrictionService::getInstance()->delete($service->getRestrictionsId());
         } catch (\Exception $e2) {
             \App::log()->warn($e2);
         }
         try {
             parent::delete($result->getId());
         } catch (\Exception $e2) {
             \App::log()->warn($e2);
         }
         throw $e;
     }
     return $result;
 }