protected function _sendEvent($action, $model)
 {
     try {
         $event = $this->_createModelActionEvent($action, $model);
         WatcherService::getInstance()->publishEvent($event);
     } catch (\Exception $ex) {
         \App::log()->warn($ex);
     }
 }
 /**
  * Builds a filter list based on params.
  * @param  array          $params
  * @return App_ListFilter | null
  */
 public function buildFilterList(array $params)
 {
     $factory = new \App_ListFilter_FilterFactory();
     $factory->setWhiteList(AlarmRuleFilterFields::getWhiteList());
     $filterList = $factory->constructFilter($params);
     $filterList->setResourceId(AlarmRuleFilterFields::getResourceId());
     if (!$filterList->isValid()) {
         $filterList = $factory->constructFilter(array());
     }
     $filterList->addExtraData('filterType', 'alarmRule');
     \App::log()->debug('Unused filters [' . implode(',', $factory->getUnusedList()) . ']');
     return $filterList;
 }
 /**
  * Builds a filter list based on params.
  * @param  array          $params
  * @return App_ListFilter | null
  */
 public function buildFilterList(array $params, $throwEx = false)
 {
     $factory = new \App_ListFilter_FilterFactory();
     $fields = PreBillFilterFields::getWhiteList();
     $factory->setWhiteList($fields);
     $filterList = $factory->constructFilter($params);
     $filterList->addExtraData('filterType', 'prebill');
     $filterList->setValidators(PreBillFilterFields::getValidatorSpec());
     $filterList->setThrowExceptionOnValidationFail($throwEx);
     $filterList = $filterList->isValid() ? $filterList : new \App_ListFilter();
     $filterList->setResourceId(PreBillFilterFields::getResourceId());
     \App::log()->debug('Unused filters [' . implode(',', $factory->getUnusedList()) . ']');
     return $filterList;
 }
 /**
  * Builds a filter list based on params.
  * @param  array          $params
  * @return App_ListFilter | null
  */
 public function buildFilterList(array $params, $org = null)
 {
     if (empty($org)) {
         throw new InvalidArgumentException('No organization provided');
     }
     $params['organizationId'] = $org->getId();
     $factory = new \App_ListFilter_FilterFactory();
     $fields = TemplateFilterFields::getWhiteList();
     $factory->setWhiteList($fields);
     $filterList = $factory->constructFilter($params);
     $filterList->addExtraData('filterType', 'template');
     $filterList->setResourceId(TemplateFilterFields::getResourceId());
     \App::log()->debug('Unused filters [' . implode(',', $factory->getUnusedList()) . ']');
     return $filterList->isValid() ? $filterList : null;
 }
 public function buildFilterList(array $params)
 {
     $factory = new \App_ListFilter_FilterFactory();
     $factory->setWhiteList(ReportFilterFields::getWhiteList());
     $factory->setGroupingWhiteList(ReportGroups::getWhiteList());
     if (!isset($params[ReportFilterFields::REPORT_TYPE])) {
         $e = new MissingParameterException("You must filter report by type");
         $e->setParamName(ReportFilterFields::REPORT_TYPE);
         throw $e;
     }
     $map = array(ReportModel::PRESENCE_DAILY => ReportModel::REPORT_GROUPS_SUPERVISION, ReportModel::PRESENCE_MONTHLY => ReportModel::REPORT_GROUPS_SUPERVISION, ReportModel::LOCATION_DAILY => ReportModel::REPORT_GROUPS_SUPERVISION, ReportModel::LOCATION_MONTHLY => ReportModel::REPORT_GROUPS_SUPERVISION, ReportModel::OPENED_SUP_ALARMS_DAILY => ReportModel::REPORT_GROUPS_SUPERVISION, ReportModel::OPENED_SUP_ALARMS_MONTHLY => ReportModel::REPORT_GROUPS_SUPERVISION, ReportModel::CLOSED_SUP_ALARMS_DAILY => ReportModel::REPORT_GROUPS_SUPERVISION, ReportModel::CLOSED_SUP_ALARMS_MONTHLY => ReportModel::REPORT_GROUPS_SUPERVISION, ReportModel::ACCUMULATED_SUMMARY_DAILY => ReportModel::REPORT_GROUPS_SUPERVISION, ReportModel::EXPENSE_DETAIL_MONTHLY => ReportModel::REPORT_GROUPS_CHARGES_DETAIL, ReportModel::EXPENSE_DETAIL_DAILY => ReportModel::REPORT_GROUPS_CHARGES_DETAIL, ReportModel::CONSUMPTION_DETAIL_DAILY => ReportModel::REPORT_GROUPS_CHARGES_DETAIL, ReportModel::SUBSCRIPTION_BASE_MONTHLY => ReportModel::REPORT_GROUPS_SUBSCRIPTION_BASE, ReportModel::SUBSCRIPTION_SNAPSHOT_DAILY => ReportModel::REPORT_GROUPS_SUBSCRIPTION_SNAPSHOT, ReportModel::KPI_MONTHLY => ReportModel::REPORT_GROUPS_KPI, ReportModel::CONSUMPTION_DAILY => ReportModel::REPORT_GROUPS_CONSUMPTION, ReportModel::SMIP_CONSUMPTION_MONTHLY => ReportModel::REPORT_GROUPS_SMIP_CONSUMPTION, ReportModel::SMIP_CONSUMPTION_DAILY => ReportModel::REPORT_GROUPS_SMIP_CONSUMPTION);
     if (!isset($map[$params[ReportFilterFields::REPORT_TYPE]])) {
         throw new InvalidArgumentException("Invalid report type");
     }
     $params[ReportFilterFields::REPORT_GROUP] = $map[$params[ReportFilterFields::REPORT_TYPE]];
     $filterList = $factory->constructFilter($params);
     $filterList->setResourceId(ReportFilterFields::getResourceId());
     $filterList->addExtraData('filterType', 'report');
     \App::log()->debug('Unused filters [' . implode(',', $factory->getUnusedList()) . ']');
     return $filterList;
 }
 public static function throwValidateException($msgs, $code, $type)
 {
     $msgs = is_array($msgs) ? $msgs : array($msgs);
     \App::log()->debug("The '{$type}' does not pass the validation rules: " . PHP_EOL . json_encode($msgs));
     // Cleanup type before throw Exception
     $parts = explode('\\', $type);
     $type = str_replace('Model', '', array_pop($parts));
     throw new ValidateException("The {$type} does not pass the validation rules.", array('validationErrors' => $msgs, 'code' => $code, 'entity' => $type));
 }
 public function delete($txId)
 {
     if (!is_string($txId)) {
         throw new InvalidArgumentException('Invalid Id');
     }
     try {
         $this->getMapper()->delete($txId);
         \App::audit("Deleted report with Id {$txId}", null);
     } catch (Exception $ex) {
         \App::log()->warn($ex);
     }
     return true;
 }
