public function testInvalidLifeCycleType()
 {
     $lifeCycle = new LifeCycleModel($this->_data);
     $result = $this->_validator->isValid($lifeCycle->getId());
     $this->assertFalse($result);
     $messages = $this->_validator->getMessages();
     $this->assertArrayHasKey(App_Validate_Ericsson_LifeCycleExistsById::ERROR_INVALID_TYPE, $messages);
 }
 protected function _validateStatus(LifeCycleModel $lifeCycle, $status)
 {
     $st = $lifeCycle->getStatusByOriginStatus($status);
     if (is_null($st)) {
         $this->_messages[self::MISSING_STATUS] = str_replace('%value%', $status, $this->_messageTemplatesUser[self::MISSING_STATUS]);
         return false;
     }
     if (isset($this->_validators[$status])) {
         $validator = $this->_validators[$status];
         $validator = new $validator(array('useTest' => static::USE_TEST, 'manual' => static::MANUAL));
         if (!$validator->isValid($st)) {
             $this->_messages[$status] = $validator->getMessages();
             return false;
         }
     }
     return true;
 }
Пример #3
0
 /**
  *
  * @param  \Application\Model\TemplateModel           $template
  * @throws App_MigrationTool_TemplatesTo23_Exception
  * @return \Application\Model\LifeCycleModel
  */
 public static function upgradeLifeCycle($template)
 {
     $oldData = $template->exportData();
     $lifeCycle = new LifeCycleModel();
     $lifeCycle->importData($oldData);
     $validatorAuto = new App_MigrationTool_TemplatesTo24_LifeCycleAutomatic();
     $validatorAutoTest = new App_MigrationTool_TemplatesTo24_LifeCycleAutomaticWithTest();
     if (!($validatorAuto->isValid($lifeCycle) || $validatorAutoTest->isValid($lifeCycle))) {
         throw new App_MigrationTool_TemplatesTo24_Exception("LifeCycle template {$template->id} does not need upgrade.");
     }
     $status = $lifeCycle->getStatusByOriginStatus(LifeCycleModel::STATUS_ACTIVATION_READY);
     $transition = $status->getTransitionByDestinationStatus(LifeCycleModel::STATUS_ACTIVE);
     if ($transition->manual) {
         throw new App_MigrationTool_TemplatesTo24_Exception("LifeCycle template {$template->id} already upgraded.");
     }
     $transition->manual = true;
     return $lifeCycle;
 }
Пример #4
0
 public function createError(\Exception $ex)
 {
     if ($ex instanceof \Application\Exceptions\ValidateException) {
         $error = $this->_getFirstError($ex->getValidationErrors(), $field, $message);
         // Error message has a valid UNICA format?
         if ($message && !preg_match('/^Supported values are (.+)/', $message)) {
             $message = '';
         }
     } else {
         $field = '#unknownField#';
         $error = '#unknownError#';
     }
     $errorModel = new ErrorModel(array('fault' => array('code' => FaultModel::FAULT_CODE_CLIENT, 'description' => "Generic Validation fault"), 'code' => 1021, 'category' => ErrorModel::ERROR_CATEGORY_SVC, 'description' => $field ? 'Invalid parameter value: ' . $field . ". " . $message : $ex->getMessage()));
     switch ($error) {
         case \Zend_Validate_StringLength::TOO_SHORT:
         case \Zend_Validate_StringLength::TOO_LONG:
             $errorModel->description = "Invalid '" . $field . "' length." . $message;
             $errorModel->code = 1011;
             break;
         case \Zend_Validate_InArray::NOT_IN_ARRAY:
             switch ($field) {
                 case 'lifeCycleState':
                     $errorModel->description = "Invalid parameter value: {$field}. Supported values are " . implode(",", LifeCycleModel::getStatuses());
                     break;
                 case 'simType':
                     $errorModel->description = "Invalid parameter value: {$field}. Supported values are " . implode(",", array(\Application\Model\SimModel::SIM_TYPE_GLOBAL, \Application\Model\SimModel::SIM_TYPE_LOCAL));
                     break;
                 default:
                     $errorModel->description = "Invalid parameter value: {$field}";
                     break;
             }
             break;
         case 'badPeriod':
             $errorModel->description = "Invalid parameter value: {$field}.";
             break;
         case \App_Validate_NotEmptyIfField::IS_EMPTY:
             $errorModel->description = "Needed parameter was not found: {$field}.";
             $errorModel->code = 1020;
             break;
     }
     return $errorModel;
 }
 public static function getValidatorSpec()
 {
     return array(self::LIFE_CYCLE_STATE => array('InArray' => array('haystack' => \Application\Model\LifeCycleModel::getStatuses(), 'strict' => true, 'breakChainOnFailure' => true)), self::REGION_ID => array('Int' => array('breakChainOnFailure' => true), 'Enum_Region' => array('breakChainOnFailure' => true)), self::COMMERCIAL_GROUP => array('Int' => array('breakChainOnFailure' => true)), self::BILLING_ACCOUNT => array('Int' => array('breakChainOnFailure' => true)), self::SIM_TYPE => array('NotEmpty' => array('breakChainOnFailure' => true), 'SimType' => array('breakChainOnFailure' => true)), self::OPERATOR => array('StringLength' => array('max' => 6, 'min' => 1, 'encoding' => "UTF-8", 'breakChainOnFailure' => true)), self::STATIC_IP => array('Ip' => array('breakChainOnFailure' => true)), self::EXPENSE_VOICE => self::getExpenseSpec(), self::EXPENSE_DATA => self::getExpenseSpec(), self::EXPENSE_SMS => self::getExpenseSpec(), self::EXPENSE_TOTAL => self::getExpenseSpec(), self::CUSTOMER => array('Ericsson_OrganizationExistsById' => array('organizationType' => \Application\Model\Organization\OrgCustomerModel::ORG_TYPE, 'breakChainOnFailure' => true)), self::LTE_ENABLED => array('NotEmpty' => array('breakChainOnFailure' => true), 'InArray' => array('haystack' => array('true', 'false', '1', '0'), 'strict' => true, 'breakChainOnFailure' => true)));
 }
