/**
  * 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;
     }
 }
Ejemplo n.º 2
0
 /**
  * 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 publishAction()
 {
     if (!$this->getRequest()->isPost()) {
         throw new AppEx\UnexpectedException("Resquest must be POST");
     }
     $dumbSim = new SimModel();
     $this->_helper->allowed('preinventory_publish_sim', $dumbSim);
     $data = $this->_helper->requestData();
     if (isset($data['list'])) {
         if (!is_array($data['list'])) {
             throw new AppEx\InvalidArgumentException('Bad Request. Invalid SIMs list.');
         }
         $listOrFilter = array();
         foreach ($data['list'] as $item) {
             if (is_array($item)) {
                 if (!isset($item['id']) && !strlen($item['id'])) {
                     throw new AppEx\InvalidArgumentException('Error publishing SIM list. Sim with no id.');
                 }
                 $idType = isset($item['type']) ? $item['type'] : 'icc';
                 $id = $item['id'];
             } else {
                 if (is_string($item)) {
                     $idType = 'icc';
                     $id = $item;
                 }
             }
             if ($id && $idType) {
                 $listOrFilter[] = new SimModel(array(strtolower($idType) => $id));
             }
         }
     } else {
         if (isset($data['filter'])) {
             if (!is_array($data['filter'])) {
                 throw new AppEx\InvalidArgumentException('Bad Request. Invalid filter list.');
             }
             $listOrFilter = $this->_stockSrv->buildFilterList($data['filter']);
             $this->_helper->filterNotAllowedFilters('filter_by', $listOrFilter);
         } else {
             throw new AppEx\UnexpectedException("Resquest must contain either a list or a filter");
         }
     }
     // Respond with the transaction ID
     $watcher = $this->_stockSrv->publish($listOrFilter);
     $this->view->watcher = $watcher->reload();
     $this->_helper->filterNotAllowedFields('read_field', $watcher);
 }
 /**
  * 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));
     }
 }