示例#8
0
 protected function _uploadBulk($sims, &$errors, $irows, $nrows, $watcher)
 {
     try {
         $n = count($sims);
         \App::log()->info("[UpdateBulk] Sending {$n} sims to Ericsson...");
         $this->getMapper()->updateBulk($sims, $watcher);
         \App::log()->info("[UpdateBulk] Ok");
     } catch (EricssonException $e) {
         foreach ($sims as $sim) {
             $ids = $sim->getIds();
             $type = key($ids);
             $value = current($ids);
             $errors[] = new Model\ErrorModel(array('line' => "{$irows} - {$nrows}", 'description' => $e->getMessage(), 'level' => Model\ErrorModel::ERROR_LEVEL_ERROR, 'code' => $e->getCode(), 'entity' => $type, 'entityId' => $value));
         }
         \App::log()->err("[UpdateBulk] Error: " . $e->getMessage());
     }
 }
 /**
  * Builds a filter list based on params.
  * @param  array          $params
  * @return App_ListFilter | null
  */
 public function buildFilterList(array $params)
 {
     /**
      * Check if ICC parameter exists and if it's valid
      */
     /* REMOVED according to GLOBALPORTAL-12528 (https://jira.tid.es/browse/GLOBALPORTAL-12528)
        if (!empty($params['icc'])) {
            if (!$this->luhn($params['icc'])) {
                throw new AppEx\InvalidArgumentException('Invalid search query');
            }
        }
        */
     /**
      * Check if IMSI parameter exists and if it's valid
      */
     if (!empty($params['imsi'])) {
         $imsis = explode('<>', $params['imsi']);
         if (count($imsis) == 2) {
             /**
              * Is it a range of IMSIs?
              */
             /* REMOVED according to GLOBALPORTAL-12528 (https://jira.tid.es/browse/GLOBALPORTAL-12528)
                if (preg_match('/^[0-9]{15}$/', trim($imsis[0])) &&
                    preg_match('/^[0-9]{15}$/', trim($imsis[1]))) {
                */
             $params['imsi'] = $imsis[0] . '<>' . $imsis[1];
             /* REMOVED according to GLOBALPORTAL-12528 (https://jira.tid.es/browse/GLOBALPORTAL-12528)
                } else {
                    throw new AppEx\InvalidArgumentException('Invalid search query');
                }
                */
         } else {
             /* REMOVED according to GLOBALPORTAL-12528 (https://jira.tid.es/browse/GLOBALPORTAL-12528)
                if (!preg_match('/^[0-9]{15}$/', trim($params['imsi']))) {
                    throw new AppEx\InvalidArgumentException('Invalid search query');
                }
                */
         }
     }
     $factory = new \App_ListFilter_FilterFactory();
     $factory->setWhiteList(StockFilterFields::getWhiteList());
     $factory->getSortingWhiteList(StockSortingFields::getWhiteList());
     $filterList = $factory->constructFilter($params);
     if (!$filterList->isValid()) {
         $filterList = new \App_ListFilter();
     }
     $filterList->setResourceId(StockFilterFields::getResourceId());
     $filterList->addExtraData('filterType', 'stock');
     \App::log()->debug('Unused filters [' . implode(',', $factory->getUnusedList()) . ']');
     return $filterList;
 }
 public function deleteAll($filterList, array $options = array())
 {
     $itemList = $this->listAll($filterList, $options + array('paging' => array('count' => -1)));
     foreach ($itemList as $item) {
         try {
             $this->delete($item);
         } catch (\Exception $e) {
             \App::log()->warn($e);
         }
     }
 }