Пример #6
0
 /**
  * @param $state
  * @param $data array|App_FilterList
  * @return void
  */
 public function changeLifeCycleStateSync($oldState, $newState, $simId)
 {
     if (!in_array($oldState, LifeCycleModel::getStatuses()) || !in_array($newState, LifeCycleModel::getStatuses())) {
         throw new InvalidArgumentException("Invalid state");
     }
     $mapper = SimMapper::getInstance();
     if ($newState === LifeCycleModel::STATUS_RESTORE) {
         $result = $mapper->restoreSuspendedLifeCycleStateSync($simId);
     } else {
         //find operation cost
         $cost = $mapper->getLifeCycleStateCost($oldState, $newState, $simId);
         $result = $mapper->changeLifeCycleStateSync($oldState, $newState, $simId, $cost);
     }
     \App::audit('Changed life cycle status on sims to ' . $newState . '. Handler: ' . $result, null);
     return $result;
 }
 protected function _updateEricsson(Model\LifeCycleModel $lifeCycle)
 {
     $methodName = self::METHOD_NAME_UPDATE;
     try {
         $proto = $this->_createProto($methodName);
         $mappedData = $this->_mapModelToEricssonModel($lifeCycle->exportData());
         $proto->parse($mappedData, new \DrSlump\Protobuf\Codec\PhpArray());
         $proto->setId($mappedData['id']);
         $response = $this->_sendRequest($methodName, array('protoMessage' => $proto));
     } catch (Exception $e) {
         \App::log()->CRIT($e);
     }
     $this->_checkPostResponse($response);
     //The request has gone ok, but there is a reason code, so we will return a 304
     if ($response->getResult()->getCode() == 0 && $response->getResult()->getReasonCode()) {
         $data = array('reason' => $response->getResult()->getReason(), 'code' => $response->getResult()->getReasonCode() ?: $response->getResult()->getCode());
         throw new EricssonException($response->getResult()->getReason(), $data, null, 304);
     }
     $lifeCycle->setId($mappedData['id']);
     return $lifeCycle->getId();
 }
 /**
  * Get one lifecycle, given its ID.
  *
  * @param  mixed $id
  * @return mixed
  */
 protected function _findOneById($id)
 {
     $proto = $this->_createProto(self::METHOD_NAME_GETDATA);
     $proto->setId($id);
     $response = $this->_sendRequest(self::METHOD_NAME_GETDATA, array('protoMessage' => $proto), $this->getEricssonService());
     if ($this->_checkGetResponse($response)) {
         $data = $response->serialize(new \DrSlump\Protobuf\Codec\PhpArray());
         if ($data) {
             unset($data['result']);
         }
         $model = new \Application\Model\LifeCycleModel($this->_mapEricssonModelToModel($data));
         $model->setId($id);
         return $model;
     }
     return NULL;
 }
