/**
  * @group EricssonPreinvetoryInt
  */
 public function testListFilterByCustomerOrder()
 {
     $fileName = __DIR__ . '/csv/StockTestingCSV.txt';
     $mimeType = new finfo(FILEINFO_MIME_TYPE);
     $data = $this->_service->getData($fileName, $mimeType->file($fileName));
     $this->assertEquals('csv', $data['_type']);
     $this->_service->createCsv($data, $this->_user->getOrganizationId());
     $params = array('customerOrderNumber' => 'GEM17223');
     $filterList = $this->_service->buildFilterList($params);
     $result = $this->_service->listAll($filterList, $params, null, $this->_user->getOrganization());
     $this->assertNotNull($result);
     $this->assertGreaterThanOrEqual(1, $result->getCount());
 }
 /**
  * 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);
         }
     }
 }
 /**
  * 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 location matching a criteria
  */
 public function locationAction()
 {
     // Check if the user is allowed to perform this action
     $dumbSim = new Application\Model\SimModel();
     $this->_helper->allowed('list', $dumbSim);
     $filterList = $this->_simSrv->buildFilterList($this->getRequest()->getParams());
     if (is_null($filterList)) {
         $filterList = new App_ListFilter();
     }
     $this->_helper->filterNotAllowedFilters('filter_by', $filterList);
     if ($this->_hasParam('limit')) {
         $limit = $this->_getParam('limit');
     } else {
         $limit = null;
     }
     $simList = $this->_simSrv->listLocations($filterList, $limit);
     $this->_checkReadRights($simList);
     $this->view->data = $simList->getItems();
     $this->view->count = $simList->getCount();
 }
 /**
  * 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();
         }
     }
 }
 public function testRemoveApn()
 {
     $filterList = $this->_service->buildFilterList(array(\Application\Model\Sorting\SimSortingFields::SIM_TYPE => \Application\Model\SimModel::SIM_TYPE_GLOBAL));
     $result = $this->_service->removeApn($filterList, array("123456"));
     $this->assertNotNull($result);
 }