public function testListAll()
 {
     $simList = $this->_service->listAll();
     $this->assertNotNull($simList);
     $sims = $simList->getItems();
     foreach ($sims as $sim) {
         $this->assertInstanceOf('\\Application\\Model\\SimModel', $sim);
     }
 }
 /**
  * Lists all sims matching a criteria
  */
 public function indexAction()
 {
     $dumpSim = new SimModel();
     $this->_helper->allowed('list', $dumpSim);
     $filters = $this->_mapToFilter($this->_getFilterParams());
     foreach (array(SimFilterFields::PROVISION_DATE, SimFilterFields::ACTIVATION_DATE) as $key) {
         if (isset($filters[$key])) {
             $filters[$key] = "!<" . $filters[$key];
         }
     }
     try {
         if (isset($filters[SimFilterFields::CURRENT_IP]) && App_Util_Ip::getIpVersion($filters[SimFilterFields::CURRENT_IP]) == App_Util_Ip::v6) {
             $filters[SimFilterFields::CURRENT_IP] = App_Util_Ip::ipv6Expand($filters[SimFilterFields::CURRENT_IP]);
         }
     } catch (InvalidArgumentException $ex) {
         throw new InvalidArgumentException("Invalid parameter value: ip.");
     }
     try {
         if (isset($filters[SimFilterFields::STATIC_IP]) && App_Util_Ip::getIpVersion($filters[SimFilterFields::STATIC_IP]) == App_Util_Ip::v6) {
             $filters[SimFilterFields::STATIC_IP] = App_Util_Ip::ipv6Expand($filters[SimFilterFields::STATIC_IP]);
         }
     } catch (InvalidArgumentException $ex) {
         throw new InvalidArgumentException("Invalid parameter value: staticIp.");
     }
     $this->_checkFilterParams($filters, SimFilterFields::getWhiteList());
     $filterList = $this->_simSrv->buildFilterList($filters);
     $filterHelper = $this->_helper->getHelper('filterNotAllowedFilters');
     $filterHelper->setThrowExOnNotAllowed(true);
     $filterHelper->direct('filter_by', $filterList);
     $params = $this->_getPaginatorParams();
     $simList = $this->_simSrv->listAll($filterList, $params, null, \App::getOrgUserLogged());
     if ($simList instanceof Application\Model\Stream\StreamResultModel) {
         $this->view->subscriptionData = array();
         $simList->getIterator()->addPlugin(new Stream\Plugin\Sim\Permissions());
         foreach ($simList as $value) {
             $subscriptionData = $value->exportData();
             $subscriptionData = $this->_mapToSdp($subscriptionData);
             // Make the data available on the view
             $this->view->subscriptionData[] = $subscriptionData;
         }
         //$this->view->count = $simList->getCount();
         if (empty($this->view->subscriptionData)) {
             $this->getResponse()->setHttpResponseCode(204);
             $this->_helper->viewRenderer->setNoRender(TRUE);
         }
     }
 }
 /**
  * @group EricssonPreinvetoryInt
  */
 public function testDeleteList()
 {
     $fileName = __DIR__ . '/xml/StockTestingList.xml';
     $mimeType = new finfo(FILEINFO_MIME_TYPE);
     $data = $this->_service->getData($fileName, $mimeType->file($fileName));
     $this->assertEquals('sim', $data['_type']);
     $this->_service->createSim($data, $this->_user->getOrganizationId());
     $result = $this->_service->listAll(null, array(), null, $this->_user->getOrganization());
     $resultItems = $result->getItems();
     try {
         $this->_service->deleteList($resultItems);
     } catch (Exception $e) {
         $this->fail('An exception has been raised: ' . $e->getMessage());
     }
     $result = $this->_service->listAll(null, array(), null, $this->_user->getOrganization());
     $this->assertEmpty(0, $result->getItems());
 }
 /**
  * Retrieve location information from a SIM
  */
 public function locationAction()
 {
     $sim = $this->_getSim();
     $this->_helper->filterNotAllowedFields('read_field', $sim);
     $filterList = $this->_simSrv->buildFilterList(array('icc' => $sim->getIcc()));
     $listResult = $this->_simSrv->listAll($filterList, array('count' => 1), null, \App::getOrgUserLogged());
     $items = $listResult->getItems();
     if (!empty($items)) {
         $item = array_shift($items);
         $sim->importData($item->exportData());
     }
     $this->view->locationDetailData = array();
     if ($sim->getLocationManual() && ($loc = $this->_mapLocationToSdp($sim->getLocationManual()->exportData()))) {
         $this->view->locationDetailData['manualLocation'] = $loc;
     }
     if ($sim->getLocationAuto() && ($loc = $this->_mapLocationToSdp($sim->getLocationAuto()->exportData()))) {
         $this->view->locationDetailData['automaticLocation'] = $loc;
     }
 }
 /**
  * Lists all sims matching a criteria
  */
 public function indexAction()
 {
     $params = array();
     if ($this->_hasParam('page')) {
         $params['page'] = $this->_getParam('page', 1);
     }
     if ($this->_hasParam('count')) {
         $params['count'] = $this->_getParam('count');
     }
     if ($this->_hasParam('maxFirstPages')) {
         $params['maxFirstPages'] = $this->_getParam('maxFirstPages');
     }
     // Create a dumb sim for the ACL system checks
     $dumbSim = $this->_createDumpSim();
     // Check if the user is allowed to perform this action
     $this->_helper->allowed('list', $dumbSim);
     switch ($this->_getParam('output')) {
         case 'csv':
             $helper = $this->_helper->output('stream_Csv');
             $helper->setFilename('sim.csv');
             // Default count
             if (empty($params['count'])) {
                 $params['count'] = App_View_Csv::DEFAULT_MAX_ROWS;
             }
             $commonHeaders = $this->_helper->csv()->getHeaders('sim');
             $commonHeaders = $this->_helper->filterNotAllowedExportFields('read_field', $dumbSim, $commonHeaders);
             $this->view->setHeaders($commonHeaders);
             $headersFilters = $this->_helper->csv()->getFilters('sim');
             $this->view->setFilters($headersFilters);
             break;
         default:
             $helper = $this->_helper->output('stream_Json');
             break;
     }
     if (isset($params['requiredFields'])) {
         $requiredFields = explode(':', $params['requiredFields']);
         $this->view->setAllowedFields($requiredFields);
     }
     if (isset($params['skipEmptyItems']) && $params['skipEmptyItems']) {
         $this->view->setSkipEmptyItems(true);
     }
     //Validate interval filter
     //Minimum of one state must be selected
     if ($this->_getParam('interval') && !$this->_getParam('startState') && !$this->_getParam('endState')) {
         throw new \Application\Exceptions\InvalidArgumentException("Minimum of one state must be selected");
     }
     $parameters = $this->getRequest()->getParams();
     $filterList = $this->_simSrv->buildFilterList($parameters);
     $this->_helper->filterNotAllowedFilters('filter_by', $filterList);
     $this->_helper->filterNotAllowedGroupBy('group_by', $filterList);
     $this->_helper->filterNotAllowedSortBy('sort_by', $filterList);
     $simList = $this->_simSrv->listAll($filterList, $params);
     if ($simList instanceof Application\Model\ListResultModel) {
         // Set view vars
         if ($simList instanceof Stream\StreamResultModel) {
             $simList->getIterator()->addPlugin(new Stream\Plugin\Sim\Permissions());
             $this->view->data = $simList;
         } else {
             $items = $simList->getItems();
             foreach ($simList->getItems() as $key => $sim) {
                 try {
                     $this->_helper->checkSimReadPermissions($sim);
                 } catch (\Application\Exceptions\ForbiddenException $e) {
                     unset($items[$key]);
                 }
             }
             $this->view->data = $items;
         }
         $this->view->count = $simList->getCount();
         if (isset($helper)) {
             $helper->addHeaders();
             $this->getResponse()->sendHeaders();
             $this->view->render('');
             $this->_helper->forceExit();
             return;
         }
     } else {
         if ($simList instanceof Application\Model\GroupListModel) {
             $this->_helper->output('json');
             $groups = $simList->getGroups();
             if ($groups) {
                 foreach ($groups as $group) {
                     $items = $group->getItems();
                     foreach ($group->getItems() as $key => $sim) {
                         try {
                             $this->_helper->checkSimReadPermissions($sim);
                         } catch (\Application\Exceptions\ForbiddenException $e) {
                             unset($items[$key]);
                         }
                     }
                     $group->setItems($items);
                 }
             }
             $this->view->data = $simList;
             $this->view->count = $simList->getCount();
         }
     }
 }