public function testUpdate()
 {
     $sim = $this->_service->load("00000000000000000015");
     do {
         $newCustomField1 = "testingServiceUpdateCustom-" . microtime(true);
     } while ($sim->getCustomField_1() == $newCustomField1);
     $sim->simType = SimModel::SIM_TYPE_GLOBAL;
     $sim->simModel = "MotorolX23";
     $sim->setApns(array());
     $sim->staticIpAddress = null;
     $sim->staticIpApnIndex = null;
     $sim->setAlias('aaaa');
     $sim->setCustomField_1($newCustomField1);
     $sim->setRegionId(-1);
     try {
         $this->_service->update($sim);
     } catch (\Exception $e) {
         \App::log()->debug($e);
         throw $e;
     }
     $simModified = $this->_service->load("00000000000000000015");
     $oldData = $sim->exportData();
     $newData = $simModified->exportData();
     unset($oldData['apns']);
     unset($newData['apns']);
     unset($oldData['staticIpApnIndex']);
     unset($newData['staticIpApnIndex']);
     unset($oldData['staticIpAddress']);
     unset($newData['staticIpAddress']);
     unset($oldData['expenseMonthly']['voiceFee']);
     unset($newData['expenseMonthly']['voiceFee']);
     unset($oldData['expenseMonthly']['smsFee']);
     unset($newData['expenseMonthly']['smsFee']);
     unset($oldData['expenseMonthly']['dataFee']);
     unset($newData['expenseMonthly']['dataFee']);
     unset($oldData['expenseMonthly']['totalFee']);
     unset($newData['expenseMonthly']['totalFee']);
     unset($oldData['expenseMonthly']['other']);
     unset($newData['expenseMonthly']['other']);
     unset($oldData['expenseMonthly']['total']);
     unset($newData['expenseMonthly']['total']);
     unset($oldData['expenseMonthly']['voiceGroupWarning']);
     unset($newData['expenseMonthly']['voiceGroupWarning']);
     unset($oldData['expenseMonthly']['smsGroupWarning']);
     unset($newData['expenseMonthly']['smsGroupWarning']);
     unset($oldData['expenseMonthly']['dataGroupWarning']);
     unset($newData['expenseMonthly']['dataGroupWarning']);
     unset($oldData['expenseMonthly']['totalGroupWarning']);
     unset($newData['expenseMonthly']['totalGroupWarning']);
     unset($oldData['regionId']);
     unset($newData['regionId']);
     $this->assertEquals($oldData, $newData);
 }
 /**
  * Update a sim identified by its Id
  */
 public function putAction()
 {
     $data = $this->_helper->requestData(true);
     // Try to load the sim
     $id = $this->_getParam('id');
     $sim = $this->_simSrv->load($id, \App::getOrgUserLogged());
     if (empty($sim)) {
         throw new NotFoundException('Sim ' . $id . ' not found', 404);
     }
     // Translate staticIp into staticIpAddress
     //TODO [alfred] No se hacen mapeos de FE!!! Borrar y hablar con FE.
     if (!empty($data['staticIp'])) {
         $data['staticIpAddress'] = $data['staticIp'];
     }
     $data = $this->_helper->filter($data)->blacklist(array('id', 'status', 'masterId', 'serviceProviderEnablerId', 'serviceProviderCommercialId', 'customerId'));
     // Check permissions
     $this->_helper->allowed('update', $sim);
     // Make sure that simType is uppercase
     if (!empty($data['simType'])) {
         $data['simType'] = strtoupper($data['simType']);
     }
     // Modify the current details with the new data
     $copy = clone $sim;
     $sim->importData($data);
     // Modify the current details with the new data
     $this->_helper->filterNotAllowedFields("update_field", $sim);
     // Add validation required fields
     $sim->setId($copy->getId());
     if ($sim->simType === null) {
         $sim->setSimType($copy->getSimType());
     }
     if ($sim->simModel === null) {
         $sim->setSimModel($copy->getSimModel());
     }
     $sim->setCustomerId($copy->getCustomerId());
     // Perform the update
     $this->_simSrv->update($sim);
     $this->view->data = $sim->getId();
 }
 /**
  * Update a sim identified by its Id
  */
 public function putAction()
 {
     $sim = $this->_getSim();
     $attr = $this->getRequest()->getParam('attribute');
     $value = $this->getRequest()->getParam('value');
     if (is_null($value)) {
         throw new InvalidArgumentException("Invalid value.");
     }
     $this->_helper->allowed('update', $sim);
     switch ($attr) {
         case 'alias':
             $sim->setAlias($value);
             break;
         case 'billingAccount':
             throw new DeprecatedException('Parameter "billingAccount" is deprecated.');
             break;
         case 'customField1':
             $sim->setCustomField_1($value);
             break;
         case 'customField2':
             $sim->setCustomField_2($value);
             break;
         case 'customField3':
             $sim->setCustomField_3($value);
             break;
         case 'customField4':
             $sim->setCustomField_4($value);
             break;
         case 'commercialGroup':
             $commercialGroup = CommercialGroupService::getInstance()->load($value);
             $this->_helper->allowed('read', $commercialGroup);
             $this->_helper->allowed('assign_sim', $commercialGroup);
             $this->_simSrv->changeCommercialGroup($commercialGroup, array($sim->getId()));
             $this->getResponse()->setHttpResponseCode(204);
             return;
         case 'lifeCycleStatus':
             // Generic permission
             $this->_helper->allowed('change_lifecycle_status', $sim);
             // Validate status
             if (!in_array($value, LifeCycleModel::getStatuses())) {
                 throw new InvalidArgumentException("Invalid parameter value: {$attr}.");
             }
             // Status permission
             switch ($value) {
                 case LifeCycleModel::STATUS_RETIRED:
                 case LifeCycleModel::STATUS_SUSPENDED:
                     $this->_helper->allowed('change_lifecycle_status_to_suspended_or_retired', $sim);
                     break;
                 case LifeCycleModel::STATUS_DEACTIVATED:
                     $this->_helper->allowed('change_lifecycle_status_to_deactivated', $sim);
                     break;
                 case LifeCycleModel::STATUS_RESTORE:
                     $this->_helper->allowed('restore_suspended_lifecycle_status', $sim);
                     break;
             }
             // Change status
             $this->_simSrv->changeLifeCycleStateSync($sim->lifeCycleStatus, $value, $sim->getId());
             $this->getResponse()->setHttpResponseCode(204);
             return;
         default:
             throw new InvalidArgumentException("Invalid attribute");
     }
     $this->_simSrv->update($sim);
     $this->getResponse()->setHttpResponseCode(204);
 }
 /**
  * Update a sim identified by its Id
  */
 public function putAction()
 {
     $sim = $this->_getSim();
     $data = $this->_helper->requestData();
     if (is_object($data)) {
         $data = get_object_vars($data);
     }
     $this->_helper->allowed('update', $sim);
     $apnsInfoModified = false;
     foreach ($data as $attr => $value) {
         if (is_null($value)) {
             throw new InvalidArgumentException("Invalid parameter value: {$attr}.");
         }
         switch ($attr) {
             case 'alias':
                 $this->_helper->allowedField('update_field', 'alias', $sim);
                 $sim->setAlias($value);
                 break;
             case 'customField1':
                 $this->_helper->allowedField('update_field', 'customField_1', $sim);
                 $sim->setCustomField_1($value);
                 break;
             case 'customField2':
                 $this->_helper->allowedField('update_field', 'customField_2', $sim);
                 $sim->setCustomField_2($value);
                 break;
             case 'customField3':
                 $this->_helper->allowedField('update_field', 'customField_4', $sim);
                 $sim->setCustomField_3($value);
                 break;
             case 'customField4':
                 $this->_helper->allowedField('update_field', 'customField_4', $sim);
                 $sim->setCustomField_4($value);
                 break;
             case 'staticIp':
                 $this->_helper->allowedField('update_field', 'staticIpAddress', $sim);
                 $sim->setStaticIpAddress($value["ipv4"]);
                 $apnsInfoModified = true;
                 break;
             case 'staticApnIndex':
                 $this->_helper->allowedField('update_field', 'apns', $sim);
                 if ($value != -1) {
                     $value++;
                 }
                 $sim->setStaticIpApnIndex($value);
                 $apnsInfoModified = true;
                 break;
             case 'apn0':
             case 'apn1':
             case 'apn2':
             case 'apn3':
             case 'apn4':
             case 'apn5':
             case 'apn6':
             case 'apn7':
             case 'apn8':
             case 'apn9':
                 $this->_helper->allowedField('update_field', 'apns', $sim);
                 //pre validate apn
                 $apnValidator = new App_Validate_SimApn();
                 if ($value == '-') {
                     $value = "";
                 }
                 $isValid = $apnValidator->isValid($value, $sim->exportData());
                 if (!$isValid) {
                     throw new InvalidArgumentException("Invalid parameter value: {$attr}");
                 }
                 $apnId = substr($attr, 3, 1);
                 $apns = $sim->getApns();
                 if ($apns[$apnId] != $value) {
                     $apns[$apnId] = $value;
                     $sim->setApns($apns);
                     $apnsInfoModified = true;
                 }
                 break;
             case 'commercialGroup':
                 if (empty($value)) {
                     throw new InvalidArgumentException("Invalid parameter value: {$attr}. Commercial group must be a not empty string.");
                 }
                 $commercialGroup = CommercialGroupService::getInstance()->load($value);
                 $this->_helper->allowed('read', $commercialGroup);
                 $this->_helper->allowed('assign_sim', $commercialGroup);
                 if ($sim->customerId != $commercialGroup->customerId) {
                     throw new InvalidArgumentException("Invalid parameter value: {$attr}. Sim CustomerId distinct to commercial Group customerId");
                 }
                 // Change commercial group
                 $this->_simSrv->changeCommercialGroup($commercialGroup, array($sim->getId()), true);
                 // End request
                 $this->getResponse()->setHttpResponseCode(204);
                 $this->_helper->viewRenderer->setNoRender(TRUE);
                 return;
             case 'lifeCycleStatus':
                 // Generic permission
                 $this->_helper->allowed('change_lifecycle_status', $sim);
                 // Validate status
                 if (!in_array($value, LifeCycleModel::getStatuses())) {
                     throw new InvalidArgumentException("Invalid parameter value: {$attr}.");
                 }
                 // Status permission
                 switch ($value) {
                     case LifeCycleModel::STATUS_RETIRED:
                     case LifeCycleModel::STATUS_SUSPENDED:
                         $this->_helper->allowed('change_lifecycle_status_to_suspended_or_retired', $sim);
                         break;
                     case LifeCycleModel::STATUS_DEACTIVATED:
                         $this->_helper->allowed('change_lifecycle_status_to_deactivated', $sim);
                         break;
                     case LifeCycleModel::STATUS_RESTORE:
                         $this->_helper->allowed('restore_suspended_lifecycle_status', $sim);
                         break;
                 }
                 // Change status
                 $this->_simSrv->changeLifeCycleStateSync($sim->lifeCycleStatus, $value, $sim->getId());
                 // End request
                 $this->getResponse()->setHttpResponseCode(204);
                 $this->_helper->viewRenderer->setNoRender(TRUE);
                 return;
             case 'dailyConsumptionThreshold':
             case 'monthlyConsumptionThreshold':
                 // Check permission
                 $this->_helper->allowed('update_consumption_control', $sim);
                 // Modification
                 $limits = new \Application\Model\Sim\ConsumptionControlLimitModel($this->_getLimits($value, $attr === 'dailyConsumptionThreshold' ? 'Daily' : 'Monthly'));
                 $this->_simSrv->updateConsumptionControl($limits, $sim);
                 break;
             case 'monthlyExpenseLimit':
                 // Check permission
                 $this->_helper->allowed('async_sim_change_expenselimit', $sim);
                 // Modification
                 $value = $this->_mapLimitDecimal($sim, $value);
                 $limits = new \Application\Model\Sim\ExpenseControlLimitModel($this->_getLimits($value));
                 $this->_simSrv->changeExpenseLimit($limits, $sim);
                 break;
             case 'lteEnabled':
                 // Check permission
                 $this->_helper->allowed('changeLte', $sim);
                 //Modification
                 $this->_simSrv->changeLteSync($value, $sim->getId());
                 break;
             default:
                 throw new InvalidArgumentException("Invalid parameter value: {$attr}.");
         }
     }
     // When some data related with the apns are received we need to send all the related data
     // otherwise staticIpAddress is fixed to null to avoid to call to changeSimApn function and
     // staticIpApnIndex and Apns are fixed to null to avoid error validations.
     if (!$apnsInfoModified) {
         $sim->setStaticIpAddress(null);
         $sim->setStaticIpApnIndex(null);
         $sim->setApns(null);
     } else {
         $this->_validateAPNsInfo($sim, $data);
     }
     try {
         $this->_simSrv->update($sim);
     } catch (ValidateException $ex) {
         throw $this->_mapException($ex);
     }
     $this->getResponse()->setHttpResponseCode(204);
     $this->_helper->viewRenderer->setNoRender(TRUE);
 }