public function testValidateLifeCycleExists()
 {
     $lifeCycle = new LifeCycleModel($this->_data);
     LifeCycleMapper::getInstance()->insert($lifeCycle);
     $this->_LifeCycleIdToDelete = $lifeCycle->getId();
     $this->assertNotNull($lifeCycle->getId());
     $result = $this->_validator->isValid($lifeCycle->getId());
     $this->assertTrue($result);
 }
 protected function _createLifeCycle()
 {
     $lifeCycle = new LifeCycleModel($this->_lifeCycleData);
     $this->_lfMapper->insert($lifeCycle);
     $this->assertNotNull($lifeCycle->getId());
     $newLifeCycle = $this->_lfMapper->findOneById($lifeCycle->getId());
     $this->assertNotNull($newLifeCycle, "LifeCycle does not exist");
     $this->_checkSavedData($this->_lifeCycleData, $lifeCycle, 'LifeCycle');
     return $lifeCycle->getId();
 }
 public function changeLifeCycleState($state, $data, $isPublishRollback = null)
 {
     $this->getCache()->clean();
     $methodName = self::METHOD_NAME_ASYNC_CHANGE_LIFE_CYCLE;
     $watcher = $this->_constructWatcherToTransaction();
     $watcher->params->action = "simChangeLifeCycleStatus";
     $watcher->params->newLifeCycleStatus = $state;
     /**
      * @var $proto \Application\Proto\Inventory\ChangeLCState proto
      */
     $proto = $this->_createSubscriptionsProto($methodName, $data, SubscriptionId\IdType::ID, $watcher);
     $proto->setNewState(LifeCycleMapper::getInstance()->mapLifeCycleStatusToEricsson($state));
     if (isset($isPublishRollback)) {
         $proto->setIsPublishRollback($isPublishRollback);
     }
     // Return the transaction ID
     return $this->_sendAsyncRequest($methodName, $proto, $data, array(), $watcher);
 }
 protected function _mapBusinessRuleToEricsson(array $businessRule)
 {
     if (isset($businessRule['type'])) {
         $businessRule['businessRuleType'] = $this->_mapBusinessRuleTypeToEricsson($businessRule['type']);
         unset($businessRule['type']);
     }
     if (isset($businessRule['nextLifeCycleStatus'])) {
         $businessRule['nextLifecycleState'] = LifeCycleMapper::getInstance()->mapLifeCycleStatusToEricsson($businessRule['nextLifeCycleStatus']);
         unset($businessRule['nextLifeCycleStatus']);
     }
     return $businessRule;
 }
 public function getLifeCycleStateCost($oldState, $newState, $simId, $idType = SubscriptionId\IdType::ID)
 {
     $methodName = self::METHOD_NAME_CHANGE_LIFE_CYCLE_COST_SYNC;
     /**
      * @var $proto \Application\Proto\Subscription\ChangeLCState proto
      */
     $proto = $this->_createProto($methodName);
     $subsId = new SubscriptionId();
     $subsId->setId($simId);
     $subsId->setType($idType);
     $proto->setSubscriptionId($subsId);
     $proto->setOldState(LifeCycleMapper::getInstance()->mapLifeCycleStatusToEricsson($oldState));
     $proto->setNewState(LifeCycleMapper::getInstance()->mapLifeCycleStatusToEricsson($newState));
     $response = $this->_sendRequest($methodName, array('protoMessage' => $proto));
     if ($this->_checkPutResponse($response)) {
         $data = $response->serialize(new Codec\PhpArray());
         if (isset($data['cost'])) {
             return $data['cost'];
         }
     }
     return null;
 }
 public function testMapEricssonTransitionToModel()
 {
     $transition = array('manualTransitionModified' => 'false');
     $this->assertEquals(array('manualModified' => 'false'), $this->_mapper->mapEricssonTransitionToModel($transition));
 }
 public function mapChargesDetail($protoData, $fieldPrefix = '')
 {
     if ($protoData instanceof \DrSlump\Protobuf\Message) {
         $protoType = $data = $protoData->serialize(new \DrSlump\Protobuf\Codec\PhpArray());
     }
     $data = $this->_filterFieldNames(new \App_Filter_UnderscoreToCamelCase(), $data);
     $commonFields = array('entity', 'amount', 'timestamp', 'currency', 'msisdn', 'icc', 'imsi', 'subscriptionState', 'isPool', 'billingCycleStart', 'billingAccountName', 'commercialPlan', 'networkOperatorName', 'commercialGroupName', 'aggregatorName');
     $fields = array_keys($data);
     foreach ($fields as $field) {
         if (!in_array($field, $commonFields)) {
             $data[$fieldPrefix . '_' . $field] = $data[$field];
             unset($data[$field]);
         }
     }
     if (isset($data['subscriptionState'])) {
         $data['subscriptionState'] = LifeCycleMapper::getInstance()->mapLifeCycleStatusFromEricsson($data['subscriptionState']);
     }
     if (isset($data['entity'])) {
         switch ($data['entity']['entityType']) {
             case PbReport\ChargesDetailReport\ChargedEntity\EntityType::SUBSCRIPTION:
                 switch ($data['entity']['subscriptionId']['id']) {
                     case Proto\SubscriptionId\IdType::ICC:
                         $subType = 'icc';
                         break;
                     case Proto\SubscriptionId\IdType::IMSI:
                         $subType = 'imsi';
                         break;
                     case Proto\SubscriptionId\IdType::MSISDN:
                         $subType = 'msisdn';
                         break;
                 }
                 $data['entity'] = $data['entity']['subscriptionId']['id'];
                 $data['entityType'] = 'Subscription';
                 if (isset($subType)) {
                     $data['entityType'] .= "({$subType})";
                 }
                 break;
             case PbReport\ChargesDetailReport\ChargedEntity\EntityType::COMMERCIAL_GROUP:
                 $data['entity'] = $data['entity']['commercialGroup']['name'];
                 $data['entityType'] = 'Commercial Group';
                 break;
             case PbReport\ChargesDetailReport\ChargedEntity\EntityType::CUSTOMER:
                 $data['entity'] = $data['entity']['customer']['name'];
                 $data['entityType'] = 'Customer';
                 break;
         }
     }
     //map common fields
     if ($protoData instanceof \Application\Proto\Report\ChargesDetailReport\VoiceDetail || $protoData instanceof \Application\Proto\Report\ChargesDetailReport\VoiceTerminatedDetail) {
         $data['voiceDetail_duration'] = $data[$fieldPrefix . '_duration'];
         $data['voiceDetail_durationRounded'] = $data[$fieldPrefix . '_durationRounded'];
         $data['voiceDetail_zone'] = $data[$fieldPrefix . '_originZone'];
     }
     //map specific fields
     if ($protoData instanceof \Application\Proto\Report\ChargesDetailReport\VoiceDetail) {
         $data['voiceDetail_typeOfCall'] = 'MO';
         $data['voiceDetail_calledOrCalling'] = $data[$fieldPrefix . '_numberCalled'];
         $data['voiceDetail_typeOfDestination'] = $data[$fieldPrefix . '_destinationZone'];
         //unset other type
     } else {
         if ($protoData instanceof \Application\Proto\Report\ChargesDetailReport\VoiceTerminatedDetail) {
             $data['voiceDetail_typeOfCall'] = 'MT';
             $data['voiceDetail_calledOrCalling'] = $data[$fieldPrefix . '_numberCalling'];
         }
     }
     return $data;
 }
 public function setUp()
 {
     $this->lifecycleMapper = LifeCycleMapper::getInstance();
     $this->_user = $this->_createAuthUser(array('userName' => 'LifeCycleUserTest', 'organizationId' => self::PROVIDER_COMMERCIAL_ORG_ID));
     $this->testArray = array('name' => 'commercial', 'description' => 'commercial', 'data' => array('states' => array(array('state' => \Application\Proto\LifeCycleState::INACTIVE_NEW, 'transitions' => array(array('manualTransition' => true, 'automaticTransition' => array('timerCause' => false, 'firstUseCause' => false), 'destinationState' => \Application\Proto\LifeCycleState::TEST), array('manualTransition' => true, 'automaticTransition' => array('timerCause' => false, 'firstUseCause' => false), 'destinationState' => \Application\Proto\LifeCycleState::ACTIVATION_READY), array('manualTransition' => true, 'automaticTransition' => array('timerCause' => false, 'firstUseCause' => false), 'destinationState' => \Application\Proto\LifeCycleState::ACTIVATION_PENDANT))), array('state' => \Application\Proto\LifeCycleState::TEST, 'transitions' => array(array('manualTransition' => true, 'automaticTransition' => array('timerCause' => false, 'firstUseCause' => false), 'destinationState' => \Application\Proto\LifeCycleState::ACTIVATION_READY), array('manualTransition' => true, 'automaticTransition' => array('timerCause' => false, 'firstUseCause' => false), 'destinationState' => \Application\Proto\LifeCycleState::ACTIVATION_PENDANT), array('manualTransition' => false, 'automaticTransition' => array('timerCause' => true, 'firstUseCause' => false), 'destinationState' => \Application\Proto\LifeCycleState::ACTIVATION_READY), array('manualTransition' => false, 'automaticTransition' => array('timerCause' => true, 'firstUseCause' => false), 'destinationState' => \Application\Proto\LifeCycleState::ACTIVATION_PENDANT)), array('state' => \Application\Proto\LifeCycleState::ACTIVATION_READY, 'transitions' => array(array('manualTransition' => false, 'automaticTransition' => array('timerCause' => false, 'firstUseCause' => true), 'destinationState' => \Application\Proto\LifeCycleState::ACTIVE))), array('state' => \Application\Proto\LifeCycleState::ACTIVATION_PENDANT, 'transitions' => array(array('manualTransition' => false, 'automaticTransition' => array('timerCause' => false, 'firstUseCause' => true), 'destinationState' => \Application\Proto\LifeCycleState::ACTIVE))), array('state' => \Application\Proto\LifeCycleState::ACTIVE, 'transitions' => array(array('manualTransition' => true, 'automaticTransition' => array('timerCause' => false, 'firstUseCause' => false), 'destinationState' => \Application\Proto\LifeCycleState::DEACTIVATED))), array('state' => \Application\Proto\LifeCycleState::DEACTIVATED), array('state' => \Application\Proto\LifeCycleState::SUSPENDED), array('state' => \Application\Proto\LifeCycleState::RETIRED)))));
 }
 protected function _mapLifeCycleHistoryFilterValue(\App_ListFilter_Interface $filter, \App_ListFilter $filterList)
 {
     $result = array();
     foreach ($filterList->getFilters() as $filter) {
         switch ($filter->getFieldName()) {
             case SimFilterFields::LIFE_CYCLE_HISTORY_START_STATE:
                 $result['start_state'] = \Application\Model\Mapper\LifeCycleMapper::getInstance()->mapLifeCycleStatusToEricsson($filter->getValue());
                 break;
             case SimFilterFields::LIFE_CYCLE_HISTORY_END_STATE:
                 $result['end_state'] = \Application\Model\Mapper\LifeCycleMapper::getInstance()->mapLifeCycleStatusToEricsson($filter->getValue());
                 break;
             case SimFilterFields::LIFE_CYCLE_HISTORY_INTERVAL:
                 if ($filter instanceof \App_ListFilter_BetweenFilter) {
                     if (!$filter->getMin() && !$filter->getMax()) {
                         $result['interval'] = array();
                     } else {
                         $result['interval'] = array('start_date' => $filter->getMin(), 'end_date' => $filter->getMax());
                     }
                 } elseif ($filter instanceof \App_ListFilter_GreaterThanFilter) {
                     $result['interval'] = array('start_date' => $filter->getValue());
                 } elseif ($filter instanceof \App_ListFilter_LessThanFilter) {
                     $result['interval'] = array('end_date' => $filter->getValue());
                 }
                 break;
         }
     }
     return $result;
 }
 protected function _mapModelToEricssonModel(array $data)
 {
     $data['data'] = array();
     if (isset($data['status'])) {
         $data['data']['states'] = $data['status'];
         unset($data['status']);
         foreach ($data['data']['states'] as $key => $state) {
             $data['data']['states'][$key]['state'] = LifeCycleMapper::getInstance()->mapLifeCycleStatusToEricsson($state['status']);
             unset($data['data']['states'][$key]['status']);
             if ($data['published'] !== ServicePackModel::STATUS_NOT_PUBLISHED && isset($data['data']['states'][$key]['cost'])) {
                 $data['data']['states'][$key]['cost_modified'] = $data['data']['states'][$key]['cost'];
                 unset($data['data']['states'][$key]['cost']);
             }
         }
     }
     if (isset($data['transitions'])) {
         $data['data']['transitions'] = $data['transitions'];
         unset($data['transitions']);
         foreach ($data['data']['transitions'] as $key => $transition) {
             $data['data']['transitions'][$key]['stateStart'] = LifeCycleMapper::getInstance()->mapLifeCycleStatusToEricsson($transition['statusStart']);
             $data['data']['transitions'][$key]['stateFinal'] = LifeCycleMapper::getInstance()->mapLifeCycleStatusToEricsson($transition['statusFinal']);
             if ($data['published'] !== ServicePackModel::STATUS_NOT_PUBLISHED && isset($data['data']['transitions'][$key]['cost'])) {
                 $data['data']['transitions'][$key]['cost_modified'] = $data['data']['transitions'][$key]['cost'];
                 unset($data['data']['transitions'][$key]['cost']);
             }
         }
     }
     $data = parent::_mapModelToEricssonModel($data);
     return $data;
 }
 /**
  * Recieve the CORE async responses
  */
 public function postAction()
 {
     \App::log()->debug("CORE notification of response of a async operation.");
     $message = new Request();
     if (!$this->_request->isPost()) {
         throw new \Application\Exceptions\UnexpectedException("Post request expected");
     }
     // Parse the first level of proto buffer
     $message->parse($this->getRequest()->getRawBody());
     // Verify the transactionId
     if (!$message->hasToken()) {
         throw new \Application\Exceptions\InvalidArgumentException("Missing transactionId.");
     }
     // Verify the proto
     if (!$message->hasProto()) {
         throw new \Application\Exceptions\InvalidArgumentException("Missing proto type.");
     }
     $event = new EventModel();
     $event->namespace = 'connectivity';
     $event->entityType = 'transaction';
     $event->entityId = $message->getToken();
     $event->created = time();
     $event->pushEventData = true;
     $protoType = $message->getProto();
     $event->hiddenData = array('protoType' => $protoType);
     \App::log()->info('Start CORE notification of response of type ' . $protoType . ' from the async operation ' . $event->entityId ?: 'empty');
     // Message decode
     $internalMessage = $this->_decodeMessage($protoType, $message->getMessage());
     // Obtaining a PHP Array from proto
     $parser = new \DrSlump\Protobuf\Codec\PhpArray();
     $data = $message->serialize($parser);
     $messageData = $internalMessage->serialize($parser);
     \App::log()->debug("Async message: " . Zend_Json::encode($messageData));
     \App_Util_Array::filterKeyNames(new \App_Filter_UnderscoreToCamelCase(), $messageData);
     \App::log()->debug("Async message (filtered): " . Zend_Json::encode($messageData));
     if (isset($data['proto'])) {
         unset($data['proto']);
     }
     if (isset($data['token'])) {
         unset($data['token']);
     }
     if (isset($messageData['result'])) {
         $data['result'] = $messageData['result'];
         unset($messageData['result']);
     }
     if (!empty($messageData['failed']) || @$data['result']['code'] != 0) {
         $data['hasFailures'] = true;
     } else {
         $data['hasFailures'] = false;
     }
     \App::log()->debug("Async message (after all): " . Zend_Json::encode($messageData));
     $data['message'] = $messageData;
     $retries = 0;
     // Map data
     switch (true) {
         case $internalMessage instanceof AsyncNotification\Service\BusinessRuleResponse:
             $event->entityType = 'businessRule';
             $event->pushEventData = false;
             $arMapper = \Application\Model\Mapper\AlarmRuleMapper::getInstance();
             // Map alarm rule condition
             $value =& $data['message']['alarmRuleCondition'];
             $value = $arMapper->mapConditionFromEricsson($value);
             // Map business rule type
             $value =& $data['message']['businessRule']['businessRuleType'];
             $value = $arMapper->mapBusinessRuleTypeToModel($value);
             // Map life cycle state (optional)
             if (isset($data['message']['businessRule']['nextLifecycleState'])) {
                 $value =& $data['message']['businessRule']['nextLifecycleState'];
                 $lcMapper = \Application\Model\Mapper\LifeCycleMapper::getInstance();
                 $value = $lcMapper->mapLifeCycleStatusFromEricsson($value);
             }
             //Workaround: organization must include orgType
             if (isset($data['message']['organizationId'])) {
                 $data['organizationId'] = OrgCustomerMapper::buildOrgId($data['message']['organizationId']);
             }
             break;
         case $internalMessage instanceof \Application\Proto\SupDiagnosisAsync\DiagnosisNotification:
             $event->entityType = 'diagnosis';
             $retries = \App::config('watcher.event_retries.diagnosis', 10);
             break;
         case $internalMessage instanceof AsyncNotification\Service\ReportResponse:
             $event->entityType = 'report';
             break;
         case $internalMessage instanceof AsyncNotification\Service\TariffSwitchResponse:
             $event->entityType = 'tariffSwitch';
             $event->entityId = OrgServiceProviderMapper::buildOrgId($internalMessage->getServiceProviderId());
             break;
     }
     $event->eventData = $data;
     $compressor = new AsyncResponseCompressorEvent();
     $compressor->compress($event);
     \App::log()->debug('The content of the CORE notification of response of type ' . $protoType . ' from the async operation ' . ($event->entityId ?: 'empty') . ' is ' . \Zend_Json::encode($data));
     // Invoke the service
     $result = AsyncService::getInstance()->publish($event, $retries);
     \App::log()->info('End CORE notification of response of type' . $protoType . ' from the async operation ' . $event->entityId ?: 'empty');
     $this->_helper->output('proto');
     $this->view->setClass('Application\\Proto\\AsyncNotification\\Service\\Response');
     $this->view->code = Application\Proto\AsyncNotification\Service\Response\Code::OK;
     $this->view->reason = "Successful operation.";
 }