public function testUpdateConsumptionControlVoiceMonthlyOneSim() { $data = array('voiceMonthly' => array('enabled' => true, 'value' => 22)); $consumptionLimitModel = new ConsumptionControlLimitModel($data); $sim = $this->_service->load("00000000000000000015"); $this->_service->updateConsumptionControl($consumptionLimitModel, $sim); }
public function consumptionControlAction() { $data = $this->_checkAndGetListData('update_consumption_control', true); if (empty($data['limits'])) { throw new InvalidArgumentException('Bad Request. Malformed Json. parameter {limits} is required'); } $limits = new \Application\Model\Sim\ConsumptionControlLimitModel($data['limits']); $this->_helper->filterNotAllowedFields('update_field', $limits); $watcher = $this->_simSrv->updateConsumptionControl($limits, $data['list']); $this->_helper->filterNotAllowedFields('read_field', $watcher); // Respond with the transaction ID $this->view->watcher = $watcher; }
/** * 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); }