protected function consumptionAction()
 {
     // get the organization ID
     $orgId = \App::getOrgUserLogged()->getId();
     $start = $this->_getParam('start');
     $end = $this->_getParam('end');
     // get target params (comma delimited targets)
     $target = $this->_getParam('target');
     if (!empty($target)) {
         $params = explode(',', $target);
     }
     $this->_reportSrv->getConsumptionData($orgId, $params, $start, $end);
 }
 /**
  * Publish a $list of SIMs into real inventory.
  *
  * The frontend should send a list of SIMs with the following format:
  *
  * {
  *   list:
  *      [
  *         {
  *           type: "subscription ID type, i.e., ID or ICC or IMSI or MSISDN",
  *           id: "the id"
  *         },
  *         {
  *           // repeated
  *         }
  *     ]
  * }
  *
  * or a filters configuration like in a listing query
  *
  * {
  *    filter: {
  *      icc: "foo"
  *    }
  * }
  */
 public function iccsAction()
 {
     if (!$this->getRequest()->isPut()) {
         throw new AppEx\ForbiddenException("Iccs action must be a put request.");
     }
     $icc = $this->getRequest()->getParam('id');
     if (empty($icc)) {
         throw new AppEx\InvalidArgumentException('Bad Request. Invalid or empty ICC.');
     }
     $dumbSim = new SimModel();
     $this->_helper->allowed('preinventory_publish_sim', $dumbSim);
     if ($this->_simSrv->load($icc, \App::getOrgUserLogged(), 'icc')) {
         throw new AppEx\InvalidArgumentException("Invalid parameter value: icc. Supported values are icc numbers only in stock");
     }
     // Syncrhonous request!!!
     $items = array(new SimModel(array('icc' => $icc)));
     try {
         $result = $this->_stockSrv->publish($items, false);
         if (is_array($result)) {
             throw new AppEx\InvalidArgumentException("Some errors publishing subscriptions", array('errorMessages' => $result));
         }
     } catch (\Application\Model\Mapper\Exception\EricssonException $e) {
         foreach ($e->getErrorMessages() as $err) {
             \App::log()->err("[ErrorMessages] " . $err->getDescription());
             if ($err->getCode() == 4100900) {
                 throw new AppEx\InvalidArgumentException("Invalid parameter value: icc. Supported values are non delegated subscriptions.");
             }
         }
         throw $e;
     }
 }
 /**
  * Publish a $list of SIMs into real inventory.
  *
  * The frontend should send a list of SIMs with the following format:
  *
  * {
  *   list:
  *      [
  *         {
  *           type: "subscription ID type, i.e., ID or ICC or IMSI or MSISDN",
  *           id: "the id"
  *         },
  *         {
  *           // repeated
  *         }
  *     ]
  * }
  *
  * or a filters configuration like in a listing query
  *
  * {
  *    filter: {
  *      icc: "foo"
  *    }
  * }
  */
 public function iccsAction()
 {
     if (!$this->getRequest()->isPut()) {
         throw new AppEx\ForbiddenException("Iccs action must be a put request.");
     }
     $icc = $this->getRequest()->getParam('id');
     if (empty($icc)) {
         throw new AppEx\InvalidArgumentException('Bad Request. Invalid or empty ICC.');
     }
     $dumbSim = new SimModel();
     $this->_helper->allowed('preinventory_publish_sim', $dumbSim);
     // Syncrhonous request!!!
     $items = array(new SimModel(array('icc' => $icc)));
     $result = $this->_stockSrv->publish($items, false);
     if (is_array($result)) {
         throw new AppEx\InvalidArgumentException("Some errors publishing subscriptions", array('errorMessages' => $result));
     }
 }
 /**
  *
  * Check permissions according to the data type and return data
  *
  * @param  null                                       $perm
  * @param  bool                                       $listOrFilter
  * @param  array                                      $allowed
  * @return mixed
  * @throws Application\Exceptions\UnexpectedException
  * @throws InvalidArgumentException
  */
 protected function _checkAndGetListData($perm = null, $listOrFilter = false, $allowed = array('POST'))
 {
     if (!in_array($this->getRequest()->getMethod(), $allowed)) {
         throw new AppEx\UnexpectedException("Resquest must be " . implode(' or ', $allowed));
     }
     if (!is_null($perm)) {
         $dumbSim = new Application\Model\SimModel();
         $this->_helper->allowed($perm, $dumbSim);
     }
     $data = $this->_helper->requestData();
     if ($listOrFilter) {
         if (isset($data['list'])) {
             if (empty($data['list']) || !is_array($data['list'])) {
                 throw new InvalidArgumentException('Bad Request. Malformed Json. parameter {list} is empty or is not an array');
             }
         } else {
             if (isset($data['filter'])) {
                 if (!is_array($data['filter'])) {
                     throw new InvalidArgumentException('Bad Request. Malformed Json. parameter {filter} must be an array');
                 }
                 $data['list'] = $this->_stockSrv->buildFilterList($data['filter']);
                 if ($data['list'] === null) {
                     throw new InvalidArgumentException('Invalid filter parameters');
                 }
                 $this->_helper->filterNotAllowedFilters('filter_by', $data['list']);
             } else {
                 throw new InvalidArgumentException('Bad Request. Malformed Json. parameter {list} or {filter} is required');
             }
         }
     } else {
         if (empty($data['list']) || !is_array($data['list'])) {
             throw new InvalidArgumentException('Bad Request. Malformed Json. parameter {list} is empty or is not an array');
         }
     }
     return $data;
 }