示例#11
0
 /**
  *
  * @param  UserModel $user
  * @param  string    $reason
  * @return boolean
  */
 public function blockUser($user, $reason)
 {
     if ($user->getStatus() !== UserModel::USER_STATUS_BLOCKED) {
         // Block user
         $user->status = UserModel::USER_STATUS_BLOCKED;
         $user->save();
         \App::audit("User " . $user->getUserName() . " has been blocked due to {$reason}", $user);
         \App::log()->debug("User " . $user->getUserName() . " status changed to BLOCKED");
         $this->_sendEvent('update', $user);
         $this->_sendEvent('block', $user);
         return true;
     }
     return false;
 }
示例#12
0
 /**
  * Builds a filter list based on params.
  * @param  array          $params
  * @return App_ListFilter | null
  */
 public function buildFilterList(array $params)
 {
     if (!isset($params['type']) || !in_array($params['type'], array(OrgMasterModel::ORG_TYPE, OrgServiceProviderModel::ORG_TYPE, OrgCustomerModel::ORG_TYPE, OrgAggregatorModel::ORG_TYPE))) {
         return;
     }
     $orgType = $params['type'];
     unset($params['type']);
     if ($orgType === OrgServiceProviderModel::ORG_TYPE && \App::getOrgUserLogged()->getType() === OrgServiceProviderModel::ORG_TYPE) {
         if (!isset($params[ServiceProviderFilterFields::SERVICE_PROVIDER_ID_FOR_COMMERCIALS])) {
             $params[ServiceProviderFilterFields::SERVICE_PROVIDER_ID_FOR_COMMERCIALS] = \App::getOrgUserLogged()->id;
         }
     }
     $factory = new \App_ListFilter_FilterFactory();
     $filterFieldsMap = array(OrgMasterModel::ORG_TYPE => '\\Application\\Model\\Filter\\Organization\\MasterFilterFields', OrgServiceProviderModel::ORG_TYPE => '\\Application\\Model\\Filter\\Organization\\ServiceProviderFilterFields', OrgCustomerModel::ORG_TYPE => '\\Application\\Model\\Filter\\Organization\\CustomerFilterFields', OrgAggregatorModel::ORG_TYPE => '\\Application\\Model\\Filter\\Organization\\AggregatorFilterFields');
     $filterFieldsValidatorsMap = array(OrgMasterModel::ORG_TYPE => MasterFilterFields::getValidatorSpec(), OrgServiceProviderModel::ORG_TYPE => ServiceProviderFilterFields::getValidatorSpec(), OrgCustomerModel::ORG_TYPE => CustomerFilterFields::getValidatorSpec(), OrgAggregatorModel::ORG_TYPE => AggregatorFilterFields::getValidatorSpec());
     if (isset($filterFieldsMap[$orgType])) {
         $class = $filterFieldsMap[$orgType];
         $factory->setWhiteList($class::getWhiteList());
     }
     $filterList = $factory->constructFilter($params);
     if (isset($class)) {
         $filterList->setResourceId($class::getResourceId());
     }
     \App::log()->debug('Unused filters [' . implode(',', $factory->getUnusedList()) . ']');
     $filterList->setValidators($filterFieldsValidatorsMap[$orgType]);
     return $filterList->isValid() ? $filterList : null;
 }
 /**
  * Builds a filter list based on params.
  * @param  array          $params
  * @return App_ListFilter | null
  */
 public function buildFilterList(array $params, $throwEx = false)
 {
     $factory = new \App_ListFilter_FilterFactory();
     $factory->setWhiteList(ServicePackFilterFields::getWhiteList());
     $factory->setSortingWhiteList(ServicePackFilterFields::getWhiteList());
     $filterList = $factory->constructFilter($params);
     $filterList->setResourceId(ServicePackFilterFields::getResourceId());
     $filterList->setValidators(ServicePackFilterFields::getValidatorSpec());
     $filterList->setThrowExceptionOnValidationFail($throwEx);
     if (!$filterList->isValid()) {
         $filterList = $factory->constructFilter(array());
     }
     $filterList->addExtraData('filterType', 'servicePack');
     \App::log()->debug('Unused filters [' . implode(',', $factory->getUnusedList()) . ']');
     return $filterList;
 }