Пример #9
0
 /**
  * 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);
 }
Пример #10
0
 public function createError(\Exception $ex)
 {
     if ($ex instanceof ValidateException) {
         $error = $this->_getFirstError($ex->getValidationErrors(), $field, $message);
         // Error message has a valid UNICA format?
         $origMessage = $message;
         if ($message && !preg_match('/^Supported values are (.+)/', $message)) {
             $message = '';
         }
     } else {
         $field = '#unknownField#';
         $error = '#unknownError#';
     }
     $exMessage = preg_replace('/(.*)filter\\s*\'(\\w+)\': (.*)/', '$1parameter value: $2.', $ex->getMessage());
     $errorModel = new ErrorModel(array('fault' => array('code' => FaultModel::FAULT_CODE_CLIENT, 'description' => "Generic Validation fault"), 'code' => 1021, 'category' => ErrorModel::ERROR_CATEGORY_SVC, 'description' => $field ? 'Invalid parameter value: ' . $field . ". " . $message : $exMessage));
     switch ($error) {
         case 'customerId':
             //TODO this validation should throw a NotFoundException instead
             //of a ValidationException this is a very dirty approach to the
             //problem
             if (preg_match("/No\\sorganization\\s'(?P<customerId>[[:ascii:]]+)'\\swas\\sfound/", $origMessage, $matches)) {
                 $message = sprintf("Resource %s does not exist", $matches['customerId']);
                 $errorModel->description = $message;
                 $errorModel->code = 1006;
             }
             break;
             //[Apism2m] SVC 1020 o SVC 1021
             //According mail from apism2m list, change 1020 code to 1021.
             //            case \Zend_Validate_NotEmpty::IS_EMPTY:
             //                $errorModel->description = "Needed parameter not found: '" . $field . "' - " . $message;
             //                $errorModel->code = 1020;
             //                break;
         //[Apism2m] SVC 1020 o SVC 1021
         //According mail from apism2m list, change 1020 code to 1021.
         //            case \Zend_Validate_NotEmpty::IS_EMPTY:
         //                $errorModel->description = "Needed parameter not found: '" . $field . "' - " . $message;
         //                $errorModel->code = 1020;
         //                break;
         case \Zend_Validate_StringLength::TOO_LONG:
             if (preg_match('/is more than (?P<num>\\d+) characters long/', $origMessage, $matches)) {
                 $message = 'Length should be less than ' . $matches['num'] . ' characters';
             }
             $errorModel->description = "Invalid '" . $field . "' length. " . $message;
             $errorModel->code = 1011;
             break;
         case \Zend_Validate_InArray::NOT_IN_ARRAY:
             switch ($field) {
                 case 'lifeCycleState':
                     $errorModel->description = "Invalid parameter value: {$field}. Supported values are " . implode(",", LifeCycleModel::getStatuses());
                     break;
                 case 'simType':
                     $errorModel->description = "Invalid parameter value: {$field}. Supported values are " . implode(",", array(\Application\Model\SimModel::SIM_TYPE_GLOBAL, \Application\Model\SimModel::SIM_TYPE_LOCAL));
                     break;
                 default:
                     $errorModel->description = "Invalid parameter value: {$field}";
                     break;
             }
             break;
         case 'badPeriod':
             $errorModel->description = "Invalid parameter value: {$field}.";
             break;
         case \App_Validate_Enum_Currency::CURRENCY:
             $errorModel->description = "Invalid parameter value: {$field}.";
             break;
         case \App_Validate_NotEmptyIfField::IS_EMPTY:
             $errorModel->description = "Needed parameter was not found: {$field}.";
             $errorModel->code = 1020;
             break;
         case \App_Validate_GSM0338Charset::INVALID_CHAR:
             $errorModel->code = 1012;
             break;
     }
     return $errorModel;
 }
Пример #11
0
 /**
  * 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);
 }
 public static function getValidatorSpec()
 {
     return array(self::LEGACY => array('NotEmpty' => array('breakChainOnFailure' => true), 'InArray' => array('haystack' => array('true', 'false', '1', '0'), 'strict' => true, 'breakChainOnFailure' => true)), self::LIFE_CYCLE_STATUS => array('InArray' => array('haystack' => \Application\Model\LifeCycleModel::getStatuses(), 'strict' => true, 'breakChainOnFailure' => true)), self::COMMERCIAL_GROUP => array('Int' => array('breakChainOnFailure' => true)));
 }